CORE: Do a bit of cleanup of core fetching

Some data, like the library context, were passed both through higher
level callback structures and through arguments to those same higher
level callbacks.  This is a bit unnecessary, so we rearrange the
callback arguments to simply pass that callback structure and rely on
the higher level fetching functionality to pick out what data they
need from that structure.

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15750)
This commit is contained in:
Richard Levitte 2021-06-15 10:18:19 +02:00 committed by Matt Caswell
parent 9932585220
commit 6882652e65
6 changed files with 48 additions and 62 deletions

View file

@ -87,7 +87,6 @@ static const OSSL_LIB_CTX_METHOD encoder_store_method = {
/* Data to be passed through ossl_method_construct() */
struct encoder_data_st {
OSSL_LIB_CTX *libctx;
OSSL_METHOD_CONSTRUCT_METHOD *mcm;
int id; /* For get_encoder_from_store() */
const char *names; /* For get_encoder_from_store() */
const char *propquery; /* For get_encoder_from_store() */
@ -126,21 +125,20 @@ static OSSL_METHOD_STORE *get_encoder_store(OSSL_LIB_CTX *libctx)
}
/* Get encoder methods from a store, or put one in */
static void *get_encoder_from_store(OSSL_LIB_CTX *libctx, void *store,
void *data)
static void *get_encoder_from_store(void *store, void *data)
{
struct encoder_data_st *methdata = data;
void *method = NULL;
int id;
if ((id = methdata->id) == 0) {
OSSL_NAMEMAP *namemap = ossl_namemap_stored(libctx);
OSSL_NAMEMAP *namemap = ossl_namemap_stored(methdata->libctx);
id = ossl_namemap_name2num(namemap, methdata->names);
}
if (store == NULL
&& (store = get_encoder_store(libctx)) == NULL)
&& (store = get_encoder_store(methdata->libctx)) == NULL)
return NULL;
if (!ossl_method_store_fetch(store, id, methdata->propquery, &method))
@ -148,19 +146,20 @@ static void *get_encoder_from_store(OSSL_LIB_CTX *libctx, void *store,
return method;
}
static int put_encoder_in_store(OSSL_LIB_CTX *libctx, void *store,
void *method, const OSSL_PROVIDER *prov,
int operation_id, const char *names,
const char *propdef, void *unused)
static int put_encoder_in_store(void *store, void *method,
const OSSL_PROVIDER *prov,
const char *names, const char *propdef,
void *data)
{
struct encoder_data_st *methdata = data;
OSSL_NAMEMAP *namemap;
int id;
if ((namemap = ossl_namemap_stored(libctx)) == NULL
if ((namemap = ossl_namemap_stored(methdata->libctx)) == NULL
|| (id = ossl_namemap_name2num(namemap, names)) == 0)
return 0;
if (store == NULL && (store = get_encoder_store(libctx)) == NULL)
if (store == NULL && (store = get_encoder_store(methdata->libctx)) == NULL)
return 0;
return ossl_method_store_add(store, prov, id, propdef, method,
@ -360,7 +359,6 @@ inner_ossl_encoder_fetch(struct encoder_data_st *methdata, int id,
destruct_encoder
};
methdata->mcm = &mcm;
methdata->id = id;
methdata->names = name;
methdata->propquery = properties;