digest_by_oid.diff

Martin Bosslet, 02/21/2011 01:45 AM

Download (1.67 KB)

View differences:

ruby/ext/openssl/ossl_digest.c (Arbeitskopie)
36 36
GetDigestPtr(VALUE obj)
37 37
{
38 38
    const EVP_MD *md;
39
    ASN1_OBJECT *oid = NULL;
39 40

  
40 41
    if (TYPE(obj) == T_STRING) {
41 42
    	const char *name = StringValueCStr(obj);
42 43

  
43
        md = EVP_get_digestbyname(name);
44
        oid = OBJ_txt2obj(name, 0);
45
        md = EVP_get_digestbyobj(oid);
46
        ASN1_OBJECT_free(oid);
47

  
44 48
        if (!md)
45 49
            ossl_raise(rb_eRuntimeError, "Unsupported digest algorithm (%s).", name);
46 50
    } else {
ruby/test/openssl/test_digest.rb (Arbeitskopie)
77 77
      assert_equal(sha384_a, encode16(OpenSSL::Digest::SHA384.digest("a")))
78 78
      assert_equal(sha512_a, encode16(OpenSSL::Digest::SHA512.digest("a")))
79 79
    end
80

  
81
    def test_by_name_and_oid
82
      check_digest(OpenSSL::ASN1::ObjectId.new('MD5'))
83
      check_digest(OpenSSL::ASN1::ObjectId.new('SHA1'))
84
      check_digest(OpenSSL::ASN1::ObjectId.new('SHA224'))
85
      check_digest(OpenSSL::ASN1::ObjectId.new('SHA256'))
86
      check_digest(OpenSSL::ASN1::ObjectId.new('SHA384'))
87
      check_digest(OpenSSL::ASN1::ObjectId.new('SHA512'))
88
    end
89

  
90
    private
91

  
92
    def check_digest(oid)
93
      d = OpenSSL::Digest.new(oid.sn)
94
      assert_not_nil(d)
95
      d = OpenSSL::Digest.new(oid.ln)
96
      assert_not_nil(d)
97
      d = OpenSSL::Digest.new(oid.oid)
98
      assert_not_nil(d)
99
    end
100

  
80 101
  end
81 102
end
82 103