mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05: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/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
This commit is contained in:
parent
911655fd17
commit
55ef220fe0
8 changed files with 182 additions and 64 deletions
|
@ -117,6 +117,29 @@ ossl_cipher_copy(VALUE self, VALUE other)
|
|||
return self;
|
||||
}
|
||||
|
||||
static void*
|
||||
add_cipher_name_to_ary(const OBJ_NAME *name, VALUE ary)
|
||||
{
|
||||
rb_ary_push(ary, rb_str_new2(name->name));
|
||||
}
|
||||
|
||||
static VALUE
|
||||
ossl_s_ciphers(VALUE self)
|
||||
{
|
||||
#ifdef HAVE_OBJ_NAME_DO_ALL_SORTED
|
||||
VALUE ary;
|
||||
|
||||
ary = rb_ary_new();
|
||||
OBJ_NAME_do_all_sorted(OBJ_NAME_TYPE_CIPHER_METH,
|
||||
(void(*)(const OBJ_NAME*,void*))add_cipher_name_to_ary,
|
||||
(void*)ary);
|
||||
|
||||
return ary;
|
||||
#else
|
||||
rb_notimplement();
|
||||
#endif
|
||||
}
|
||||
|
||||
static VALUE
|
||||
ossl_cipher_reset(VALUE self)
|
||||
{
|
||||
|
@ -143,13 +166,14 @@ ossl_cipher_init(int argc, VALUE *argv, VALUE self, int mode)
|
|||
* We deprecated the arguments for this method, but we decided
|
||||
* keeping this behaviour for backward compatibility.
|
||||
*/
|
||||
char *cname = rb_class2name(rb_obj_class(self));
|
||||
rb_warn("argumtents for %s#encrypt and %s#decrypt were deprecated; "
|
||||
"use %s#pkcs5_keyivgen to derive key and IV",
|
||||
cname, cname, cname);
|
||||
StringValue(pass);
|
||||
GetCipher(self, ctx);
|
||||
if (NIL_P(init_v)) memcpy(iv, "OpenSSL for Ruby rulez!", sizeof(iv));
|
||||
else{
|
||||
char *cname = rb_class2name(rb_obj_class(self));
|
||||
rb_warning("key derivation by %s#encrypt is deprecated; "
|
||||
"use %s::pkcs5_keyivgen instead", cname, cname);
|
||||
StringValue(init_v);
|
||||
if (EVP_MAX_IV_LENGTH > RSTRING(init_v)->len) {
|
||||
memset(iv, 0, EVP_MAX_IV_LENGTH);
|
||||
|
@ -352,6 +376,7 @@ Init_ossl_cipher(void)
|
|||
|
||||
rb_define_alloc_func(cCipher, ossl_cipher_alloc);
|
||||
rb_define_copy_func(cCipher, ossl_cipher_copy);
|
||||
rb_define_module_function(mCipher, "ciphers", ossl_s_ciphers, 0);
|
||||
rb_define_method(cCipher, "initialize", ossl_cipher_initialize, 1);
|
||||
rb_define_method(cCipher, "reset", ossl_cipher_reset, 0);
|
||||
rb_define_method(cCipher, "encrypt", ossl_cipher_encrypt, -1);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue