Class: HMACAuth::Signature

Inherits:
Object
  • Object
show all
Defined in:
lib/hmac_auth/signature.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params, options = {}) ⇒ Signature

Returns a new instance of Signature.



15
16
17
18
19
20
21
22
23
24
# File 'lib/hmac_auth/signature.rb', line 15

def initialize(params, options = {})
  @secret = options.delete(:secret) || HMACAuth.secret
  @valid_for = options.delete(:valid_for) || HMACAuth.valid_for
  @reject_keys = options.delete(:reject_keys) || HMACAuth.reject_keys
  @keep_values_type = options.delete(:keep_values_type) ||
    HMACAuth.keep_values_type
  @_params = params

  raise Error.new 'You *must* tell me a secret!' unless @secret
end

Class Method Details

.sign(params, options = {}) ⇒ Object



10
11
12
# File 'lib/hmac_auth/signature.rb', line 10

def sign(params, options = {})
  self.new(params, options).sign
end

.verify(params, options = {}) ⇒ Object



6
7
8
# File 'lib/hmac_auth/signature.rb', line 6

def verify(params, options = {})
  self.new(params, options).verify
end

Instance Method Details

#signHash

Returns Signed parameters.

Returns:

  • (Hash)

    Signed parameters



31
32
33
34
# File 'lib/hmac_auth/signature.rb', line 31

def sign
  timestamp || params['timestamp'] = Time.now.to_i.to_s
  params.merge('signature' => calculated_signature)
end

#verifyObject



26
27
28
# File 'lib/hmac_auth/signature.rb', line 26

def verify
  valid_timestamp && signature == calculated_signature
end