encoder: add a _name() function for encoders and decoders

Reviewed-by: Tim Hudson <tjh@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15211)
This commit is contained in:
Pauli 2021-05-10 13:05:08 +10:00
parent b337741372
commit 4966411789
5 changed files with 23 additions and 0 deletions

View 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;

View File

@ -19,6 +19,7 @@
struct ossl_endecode_base_st {
OSSL_PROVIDER *prov;
int id;
char *name;
const char *propdef;
const char *description;

View 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;

View 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);

View 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);