Module: Ixtlan::Remote::ConstantTimeCompare

Included in:
AccessController
Defined in:
lib/ixtlan/remote/constant_time_compare.rb

Instance Method Summary collapse

Instance Method Details

#constant_time_compare(val1, val2) ⇒ Object

from github.com/django/django/blob/master/django/utils/crypto.py#L82 time to compare is independent of the number of matching characters



27
28
29
30
31
32
33
34
35
36
# File 'lib/ixtlan/remote/constant_time_compare.rb', line 27

def constant_time_compare(val1, val2)
  if val1.size != val2.size
    return false
  end
  result = 0
  val1.unpack('C*').zip(val2.unpack('C*')).each do |a|
    result |= a[0][0] ^ a[1][0]
  end
  result == 0
end