From 783c99e6c7e0f173f8d804d2909522ce3041e8dc Mon Sep 17 00:00:00 2001 From: Augustin Gottlieb <33221555+aguspe@users.noreply.github.com> Date: Fri, 2 Jan 2026 17:54:42 +0100 Subject: [PATCH] Improve Argument Error Message in EC:Group.new Before, passing the wrong number of arguments (e.g., 2) to OpenSSL::PKey::EC::Group.new raised a generic "wrong number of arguments" error. This change updates it to show the actual argument count and the expected options (1 or 4), making debugging easier for the user. Example: ArgumentError: wrong number of arguments (given 2, expected 1 or 4) I hope it helps! --- ext/openssl/ossl_pkey_ec.c | 2 +- test/openssl/test_pkey_ec.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/ext/openssl/ossl_pkey_ec.c b/ext/openssl/ossl_pkey_ec.c index bb19533ed..35f031819 100644 --- a/ext/openssl/ossl_pkey_ec.c +++ b/ext/openssl/ossl_pkey_ec.c @@ -702,7 +702,7 @@ static VALUE ossl_ec_group_initialize(int argc, VALUE *argv, VALUE self) break; default: - ossl_raise(rb_eArgError, "wrong number of arguments"); + ossl_raise(rb_eArgError, "wrong number of arguments (given %d, expected 1 or 4)", argc); } ASSUME(group); diff --git a/test/openssl/test_pkey_ec.rb b/test/openssl/test_pkey_ec.rb index 88085bc68..ec97a747a 100644 --- a/test/openssl/test_pkey_ec.rb +++ b/test/openssl/test_pkey_ec.rb @@ -345,6 +345,15 @@ def test_ec_group assert_equal group1.degree, group4.degree end + def test_ec_group_initialize_error_message + # Test that passing 2 arguments raises the helpful error + e = assert_raise(ArgumentError) do + OpenSSL::PKey::EC::Group.new(:GFp, 123) + end + + assert_equal("wrong number of arguments (given 2, expected 1 or 4)", e.message) + end + def test_ec_point group = OpenSSL::PKey::EC::Group.new("prime256v1") key = OpenSSL::PKey::EC.generate(group)