From b2b77527fd338c96028565e78e1b05832e312e34 Mon Sep 17 00:00:00 2001 From: Kazuki Yamaguchi Date: Fri, 2 Apr 2021 23:58:48 +0900 Subject: 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. --- ext/openssl/ossl_pkey.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'ext/openssl/ossl_pkey.c') diff --git a/ext/openssl/ossl_pkey.c b/ext/openssl/ossl_pkey.c index d3c65a4b..718e868c 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); -- cgit v1.2.3