Class: Themis::Smessage
- Inherits:
-
Object
- Object
- Themis::Smessage
- 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
-
#initialize(private_key, peer_public_key) ⇒ Smessage
constructor
A new instance of Smessage.
- #unwrap(message) ⇒ Object
- #wrap(message) ⇒ Object
Methods included from ThemisCommon
Constructor Details
#initialize(private_key, peer_public_key) ⇒ Smessage
Returns a new instance of Smessage.
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 |
# File 'lib/rbthemis.rb', line 338 def initialize(private_key, peer_public_key) if not Themis.valid_key(private_key) raise ThemisError, "Secure Message: invalid private key" end if not Themis.valid_key(peer_public_key) raise ThemisError, "Secure Message: invalid public key" end if not Themis.private_key(private_key) raise ThemisError, "Secure Message: public key used instead of private" end if not Themis.public_key(peer_public_key) raise ThemisError, "Secure Message: private key used instead of public" end @private_key, @private_key_length = string_to_pointer_size(private_key) @peer_public_key, @peer_public_key_length = string_to_pointer_size(peer_public_key) end |
Instance Method Details
#unwrap(message) ⇒ Object
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 |
# File 'lib/rbthemis.rb', line 382 def unwrap() , = string_to_pointer_size() = FFI::MemoryPointer.new(:uint) res = ( @private_key, @private_key_length, @peer_public_key, @peer_public_key_length, , , nil, ) if res != BUFFER_TOO_SMALL raise ThemisError, "Secure Message failed to decrypt: #{res}" end = FFI::MemoryPointer.new( :char, .read_uint) res = ( @private_key, @private_key_length, @peer_public_key, @peer_public_key_length, , , , ) if res != SUCCESS raise ThemisError, "Secure Message failed to decrypt: #{res}" end .get_bytes(0, .read_uint) end |
#wrap(message) ⇒ Object
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 |
# File 'lib/rbthemis.rb', line 357 def wrap() , = string_to_pointer_size() = FFI::MemoryPointer.new(:uint) res = ( @private_key, @private_key_length, @peer_public_key, @peer_public_key_length, , , nil, ) if res != BUFFER_TOO_SMALL raise ThemisError, "Secure Message failed to encrypt: #{res}" end = FFI::MemoryPointer.new( :char, .read_uint) res = ( @private_key, @private_key_length, @peer_public_key, @peer_public_key_length, , , , ) if res != SUCCESS raise ThemisError, "Secure Message failed to encrypt: #{res}" end .get_bytes(0, .read_uint) end |