mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
fdb57d043d
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26744 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
36 lines
916 B
Ruby
36 lines
916 B
Ruby
begin
|
|
require "openssl"
|
|
rescue LoadError
|
|
end
|
|
require "test/unit"
|
|
|
|
class OpenSSL::TestHMAC < Test::Unit::TestCase
|
|
def setup
|
|
@digest = OpenSSL::Digest::MD5
|
|
@key = "KEY"
|
|
@data = "DATA"
|
|
@h1 = OpenSSL::HMAC.new(@key, @digest.new)
|
|
@h2 = OpenSSL::HMAC.new(@key, "MD5")
|
|
end
|
|
|
|
def teardown
|
|
end
|
|
|
|
def test_hmac
|
|
@h1.update(@data)
|
|
@h2.update(@data)
|
|
assert_equal(@h1.digest, @h2.digest)
|
|
|
|
assert_equal(OpenSSL::HMAC.digest(@digest.new, @key, @data), @h1.digest, "digest")
|
|
assert_equal(OpenSSL::HMAC.hexdigest(@digest.new, @key, @data), @h1.hexdigest, "hexdigest")
|
|
|
|
assert_equal(OpenSSL::HMAC.digest("MD5", @key, @data), @h2.digest, "digest")
|
|
assert_equal(OpenSSL::HMAC.hexdigest("MD5", @key, @data), @h2.hexdigest, "hexdigest")
|
|
end
|
|
|
|
def test_dup
|
|
@h1.update(@data)
|
|
h = @h1.dup
|
|
assert_equal(@h1.digest, h.digest, "dup digest")
|
|
end
|
|
end if defined?(OpenSSL)
|