Skip to content
This repository was archived by the owner on Jul 24, 2023. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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