Class: Veryfi::Signature

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(secret, params, timestamp) ⇒ Signature

Returns a new instance of Signature.



10
11
12
13
14
# File 'lib/veryfi/signature.rb', line 10

def initialize(secret, params, timestamp)
  @secret = secret
  @params = params
  @timestamp = timestamp
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



8
9
10
# File 'lib/veryfi/signature.rb', line 8

def params
  @params
end

#secretObject (readonly)

Returns the value of attribute secret.



8
9
10
# File 'lib/veryfi/signature.rb', line 8

def secret
  @secret
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



8
9
10
# File 'lib/veryfi/signature.rb', line 8

def timestamp
  @timestamp
end

Instance Method Details

#digestObject

private



22
23
24
# File 'lib/veryfi/signature.rb', line 22

def digest
  OpenSSL::HMAC.digest(OpenSSL::Digest.new("sha256"), secret, payload)
end

#payloadObject



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

def payload
  "timestamp:#{timestamp}," + params.to_a.map { |i| "#{i[0]}:#{i[1]}" }.join(",")
end

#to_base64Object



16
17
18
# File 'lib/veryfi/signature.rb', line 16

def to_base64
  Base64.encode64(digest).strip
end