encoder: add a _name() function for encoders and decoders
authorPauli <pauli@openssl.org>
Mon, 10 May 2021 03:05:08 +0000 (13:05 +1000)
committerPauli <pauli@openssl.org>
Wed, 12 May 2021 08:40:57 +0000 (18:40 +1000)
Reviewed-by: Tim Hudson <tjh@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15211)

crypto/encode_decode/decoder_meth.c
crypto/encode_decode/encoder_local.h
crypto/encode_decode/encoder_meth.c
include/openssl/decoder.h
include/openssl/encoder.h

index 7a271f7408a2633f12d83800b48177353614e25f..48a52c9612e793b1183d8ee25b2e778bb1fbc308 100644 (file)
@@ -58,6 +58,7 @@ void OSSL_DECODER_free(OSSL_DECODER *decoder)
     CRYPTO_DOWN_REF(&decoder->base.refcnt, &ref, decoder->base.lock);
     if (ref > 0)
         return;
+    OPENSSL_free(decoder->base.name);
     ossl_provider_free(decoder->base.prov);
     CRYPTO_THREAD_lock_free(decoder->base.lock);
     OPENSSL_free(decoder);
@@ -169,6 +170,10 @@ void *ossl_decoder_from_algorithm(int id, const OSSL_ALGORITHM *algodef,
     if ((decoder = ossl_decoder_new()) == NULL)
         return NULL;
     decoder->base.id = id;
+    if ((decoder->base.name = ossl_algorithm_get1_first_name(algodef)) == NULL) {
+        OSSL_DECODER_free(decoder);
+        return NULL;
+    }
     decoder->base.propdef = algodef->property_definition;
     decoder->base.description = algodef->algorithm_description;
 
@@ -426,6 +431,11 @@ int OSSL_DECODER_number(const OSSL_DECODER *decoder)
     return decoder->base.id;
 }
 
+const char *OSSL_DECODER_name(const OSSL_DECODER *decoder)
+{
+    return decoder->base.name;
+}
+
 const char *OSSL_DECODER_description(const OSSL_DECODER *decoder)
 {
     return decoder->base.description;
index c58362ae027268e8ff5f3b9c075286b57172191d..d53f760379413a2676f37b038f78371cb2788bc3 100644 (file)
@@ -19,6 +19,7 @@
 struct ossl_endecode_base_st {
     OSSL_PROVIDER *prov;
     int id;
+    char *name;
     const char *propdef;
     const char *description;
 
index bb319460b942822c15ec196ac1c4c739e8289c07..3b2bc2d83e01bb4c9d936edf5cf9a504dd548202 100644 (file)
@@ -58,6 +58,7 @@ void OSSL_ENCODER_free(OSSL_ENCODER *encoder)
     CRYPTO_DOWN_REF(&encoder->base.refcnt, &ref, encoder->base.lock);
     if (ref > 0)
         return;
+    OPENSSL_free(encoder->base.name);
     ossl_provider_free(encoder->base.prov);
     CRYPTO_THREAD_lock_free(encoder->base.lock);
     OPENSSL_free(encoder);
@@ -169,6 +170,10 @@ static void *encoder_from_algorithm(int id, const OSSL_ALGORITHM *algodef,
     if ((encoder = ossl_encoder_new()) == NULL)
         return NULL;
     encoder->base.id = id;
+    if ((encoder->base.name = ossl_algorithm_get1_first_name(algodef)) == NULL) {
+        OSSL_ENCODER_free(encoder);
+        return NULL;
+    }
     encoder->base.propdef = algodef->property_definition;
     encoder->base.description = algodef->algorithm_description;
 
@@ -438,6 +443,11 @@ int OSSL_ENCODER_number(const OSSL_ENCODER *encoder)
     return encoder->base.id;
 }
 
+const char *OSSL_ENCODER_name(const OSSL_ENCODER *encoder)
+{
+    return encoder->base.name;
+}
+
 const char *OSSL_ENCODER_description(const OSSL_ENCODER *encoder)
 {
     return encoder->base.description;
index 974fbb02ad65d6e2ba984f624c2042c544dd4675..afe4988fdb901f13b04ea11d3f0f038bf2509565 100644 (file)
@@ -34,6 +34,7 @@ void OSSL_DECODER_free(OSSL_DECODER *encoder);
 const OSSL_PROVIDER *OSSL_DECODER_provider(const OSSL_DECODER *encoder);
 const char *OSSL_DECODER_properties(const OSSL_DECODER *encoder);
 int OSSL_DECODER_number(const OSSL_DECODER *encoder);
+const char *OSSL_DECODER_name(const OSSL_DECODER *decoder);
 const char *OSSL_DECODER_description(const OSSL_DECODER *decoder);
 int OSSL_DECODER_is_a(const OSSL_DECODER *encoder, const char *name);
 
index c51bd02a2b3509b258765532c55d21206cc9899f..4e2c5fe23ccd04ed40f904fb00a1c2e14034828a 100644 (file)
@@ -34,6 +34,7 @@ void OSSL_ENCODER_free(OSSL_ENCODER *encoder);
 const OSSL_PROVIDER *OSSL_ENCODER_provider(const OSSL_ENCODER *encoder);
 const char *OSSL_ENCODER_properties(const OSSL_ENCODER *encoder);
 int OSSL_ENCODER_number(const OSSL_ENCODER *encoder);
+const char *OSSL_ENCODER_name(const OSSL_ENCODER *kdf);
 const char *OSSL_ENCODER_description(const OSSL_ENCODER *kdf);
 int OSSL_ENCODER_is_a(const OSSL_ENCODER *encoder, const char *name);