tags:

views:

405

answers:

1

Hi,

i'm working with some codes that has a:

begin
require 'digest/hmac'
USE_EMBEDDED_HMAC = false
rescue
puts "HMAC, not found in standard lib." + $!.message
require 'hmac-sha1'
USE_EMBEDDED_HMAC = true
end


As i could see, at least in rails 1.8.6 its not part of the standard lib. Is it part from the ruby 1.9 lib? If not, should i install any gem?

Note that solutions using OpenSSL won't be accepted because it will fail anyway in "require 'digest/hmac'"

The code in question is here http://github.com/quetzall/cloud%5Fcache/blob/master/lib/cloud%5Fcache.rb

+5  A: 

It's available in 1.8.7. Try this:

ruby -v
ruby 1.8.7 (2008-08-11 patchlevel 72) [i686-darwin9]

require 'openssl'
digest  = OpenSSL::Digest::Digest.new('sha1')
OpenSSL::HMAC.digest(digest, "superscret", "Lorem ipsum dolor sit amet")
OpenSSL::HMAC.hexdigest(digest, "superscret", "Lorem ipsum dolor sit amet")
Chandra Patni
This example works on v1.8.6 too.
ewall