From 55ef220fe08ddaafdc874f423e92d6d23bddf1eb Mon Sep 17 00:00:00 2001 From: gotoyuzo Date: Mon, 8 May 2006 00:12:00 +0000 Subject: * 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/ossl_cipher.c (ossl_cipher_init): refine warning message. * ext/openssl/lib/openssl/cipher.rb: reimplement without eval() and add constants AES128, AES192, AES256. [ruby-dev:28610] * 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/trunk@10137 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/openssl/test_cipher.rb | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) (limited to 'test/openssl/test_cipher.rb') diff --git a/test/openssl/test_cipher.rb b/test/openssl/test_cipher.rb index c84b47b7f4..d671908165 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 -- cgit v1.2.3