class Castle::Utils::SecureCompare

Code borrowed from ActiveSupport

Public Class Methods

call(str_a, str_b) click to toggle source

@param str_a [String] first string to be compared @param str_b [String] second string to be compared

# 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