Sha256: 2a5ea18b5ab05ca922749a7fa2a8dc7c27630b6c8ea31761c12788f5b37a5295

Contents?: true

Size: 526 Bytes

Versions: 7

Compression:

Stored size: 526 Bytes

Contents

class DiscoApp::CarrierRequestService

  # Return true iff the provided hmac_to_verify matches that calculated from the
  # given data and secret.
  def self.valid_hmac?(body, secret, hmac_to_verify)
    ActiveSupport::SecurityUtils.secure_compare(calculated_hmac(body, secret), hmac_to_verify.to_s)
  end

  # Calculate the HMAC for the given data and secret.
  def self.calculated_hmac(body, secret)
    digest = OpenSSL::Digest.new('sha256')
    Base64.encode64(OpenSSL::HMAC.digest(digest, secret, body)).strip
  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
disco_app-0.17.0 app/services/disco_app/carrier_request_service.rb
disco_app-0.18.0 app/services/disco_app/carrier_request_service.rb
disco_app-0.18.2 app/services/disco_app/carrier_request_service.rb
disco_app-0.18.3 app/services/disco_app/carrier_request_service.rb
disco_app-0.18.6 app/services/disco_app/carrier_request_service.rb
disco_app-0.18.4 app/services/disco_app/carrier_request_service.rb
disco_app-0.18.1 app/services/disco_app/carrier_request_service.rb