Method: Themis.s_verify

Defined in:
lib/rbthemis.rb

.s_verify(peer_public_key, message) ⇒ Object



514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
# File 'lib/rbthemis.rb', line 514

def s_verify(peer_public_key, message)
  if not valid_key(peer_public_key)
    raise ThemisError, "Secure Message: invalid public key"
  end
  if not public_key(peer_public_key)
    raise ThemisError, "Secure Message: private key used instead of public"
  end

  public_key_, public_key_length_ = string_to_pointer_size(peer_public_key)
  message_, message_length_ = string_to_pointer_size(message)

  unwrapped_message_length = FFI::MemoryPointer.new(:uint)
  res = themis_secure_message_verify(
    public_key_, public_key_length_, message_,
    message_length_, nil, unwrapped_message_length)
  if res != BUFFER_TOO_SMALL
    raise ThemisError, "Secure Message failed to verify: #{res}"
  end

  unwrapped_message = FFI::MemoryPointer.new(
    :char, unwrapped_message_length.read_uint)
  res = themis_secure_message_verify(
    public_key_, public_key_length_, message_,
    message_length_, unwrapped_message, unwrapped_message_length)
  if res != SUCCESS
    raise ThemisError, "Secure Message failed to verify: #{res}"
  end

  unwrapped_message.get_bytes(0, unwrapped_message_length.read_uint)
end