class ActionMailbox::Ingresses::Mailgun::InboundEmailsController::Authenticator

def authenticated?

def authenticated?
  signed? && recent?
end

def expected_signature

def expected_signature
  OpenSSL::HMAC.hexdigest OpenSSL::Digest::SHA256.new, key, "#{timestamp}#{token}"
end

def initialize(key:, timestamp:, token:, signature:)

def initialize(key:, timestamp:, token:, signature:)
  @key, @timestamp, @token, @signature = key, Integer(timestamp), token, signature
end

def recent?

Allow for 2 minutes of drift between Mailgun time and local server time.
def recent?
  Time.at(timestamp) >= 2.minutes.ago
end

def signed?

def signed?
  ActiveSupport::SecurityUtils.secure_compare signature, expected_signature
end