summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/openssl/test_hmac.rb16
1 files changed, 14 insertions, 2 deletions
diff --git a/test/openssl/test_hmac.rb b/test/openssl/test_hmac.rb
index 2f8d6bba205..1b571e6b19c 100644
--- a/test/openssl/test_hmac.rb
+++ b/test/openssl/test_hmac.rb
@@ -8,11 +8,12 @@ if defined?(OpenSSL)
class OpenSSL::TestHMAC < Test::Unit::TestCase
def setup
- @digest = OpenSSL::Digest::MD5.new
+ @digest = OpenSSL::Digest::MD5
@key = "KEY"
@data = "DATA"
@h1 = OpenSSL::HMAC.new(@key, @digest)
- @h2 = OpenSSL::HMAC.new(@key, @digest)
+ @h2 = OpenSSL::HMAC.new(@key, @digest.new)
+ @h3 = OpenSSL::HMAC.new(@key, "MD5")
end
def teardown
@@ -20,8 +21,19 @@ class OpenSSL::TestHMAC < Test::Unit::TestCase
def test_hmac
@h1.update(@data)
+ @h2.update(@data)
+ @h3.update(@data)
+ assert_equal(@h1.digest, @h2.digest)
+ assert_equal(@h2.digest, @h3.digest)
+
assert_equal(OpenSSL::HMAC.digest(@digest, @key, @data), @h1.digest, "digest")
assert_equal(OpenSSL::HMAC.hexdigest(@digest, @key, @data), @h1.hexdigest, "hexdigest")
+
+ assert_equal(OpenSSL::HMAC.digest(@digest.new, @key, @data), @h2.digest, "digest")
+ assert_equal(OpenSSL::HMAC.hexdigest(@digest.new, @key, @data), @h2.hexdigest, "hexdigest")
+
+ assert_equal(OpenSSL::HMAC.digest("MD5", @key, @data), @h3.digest, "digest")
+ assert_equal(OpenSSL::HMAC.hexdigest("MD5", @key, @data), @h3.hexdigest, "hexdigest")
end
def test_dup