From: Pauli Date: Mon, 10 May 2021 03:05:08 +0000 (+1000) Subject: encoder: add a _name() function for encoders and decoders X-Git-Tag: openssl-3.0.0-alpha17~165 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4966411789f9337b311eacb5c45ddd3e750d4c17;p=thirdparty%2Fopenssl.git encoder: add a _name() function for encoders and decoders Reviewed-by: Tim Hudson (Merged from https://github.com/openssl/openssl/pull/15211) --- diff --git a/crypto/encode_decode/decoder_meth.c b/crypto/encode_decode/decoder_meth.c index 7a271f7408a..48a52c9612e 100644 --- a/crypto/encode_decode/decoder_meth.c +++ b/crypto/encode_decode/decoder_meth.c @@ -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; diff --git a/crypto/encode_decode/encoder_local.h b/crypto/encode_decode/encoder_local.h index c58362ae027..d53f7603794 100644 --- a/crypto/encode_decode/encoder_local.h +++ b/crypto/encode_decode/encoder_local.h @@ -19,6 +19,7 @@ struct ossl_endecode_base_st { OSSL_PROVIDER *prov; int id; + char *name; const char *propdef; const char *description; diff --git a/crypto/encode_decode/encoder_meth.c b/crypto/encode_decode/encoder_meth.c index bb319460b94..3b2bc2d83e0 100644 --- a/crypto/encode_decode/encoder_meth.c +++ b/crypto/encode_decode/encoder_meth.c @@ -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; diff --git a/include/openssl/decoder.h b/include/openssl/decoder.h index 974fbb02ad6..afe4988fdb9 100644 --- a/include/openssl/decoder.h +++ b/include/openssl/decoder.h @@ -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); diff --git a/include/openssl/encoder.h b/include/openssl/encoder.h index c51bd02a2b3..4e2c5fe23cc 100644 --- a/include/openssl/encoder.h +++ b/include/openssl/encoder.h @@ -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);