Skip to content

Commit 9427a05

Browse files
committed
digest: raise DigestError for unsupported algorithm name
We generally raise OpenSSL::OpenSSLError or its subclass for errors originating from the OpenSSL library, which may include extra details appended by ossl_raise().
1 parent dcfd2e7 commit 9427a05

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

ext/openssl/ossl_digest.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ ossl_evp_get_digestbyname(VALUE obj)
5656
md = EVP_get_digestbyobj(oid);
5757
ASN1_OBJECT_free(oid);
5858
}
59-
if(!md)
60-
ossl_raise(rb_eRuntimeError, "Unsupported digest algorithm (%"PRIsVALUE").", obj);
59+
if (!md)
60+
ossl_raise(eDigestError, "unsupported digest algorithm: %"PRIsVALUE,
61+
obj);
6162
} else {
6263
EVP_MD_CTX *ctx;
6364

test/openssl/test_digest.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ def setup
1010
@d2 = OpenSSL::Digest::MD5.new
1111
end
1212

13+
def test_initialize
14+
assert_raise(OpenSSL::Digest::DigestError) {
15+
OpenSSL::Digest.new("no such algorithm")
16+
}
17+
end
18+
1319
def test_digest
1420
null_hex = "d41d8cd98f00b204e9800998ecf8427e"
1521
null_bin = [null_hex].pack("H*")

0 commit comments

Comments
 (0)