class Themis::Scomparator

Constants

MATCH
NOT_MATCH
NOT_READY

Public Class Methods

new(shared_secret) click to toggle source
# File lib/rubythemis.rb, line 358
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" unless @comparator
  res=secure_comparator_append_secret(@comparator, shared_secret_buf, shared_secret_length)
  raise ThemisError, "Secure Comparator failed appending secret" unless res==SUCCESS            
end

Public Instance Methods

begin_compare() click to toggle source
# File lib/rubythemis.rb, line 371
def begin_compare()
  res_length=FFI::MemoryPointer.new(:uint)
  res=secure_comparator_begin_compare(@comparator, nil, res_length)
  raise ThemisError, "Secure Comparator failed making initialisation message" unless res==BUFFER_TOO_SMALL
  res_buffer=FFI::MemoryPointer.new(:char, res_length.read_uint)
  res=secure_comparator_begin_compare(@comparator, res_buffer, res_length)
  raise ThemisError, "Secure Comparator failed making initialisation message" unless res==SUCCESS || res==SEND_AS_IS
  return res_buffer.get_bytes(0,res_length.read_uint)
end
finalize() click to toggle source
# File lib/rubythemis.rb, line 366
def finalize()
  res=secure_comparator_destroy(@comparator)
  raise ThemisError, "Secure Comparator failed destroying" unless res==SUCCESS                      
end
proceed_compare(control_message) click to toggle source
# File lib/rubythemis.rb, line 381
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)
  raise ThemisError, "Secure Comparator failed proeeding message" unless res==SUCCESS || res == BUFFER_TOO_SMALL
  if res == SUCCESS
    return ""
  end
  res_buffer=FFI::MemoryPointer.new(:char, res_length.read_uint)
  res=secure_comparator_proceed_compare(@comparator, message, message_length, res_buffer, res_length)
  raise ThemisError, "Secure Comparator failed proeeding message" unless res==SUCCESS || res==SEND_AS_IS
  return res_buffer.get_bytes(0,res_length.read_uint)          
end
result() click to toggle source
# File lib/rubythemis.rb, line 395
def result()
  return secure_comparator_get_result(@comparator)
end