[#35027] [Ruby 1.9-Bug#4352][Open] [patch] Fix eval(s, b) backtrace; make eval(s, b) consistent with eval(s) — "James M. Lawrence" <redmine@...>

Bug #4352: [patch] Fix eval(s, b) backtrace; make eval(s, b) consistent with eval(s)

16 messages 2011/02/01

[#35114] [Ruby 1.9-Bug#4373][Open] http.rb:677: [BUG] Segmentation fault — Christian Fazzini <redmine@...>

Bug #4373: http.rb:677: [BUG] Segmentation fault

59 messages 2011/02/06

[#35171] [Ruby 1.9-Bug#4386][Open] encoding: directive does not affect regex expressions — mathew murphy <redmine@...>

Bug #4386: encoding: directive does not affect regex expressions

9 messages 2011/02/09

[#35237] [Ruby 1.9-Bug#4400][Open] nested at_exit hooks run in strange order — Suraj Kurapati <redmine@...>

Bug #4400: nested at_exit hooks run in strange order

12 messages 2011/02/15

[ruby-core:35319] [Ruby 1.9-Feature#4412][Open] [ext/openssl] Create Digest by OID

From: Martin Bosslet <redmine@...>
Date: 2011-02-20 16:45:47 UTC
List: ruby-core #35319
Feature #4412: [ext/openssl] Create Digest by OID
http://redmine.ruby-lang.org/issues/show/4412

Author: Martin Bosslet
Status: Open, Priority: Normal
Category: ext, Target version: 1.9.3

Currently it is not possible to create a Digest instance by using 
the OID instead of the name (sn or ln).

oid = OpenSSL::ASN1::ObjectId.new('SHA1')
digest = OpenSSL::ASN1::Digest.new(oid.oid)

=> Unsupported digest algorithm (1.3.14.3.2.26).

This is counter-intuitive, since the only thing that is always
available in the case of object identifiers is the numeric oid,
sn or ln are not always present. Since sn and ln are also quite
error-prone (spelling), I'd like to suggest to have all three possibilities
for instantiating a Digest: by sn, by ln and by oid.

I included a patch and a test to support this behaviour.

Regards,
Martin


----------------------------------------
http://redmine.ruby-lang.org

Attachments (1)

digest_by_oid.diff (1.67 KB, text/x-diff)
Index: ruby/ext/openssl/ossl_digest.c
===================================================================
--- ruby/ext/openssl/ossl_digest.c	(Revision 30927)
+++ ruby/ext/openssl/ossl_digest.c	(Arbeitskopie)
@@ -36,11 +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);
+        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 {
Index: ruby/test/openssl/test_digest.rb
===================================================================
--- ruby/test/openssl/test_digest.rb	(Revision 30927)
+++ ruby/test/openssl/test_digest.rb	(Arbeitskopie)
@@ -77,6 +77,27 @@
       assert_equal(sha384_a, encode16(OpenSSL::Digest::SHA384.digest("a")))
       assert_equal(sha512_a, encode16(OpenSSL::Digest::SHA512.digest("a")))
     end
+
+    def test_by_name_and_oid
+      check_digest(OpenSSL::ASN1::ObjectId.new('MD5'))
+      check_digest(OpenSSL::ASN1::ObjectId.new('SHA1'))
+      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
+
+    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
 

In This Thread

Prev Next