summaryrefslogtreecommitdiffstats
path: root/crypto/encode_decode/encoder_meth.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/encode_decode/encoder_meth.c')
-rw-r--r--crypto/encode_decode/encoder_meth.c63
1 files changed, 40 insertions, 23 deletions
diff --git a/crypto/encode_decode/encoder_meth.c b/crypto/encode_decode/encoder_meth.c
index 5e57848054..eff9ddac54 100644
--- a/crypto/encode_decode/encoder_meth.c
+++ b/crypto/encode_decode/encoder_meth.c
@@ -91,6 +91,8 @@ struct encoder_data_st {
const char *names; /* For get_encoder_from_store() */
const char *propquery; /* For get_encoder_from_store() */
+ OSSL_METHOD_STORE *tmp_store; /* For get_tmp_encoder_store() */
+
unsigned int flag_construct_error_occurred : 1;
};
@@ -100,9 +102,13 @@ struct encoder_data_st {
*/
/* Temporary encoder method store, constructor and destructor */
-static void *alloc_tmp_encoder_store(OSSL_LIB_CTX *ctx)
+static void *get_tmp_encoder_store(void *data)
{
- return ossl_method_store_new(ctx);
+ struct encoder_data_st *methdata = data;
+
+ if (methdata->tmp_store == NULL)
+ methdata->tmp_store = ossl_method_store_new(methdata->libctx);
+ return methdata->tmp_store;
}
static void dealloc_tmp_encoder_store(void *store)
@@ -310,12 +316,12 @@ static void free_encoder(void *method)
}
/* Fetching support. Can fetch by numeric identity or by name */
-static OSSL_ENCODER *inner_ossl_encoder_fetch(OSSL_LIB_CTX *libctx,
- int id, const char *name,
- const char *properties)
+static OSSL_ENCODER *
+inner_ossl_encoder_fetch(struct encoder_data_st *methdata, int id,
+ const char *name, const char *properties)
{
- OSSL_METHOD_STORE *store = get_encoder_store(libctx);
- OSSL_NAMEMAP *namemap = ossl_namemap_stored(libctx);
+ OSSL_METHOD_STORE *store = get_encoder_store(methdata->libctx);
+ OSSL_NAMEMAP *namemap = ossl_namemap_stored(methdata->libctx);
void *method = NULL;
int unsupported = 0;
@@ -346,24 +352,21 @@ static OSSL_ENCODER *inner_ossl_encoder_fetch(OSSL_LIB_CTX *libctx,
if (id == 0
|| !ossl_method_store_cache_get(store, id, properties, &method)) {
OSSL_METHOD_CONSTRUCT_METHOD mcm = {
- alloc_tmp_encoder_store,
- dealloc_tmp_encoder_store,
+ get_tmp_encoder_store,
get_encoder_from_store,
put_encoder_in_store,
construct_encoder,
destruct_encoder
};
- struct encoder_data_st mcmdata;
-
- mcmdata.libctx = libctx;
- mcmdata.mcm = &mcm;
- mcmdata.id = id;
- mcmdata.names = name;
- mcmdata.propquery = properties;
- mcmdata.flag_construct_error_occurred = 0;
- if ((method = ossl_method_construct(libctx, OSSL_OP_ENCODER,
+
+ methdata->mcm = &mcm;
+ methdata->id = id;
+ methdata->names = name;
+ methdata->propquery = properties;
+ methdata->flag_construct_error_occurred = 0;
+ if ((method = ossl_method_construct(methdata->libctx, OSSL_OP_ENCODER,
0 /* !force_cache */,
- &mcm, &mcmdata)) != NULL) {
+ &mcm, methdata)) != NULL) {
/*
* If construction did create a method for us, we know that
* there is a correct name_id and meth_id, since those have
@@ -380,7 +383,7 @@ static OSSL_ENCODER *inner_ossl_encoder_fetch(OSSL_LIB_CTX *libctx,
* If we never were in the constructor, the algorithm to be fetched
* is unsupported.
*/
- unsupported = !mcmdata.flag_construct_error_occurred;
+ unsupported = !methdata->flag_construct_error_occurred;
}
if (method == NULL) {
@@ -390,7 +393,7 @@ static OSSL_ENCODER *inner_ossl_encoder_fetch(OSSL_LIB_CTX *libctx,
name = ossl_namemap_num2name(namemap, id, 0);
ERR_raise_data(ERR_LIB_OSSL_ENCODER, code,
"%s, Name (%s : %d), Properties (%s)",
- ossl_lib_ctx_get_descriptor(libctx),
+ ossl_lib_ctx_get_descriptor(methdata->libctx),
name = NULL ? "<null>" : name, id,
properties == NULL ? "<null>" : properties);
}
@@ -401,13 +404,27 @@ static OSSL_ENCODER *inner_ossl_encoder_fetch(OSSL_LIB_CTX *libctx,
OSSL_ENCODER *OSSL_ENCODER_fetch(OSSL_LIB_CTX *libctx, const char *name,
const char *properties)
{
- return inner_ossl_encoder_fetch(libctx, 0, name, properties);
+ struct encoder_data_st methdata;
+ void *method;
+
+ methdata.libctx = libctx;
+ methdata.tmp_store = NULL;
+ method = inner_ossl_encoder_fetch(&methdata, 0, name, properties);
+ dealloc_tmp_encoder_store(methdata.tmp_store);
+ return method;
}
OSSL_ENCODER *ossl_encoder_fetch_by_number(OSSL_LIB_CTX *libctx, int id,
const char *properties)
{
- return inner_ossl_encoder_fetch(libctx, id, NULL, properties);
+ struct encoder_data_st methdata;
+ void *method;
+
+ methdata.libctx = libctx;
+ methdata.tmp_store = NULL;
+ method = inner_ossl_encoder_fetch(&methdata, id, NULL, properties);
+ dealloc_tmp_encoder_store(methdata.tmp_store);
+ return method;
}
/*