Class: Platbamobilom::Verification

Inherits:
Object
  • Object
show all
Defined in:
lib/platbamobilom/verification.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, result:, phone:, signature:) ⇒ Verification

Returns a new instance of Verification.



8
9
10
11
12
13
# File 'lib/platbamobilom/verification.rb', line 8

def initialize(id:, result:, phone:, signature:)
  @id        = id
  @result    = result
  @phone     = phone
  @signature = signature
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/platbamobilom/verification.rb', line 3

def id
  @id
end

#phoneObject (readonly)

Returns the value of attribute phone.



5
6
7
# File 'lib/platbamobilom/verification.rb', line 5

def phone
  @phone
end

#resultObject (readonly)

Returns the value of attribute result.



4
5
6
# File 'lib/platbamobilom/verification.rb', line 4

def result
  @result
end

#signatureObject (readonly)

Returns the value of attribute signature.



6
7
8
# File 'lib/platbamobilom/verification.rb', line 6

def signature
  @signature
end

Instance Method Details

#verify(secret) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/platbamobilom/verification.rb', line 15

def verify(secret)
  signing_data  = [id, result, phone].join
  digest        = OpenSSL::Digest.new('sha256')
  hmac          = OpenSSL::HMAC.digest(digest, secret, signing_data)
  our_signature = hmac.unpack('H*').join.upcase

  our_signature == signature
end