@@ -544,11 +544,18 @@ pkey_from_parameters(int argc, VALUE *argv, VALUE self)
544544
545545 from_params_args .param_bld = OSSL_PARAM_BLD_new ();
546546
547- if (from_params_args .param_bld == NULL )
547+ if (from_params_args .param_bld == NULL ) {
548+ EVP_PKEY_CTX_free (ctx );
548549 ossl_raise (ePKeyError , "OSSL_PARAM_BLD_new" );
550+ }
549551
550552 from_params_args .settable_params = EVP_PKEY_fromdata_settable (ctx , EVP_PKEY_KEYPAIR );
551553
554+ if (from_params_args .settable_params == NULL ) {
555+ EVP_PKEY_CTX_free (ctx );
556+ ossl_raise (ePKeyError , "EVP_PKEY_fromdata_settable" );
557+ }
558+
552559 if (strcmp ("RSA" , algorithm ) == 0 ) {
553560 from_params_args .aliases = rsa_aliases ;
554561 from_params_args .nAliases = sizeof (rsa_aliases )/sizeof ((rsa_aliases )[0 ]);
@@ -638,6 +645,22 @@ ossl_pkey_s_generate_key(int argc, VALUE *argv, VALUE self)
638645 return pkey_generate (argc , argv , self , 0 );
639646}
640647
648+ /*
649+ * call-seq:
650+ * OpenSSL::PKey.from_parameters(algo_name, parameters) -> pkey
651+ *
652+ * Generates a new key based on given key parameters.
653+ *
654+ * The first parameter is the type of the key to create, given as a String, for example RSA, DSA, EC etc.
655+ * Second parameter is the parameters to be used for the key.
656+ *
657+ * For details algorithms and parameters see https://www.openssl.org/docs/man3.0/man3/EVP_PKEY_fromdata.html
658+ *
659+ * == Example
660+ * pkey = OpenSSL::PKey.from_parameters("RSA", n: 3161751493, e: 65537, d: 2064855961)
661+ * pkey.private? #=> true
662+ * pkey.public_key #=> #<OpenSSL::PKey::RSA...
663+ */
641664static VALUE
642665ossl_pkey_s_from_parameters (int argc , VALUE * argv , VALUE self )
643666{
0 commit comments