mirror of
https://github.com/ruby/ruby.git
synced 2025-09-17 09:33:59 +02:00
* 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
This commit is contained in:
parent
d5a2139dfb
commit
128eaaad11
7 changed files with 119 additions and 37 deletions
|
@ -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
|
||||
|
|
|
@ -26,22 +26,22 @@ module OpenSSL
|
|||
alg += %w(SHA224 SHA256 SHA384 SHA512)
|
||||
end
|
||||
|
||||
alg.each{|digest|
|
||||
self.module_eval(<<-EOD)
|
||||
class #{digest} < Digest
|
||||
def initialize(data=nil)
|
||||
super(\"#{digest}\", data)
|
||||
alg.each{|name|
|
||||
klass = Class.new(Digest){
|
||||
define_method(:initialize){|*data|
|
||||
if data.length > 1
|
||||
raise ArgumentError,
|
||||
"wrong number of arguments (#{data.length} for 1)"
|
||||
end
|
||||
|
||||
def #{digest}::digest(data)
|
||||
Digest::digest(\"#{digest}\", data)
|
||||
end
|
||||
|
||||
def #{digest}::hexdigest(data)
|
||||
Digest::hexdigest(\"#{digest}\", data)
|
||||
end
|
||||
end
|
||||
EOD
|
||||
super(name, data.first)
|
||||
}
|
||||
}
|
||||
singleton = (class <<klass; self; end)
|
||||
singleton.class_eval{
|
||||
define_method(:digest){|data| Digest.digest(name, data) }
|
||||
define_method(:hexdigest){|data| Digest.hexdigest(name, data) }
|
||||
}
|
||||
const_set(name, klass)
|
||||
}
|
||||
|
||||
end # Digest
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue