module Signauth::Signer
Constants
- ALGORITHM_DIGEST_MAPPING
Public Instance Methods
hmac(key, value, algorithm = 'HMAC-SHA-256')
click to toggle source
# File lib/signauth/signer.rb, line 12 def hmac(key, value, algorithm = 'HMAC-SHA-256') digest = digest_name(algorithm) OpenSSL::HMAC.digest(OpenSSL::Digest.new(digest), key, value) end
sign(secret, string_to_sign, algorithm = 'HMAC-SHA-256')
click to toggle source
# File lib/signauth/signer.rb, line 8 def sign(secret, string_to_sign, algorithm = 'HMAC-SHA-256') Base64.encode64(hmac(secret, string_to_sign, algorithm)).strip end
slow_string_comparison(given, computed)
click to toggle source
# File lib/signauth/signer.rb, line 17 def slow_string_comparison(given, computed) return false if given.nil? || computed.nil? || given.length != computed.length match = true computed.chars.each_with_index{|c, i| match &= c == given[i] } match end
Private Instance Methods
digest_name(algorithm)
click to toggle source
# File lib/signauth/signer.rb, line 26 def digest_name(algorithm) ALGORITHM_DIGEST_MAPPING[algorithm] end