Skip to content

Commit

Permalink
Use empty entry to indicate end of aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
anakinj committed Jan 6, 2023
1 parent 4dbf24d commit e3c722f
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions ext/openssl/ossl_pkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -437,19 +437,20 @@ static const struct pkey_from_parameters_alias rsa_aliases[] = {
{ "q", OSSL_PKEY_PARAM_RSA_FACTOR2 },
{ "dmp1", OSSL_PKEY_PARAM_RSA_EXPONENT1 },
{ "dmq1", OSSL_PKEY_PARAM_RSA_EXPONENT2 },
{ "iqmp", OSSL_PKEY_PARAM_RSA_COEFFICIENT1 }
{ "iqmp", OSSL_PKEY_PARAM_RSA_COEFFICIENT1 },
{ "", "" }
};

static const struct pkey_from_parameters_alias fcc_aliases[] = {
{ "pub_key", OSSL_PKEY_PARAM_PUB_KEY },
{ "priv_key", OSSL_PKEY_PARAM_PRIV_KEY }
{ "priv_key", OSSL_PKEY_PARAM_PRIV_KEY },
{ "", "" }
};

struct pkey_from_parameters_arg {
OSSL_PARAM_BLD *param_bld;
const OSSL_PARAM *settable_params;
const struct pkey_from_parameters_alias *aliases;
size_t nAliases;
};

static int
Expand All @@ -463,7 +464,7 @@ add_parameter_to_builder(VALUE key, VALUE value, VALUE arg) {
const char *key_ptr = StringValueCStr(key);
const struct pkey_from_parameters_arg *params = (const struct pkey_from_parameters_arg *) arg;

for(size_t i = 0; i < params->nAliases; i++) {
for(int i = 0; strlen(params->aliases[i].alias) > 0; i++) {
if(strcmp(params->aliases[i].alias, key_ptr) == 0) {
key_ptr = params->aliases[i].param_name;
break;
Expand Down Expand Up @@ -517,7 +518,7 @@ add_parameter_to_builder(VALUE key, VALUE value, VALUE arg) {
cur += snprintf(cur, end-cur, fmt, settable_params->key);
}

for(size_t i = 0; i < params->nAliases; i++) {
for(int i = 0; strlen(params->aliases[i].alias) > 0; i++) {
const char *fmt = cur == message_buffer ? "%s" : ", %s";
if (cur > end)
break;
Expand Down Expand Up @@ -556,13 +557,10 @@ pkey_from_parameters(int argc, VALUE *argv, VALUE self)
ossl_raise(ePKeyError, "EVP_PKEY_fromdata_settable");
}

if (strcmp("RSA", algorithm) == 0) {
if (strcmp("RSA", algorithm) == 0)
from_params_args.aliases = rsa_aliases;
from_params_args.nAliases = sizeof(rsa_aliases)/sizeof((rsa_aliases)[0]);
} else {
else
from_params_args.aliases = fcc_aliases;
from_params_args.nAliases = sizeof(fcc_aliases)/sizeof((fcc_aliases)[0]);
}

rb_hash_foreach(options, &add_parameter_to_builder, (VALUE) &from_params_args);

Expand Down

0 comments on commit e3c722f

Please sign in to comment.