Skip to content
This repository was archived by the owner on Jul 24, 2023. It is now read-only.

Commit e7e9f81

Browse files
committed
Avoid checking ancestors for constant
When checking if `Digest::HMAC` is defined, we should not check ancestors, we're only interested if `HMAC` is defined on `Digest`. This will fix an issue in Ruby 2.2 where `Digest::HMAC` has been removed, but the current check will result in the `Digest` library trying to load `digest/hmac` in `Digest.const_missing` and thus causing an error.
1 parent 197d002 commit e7e9f81

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

lib/openid/cryptutil.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def CryptUtil.sha1(text)
3737
end
3838

3939
def CryptUtil.hmac_sha1(key, text)
40-
if Digest.const_defined? :HMAC
40+
if Digest.const_defined? :HMAC, false
4141
Digest::HMAC.new(key,Digest::SHA1).update(text).digest
4242
else
4343
return HMAC::SHA1.digest(key, text)
@@ -49,7 +49,7 @@ def CryptUtil.sha256(text)
4949
end
5050

5151
def CryptUtil.hmac_sha256(key, text)
52-
if Digest.const_defined? :HMAC
52+
if Digest.const_defined? :HMAC, false
5353
Digest::HMAC.new(key,Digest::SHA256).update(text).digest
5454
else
5555
return HMAC::SHA256.digest(key, text)

0 commit comments

Comments
 (0)