@@ -478,7 +478,8 @@ struct pkey_from_data_arg {
478
478
};
479
479
480
480
static int
481
- add_data_to_builder (VALUE key , VALUE value , VALUE arg ) {
481
+ add_data_to_builder (VALUE key , VALUE value , VALUE arg )
482
+ {
482
483
if (NIL_P (value ))
483
484
return ST_CONTINUE ;
484
485
@@ -521,6 +522,9 @@ add_data_to_builder(VALUE key, VALUE value, VALUE arg) {
521
522
case OSSL_PARAM_OCTET_PTR :
522
523
ossl_raise (ePKeyError , "Unsupported parameter \"%s\", handling of OSSL_PARAM_UTF8_PTR and OSSL_PARAM_OCTET_PTR not implemented" , key_ptr );
523
524
break ;
525
+ default :
526
+ ossl_raise (ePKeyError , "Unsupported parameter \"%s\"" , key_ptr );
527
+ break ;
524
528
}
525
529
526
530
return ST_CONTINUE ;
@@ -612,7 +616,6 @@ pkey_from_data(int argc, VALUE *argv, VALUE self)
612
616
613
617
if (EVP_PKEY_fromdata (ctx , & pkey , EVP_PKEY_KEYPAIR , params ) <= 0 ) {
614
618
EVP_PKEY_CTX_free (ctx );
615
- EVP_PKEY_free (pkey );
616
619
ossl_raise (ePKeyError , "EVP_PKEY_fromdata" );
617
620
}
618
621
@@ -690,18 +693,15 @@ ossl_pkey_s_generate_key(int argc, VALUE *argv, VALUE self)
690
693
* == Example
691
694
* pkey = OpenSSL::PKey.from_data("RSA", n: 3161751493, e: 65537, d: 2064855961)
692
695
* pkey.private? #=> true
693
- * pkey.public_key #=> #<OpenSSL::PKey::RSA...
696
+ * pkey.n #=> #<OpenSSL::BN 3161751493>
694
697
*/
698
+ #if OSSL_OPENSSL_PREREQ (3 , 0 , 0 )
695
699
static VALUE
696
700
ossl_pkey_s_from_data (int argc , VALUE * argv , VALUE self )
697
701
{
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 );
703
703
}
704
-
704
+ #endif
705
705
/*
706
706
* TODO: There is no convenient way to check the presence of public key
707
707
* components on OpenSSL 3.0. But since keys are immutable on 3.0, pkeys without
@@ -1955,8 +1955,9 @@ Init_ossl_pkey(void)
1955
1955
rb_define_module_function (mPKey , "read" , ossl_pkey_new_from_data , -1 );
1956
1956
rb_define_module_function (mPKey , "generate_parameters" , ossl_pkey_s_generate_parameters , -1 );
1957
1957
rb_define_module_function (mPKey , "generate_key" , ossl_pkey_s_generate_key , -1 );
1958
+ #if OSSL_OPENSSL_PREREQ (3 , 0 , 0 )
1958
1959
rb_define_module_function (mPKey , "from_data" , ossl_pkey_s_from_data , -1 );
1959
-
1960
+ #endif
1960
1961
#ifdef HAVE_EVP_PKEY_NEW_RAW_PRIVATE_KEY
1961
1962
rb_define_module_function (mPKey , "new_raw_private_key" , ossl_pkey_new_raw_private_key , 2 );
1962
1963
rb_define_module_function (mPKey , "new_raw_public_key" , ossl_pkey_new_raw_public_key , 2 );
0 commit comments