Class: Castle::Utils::SecureCompare

Inherits:
Object
  • Object
show all
Defined in:
lib/castle/utils/secure_compare.rb

Overview

Code borrowed from ActiveSupport

Class Method Summary collapse

Class Method Details

.call(str_a, str_b) ⇒ Object

Parameters:

  • str_a (String)

    first string to be compared

  • str_b (String)

    second string to be compared



10
11
12
13
14
15
16
17
18
# File 'lib/castle/utils/secure_compare.rb', line 10

def call(str_a, str_b)
  return false unless str_a.bytesize == str_b.bytesize

  l = str_a.unpack "C#{str_a.bytesize}"

  res = 0
  str_b.each_byte { |byte| res |= byte ^ l.shift }
  res.zero?
end