Class: DiscoApp::CarrierRequestService
- Inherits:
-
Object
- Object
- DiscoApp::CarrierRequestService
- Defined in:
- app/services/disco_app/carrier_request_service.rb
Class Method Summary collapse
-
.calculated_hmac(body, secret) ⇒ Object
Calculate the HMAC for the given data and secret.
-
.valid_hmac?(body, secret, hmac_to_verify) ⇒ Boolean
Return true iff the provided hmac_to_verify matches that calculated from the given data and secret.
Class Method Details
.calculated_hmac(body, secret) ⇒ Object
Calculate the HMAC for the given data and secret.
10 11 12 13 |
# File 'app/services/disco_app/carrier_request_service.rb', line 10 def self.calculated_hmac(body, secret) digest = OpenSSL::Digest.new('sha256') Base64.encode64(OpenSSL::HMAC.digest(digest, secret, body)).strip end |
.valid_hmac?(body, secret, hmac_to_verify) ⇒ Boolean
Return true iff the provided hmac_to_verify matches that calculated from the given data and secret.
5 6 7 |
# File 'app/services/disco_app/carrier_request_service.rb', line 5 def self.valid_hmac?(body, secret, hmac_to_verify) ActiveSupport::SecurityUtils.secure_compare(calculated_hmac(body, secret), hmac_to_verify.to_s) end |