Class: Themis::Scomparator

Inherits:
Object
  • Object
show all
Includes:
ThemisCommon, ThemisImport
Defined in:
lib/rbthemis.rb

Constant Summary collapse

MATCH =
21
NOT_MATCH =
22
NOT_READY =
0

Constants included from ThemisImport

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

Methods included from ThemisCommon

string_to_pointer_size

Constructor Details

#initialize(shared_secret) ⇒ Scomparator

Returns a new instance of Scomparator.

Raises:



638
639
640
641
642
643
644
645
646
647
648
# File 'lib/rbthemis.rb', line 638

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)
  if res != SUCCESS
    raise ThemisError, 'Secure Comparator failed appending secret'
  end
end

Instance Method Details

#begin_compareObject



657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
# File 'lib/rbthemis.rb', line 657

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

#finalizeObject



650
651
652
653
654
655
# File 'lib/rbthemis.rb', line 650

def finalize
  res = secure_comparator_destroy(@comparator)
  if res != SUCCESS
    raise ThemisError, 'Secure Comparator failed destroying'
  end
end

#proceed_compare(control_message) ⇒ Object



675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
# File 'lib/rbthemis.rb', line 675

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

#resultObject



696
697
698
# File 'lib/rbthemis.rb', line 696

def result
  secure_comparator_get_result(@comparator)
end