diff options
author | gotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2006-05-08 00:12:00 +0000 |
---|---|---|
committer | gotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2006-05-08 00:12:00 +0000 |
commit | 55ef220fe08ddaafdc874f423e92d6d23bddf1eb (patch) | |
tree | 90c3acf56c889e138d1ff5f9240a105751779537 /test/openssl/test_cipher.rb | |
parent | 911655fd17b2787ac3a3042b738a58eb749ce4d4 (diff) | |
download | ruby-55ef220fe08ddaafdc874f423e92d6d23bddf1eb.tar.gz |
* 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
Diffstat (limited to 'test/openssl/test_cipher.rb')
-rw-r--r-- | test/openssl/test_cipher.rb | 38 |
1 files changed, 33 insertions, 5 deletions
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 |