* 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
This commit is contained in:
emboss 2011-06-13 04:09:04 +00:00
Родитель 60947ded03
Коммит 1c629eff85
3 изменённых файлов: 24 добавлений и 3 удалений

Просмотреть файл

@ -1,3 +1,9 @@
Mon Jun 13 13:04:20 2011 Martin Bosslet <Martin.Bosslet@googlemail.com>
* 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@ruby-lang.org>
* lib/yaml.rb: load psych only when syck is not loaded.

Просмотреть файл

@ -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 {

Просмотреть файл

@ -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"))