Sha256: 8019526ad234547f15c148ccec6812bf5552d5331aa80fda1d05d377645f7aea

Contents?: true

Size: 725 Bytes

Versions: 14

Compression:

Stored size: 725 Bytes

Contents

module Braintree
  module Digest # :nodoc:
    def self.hexdigest(private_key, string)
      _hmac_sha1(private_key, string)
    end

    def self.secure_compare(left, right)
      return false unless left && right

      left_bytes = left.unpack("C*")
      right_bytes = right.unpack("C*")
      return false if left_bytes.size != right_bytes.size

      result = 0
      left_bytes.zip(right_bytes).each do |left_byte, right_byte|
        result |= left_byte ^ right_byte
      end
      result == 0
    end

    def self._hmac_sha1(key, message)
      key_digest = ::Digest::SHA1.digest(key)
      sha1 = OpenSSL::Digest::Digest.new("sha1")
      OpenSSL::HMAC.hexdigest(sha1, key_digest, message.to_s)
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
braintree-2.28.0 lib/braintree/digest.rb
braintree-2.27.1 lib/braintree/digest.rb
braintree-2.27.0 lib/braintree/digest.rb
braintree-2.26.0 lib/braintree/digest.rb
braintree-2.25.0 lib/braintree/digest.rb
braintree-2.24.0 lib/braintree/digest.rb
braintree-2.23.0 lib/braintree/digest.rb
braintree-2.22.0 lib/braintree/digest.rb
braintree-2.21.0 lib/braintree/digest.rb
braintree-2.20.0 lib/braintree/digest.rb
braintree-2.19.0 lib/braintree/digest.rb
braintree-2.18.0 lib/braintree/digest.rb
braintree-2.17.0 lib/braintree/digest.rb
braintree-2.16.0 lib/braintree/digest.rb