Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions ext/openssl/ossl_pkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,9 @@ ossl_pkey_new_from_data(int argc, VALUE *argv, VALUE self)
return ossl_pkey_wrap(pkey);
}

static VALUE
pkey_ctx_apply_options_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, ctx_v))
static int
pkey_ctx_apply_options_i(VALUE key, VALUE value, VALUE ctx_v)
{
VALUE key = rb_ary_entry(i, 0), value = rb_ary_entry(i, 1);
EVP_PKEY_CTX *ctx = (EVP_PKEY_CTX *)ctx_v;

if (SYMBOL_P(key))
Expand All @@ -255,7 +254,7 @@ pkey_ctx_apply_options_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, ctx_v))
if (EVP_PKEY_CTX_ctrl_str(ctx, StringValueCStr(key), StringValueCStr(value)) <= 0)
ossl_raise(ePKeyError, "EVP_PKEY_CTX_ctrl_str(ctx, %+"PRIsVALUE", %+"PRIsVALUE")",
key, value);
return Qnil;
return ST_CONTINUE;
}

static VALUE
Expand All @@ -264,8 +263,7 @@ pkey_ctx_apply_options0(VALUE args_v)
VALUE *args = (VALUE *)args_v;
Check_Type(args[1], T_HASH);

rb_block_call(args[1], rb_intern("each"), 0, NULL,
pkey_ctx_apply_options_i, args[0]);
rb_hash_foreach(args[1], pkey_ctx_apply_options_i, args[0]);
return Qnil;
}

Expand Down
13 changes: 13 additions & 0 deletions test/openssl/test_pkey.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ def test_s_generate_parameters
}
end

def test_s_generate_parameters_options_without_each
omit "rb_hash_foreach() works differently" if RUBY_ENGINE == "truffleruby"

options_class = Class.new(Hash) {
def each
raise "must not be called"
end
}
options = options_class["ec_paramgen_curve" => "secp384r1"]
pkey = OpenSSL::PKey.generate_parameters("EC", options)
assert_equal "secp384r1", pkey.group.curve_name
end

def test_s_generate_parameters_with_block
# DSA kengen is not FIPS-approved.
# https://github.com/openssl/openssl/commit/49a35f0#diff-605396c063194975af8ce31399d42690ab18186b422fb5012101cc9132660fe1R611-R614
Expand Down
Loading