Class: Freeclimb::SignatureInformation
- Inherits:
-
Object
- Object
- Freeclimb::SignatureInformation
- Defined in:
- lib/freeclimb/utils/signature_information.rb
Instance Attribute Summary collapse
-
#request_timestamp ⇒ Object
Returns the value of attribute request_timestamp.
-
#signatures ⇒ Object
Returns the value of attribute signatures.
Instance Method Summary collapse
- #get_current_unix_time ⇒ Object
-
#initialize(request_header) ⇒ SignatureInformation
constructor
A new instance of SignatureInformation.
- #is_request_time_valid(tolerance) ⇒ Object
- #is_signature_safe(request_body, signing_secret) ⇒ Object
Constructor Details
#initialize(request_header) ⇒ SignatureInformation
Returns a new instance of SignatureInformation.
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/freeclimb/utils/signature_information.rb', line 9 def initialize(request_header) @request_timestamp = 0 @signatures = [] signatureHeader = request_header.try(:split, ",") signatureHeader.each { |signature| header, value = signature.try(:split, "=") if header == "t" @request_timestamp = value.to_i elsif header == "v1" @signatures.append(value) end } end |
Instance Attribute Details
#request_timestamp ⇒ Object
Returns the value of attribute request_timestamp.
6 7 8 |
# File 'lib/freeclimb/utils/signature_information.rb', line 6 def @request_timestamp end |
#signatures ⇒ Object
Returns the value of attribute signatures.
7 8 9 |
# File 'lib/freeclimb/utils/signature_information.rb', line 7 def signatures @signatures end |
Instance Method Details
#get_current_unix_time ⇒ Object
39 40 41 |
# File 'lib/freeclimb/utils/signature_information.rb', line 39 def get_current_unix_time() return DateTime.now.strftime('%s').to_i end |
#is_request_time_valid(tolerance) ⇒ Object
23 24 25 26 27 |
# File 'lib/freeclimb/utils/signature_information.rb', line 23 def is_request_time_valid(tolerance) currentTime = self.get_current_unix_time() timeCalculation = @request_timestamp + tolerance return currentTime < (timeCalculation) end |
#is_signature_safe(request_body, signing_secret) ⇒ Object
29 30 31 32 |
# File 'lib/freeclimb/utils/signature_information.rb', line 29 def is_signature_safe(request_body, signing_secret) hashValue = self.compute_hash(request_body, signing_secret) return @signatures.include? hashValue end |