diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2021-04-02 23:58:48 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2021-07-18 17:44:45 +0900 |
commit | e2014d03542b7d1a9d4a624f82fb94c9a8119fdb (patch) | |
tree | bda85f4b80e4040d9f9715737177d92040e9c373 /ext | |
parent | 1706302be51454c4c81ab06b771e8cad8879078e (diff) | |
download | ruby-e2014d03542b7d1a9d4a624f82fb94c9a8119fdb.tar.gz |
[ruby/openssl] pkey: prepare pkey_ctx_apply_options() for usage by other operations
The routine to apply Hash to EVP_PKEY_CTX_ctrl_str() is currently used
by key generation, but it is useful for other operations too. Let's
change it to a slightly more generic name.
https://github.com/ruby/openssl/commit/b2b77527fd
Diffstat (limited to 'ext')
-rw-r--r-- | ext/openssl/ossl_pkey.c | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/ext/openssl/ossl_pkey.c b/ext/openssl/ossl_pkey.c index d3c65a4b3e..718e868cb9 100644 --- a/ext/openssl/ossl_pkey.c +++ b/ext/openssl/ossl_pkey.c @@ -198,7 +198,7 @@ ossl_pkey_new_from_data(int argc, VALUE *argv, VALUE self) } static VALUE -pkey_gen_apply_options_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, ctx_v)) +pkey_ctx_apply_options_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, ctx_v)) { VALUE key = rb_ary_entry(i, 0), value = rb_ary_entry(i, 1); EVP_PKEY_CTX *ctx = (EVP_PKEY_CTX *)ctx_v; @@ -214,15 +214,25 @@ pkey_gen_apply_options_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, ctx_v)) } static VALUE -pkey_gen_apply_options0(VALUE args_v) +pkey_ctx_apply_options0(VALUE args_v) { VALUE *args = (VALUE *)args_v; rb_block_call(args[1], rb_intern("each"), 0, NULL, - pkey_gen_apply_options_i, args[0]); + pkey_ctx_apply_options_i, args[0]); return Qnil; } +static void +pkey_ctx_apply_options(EVP_PKEY_CTX *ctx, VALUE options, int *state) +{ + VALUE args[2]; + args[0] = (VALUE)ctx; + args[1] = options; + + rb_protect(pkey_ctx_apply_options0, (VALUE)args, state); +} + struct pkey_blocking_generate_arg { EVP_PKEY_CTX *ctx; EVP_PKEY *pkey; @@ -330,11 +340,7 @@ pkey_generate(int argc, VALUE *argv, VALUE self, int genparam) } if (!NIL_P(options)) { - VALUE args[2]; - - args[0] = (VALUE)ctx; - args[1] = options; - rb_protect(pkey_gen_apply_options0, (VALUE)args, &state); + pkey_ctx_apply_options(ctx, options, &state); if (state) { EVP_PKEY_CTX_free(ctx); rb_jump_tag(state); |