@@ -478,7 +478,8 @@ struct pkey_from_data_arg {
478478};
479479
480480static  int 
481- add_data_to_builder (VALUE  key , VALUE  value , VALUE  arg ) {
481+ add_data_to_builder (VALUE  key , VALUE  value , VALUE  arg )
482+ {
482483    if (NIL_P (value ))
483484        return  ST_CONTINUE ;
484485
@@ -521,6 +522,9 @@ add_data_to_builder(VALUE key, VALUE value, VALUE arg) {
521522            case  OSSL_PARAM_OCTET_PTR :
522523                ossl_raise (ePKeyError , "Unsupported parameter \"%s\", handling of OSSL_PARAM_UTF8_PTR and OSSL_PARAM_OCTET_PTR not implemented" , key_ptr );
523524                break ;
525+             default :
526+                 ossl_raise (ePKeyError , "Unsupported parameter \"%s\"" , key_ptr );
527+                 break ;
524528            }
525529
526530            return  ST_CONTINUE ;
@@ -612,7 +616,6 @@ pkey_from_data(int argc, VALUE *argv, VALUE self)
612616
613617    if  (EVP_PKEY_fromdata (ctx , & pkey , EVP_PKEY_KEYPAIR , params ) <= 0 ) {
614618        EVP_PKEY_CTX_free (ctx );
615-         EVP_PKEY_free (pkey );
616619        ossl_raise (ePKeyError , "EVP_PKEY_fromdata" );
617620    }
618621
@@ -690,18 +693,15 @@ ossl_pkey_s_generate_key(int argc, VALUE *argv, VALUE self)
690693 * == Example 
691694 *   pkey = OpenSSL::PKey.from_data("RSA", n: 3161751493, e: 65537, d: 2064855961) 
692695 *   pkey.private? #=> true 
693-  *   pkey.public_key  #=> #<OpenSSL::PKey::RSA...  
696+  *   pkey.n  #=> #<OpenSSL::BN 3161751493>  
694697 */ 
698+ #if  OSSL_OPENSSL_PREREQ (3 , 0 , 0 )
695699static  VALUE 
696700ossl_pkey_s_from_data (int  argc , VALUE  * argv , VALUE  self )
697701{
698- #if  OSSL_OPENSSL_PREREQ (3 , 0 , 0 )
699-     return  pkey_from_data (argc , argv , self );
700- #else 
701-     rb_raise (ePKeyError , "OpenSSL::PKey.from_data requires OpenSSL 3.0 or later" );
702- #endif 
702+   return  pkey_from_data (argc , argv , self );
703703}
704- 
704+ #endif 
705705/* 
706706 * TODO: There is no convenient way to check the presence of public key 
707707 * components on OpenSSL 3.0. But since keys are immutable on 3.0, pkeys without 
@@ -1955,8 +1955,9 @@ Init_ossl_pkey(void)
19551955    rb_define_module_function (mPKey , "read" , ossl_pkey_new_from_data , -1 );
19561956    rb_define_module_function (mPKey , "generate_parameters" , ossl_pkey_s_generate_parameters , -1 );
19571957    rb_define_module_function (mPKey , "generate_key" , ossl_pkey_s_generate_key , -1 );
1958+ #if  OSSL_OPENSSL_PREREQ (3 , 0 , 0 )
19581959    rb_define_module_function (mPKey , "from_data" , ossl_pkey_s_from_data , -1 );
1959- 
1960+ #endif 
19601961#ifdef  HAVE_EVP_PKEY_NEW_RAW_PRIVATE_KEY 
19611962    rb_define_module_function (mPKey , "new_raw_private_key" , ossl_pkey_new_raw_private_key , 2 );
19621963    rb_define_module_function (mPKey , "new_raw_public_key" , ossl_pkey_new_raw_public_key , 2 );
0 commit comments