module FidoMetadata::Refinement::FixedLengthSecureCompare

Public Instance Methods

fixed_length_secure_compare(a, b) click to toggle source
# File lib/fido_metadata/refinement/fixed_length_secure_compare.rb, line 10
def fixed_length_secure_compare(a, b) # rubocop:disable Naming/UncommunicativeMethodParamName
  raise ArgumentError, "inputs must be of equal length" unless a.bytesize == b.bytesize

  # borrowed from Rack::Utils
  l = a.unpack("C*")
  r, i = 0, -1
  b.each_byte { |v| r |= v ^ l[i += 1] }
  r == 0
end