Sha256: cf6f9f0d8848d8661c1e8dd7cdaa895a560392f0183a630062f9eae9ecbc149a

Contents?: true

Size: 674 Bytes

Versions: 3

Compression:

Stored size: 674 Bytes

Contents

# frozen_string_literal: true

require "openssl"

module FidoMetadata
  module Refinement
    module FixedLengthSecureCompare
      unless OpenSSL.singleton_class.method_defined?(:fixed_length_secure_compare)
        refine OpenSSL.singleton_class do
          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
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fido_metadata-0.4.0 lib/fido_metadata/refinement/fixed_length_secure_compare.rb
fido_metadata-0.3.0 lib/fido_metadata/refinement/fixed_length_secure_compare.rb
fido_metadata-0.2.0 lib/fido_metadata/refinement/fixed_length_secure_compare.rb