Sha256: d445c726f67f2fb59b793af7892101a471a481d80f1352f275ca8418c27cff84

Contents?: true

Size: 473 Bytes

Versions: 1

Compression:

Stored size: 473 Bytes

Contents

# frozen_string_literal: true

module Mergent
  class RequestValidator
    def initialize(api_key)
      @api_key = api_key || Mergent.api_key
    end

    def build_signature_for(url, body)
      data = (url || "") + (body || "")
      digest = OpenSSL::Digest.new("sha1")
      Base64.strict_encode64(OpenSSL::HMAC.digest(digest, @api_key, data))
    end

    def valid_signature?(url, body, signature)
      build_signature_for(url, body) == signature
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mergent-0.2.0 lib/mergent/request_validator.rb