summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorgotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-06-20 11:18:16 +0000
committergotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-06-20 11:18:16 +0000
commit128eaaad11bbd3d38e51400f824f87c0100f28ad (patch)
tree02bf956e2cf73a2ee74e3e56122e22afc843a2d9 /test
parentd5a2139dfb854cf59192dfd36e16075786b9297e (diff)
* ext/openssl/extconf.rb: add check for OBJ_NAME_do_all_sorted.
* ext/openssl/ossl_cipher.c (ossl_s_ciphers): new method OpenSSL::Cipher.ciphers. it returns all the cipher names. * ext/openssl/lib/openssl/cipher.rb: - add constants AES128, AES192, AES256. [ruby-dev:28610] - reimplement without eval() * ext/openssl/lib/openssl/digest.rb: reimplement without eval(). * test/openssl/test_cipher.rb, test_digest: fix about reimplemented features. * sample/openssl/cipher.rb: rewrite all. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@10339 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/openssl/test_cipher.rb38
1 files changed, 33 insertions, 5 deletions
diff --git a/test/openssl/test_cipher.rb b/test/openssl/test_cipher.rb
index c84b47b..d671908 100644
--- a/test/openssl/test_cipher.rb
+++ b/test/openssl/test_cipher.rb
@@ -11,7 +11,7 @@ class OpenSSL::TestCipher < Test::Unit::TestCase
@c1 = OpenSSL::Cipher::Cipher.new("DES-EDE3-CBC")
@c2 = OpenSSL::Cipher::DES.new(:EDE3, "CBC")
@key = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
- @iv = @key
+ @iv = "\0\0\0\0\0\0\0\0"
@hexkey = "0000000000000000000000000000000000000000000000"
@hexiv = "0000000000000000"
@data = "DATA"
@@ -22,11 +22,16 @@ class OpenSSL::TestCipher < Test::Unit::TestCase
end
def test_crypt
- s1 = @c1.encrypt(@key, @iv).update(@data) + @c1.final
- s2 = @c2.encrypt(@key, @iv).update(@data) + @c2.final
+ @c1.encrypt.pkcs5_keyivgen(@key, @iv)
+ @c2.encrypt.pkcs5_keyivgen(@key, @iv)
+ s1 = @c1.update(@data) + @c1.final
+ s2 = @c2.update(@data) + @c2.final
assert_equal(s1, s2, "encrypt")
- assert_equal(@data, @c1.decrypt(@key, @iv).update(s2)+@c1.final, "decrypt")
- assert_equal(@data, @c2.decrypt(@key, @iv).update(s1)+@c2.final, "decrypt")
+
+ @c1.decrypt.pkcs5_keyivgen(@key, @iv)
+ @c2.decrypt.pkcs5_keyivgen(@key, @iv)
+ assert_equal(@data, @c1.update(s1)+@c1.final, "decrypt")
+ assert_equal(@data, @c2.update(s2)+@c2.final, "decrypt")
end
def test_info
@@ -62,6 +67,29 @@ class OpenSSL::TestCipher < Test::Unit::TestCase
@c1.encrypt
assert_raises(ArgumentError){ @c1.update("") }
end
+
+ if OpenSSL::OPENSSL_VERSION_NUMBER > 0x00907000
+ def test_ciphers
+ OpenSSL::Cipher.ciphers.each{|name|
+ assert(OpenSSL::Cipher::Cipher.new(name).is_a?(OpenSSL::Cipher::Cipher))
+ }
+ end
+
+ def test_AES
+ pt = File.read(__FILE__)
+ %w(ECB CBC CFB OFB).each{|mode|
+ c1 = OpenSSL::Cipher::AES256.new(mode)
+ c1.encrypt
+ c1.pkcs5_keyivgen("passwd")
+ ct = c1.update(pt) + c1.final
+
+ c2 = OpenSSL::Cipher::AES256.new(mode)
+ c2.decrypt
+ c2.pkcs5_keyivgen("passwd")
+ assert_equal(pt, c2.update(ct) + c2.final)
+ }
+ end
+ end
end
end