diff options
author | Richard Levitte <levitte@openssl.org> | 2020-10-17 07:57:04 +0200 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2020-11-11 12:43:27 +0100 |
commit | 8a98a507fb9a06254c79af4d9c9104f5f300a032 (patch) | |
tree | be686ba59fee1a693640b6cd19075243d7fe12df /crypto/encode_decode/encoder_lib.c | |
parent | 45da4a0fc54bce2c5fd99ce4a3fbe8e5456092ea (diff) |
ENCODER: Add support for specifying the outermost output structure
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/13167)
Diffstat (limited to 'crypto/encode_decode/encoder_lib.c')
-rw-r--r-- | crypto/encode_decode/encoder_lib.c | 60 |
1 files changed, 48 insertions, 12 deletions
diff --git a/crypto/encode_decode/encoder_lib.c b/crypto/encode_decode/encoder_lib.c index 593483313c..5e4bf69787 100644 --- a/crypto/encode_decode/encoder_lib.c +++ b/crypto/encode_decode/encoder_lib.c @@ -97,6 +97,22 @@ int OSSL_ENCODER_to_data(OSSL_ENCODER_CTX *ctx, unsigned char **pdata, return ret; } +int OSSL_ENCODER_CTX_set_selection(OSSL_ENCODER_CTX *ctx, int selection) +{ + if (!ossl_assert(ctx != NULL)) { + ERR_raise(ERR_LIB_OSSL_ENCODER, ERR_R_PASSED_NULL_PARAMETER); + return 0; + } + + if (!ossl_assert(selection != 0)) { + ERR_raise(ERR_LIB_OSSL_ENCODER, ERR_R_PASSED_INVALID_ARGUMENT); + return 0; + } + + ctx->selection = selection; + return 1; +} + int OSSL_ENCODER_CTX_set_output_type(OSSL_ENCODER_CTX *ctx, const char *output_type) { @@ -109,19 +125,15 @@ int OSSL_ENCODER_CTX_set_output_type(OSSL_ENCODER_CTX *ctx, return 1; } -int OSSL_ENCODER_CTX_set_selection(OSSL_ENCODER_CTX *ctx, int selection) +int OSSL_ENCODER_CTX_set_output_structure(OSSL_ENCODER_CTX *ctx, + const char *output_structure) { - if (!ossl_assert(ctx != NULL)) { + if (!ossl_assert(ctx != NULL) || !ossl_assert(output_structure != NULL)) { ERR_raise(ERR_LIB_OSSL_ENCODER, ERR_R_PASSED_NULL_PARAMETER); return 0; } - if (!ossl_assert(selection != 0)) { - ERR_raise(ERR_LIB_OSSL_ENCODER, ERR_R_PASSED_INVALID_ARGUMENT); - return 0; - } - - ctx->selection = selection; + ctx->output_structure = output_structure; return 1; } @@ -129,7 +141,7 @@ static OSSL_ENCODER_INSTANCE *ossl_encoder_instance_new(OSSL_ENCODER *encoder, void *encoderctx) { OSSL_ENCODER_INSTANCE *encoder_inst = NULL; - OSSL_PARAM params[3]; + OSSL_PARAM params[4]; if (!ossl_assert(encoder != NULL)) { ERR_raise(ERR_LIB_OSSL_ENCODER, ERR_R_PASSED_NULL_PARAMETER); @@ -155,12 +167,16 @@ static OSSL_ENCODER_INSTANCE *ossl_encoder_instance_new(OSSL_ENCODER *encoder, OSSL_PARAM_construct_utf8_ptr(OSSL_ENCODER_PARAM_OUTPUT_TYPE, (char **)&encoder_inst->output_type, 0); params[1] = + OSSL_PARAM_construct_utf8_ptr(OSSL_ENCODER_PARAM_OUTPUT_STRUCTURE, + (char **)&encoder_inst->output_structure, + 0); + params[2] = OSSL_PARAM_construct_utf8_ptr(OSSL_ENCODER_PARAM_INPUT_TYPE, (char **)&encoder_inst->input_type, 0); - params[2] = OSSL_PARAM_construct_end(); + params[3] = OSSL_PARAM_construct_end(); if (!encoder->get_params(params) - || !OSSL_PARAM_modified(¶ms[1])) + || !OSSL_PARAM_modified(¶ms[0])) goto err; if (!OSSL_ENCODER_up_ref(encoder)) { @@ -312,6 +328,14 @@ OSSL_ENCODER_INSTANCE_get_output_type(OSSL_ENCODER_INSTANCE *encoder_inst) return encoder_inst->output_type; } +const char * +OSSL_ENCODER_INSTANCE_get_output_structure(OSSL_ENCODER_INSTANCE *encoder_inst) +{ + if (encoder_inst == NULL) + return NULL; + return encoder_inst->output_structure; +} + static int encoder_process(OSSL_ENCODER_CTX *ctx, BIO *out) { size_t i, end; @@ -319,6 +343,7 @@ static int encoder_process(OSSL_ENCODER_CTX *ctx, BIO *out) size_t latest_output_length = 0; const char *latest_output_type = NULL; const char *last_input_type = NULL; + const char *last_output_structure = NULL; int ok = 0; end = OSSL_ENCODER_CTX_get_num_encoders(ctx); @@ -331,10 +356,12 @@ static int encoder_process(OSSL_ENCODER_CTX *ctx, BIO *out) OSSL_ENCODER_INSTANCE_get_input_type(encoder_inst); const char *current_output_type = OSSL_ENCODER_INSTANCE_get_output_type(encoder_inst); + const char *current_output_structure = + OSSL_ENCODER_INSTANCE_get_output_structure(encoder_inst); BIO *current_out; BIO *allocated_out = NULL; const void *current_data = NULL; - OSSL_PARAM abstract[3]; + OSSL_PARAM abstract[10]; OSSL_PARAM *abstract_p; const OSSL_PARAM *current_abstract = NULL; @@ -374,6 +401,11 @@ static int encoder_process(OSSL_ENCODER_CTX *ctx, BIO *out) *abstract_p++ = OSSL_PARAM_construct_utf8_string(OSSL_OBJECT_PARAM_DATA_TYPE, (char *)last_input_type, 0); + if (last_output_structure != NULL) + *abstract_p++ = + OSSL_PARAM_construct_utf8_string(OSSL_OBJECT_PARAM_DATA_STRUCTURE, + (char *)last_output_structure, + 0); *abstract_p++ = OSSL_PARAM_construct_octet_string(OSSL_OBJECT_PARAM_DATA, latest_output, @@ -398,6 +430,8 @@ static int encoder_process(OSSL_ENCODER_CTX *ctx, BIO *out) if (current_input_type != NULL) last_input_type = current_input_type; + if (current_output_structure != NULL) + last_output_structure = current_output_structure; if (!ok) goto loop_end; @@ -418,6 +452,8 @@ static int encoder_process(OSSL_ENCODER_CTX *ctx, BIO *out) BIO_free(allocated_out); } + latest_output_type = encoder_inst->output_type; + loop_end: if (current_data != NULL) ctx->cleanup(ctx->construct_data); |