1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/core/hmac.rb
Mike Fiedler 6d663919b5 drop dependency on deprecated ruby-hmac gem, fixes #2034
Ruby 1.8 compiled against OpenSSL 0.9.8 supports SHA256 for some time now.
Ref: https://github.com/ruby/ruby/blob/ruby_1_8_7/ChangeLog#L12025-L12029
2013-12-26 21:44:37 -05:00

35 lines
595 B
Ruby

module Fog
class HMAC
def initialize(type, key)
@key = key
case type
when 'sha1'
setup_sha1
when 'sha256'
setup_sha256
end
end
def sign(data)
@signer.call(data)
end
private
def setup_sha1
@digest = OpenSSL::Digest.new('sha1')
@signer = lambda do |data|
OpenSSL::HMAC.digest(@digest, @key, data)
end
end
def setup_sha256
@digest = OpenSSL::Digest.new('sha256')
@signer = lambda do |data|
OpenSSL::HMAC.digest(@digest, @key, data)
end
end
end
end