Class: Freeclimb::SignatureInformation

Inherits:
Object
  • Object
show all
Defined in:
lib/freeclimb/utils/signature_information.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_timestampObject

Returns the value of attribute request_timestamp.



6
7
8
# File 'lib/freeclimb/utils/signature_information.rb', line 6

def request_timestamp
  @request_timestamp
end

#signaturesObject

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_timeObject



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