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

Commit 8a54dd7

Browse files
committed
Merge pull request #84 from tobiashm/openssl
Use HMAC from OpenSSL rather than Digest.
2 parents ff3acd6 + eb4018f commit 8a54dd7

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

lib/openid/cryptutil.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
require "digest/sha1"
33
require "digest/sha2"
44
begin
5-
require "digest/hmac"
5+
require "openssl"
66
rescue LoadError
77
begin
88
# Try loading the ruby-hmac files if they exist
@@ -37,8 +37,8 @@ def CryptUtil.sha1(text)
3737
end
3838

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

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

0 commit comments

Comments
 (0)