diff options
author | emboss <emboss@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-06-13 04:09:04 +0000 |
---|---|---|
committer | emboss <emboss@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-06-13 04:09:04 +0000 |
commit | 1c629eff858830131539a5abab1717d93e029439 (patch) | |
tree | 208b6d199947743bc994452580e51b80bd2cc62c | |
parent | 60947ded03b815692e23c61361c213f35a653e6b (diff) |
* 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
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | ext/openssl/ossl_digest.c | 9 | ||||
-rw-r--r-- | test/openssl/test_digest.rb | 12 |
3 files changed, 24 insertions, 3 deletions
@@ -1,3 +1,9 @@ +Mon Jun 13 13:04:20 2011 Martin Bosslet <[email protected]> + + * 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 <[email protected]> * 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")) |