diff options
author | gotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2006-06-20 11:18:16 +0000 |
---|---|---|
committer | gotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2006-06-20 11:18:16 +0000 |
commit | 128eaaad11bbd3d38e51400f824f87c0100f28ad (patch) | |
tree | 02bf956e2cf73a2ee74e3e56122e22afc843a2d9 /ext/openssl/lib/openssl/cipher.rb | |
parent | d5a2139dfb854cf59192dfd36e16075786b9297e (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 'ext/openssl/lib/openssl/cipher.rb')
-rw-r--r-- | ext/openssl/lib/openssl/cipher.rb | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/ext/openssl/lib/openssl/cipher.rb b/ext/openssl/lib/openssl/cipher.rb index 9f8776d6fc..049533d06b 100644 --- a/ext/openssl/lib/openssl/cipher.rb +++ b/ext/openssl/lib/openssl/cipher.rb @@ -20,19 +20,25 @@ module OpenSSL module Cipher - %w(AES CAST5 BF DES IDEA RC2 RC4 RC5).each{|cipher| - eval(<<-EOD) - class #{cipher} < Cipher - def initialize(*args) - args = args.join('-') - if args.size == 0 - super(\"#{cipher}\") - else - super(\"#{cipher}-#\{args\}\") - end - end - end - EOD + %w(AES CAST5 BF DES IDEA RC2 RC4 RC5).each{|name| + klass = Class.new(Cipher){ + define_method(:initialize){|*args| + cipher_name = args.inject(name){|n, arg| "#{n}-#{arg}" } + super(cipher_name) + } + } + const_set(name, klass) + } + + %w(128 192 256).each{|keylen| + klass = Class.new(Cipher){ + define_method(:initialize){|mode| + mode ||= "CBC" + cipher_name = "AES-#{keylen}-#{mode}" + super(cipher_name) + } + } + const_set("AES#{keylen}", klass) } class Cipher |