Class: Rack::GithubWebhooks::Signature

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/github_webhooks.rb

Constant Summary collapse

HMAC_DIGEST =
OpenSSL::Digest.new('sha256')

Instance Method Summary collapse

Constructor Details

#initialize(secret, hub_signature, payload_body) ⇒ Signature



10
11
12
13
14
# File 'lib/rack/github_webhooks.rb', line 10

def initialize(secret, hub_signature, payload_body)
  @secret = secret
  @hub_signature = hub_signature
  @signature = "sha256=#{OpenSSL::HMAC.hexdigest(HMAC_DIGEST, secret, payload_body)}"
end

Instance Method Details

#valid?Boolean



16
17
18
19
20
# File 'lib/rack/github_webhooks.rb', line 16

def valid?
  return true unless @secret
  return false unless @hub_signature
  Rack::Utils.secure_compare(@signature, @hub_signature)
end