Module: Braintree::Digest
- Defined in:
- lib/braintree/digest.rb
Class Method Summary collapse
- ._hmac_sha1(key, message) ⇒ Object
- .hexdigest(private_key, string) ⇒ Object
- .secure_compare(left, right) ⇒ Object
Class Method Details
._hmac_sha1(key, message) ⇒ Object
21 22 23 24 25 |
# File 'lib/braintree/digest.rb', line 21 def self._hmac_sha1(key, ) key_digest = ::Digest::SHA1.digest(key) sha1 = OpenSSL::Digest.new("sha1") OpenSSL::HMAC.hexdigest(sha1, key_digest, .to_s) end |
.hexdigest(private_key, string) ⇒ Object
3 4 5 |
# File 'lib/braintree/digest.rb', line 3 def self.hexdigest(private_key, string) _hmac_sha1(private_key, string) end |
.secure_compare(left, right) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/braintree/digest.rb', line 7 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 |