Class: Themis::Scomparator
Constant Summary
collapse
- MATCH =
21
- NOT_MATCH =
22
- NOT_READY =
0
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
empty?, string_to_pointer_size
Constructor Details
#initialize(shared_secret) ⇒ Scomparator
Returns a new instance of Scomparator.
924
925
926
927
928
929
930
931
932
933
934
|
# File 'lib/rbthemis.rb', line 924
def initialize(shared_secret)
shared_secret_buf, shared_secret_length =
string_to_pointer_size(shared_secret)
@comparator = secure_comparator_create
raise ThemisError, 'Secure Comparator failed creating' if @comparator.null?
res = secure_comparator_append_secret(
@comparator, shared_secret_buf, shared_secret_length)
if res != SUCCESS
raise ThemisError, 'Secure Comparator failed appending secret'
end
end
|
Instance Method Details
#begin_compare ⇒ Object
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
|
# File 'lib/rbthemis.rb', line 943
def begin_compare
res_length = FFI::MemoryPointer.new(:uint)
res = secure_comparator_begin_compare(@comparator, nil, res_length)
if res != BUFFER_TOO_SMALL
raise(ThemisError,
'Secure Comparator failed making initialisation message')
end
res_buffer = FFI::MemoryPointer.new(:char, res_length.read_uint)
res = secure_comparator_begin_compare(@comparator, res_buffer, res_length)
if res != SUCCESS && res != SEND_AS_IS
raise(ThemisError,
'Secure Comparator failed making initialisation message')
end
res_buffer.get_bytes(0, res_length.read_uint)
end
|
#finalize ⇒ Object
936
937
938
939
940
941
|
# File 'lib/rbthemis.rb', line 936
def finalize
res = secure_comparator_destroy(@comparator)
if res != SUCCESS
raise ThemisError, 'Secure Comparator failed destroying'
end
end
|
#proceed_compare(control_message) ⇒ Object
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
|
# File 'lib/rbthemis.rb', line 961
def proceed_compare(control_message)
message, message_length = string_to_pointer_size(control_message)
res_length = FFI::MemoryPointer.new(:uint)
res = secure_comparator_proceed_compare(
@comparator, message, message_length, nil, res_length)
return '' if res == SUCCESS
if res != BUFFER_TOO_SMALL
raise ThemisError, 'Secure Comparator failed proceeding message'
end
res_buffer = FFI::MemoryPointer.new(:char, res_length.read_uint)
res = secure_comparator_proceed_compare(
@comparator, message, message_length, res_buffer, res_length)
if res != SUCCESS && res != SEND_AS_IS
raise ThemisError, 'Secure Comparator failed proceeding message'
end
res_buffer.get_bytes(0, res_length.read_uint)
end
|
#result ⇒ Object
982
983
984
|
# File 'lib/rbthemis.rb', line 982
def result
secure_comparator_get_result(@comparator)
end
|