ruby-changes:19998
From: emboss <ko1@a...>
Date: Mon, 13 Jun 2011 13:11:28 +0900 (JST)
Subject: [ruby-changes:19998] emboss:r32045 (trunk): * ext/openssl/ossl_digest.c: fix error for digests that have no oid
emboss 2011-06-13 13:09:04 +0900 (Mon, 13 Jun 2011) New Revision: 32045 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=32045 Log: * 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. Modified files: trunk/ChangeLog trunk/ext/openssl/ossl_digest.c trunk/test/openssl/test_digest.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 32044) +++ ChangeLog (revision 32045) @@ -1,3 +1,9 @@ +Mon Jun 13 13:04:20 2011 Martin Bosslet <Martin.Bosslet@g...> + + * 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 <naruse@r...> * lib/yaml.rb: load psych only when syck is not loaded. Index: ext/openssl/ossl_digest.c =================================================================== --- ext/openssl/ossl_digest.c (revision 32044) +++ ext/openssl/ossl_digest.c (revision 32045) @@ -41,9 +41,12 @@ 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 { Index: test/openssl/test_digest.rb =================================================================== --- test/openssl/test_digest.rb (revision 32044) +++ test/openssl/test_digest.rb (revision 32045) @@ -56,6 +56,18 @@ 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")) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/