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

ruby-changes:19993

From: emboss <ko1@a...>
Date: Mon, 13 Jun 2011 11:37:47 +0900 (JST)
Subject: [ruby-changes:19993] emboss:r32040 (trunk): * ext/openssl/ossl_digest.c: allow Digests to be created by sn, ln or

emboss	2011-06-13 11:37:35 +0900 (Mon, 13 Jun 2011)

  New Revision: 32040

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

  Log:
    * ext/openssl/ossl_digest.c: allow Digests to be created by sn, ln or
      oid.
    * test/openssl/test_digest.rb: add tests for this.
      [Ruby 1.9 - Feature #4412] [ruby-core:35319]

  Modified files:
    trunk/ChangeLog
    trunk/ext/openssl/ossl_digest.c
    trunk/test/openssl/test_digest.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 32039)
+++ ChangeLog	(revision 32040)
@@ -1,3 +1,10 @@
+Mon Jun 13 11:30:10 2011  Martin Bosslet  <Martin.Bosslet@g...>
+
+	* ext/openssl/ossl_digest.c: allow Digests to be created by sn, ln or
+	  oid.
+	* test/openssl/test_digest.rb: add tests for this.
+	  [Ruby 1.9 - Feature #4412] [ruby-core:35319]
+
 Mon Jun 13 10:54:03 2011  Martin Bosslet  <Martin.Bosslet@g...>
 
 	* ext/openssl/pkey_dh.c: corrected documentation.
Index: ext/openssl/ossl_digest.c
===================================================================
--- ext/openssl/ossl_digest.c	(revision 32039)
+++ ext/openssl/ossl_digest.c	(revision 32040)
@@ -36,12 +36,15 @@
 GetDigestPtr(VALUE obj)
 {
     const EVP_MD *md;
+    ASN1_OBJECT *oid = NULL;
 
     if (TYPE(obj) == T_STRING) {
     	const char *name = StringValueCStr(obj);
 
-        md = EVP_get_digestbyname(name);
-        if (!md)
+	oid = OBJ_txt2obj(name, 0);
+	md = EVP_get_digestbyobj(oid);
+	ASN1_OBJECT_free(oid);
+	if(!md)
             ossl_raise(rb_eRuntimeError, "Unsupported digest algorithm (%s).", name);
     } else {
         EVP_MD_CTX *ctx;
@@ -260,8 +263,9 @@
  *      digest.block_length -> integer
  *
  * Returns the block length of the digest algorithm, i.e. the length in bytes
- * of an individual block. Most modern partition a message to be digested into
- * a sequence of fix-sized blocks that are processed consecutively.
+ * of an individual block. Most modern algorithms partition a message to be
+ * digested into a sequence of fix-sized blocks that are processed
+ * consecutively.
  *
  * === Example
  *   digest = OpenSSL::Digest::SHA1.new
Index: test/openssl/test_digest.rb
===================================================================
--- test/openssl/test_digest.rb	(revision 32039)
+++ test/openssl/test_digest.rb	(revision 32040)
@@ -56,6 +56,11 @@
     assert_equal(dig1, dig2, "reset")
   end
 
+  def test_digest_by_oid_and_name
+    check_digest(OpenSSL::ASN1::ObjectId.new("MD5"))
+    check_digest(OpenSSL::ASN1::ObjectId.new("SHA1"))
+  end
+
   if OpenSSL::OPENSSL_VERSION_NUMBER > 0x00908000
     def encode16(str)
       str.unpack("H*").first
@@ -77,7 +82,25 @@
       assert_equal(sha384_a, encode16(OpenSSL::Digest::SHA384.digest("a")))
       assert_equal(sha512_a, encode16(OpenSSL::Digest::SHA512.digest("a")))
     end
+
+    def test_digest_by_oid_and_name_sha2
+      check_digest(OpenSSL::ASN1::ObjectId.new("SHA224"))
+      check_digest(OpenSSL::ASN1::ObjectId.new("SHA256"))
+      check_digest(OpenSSL::ASN1::ObjectId.new("SHA384"))
+      check_digest(OpenSSL::ASN1::ObjectId.new("SHA512"))
+    end
   end
+
+  private
+
+  def check_digest(oid)
+    d = OpenSSL::Digest.new(oid.sn)
+    assert_not_nil(d)
+    d = OpenSSL::Digest.new(oid.ln)
+    assert_not_nil(d)
+    d = OpenSSL::Digest.new(oid.oid)
+    assert_not_nil(d)
+  end
 end
 
 end

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

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