312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
|
# File 'lib/rubythemis.rb', line 312
def decrypt(message, context=nil)
context_, context_length_ = context.nil? ? [nil,0] : string_to_pointer_size(context)
decrypted_message_length=FFI::MemoryPointer.new(:uint)
case @mode
when SEAL_MODE
message_, message_length_ = string_to_pointer_size(message)
res=themis_secure_cell_decrypt_seal(@key, @key_length, context_, context_length_, message_, message_length_, nil, decrypted_message_length)
raise ThemisError, "themis_secure_cell_decrypt_seal (length determination) error: #{res}" unless res == BUFFER_TOO_SMALL
decrypted_message = FFI::MemoryPointer.new(:char, decrypted_message_length.read_uint)
res=themis_secure_cell_decrypt_seal(@key, @key_length, context_, context_length_, message_, message_length_, decrypted_message, decrypted_message_length)
raise ThemisError, "themis_secure_cell_decrypt_seal error: #{res}" unless res == SUCCESS
return decrypted_message.get_bytes(0, decrypted_message_length.read_uint)
when TOKEN_PROTECT_MODE
enccontext, message_ = message
message__, message_length__ = string_to_pointer_size(message_)
enccontext_, enccontext_length = string_to_pointer_size(enccontext)
res=themis_secure_cell_decrypt_token_protect(@key, @key_length, context_, context_length_, message__, message_length__, enccontext_, enccontext_length, nil, decrypted_message_length)
raise ThemisError, "themis_secure_cell_encrypt_token_protect (length determination) error: #{res}" unless res == BUFFER_TOO_SMALL
decrypted_message = FFI::MemoryPointer.new(:char, decrypted_message_length.read_uint)
res=themis_secure_cell_decrypt_token_protect(@key, @key_length, context_, context_length_, message__, message_length__, enccontext_, enccontext_length, decrypted_message, decrypted_message_length)
raise ThemisError, "themis_secure_cell_encrypt_token_protect error: #{res}" unless res == SUCCESS
return decrypted_message.get_bytes(0, decrypted_message_length.read_uint)
when CONTEXT_IMPRINT_MODE
message_, message_length_ = string_to_pointer_size(message)
res=themis_secure_cell_decrypt_context_imprint(@key, @key_length, message_, message_length_, context_, context_length_, nil, decrypted_message_length)
raise ThemisError, "themis_secure_cell_decrypt_context_imprint (length determination) error: #{res}" unless res == BUFFER_TOO_SMALL
decrypted_message = FFI::MemoryPointer.new(:char, decrypted_message_length.read_uint)
res=themis_secure_cell_decrypt_context_imprint(@key, @key_length, message_, message_length_, context_, context_length_, decrypted_message, decrypted_message_length)
raise ThemisError, "themis_secure_cell_decrypt_context_imprint error: #{res}" unless res == SUCCESS
return decrypted_message.get_bytes(0, decrypted_message_length.read_uint)
else
raise ThemisError, "themis_secure_cell not supported mode"
end
end
|