[前][次][番号順一覧][スレッド一覧]

ruby-changes:14872

From: knu <ko1@a...>
Date: Wed, 24 Feb 2010 00:51:20 +0900 (JST)
Subject: [ruby-changes:14872] Ruby:r26739 (trunk): * ext/openssl/ossl_digest.c (GetDigestPtr): Allow to pass the

knu	2010-02-24 00:51:01 +0900 (Wed, 24 Feb 2010)

  New Revision: 26739

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=26739

  Log:
    * ext/openssl/ossl_digest.c (GetDigestPtr): Allow to pass the
      OpenSSL::Digest class in place of where either an instance of
      the class or the algorithm name was demanded.  For example,
      OpenSSL::HMAC.digest(OpenSSL::Digest::SHA1, key, data) is now
      accepted as well as the usual
      OpenSSL::HMAC.digest(OpenSSL::Digest::SHA1.new, key, data) and
      OpenSSL::HMAC.digest("SHA1", key, data).

  Modified files:
    trunk/ChangeLog
    trunk/ext/openssl/ossl_digest.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 26738)
+++ ChangeLog	(revision 26739)
@@ -1,3 +1,13 @@
+Wed Feb 24 00:50:09 2010  Akinori MUSHA  <knu@i...>
+
+	* ext/openssl/ossl_digest.c (GetDigestPtr): Allow to pass the
+	  OpenSSL::Digest class in place of where either an instance of
+	  the class or the algorithm name was demanded.  For example,
+	  OpenSSL::HMAC.digest(OpenSSL::Digest::SHA1, key, data) is now
+	  accepted as well as the usual
+	  OpenSSL::HMAC.digest(OpenSSL::Digest::SHA1.new, key, data) and
+	  OpenSSL::HMAC.digest("SHA1", key, data).
+
 Wed Feb 24 00:39:17 2010  Yusuke Endoh  <mame@t...>
 
 	* string.c (str_new_empty): String#split, partition, rpartition
Index: ext/openssl/ossl_digest.c
===================================================================
--- ext/openssl/ossl_digest.c	(revision 26738)
+++ ext/openssl/ossl_digest.c	(revision 26739)
@@ -37,18 +37,25 @@
 {
     const EVP_MD *md;
 
-    if (TYPE(obj) == T_STRING) {
-    	const char *name = StringValueCStr(obj);
+    if (TYPE(obj) == T_CLASS) {
+        EVP_MD_CTX *ctx;
+	VALUE digest = rb_funcall(obj, rb_intern("new"), 0, 0);
 
-        md = EVP_get_digestbyname(name);
-        if (!md)
-            ossl_raise(rb_eRuntimeError, "Unsupported digest algorithm (%s).", name);
-    } else {
+        SafeGetDigest(digest, ctx);
+
+        md = EVP_MD_CTX_md(ctx);
+    } else if (rb_obj_is_kind_of(obj, cDigest)) {
         EVP_MD_CTX *ctx;
 
         SafeGetDigest(obj, ctx);
 
         md = EVP_MD_CTX_md(ctx);
+    } else {
+    	const char *name = StringValueCStr(obj);
+
+        md = EVP_get_digestbyname(name);
+        if (!md)
+            ossl_raise(rb_eRuntimeError, "Unsupported digest algorithm (%s).", name);
     }
 
     return md;

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]