summaryrefslogtreecommitdiffstats
path: root/crypto/encode_decode
diff options
context:
space:
mode:
authorRichard Levitte <levitte@openssl.org>2021-06-24 18:44:26 +0200
committerPauli <pauli@openssl.org>2021-06-26 16:44:22 +1000
commit92eb592b3b70a1f8e08b7160e54e367ba0d0aca2 (patch)
tree418d49489284889a8170300a3a02f2177109a030 /crypto/encode_decode
parent56ba2b78eb68239166dc7e2373b34f3f10be7fc3 (diff)
ENCODER & DECODER: Allow en/decoders to have multiple names
We had prepared for this a little bit, but apparently not completed it. Reviewed-by: Paul Dale <pauli@openssl.org> (Merged from https://github.com/openssl/openssl/pull/15904)
Diffstat (limited to 'crypto/encode_decode')
-rw-r--r--crypto/encode_decode/decoder_meth.c32
-rw-r--r--crypto/encode_decode/encoder_meth.c32
2 files changed, 58 insertions, 6 deletions
diff --git a/crypto/encode_decode/decoder_meth.c b/crypto/encode_decode/decoder_meth.c
index 097605cfdc..8f0786c941 100644
--- a/crypto/encode_decode/decoder_meth.c
+++ b/crypto/encode_decode/decoder_meth.c
@@ -131,12 +131,25 @@ static void *get_decoder_from_store(void *store, void *data)
void *method = NULL;
int id;
- if ((id = methdata->id) == 0) {
+ /*
+ * get_decoder_from_store() is only called to try and get the method
+ * that OSSL_DECODER_fetch() is asking for, and the name or name id are
+ * passed via methdata.
+ */
+ if ((id = methdata->id) == 0 && methdata->names != NULL) {
OSSL_NAMEMAP *namemap = ossl_namemap_stored(methdata->libctx);
+ const char *names = methdata->names;
+ const char *q = strchr(names, NAME_SEPARATOR);
+ size_t l = (q == NULL ? strlen(names) : (size_t)(q - names));
- id = ossl_namemap_name2num(namemap, methdata->names);
+ if (namemap == 0)
+ return NULL;
+ id = ossl_namemap_name2num_n(namemap, names, l);
}
+ if (id == 0)
+ return NULL;
+
if (store == NULL
&& (store = get_decoder_store(methdata->libctx)) == NULL)
return NULL;
@@ -154,9 +167,22 @@ static int put_decoder_in_store(void *store, void *method,
struct decoder_data_st *methdata = data;
OSSL_NAMEMAP *namemap;
int id;
+ size_t l = 0;
+
+ /*
+ * put_decoder_in_store() is only called with an OSSL_DECODER method that
+ * was successfully created by construct_decoder() below, which means that
+ * all the names should already be stored in the namemap with the same
+ * numeric identity, so just use the first to get that identity.
+ */
+ if (names != NULL) {
+ const char *q = strchr(names, NAME_SEPARATOR);
+
+ l = (q == NULL ? strlen(names) : (size_t)(q - names));
+ }
if ((namemap = ossl_namemap_stored(methdata->libctx)) == NULL
- || (id = ossl_namemap_name2num(namemap, names)) == 0)
+ || (id = ossl_namemap_name2num_n(namemap, names, l)) == 0)
return 0;
if (store == NULL && (store = get_decoder_store(methdata->libctx)) == NULL)
diff --git a/crypto/encode_decode/encoder_meth.c b/crypto/encode_decode/encoder_meth.c
index 823def8843..9f7ecc82cb 100644
--- a/crypto/encode_decode/encoder_meth.c
+++ b/crypto/encode_decode/encoder_meth.c
@@ -131,12 +131,25 @@ static void *get_encoder_from_store(void *store, void *data)
void *method = NULL;
int id;
- if ((id = methdata->id) == 0) {
+ /*
+ * get_encoder_from_store() is only called to try and get the method
+ * that OSSL_ENCODER_fetch() is asking for, and the name or name id are
+ * passed via methdata.
+ */
+ if ((id = methdata->id) == 0 && methdata->names != NULL) {
OSSL_NAMEMAP *namemap = ossl_namemap_stored(methdata->libctx);
+ const char *names = methdata->names;
+ const char *q = strchr(names, NAME_SEPARATOR);
+ size_t l = (q == NULL ? strlen(names) : (size_t)(q - names));
- id = ossl_namemap_name2num(namemap, methdata->names);
+ if (namemap == 0)
+ return NULL;
+ id = ossl_namemap_name2num_n(namemap, methdata->names, l);
}
+ if (id == 0)
+ return NULL;
+
if (store == NULL
&& (store = get_encoder_store(methdata->libctx)) == NULL)
return NULL;
@@ -154,9 +167,22 @@ static int put_encoder_in_store(void *store, void *method,
struct encoder_data_st *methdata = data;
OSSL_NAMEMAP *namemap;
int id;
+ size_t l = 0;
+
+ /*
+ * put_encoder_in_store() is only called with an OSSL_ENCODER method that
+ * was successfully created by construct_encoder() below, which means that
+ * all the names should already be stored in the namemap with the same
+ * numeric identity, so just use the first to get that identity.
+ */
+ if (names != NULL) {
+ const char *q = strchr(names, NAME_SEPARATOR);
+
+ l = (q == NULL ? strlen(names) : (size_t)(q - names));
+ }
if ((namemap = ossl_namemap_stored(methdata->libctx)) == NULL
- || (id = ossl_namemap_name2num(namemap, names)) == 0)
+ || (id = ossl_namemap_name2num_n(namemap, names, l)) == 0)
return 0;
if (store == NULL && (store = get_encoder_store(methdata->libctx)) == NULL)