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 ThemisImport
canonical_themis_paths, load_themis
Methods included from ThemisCommon
empty?, string_to_pointer_size
Constructor Details
#initialize(private_key, peer_public_key) ⇒ Smessage
Returns a new instance of Smessage.
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 |
# File 'lib/rbthemis.rb', line 404 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
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 |
# File 'lib/rbthemis.rb', line 448 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
423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 |
# File 'lib/rbthemis.rb', line 423 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 |