Class: Mach::Signature
- Inherits:
-
Object
- Object
- Mach::Signature
- Defined in:
- lib/mach/signature.rb
Constant Summary collapse
- ALGORITHMS =
{'hmac-sha-256' => 'sha256', 'hmac-sha-1' => 'sha1'}
- DEFAULT_ALGORITHM =
'hmac-sha-256'
Instance Method Summary collapse
-
#initialize(key, data, algorithm = DEFAULT_ALGORITHM) ⇒ Signature
constructor
A new instance of Signature.
- #matches?(base64_expected_signature) ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(key, data, algorithm = DEFAULT_ALGORITHM) ⇒ Signature
Returns a new instance of Signature.
9 10 11 12 13 |
# File 'lib/mach/signature.rb', line 9 def initialize(key, data, algorithm = DEFAULT_ALGORITHM) @algorithm = algorithm @data = data @key = key end |
Instance Method Details
#matches?(base64_expected_signature) ⇒ Boolean
19 20 21 |
# File 'lib/mach/signature.rb', line 19 def matches?(base64_expected_signature) to_s == base64_expected_signature end |
#to_s ⇒ Object
15 16 17 |
# File 'lib/mach/signature.rb', line 15 def to_s Base64.strict_encode64(OpenSSL::HMAC.digest(digest, @key, @data)) end |