summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-02-23 17:36:12 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-02-23 17:36:12 +0000
commitfdb57d043d96821a79d52750a761b43e8676cc61 (patch)
tree576de5ed433c51a3f0cbe866b4c145112e46afd0
parentd22373455532e99c0adf1a1e5d0b3a864691e2f9 (diff)
Add some more tests, revisited.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26744 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--test/openssl/test_hmac.rb22
1 files changed, 12 insertions, 10 deletions
diff --git a/test/openssl/test_hmac.rb b/test/openssl/test_hmac.rb
index 2f8d6bb..23a3ce4 100644
--- a/test/openssl/test_hmac.rb
+++ b/test/openssl/test_hmac.rb
@@ -4,15 +4,13 @@ rescue LoadError
end
require "test/unit"
-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)
+ @h1 = OpenSSL::HMAC.new(@key, @digest.new)
+ @h2 = OpenSSL::HMAC.new(@key, "MD5")
end
def teardown
@@ -20,8 +18,14 @@ class OpenSSL::TestHMAC < Test::Unit::TestCase
def test_hmac
@h1.update(@data)
- assert_equal(OpenSSL::HMAC.digest(@digest, @key, @data), @h1.digest, "digest")
- assert_equal(OpenSSL::HMAC.hexdigest(@digest, @key, @data), @h1.hexdigest, "hexdigest")
+ @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
@@ -29,6 +33,4 @@ class OpenSSL::TestHMAC < Test::Unit::TestCase
h = @h1.dup
assert_equal(@h1.digest, h.digest, "dup digest")
end
-end
-
-end
+end if defined?(OpenSSL)