Project

General

Profile

Feature #4412 ยป digest_by_oid.diff

MartinBosslet (Martin Bosslet), 02/21/2011 01:45 AM

View differences:

ruby/ext/openssl/ossl_digest.c (Arbeitskopie)
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 {
ruby/test/openssl/test_digest.rb (Arbeitskopie)
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
    (1-1/1)