Class: Rack::GithubWebhooks::Signature

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

Constant Summary collapse

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

Instance Method Summary collapse

Constructor Details

#initialize(secret, hub_signature, payload_body) ⇒ Signature

Returns a new instance of Signature.



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

def initialize(secret, hub_signature, payload_body)
  @secret = secret
  @hub_signature = hub_signature
  @signature = 'sha1=' +
               OpenSSL::HMAC.hexdigest(HMAC_DIGEST, secret, payload_body)
end

Instance Method Details

#valid?Boolean

Returns:

  • (Boolean)


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

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