Skip to content

Commit b2b7752

Browse files
committed
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.
1 parent 99e8630 commit b2b7752

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

ext/openssl/ossl_pkey.c

+14-8
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ ossl_pkey_new_from_data(int argc, VALUE *argv, VALUE self)
198198
}
199199

200200
static VALUE
201-
pkey_gen_apply_options_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, ctx_v))
201+
pkey_ctx_apply_options_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, ctx_v))
202202
{
203203
VALUE key = rb_ary_entry(i, 0), value = rb_ary_entry(i, 1);
204204
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))
214214
}
215215

216216
static VALUE
217-
pkey_gen_apply_options0(VALUE args_v)
217+
pkey_ctx_apply_options0(VALUE args_v)
218218
{
219219
VALUE *args = (VALUE *)args_v;
220220

221221
rb_block_call(args[1], rb_intern("each"), 0, NULL,
222-
pkey_gen_apply_options_i, args[0]);
222+
pkey_ctx_apply_options_i, args[0]);
223223
return Qnil;
224224
}
225225

226+
static void
227+
pkey_ctx_apply_options(EVP_PKEY_CTX *ctx, VALUE options, int *state)
228+
{
229+
VALUE args[2];
230+
args[0] = (VALUE)ctx;
231+
args[1] = options;
232+
233+
rb_protect(pkey_ctx_apply_options0, (VALUE)args, state);
234+
}
235+
226236
struct pkey_blocking_generate_arg {
227237
EVP_PKEY_CTX *ctx;
228238
EVP_PKEY *pkey;
@@ -330,11 +340,7 @@ pkey_generate(int argc, VALUE *argv, VALUE self, int genparam)
330340
}
331341

332342
if (!NIL_P(options)) {
333-
VALUE args[2];
334-
335-
args[0] = (VALUE)ctx;
336-
args[1] = options;
337-
rb_protect(pkey_gen_apply_options0, (VALUE)args, &state);
343+
pkey_ctx_apply_options(ctx, options, &state);
338344
if (state) {
339345
EVP_PKEY_CTX_free(ctx);
340346
rb_jump_tag(state);

0 commit comments

Comments
 (0)