Sha256: 15feb843c11e57b631d3837acbfc8a87db29aac9fa97f7c18f4426e4af829d5a

Contents?: true

Size: 424 Bytes

Versions: 1

Compression:

Stored size: 424 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(body)
      digest = OpenSSL::Digest.new("sha1")
      Base64.strict_encode64(OpenSSL::HMAC.digest(digest, @api_key, body || ""))
    end

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

Version data entries

1 entries across 1 versions & 1 rubygems

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