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

Commit

Permalink
Merge pull request #84 from tobiashm/openssl
Browse files Browse the repository at this point in the history
Use HMAC from OpenSSL rather than Digest.
  • Loading branch information
dennisreimann committed Mar 5, 2015
2 parents ff3acd6 + eb4018f commit 8a54dd7
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/openid/cryptutil.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require "digest/sha1"
require "digest/sha2"
begin
require "digest/hmac"
require "openssl"
rescue LoadError
begin
# Try loading the ruby-hmac files if they exist
Expand Down Expand Up @@ -37,8 +37,8 @@ def CryptUtil.sha1(text)
end

def CryptUtil.hmac_sha1(key, text)
if Digest.const_defined? :HMAC, false
Digest::HMAC.new(key,Digest::SHA1).update(text).digest
if defined? OpenSSL
OpenSSL::HMAC.digest(OpenSSL::Digest::SHA1.new, key, text)
else
return HMAC::SHA1.digest(key, text)
end
Expand All @@ -49,8 +49,8 @@ def CryptUtil.sha256(text)
end

def CryptUtil.hmac_sha256(key, text)
if Digest.const_defined? :HMAC, false
Digest::HMAC.new(key,Digest::SHA256).update(text).digest
if defined? OpenSSL
OpenSSL::HMAC.digest(OpenSSL::Digest::SHA256.new, key, text)
else
return HMAC::SHA256.digest(key, text)
end
Expand Down

0 comments on commit 8a54dd7

Please sign in to comment.