Class: Mach::Signature

Inherits:
Object
  • Object
show all
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

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

Returns:

  • (Boolean)


19
20
21
# File 'lib/mach/signature.rb', line 19

def matches?(base64_expected_signature)
  to_s == base64_expected_signature
end

#to_sObject



15
16
17
# File 'lib/mach/signature.rb', line 15

def to_s
  Base64.strict_encode64(OpenSSL::HMAC.digest(digest, @key, @data))
end