summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2025-11-03 18:31:09 +0900
committergit <svn-admin@ruby-lang.org>2025-11-06 13:25:09 +0000
commit18ab5023b63af88eddb083e89e19224e9f25af4d (patch)
treeb3e64c3ff56e211a182d1a290070e2352d617e87
parent2612915c3489c76fcb3828eefd3b29fdf30a9a5e (diff)
[ruby/openssl] 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(). https://github.com/ruby/openssl/commit/9427a05ce5
-rw-r--r--ext/openssl/ossl_digest.c5
-rw-r--r--test/openssl/test_digest.rb6
2 files changed, 9 insertions, 2 deletions
diff --git a/ext/openssl/ossl_digest.c b/ext/openssl/ossl_digest.c
index 329de6c1ba..80cc041734 100644
--- a/ext/openssl/ossl_digest.c
+++ b/ext/openssl/ossl_digest.c
@@ -56,8 +56,9 @@ ossl_evp_get_digestbyname(VALUE obj)
md = EVP_get_digestbyobj(oid);
ASN1_OBJECT_free(oid);
}
- if(!md)
- ossl_raise(rb_eRuntimeError, "Unsupported digest algorithm (%"PRIsVALUE").", obj);
+ if (!md)
+ ossl_raise(eDigestError, "unsupported digest algorithm: %"PRIsVALUE,
+ obj);
} else {
EVP_MD_CTX *ctx;
diff --git a/test/openssl/test_digest.rb b/test/openssl/test_digest.rb
index 567cebf4b7..b5dc56928d 100644
--- a/test/openssl/test_digest.rb
+++ b/test/openssl/test_digest.rb
@@ -10,6 +10,12 @@ class OpenSSL::TestDigest < OpenSSL::TestCase
@d2 = OpenSSL::Digest::MD5.new
end
+ def test_initialize
+ assert_raise(OpenSSL::Digest::DigestError) {
+ OpenSSL::Digest.new("no such algorithm")
+ }
+ end
+
def test_digest
null_hex = "d41d8cd98f00b204e9800998ecf8427e"
null_bin = [null_hex].pack("H*")