Sha256: dc691d1b4cee1eef27c479dac418c1e396cad61707bbb26a2e63465453b20e21

Contents?: true

Size: 628 Bytes

Versions: 4

Compression:

Stored size: 628 Bytes

Contents

# frozen_string_literal: true

require "openssl"

module SafetyNetAttestation
  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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
safety_net_attestation-0.4.0 lib/safety_net_attestation/fixed_length_secure_compare.rb
safety_net_attestation-0.3.0 lib/safety_net_attestation/fixed_length_secure_compare.rb
safety_net_attestation-0.2.0 lib/safety_net_attestation/fixed_length_secure_compare.rb
safety_net_attestation-0.1.0 lib/safety_net_attestation/fixed_length_secure_compare.rb