From 1c629eff858830131539a5abab1717d93e029439 Mon Sep 17 00:00:00 2001 From: emboss Date: Mon, 13 Jun 2011 04:09:04 +0000 Subject: [PATCH] * ext/openssl/ossl_digest.c: fix error for digests that have no oid (e.g. DSS1). * test/openssl/test_digest.c: add tests for this. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32045 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ ext/openssl/ossl_digest.c | 9 ++++++--- test/openssl/test_digest.rb | 12 ++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index bc62802a09..de305f7dd0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Mon Jun 13 13:04:20 2011 Martin Bosslet + + * ext/openssl/ossl_digest.c: fix error for digests that have no oid + (e.g. DSS1). + * test/openssl/test_digest.c: add tests for this. + Mon Jun 13 12:51:51 2011 NARUSE, Yui * lib/yaml.rb: load psych only when syck is not loaded. diff --git a/ext/openssl/ossl_digest.c b/ext/openssl/ossl_digest.c index ebfca120da..cb0cade1bf 100644 --- a/ext/openssl/ossl_digest.c +++ b/ext/openssl/ossl_digest.c @@ -41,9 +41,12 @@ GetDigestPtr(VALUE obj) if (TYPE(obj) == T_STRING) { const char *name = StringValueCStr(obj); - oid = OBJ_txt2obj(name, 0); - md = EVP_get_digestbyobj(oid); - ASN1_OBJECT_free(oid); + 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 { diff --git a/test/openssl/test_digest.rb b/test/openssl/test_digest.rb index ce0d85fe55..5f9a563d1c 100644 --- a/test/openssl/test_digest.rb +++ b/test/openssl/test_digest.rb @@ -56,6 +56,18 @@ class OpenSSL::TestDigest < Test::Unit::TestCase assert_equal(dig1, dig2, "reset") end + def test_digest_constants + algs = %w(DSS1 MD4 MD5 MDC2 RIPEMD160 SHA SHA1) + if OpenSSL::OPENSSL_VERSION_NUMBER > 0x00908000 + algs += %w(SHA224 SHA256 SHA384 SHA512) + end + algs.each do |alg| + assert_not_nil(OpenSSL::Digest.new(alg)) + klass = OpenSSL::Digest.const_get(alg) + assert_not_nil(klass.new) + end + end + def test_digest_by_oid_and_name check_digest(OpenSSL::ASN1::ObjectId.new("MD5")) check_digest(OpenSSL::ASN1::ObjectId.new("SHA1"))