@@ -462,7 +462,6 @@ add_parameter_to_builder(VALUE key, VALUE value, VALUE arg) {
462462
463463 const char * key_ptr = StringValueCStr (key );
464464 const struct pkey_from_parameters_arg * params = (const struct pkey_from_parameters_arg * ) arg ;
465- const OSSL_PARAM * settable_params = params -> settable_params ;
466465
467466 for (size_t i = 0 ; i < params -> nAliases ; i ++ ) {
468467 if (strcmp (params -> aliases [i ].alias , key_ptr ) == 0 ) {
@@ -471,7 +470,7 @@ add_parameter_to_builder(VALUE key, VALUE value, VALUE arg) {
471470 }
472471 }
473472
474- for (; settable_params -> key != NULL ; settable_params ++ ) {
473+ for (const OSSL_PARAM * settable_params = params -> settable_params ; settable_params -> key != NULL ; settable_params ++ ) {
475474 if (strcmp (settable_params -> key , key_ptr ) == 0 ) {
476475 switch (settable_params -> data_type ) {
477476 case OSSL_PARAM_INTEGER :
@@ -506,9 +505,19 @@ add_parameter_to_builder(VALUE key, VALUE value, VALUE arg) {
506505 return ST_CONTINUE ;
507506 }
508507 }
509-
510508 OSSL_PARAM_BLD_free (params -> param_bld );
511- ossl_raise (ePKeyError , "Unsupported parameter \"%s\"" , key_ptr );
509+
510+ char message_buffer [512 ] = { 0 };
511+ char * cur = message_buffer ;
512+ char * end = message_buffer + sizeof (message_buffer );
513+ for (const OSSL_PARAM * settable_params = params -> settable_params ; settable_params -> key != NULL ; settable_params ++ ) {
514+ const char * fmt = cur == message_buffer ? "%s" : ", %s" ;
515+ if (cur > end )
516+ break ;
517+ cur += snprintf (cur , end - cur , fmt , settable_params -> key );
518+ }
519+
520+ ossl_raise (ePKeyError , "Invalid parameter \"%s\". Supported parameters: \"%s\"" , key_ptr , message_buffer );
512521}
513522
514523static VALUE
@@ -517,12 +526,14 @@ pkey_from_parameters(int argc, VALUE *argv, VALUE self)
517526 VALUE alg , options ;
518527 rb_scan_args (argc , argv , "11" , & alg , & options );
519528
520- EVP_PKEY_CTX * ctx = EVP_PKEY_CTX_new_from_name (NULL , StringValueCStr (alg ), NULL );
529+ const char * algorithm = StringValueCStr (alg );
530+
531+ EVP_PKEY_CTX * ctx = EVP_PKEY_CTX_new_from_name (NULL , algorithm , NULL );
521532
522533 if (ctx == NULL )
523534 ossl_raise (ePKeyError , "EVP_PKEY_CTX_new_from_name" );
524535
525- struct pkey_from_parameters_arg from_params_args ;
536+ struct pkey_from_parameters_arg from_params_args = { 0 } ;
526537
527538 from_params_args .param_bld = OSSL_PARAM_BLD_new ();
528539
@@ -531,15 +542,12 @@ pkey_from_parameters(int argc, VALUE *argv, VALUE self)
531542
532543 from_params_args .settable_params = EVP_PKEY_fromdata_settable (ctx , EVP_PKEY_KEYPAIR );
533544
534- if (strcmp ("RSA" , StringValueCStr ( alg ) ) == 0 ) {
545+ if (strcmp ("RSA" , algorithm ) == 0 ) {
535546 from_params_args .aliases = rsa_aliases ;
536547 from_params_args .nAliases = sizeof (rsa_aliases )/sizeof ((rsa_aliases )[0 ]);
537- } else if (strcmp ("DSA" , StringValueCStr (alg )) == 0 ||
538- strcmp ("DH" , StringValueCStr (alg )) == 0 ) {
548+ } else {
539549 from_params_args .aliases = fcc_aliases ;
540550 from_params_args .nAliases = sizeof (fcc_aliases )/sizeof ((fcc_aliases )[0 ]);
541- } else {
542- from_params_args .nAliases = 0 ;
543551 }
544552
545553 rb_hash_foreach (options , & add_parameter_to_builder , (VALUE ) & from_params_args );
@@ -559,7 +567,7 @@ pkey_from_parameters(int argc, VALUE *argv, VALUE self)
559567 ossl_raise (ePKeyError , "EVP_PKEY_fromdata_init" );
560568 }
561569
562- if (EVP_PKEY_fromdata (ctx , & pkey , EVP_PKEY_KEYPAIR , params ) <= 0 ) {
570+ if (EVP_PKEY_fromdata (ctx , & pkey , EVP_PKEY_KEYPAIR , params ) <= 0 ) {
563571 EVP_PKEY_CTX_free (ctx );
564572 EVP_PKEY_free (pkey );
565573 ossl_raise (ePKeyError , "EVP_PKEY_fromdata" );
0 commit comments