Class: Themis::SKeyPairGen

Inherits:
Object
  • Object
show all
Includes:
ThemisCommon, ThemisImport
Defined in:
lib/rbthemis.rb

Constant Summary

Constants included from ThemisImport

ThemisImport::THEMIS_KEY_EC_PRIVATE, ThemisImport::THEMIS_KEY_EC_PUBLIC, ThemisImport::THEMIS_KEY_INVALID, ThemisImport::THEMIS_KEY_RSA_PRIVATE, ThemisImport::THEMIS_KEY_RSA_PUBLIC

Instance Method Summary collapse

Methods included from ThemisImport

canonical_themis_paths, load_themis

Methods included from ThemisCommon

empty?, string_to_pointer_size

Instance Method Details

#ecObject



218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# File 'lib/rbthemis.rb', line 218

def ec
  private_key_length = FFI::MemoryPointer.new(:uint)
  public_key_length = FFI::MemoryPointer.new(:uint)

  res = themis_gen_ec_key_pair(
    nil, private_key_length, nil, public_key_length)
  if res != BUFFER_TOO_SMALL
    raise ThemisError, "Themis failed generating EC KeyPair: #{res}"
  end

  private_key = FFI::MemoryPointer.new(:char, private_key_length.read_uint)
  public_key = FFI::MemoryPointer.new(:char, public_key_length.read_uint)

  res = themis_gen_ec_key_pair(
    private_key, private_key_length, public_key, public_key_length)
  if res != SUCCESS
    raise ThemisError, "Themis failed generating EC KeyPair: #{res}"
  end

  [private_key.get_bytes(0, private_key_length.read_uint),
   public_key.get_bytes(0, public_key_length.read_uint)]
end

#rsaObject



241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
# File 'lib/rbthemis.rb', line 241

def rsa
  private_key_length = FFI::MemoryPointer.new(:uint)
  public_key_length = FFI::MemoryPointer.new(:uint)

  res = themis_gen_rsa_key_pair(
    nil, private_key_length, nil, public_key_length)
  if res != BUFFER_TOO_SMALL
    raise ThemisError, "Themis failed generating RSA KeyPair: #{res}"
  end

  private_key = FFI::MemoryPointer.new(:char, private_key_length.read_uint)
  public_key = FFI::MemoryPointer.new(:char, public_key_length.read_uint)

  res = themis_gen_rsa_key_pair(
    private_key, private_key_length, public_key, public_key_length)
  if res != SUCCESS
    raise ThemisError, "Themis failed generating RSA KeyPair: #{res}"
  end

  [private_key.get_bytes(0, private_key_length.read_uint),
   public_key.get_bytes(0, public_key_length.read_uint)]
end