Method: Themis.s_sign

Defined in:
lib/rbthemis.rb

.s_sign(private_key, message) ⇒ Object



478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
# File 'lib/rbthemis.rb', line 478

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

  private_key_, private_key_length_ = string_to_pointer_size(private_key)
  message_, message_length_ = string_to_pointer_size(message)

  wrapped_message_length = FFI::MemoryPointer.new(:uint)
  res = themis_secure_message_sign(
    private_key_, private_key_length_, message_,
    message_length_, nil, wrapped_message_length)
  if res != BUFFER_TOO_SMALL
    raise ThemisError, "Secure Message failed to sign: #{res}"
  end

  wrapped_message = FFI::MemoryPointer.new(
    :char, wrapped_message_length.read_uint)
  res = themis_secure_message_sign(
    private_key_, private_key_length_, message_,
    message_length_, wrapped_message, wrapped_message_length)
  if res != SUCCESS
    raise ThemisError, "Secure Message failed to sign: #{res}"
  end

  wrapped_message.get_bytes(0, wrapped_message_length.read_uint)
end