Module: HmacAuthentication

Defined in:
lib/hmac_authentication/version.rb,
lib/hmac_authentication/signature.rb

Defined Under Namespace

Classes: HmacAuth

Constant Summary collapse

VERSION =
'1.0.0'
NO_SIGNATURE =
1
INVALID_FORMAT =
2
UNSUPPORTED_ALGORITHM =
3
MATCH =
4
MISMATCH =
5
RESULT_CODE_STRINGS =
%w(
  NO_SIGNATURE
  INVALID_FORMAT
  UNSUPPORTED_ALGORITHM
  MATCH
  MISMATCH
)

Class Method Summary collapse

Class Method Details

.compare_signatures(header, computed) ⇒ Object



88
89
90
# File 'lib/hmac_authentication/signature.rb', line 88

def self.compare_signatures(header, computed)
  FastSecureCompare.compare(computed, header) ? MATCH : MISMATCH
end

.hash_url(req) ⇒ Object



92
93
94
95
96
97
# File 'lib/hmac_authentication/signature.rb', line 92

def self.hash_url(req)
  result = "#{req.uri.path}"
  result << '?' << req.uri.query if req.uri.query
  result << '#' << req.uri.fragment if req.uri.fragment
  result
end

.parse_digest(name) ⇒ Object



82
83
84
85
86
# File 'lib/hmac_authentication/signature.rb', line 82

def self.parse_digest(name)
  OpenSSL::Digest.new name
rescue
  nil
end

.result_code_to_string(code) ⇒ Object



20
21
22
23
# File 'lib/hmac_authentication/signature.rb', line 20

def self.result_code_to_string(code)
  index = code - 1
  index >= 0 ? RESULT_CODE_STRINGS[index] : nil
end