Skip to content

Commit

Permalink
pkey: prepare pkey_ctx_apply_options() for usage by other operations
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rhenium committed Apr 4, 2021
1 parent 99e8630 commit b2b7752
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions ext/openssl/ossl_pkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit b2b7752

Please sign in to comment.