diff options
| author | Enji Cooper <ngie@FreeBSD.org> | 2026-01-29 01:27:53 +0000 |
|---|---|---|
| committer | Enji Cooper <ngie@FreeBSD.org> | 2026-01-29 01:27:53 +0000 |
| commit | 808413da28df9fb93e1f304e6016b15e660f54c8 (patch) | |
| tree | f3ecb4f928716223c9563ee34e044ab84549debb /crypto/encode_decode/decoder_lib.c | |
| parent | 8e12a5c4eb3507846b507d0afe87d115af41df40 (diff) | |
Diffstat (limited to 'crypto/encode_decode/decoder_lib.c')
| -rw-r--r-- | crypto/encode_decode/decoder_lib.c | 386 |
1 files changed, 206 insertions, 180 deletions
diff --git a/crypto/encode_decode/decoder_lib.c b/crypto/encode_decode/decoder_lib.c index dedfb24e569e..c0b32d7d9c42 100644 --- a/crypto/encode_decode/decoder_lib.c +++ b/crypto/encode_decode/decoder_lib.c @@ -58,9 +58,9 @@ int OSSL_DECODER_from_bio(OSSL_DECODER_CTX *ctx, BIO *in) if (OSSL_DECODER_CTX_get_num_decoders(ctx) == 0) { ERR_raise_data(ERR_LIB_OSSL_DECODER, OSSL_DECODER_R_DECODER_NOT_FOUND, - "No decoders were found. For standard decoders you need " - "at least one of the default or base providers " - "available. Did you forget to load them?"); + "No decoders were found. For standard decoders you need " + "at least one of the default or base providers " + "available. Did you forget to load them?"); return 0; } @@ -84,14 +84,16 @@ int OSSL_DECODER_from_bio(OSSL_DECODER_CTX *ctx, BIO *in) if (!data.flag_construct_called) { const char *spaces = ctx->start_input_type != NULL && ctx->input_structure != NULL - ? " " : ""; + ? " " + : ""; const char *input_type_label = ctx->start_input_type != NULL ? "Input type: " : ""; const char *input_structure_label = ctx->input_structure != NULL ? "Input structure: " : ""; const char *comma = ctx->start_input_type != NULL && ctx->input_structure != NULL - ? ", " : ""; + ? ", " + : ""; const char *input_type = ctx->start_input_type != NULL ? ctx->start_input_type : ""; const char *input_structure @@ -100,9 +102,9 @@ int OSSL_DECODER_from_bio(OSSL_DECODER_CTX *ctx, BIO *in) if (ERR_peek_last_error() == lasterr || ERR_peek_error() == 0) /* Prevent spurious decoding error but add at least something */ ERR_raise_data(ERR_LIB_OSSL_DECODER, ERR_R_UNSUPPORTED, - "No supported data to decode. %s%s%s%s%s%s", - spaces, input_type_label, input_type, comma, - input_structure_label, input_structure); + "No supported data to decode. %s%s%s%s%s%s", + spaces, input_type_label, input_type, comma, + input_structure_label, input_structure); ok = 0; } @@ -143,7 +145,7 @@ int OSSL_DECODER_from_fp(OSSL_DECODER_CTX *ctx, FILE *fp) #endif int OSSL_DECODER_from_data(OSSL_DECODER_CTX *ctx, const unsigned char **pdata, - size_t *pdata_len) + size_t *pdata_len) { BIO *membio; int ret = 0; @@ -179,7 +181,7 @@ int OSSL_DECODER_CTX_set_selection(OSSL_DECODER_CTX *ctx, int selection) } int OSSL_DECODER_CTX_set_input_type(OSSL_DECODER_CTX *ctx, - const char *input_type) + const char *input_type) { if (!ossl_assert(ctx != NULL)) { ERR_raise(ERR_LIB_OSSL_DECODER, ERR_R_PASSED_NULL_PARAMETER); @@ -195,7 +197,7 @@ int OSSL_DECODER_CTX_set_input_type(OSSL_DECODER_CTX *ctx, } int OSSL_DECODER_CTX_set_input_structure(OSSL_DECODER_CTX *ctx, - const char *input_structure) + const char *input_structure) { if (!ossl_assert(ctx != NULL)) { ERR_raise(ERR_LIB_OSSL_DECODER, ERR_R_PASSED_NULL_PARAMETER); @@ -212,7 +214,7 @@ int OSSL_DECODER_CTX_set_input_structure(OSSL_DECODER_CTX *ctx, OSSL_DECODER_INSTANCE * ossl_decoder_instance_new_forprov(OSSL_DECODER *decoder, void *provctx, - const char *input_structure) + const char *input_structure) { void *decoderctx; @@ -227,9 +229,8 @@ ossl_decoder_instance_new_forprov(OSSL_DECODER *decoder, void *provctx, if (input_structure != NULL && decoder->set_ctx_params != NULL) { OSSL_PARAM params[] = { OSSL_PARAM_END, OSSL_PARAM_END }; - params[0] = - OSSL_PARAM_construct_utf8_string(OSSL_OBJECT_PARAM_DATA_STRUCTURE, - (char *)input_structure, 0); + params[0] = OSSL_PARAM_construct_utf8_string(OSSL_OBJECT_PARAM_DATA_STRUCTURE, + (char *)input_structure, 0); if (!decoder->set_ctx_params(decoderctx, params)) { decoder->freectx(decoderctx); return 0; @@ -239,7 +240,7 @@ ossl_decoder_instance_new_forprov(OSSL_DECODER *decoder, void *provctx, } OSSL_DECODER_INSTANCE *ossl_decoder_instance_new(OSSL_DECODER *decoder, - void *decoderctx) + void *decoderctx) { OSSL_DECODER_INSTANCE *decoder_inst = NULL; const OSSL_PROVIDER *prov; @@ -260,8 +261,8 @@ OSSL_DECODER_INSTANCE *ossl_decoder_instance_new(OSSL_DECODER *decoder, props = ossl_decoder_parsed_properties(decoder); if (props == NULL) { ERR_raise_data(ERR_LIB_OSSL_DECODER, ERR_R_INVALID_PROPERTY_DEFINITION, - "there are no property definitions with decoder %s", - OSSL_DECODER_get0_name(decoder)); + "there are no property definitions with decoder %s", + OSSL_DECODER_get0_name(decoder)); goto err; } @@ -271,10 +272,10 @@ OSSL_DECODER_INSTANCE *ossl_decoder_instance_new(OSSL_DECODER *decoder, decoder_inst->input_type_id = 0; if (decoder_inst->input_type == NULL) { ERR_raise_data(ERR_LIB_OSSL_DECODER, ERR_R_INVALID_PROPERTY_DEFINITION, - "the mandatory 'input' property is missing " - "for decoder %s (properties: %s)", - OSSL_DECODER_get0_name(decoder), - OSSL_DECODER_get0_properties(decoder)); + "the mandatory 'input' property is missing " + "for decoder %s (properties: %s)", + OSSL_DECODER_get0_name(decoder), + OSSL_DECODER_get0_properties(decoder)); goto err; } @@ -292,7 +293,7 @@ OSSL_DECODER_INSTANCE *ossl_decoder_instance_new(OSSL_DECODER *decoder, decoder_inst->decoder = decoder; decoder_inst->decoderctx = decoderctx; return decoder_inst; - err: +err: ossl_decoder_instance_free(decoder_inst); return NULL; } @@ -335,7 +336,7 @@ OSSL_DECODER_INSTANCE *ossl_decoder_instance_dup(const OSSL_DECODER_INSTANCE *sr return dest; - err: +err: OPENSSL_free(dest); return NULL; } @@ -351,27 +352,28 @@ int ossl_decoder_ctx_get_harderr(const OSSL_DECODER_CTX *ctx) } int ossl_decoder_ctx_add_decoder_inst(OSSL_DECODER_CTX *ctx, - OSSL_DECODER_INSTANCE *di) + OSSL_DECODER_INSTANCE *di) { int ok; if (ctx->decoder_insts == NULL - && (ctx->decoder_insts = - sk_OSSL_DECODER_INSTANCE_new_null()) == NULL) { + && (ctx->decoder_insts = sk_OSSL_DECODER_INSTANCE_new_null()) == NULL) { ERR_raise(ERR_LIB_OSSL_DECODER, ERR_R_CRYPTO_LIB); return 0; } ok = (sk_OSSL_DECODER_INSTANCE_push(ctx->decoder_insts, di) > 0); if (ok) { - OSSL_TRACE_BEGIN(DECODER) { + OSSL_TRACE_BEGIN(DECODER) + { BIO_printf(trc_out, - "(ctx %p) Added decoder instance %p for decoder %p\n" - " %s with %s\n", - (void *)ctx, (void *)di, (void *)di->decoder, - OSSL_DECODER_get0_name(di->decoder), - OSSL_DECODER_get0_properties(di->decoder)); - } OSSL_TRACE_END(DECODER); + "(ctx %p) Added decoder instance %p for decoder %p\n" + " %s with %s\n", + (void *)ctx, (void *)di, (void *)di->decoder, + OSSL_DECODER_get0_name(di->decoder), + OSSL_DECODER_get0_properties(di->decoder)); + } + OSSL_TRACE_END(DECODER); } return ok; } @@ -392,8 +394,7 @@ int OSSL_DECODER_CTX_add_decoder(OSSL_DECODER_CTX *ctx, OSSL_DECODER *decoder) provctx = OSSL_PROVIDER_get0_provider_ctx(prov); if ((decoderctx = decoder->newctx(provctx)) == NULL - || (decoder_inst = - ossl_decoder_instance_new(decoder, decoderctx)) == NULL) + || (decoder_inst = ossl_decoder_instance_new(decoder, decoderctx)) == NULL) goto err; /* Avoid double free of decoderctx on further errors */ decoderctx = NULL; @@ -402,7 +403,7 @@ int OSSL_DECODER_CTX_add_decoder(OSSL_DECODER_CTX *ctx, OSSL_DECODER *decoder) goto err; return 1; - err: +err: ossl_decoder_instance_free(decoder_inst); if (decoderctx != NULL) decoder->freectx(decoderctx); @@ -418,9 +419,10 @@ struct collect_extra_decoder_data_st { * 0 to check that the decoder's input type is the same as the decoder name * 1 to check that the decoder's input type differs from the decoder name */ - enum { IS_SAME = 0, IS_DIFFERENT = 1 } type_check; + enum { IS_SAME = 0, + IS_DIFFERENT = 1 } type_check; size_t w_prev_start, w_prev_end; /* "previous" decoders */ - size_t w_new_start, w_new_end; /* "new" decoders */ + size_t w_new_start, w_new_end; /* "new" decoders */ }; DEFINE_STACK_OF(OSSL_DECODER) @@ -430,7 +432,7 @@ static void collect_all_decoders(OSSL_DECODER *decoder, void *arg) STACK_OF(OSSL_DECODER) *skdecoders = arg; if (OSSL_DECODER_up_ref(decoder) - && !sk_OSSL_DECODER_push(skdecoders, decoder)) + && !sk_OSSL_DECODER_push(skdecoders, decoder)) OSSL_DECODER_free(decoder); } @@ -445,14 +447,16 @@ static void collect_extra_decoder(OSSL_DECODER *decoder, void *arg) void *decoderctx = NULL; OSSL_DECODER_INSTANCE *di = NULL; - OSSL_TRACE_BEGIN(DECODER) { + OSSL_TRACE_BEGIN(DECODER) + { BIO_printf(trc_out, - "(ctx %p) [%d] Checking out decoder %p:\n" - " %s with %s\n", - (void *)data->ctx, data->type_check, (void *)decoder, - OSSL_DECODER_get0_name(decoder), - OSSL_DECODER_get0_properties(decoder)); - } OSSL_TRACE_END(DECODER); + "(ctx %p) [%d] Checking out decoder %p:\n" + " %s with %s\n", + (void *)data->ctx, data->type_check, (void *)decoder, + OSSL_DECODER_get0_name(decoder), + OSSL_DECODER_get0_properties(decoder)); + } + OSSL_TRACE_END(DECODER); /* * Check that we don't already have this decoder in our stack, @@ -460,15 +464,16 @@ static void collect_extra_decoder(OSSL_DECODER *decoder, void *arg) * we have added in the current window. */ for (j = data->w_prev_start; j < data->w_new_end; j++) { - OSSL_DECODER_INSTANCE *check_inst = - sk_OSSL_DECODER_INSTANCE_value(data->ctx->decoder_insts, j); + OSSL_DECODER_INSTANCE *check_inst = sk_OSSL_DECODER_INSTANCE_value(data->ctx->decoder_insts, j); if (decoder->base.algodef == check_inst->decoder->base.algodef) { /* We found it, so don't do anything more */ - OSSL_TRACE_BEGIN(DECODER) { + OSSL_TRACE_BEGIN(DECODER) + { BIO_printf(trc_out, - " REJECTED: already exists in the chain\n"); - } OSSL_TRACE_END(DECODER); + " REJECTED: already exists in the chain\n"); + } + OSSL_TRACE_END(DECODER); return; } } @@ -481,9 +486,8 @@ static void collect_extra_decoder(OSSL_DECODER *decoder, void *arg) OSSL_PARAM params[] = { OSSL_PARAM_END, OSSL_PARAM_END }; const char *str = data->ctx->input_structure; - params[0] = - OSSL_PARAM_construct_utf8_string(OSSL_OBJECT_PARAM_DATA_STRUCTURE, - (char *)str, 0); + params[0] = OSSL_PARAM_construct_utf8_string(OSSL_OBJECT_PARAM_DATA_STRUCTURE, + (char *)str, 0); if (!decoder->set_ctx_params(decoderctx, params)) { decoder->freectx(decoderctx); return; @@ -499,26 +503,30 @@ static void collect_extra_decoder(OSSL_DECODER *decoder, void *arg) case IS_SAME: /* If it differs, this is not a decoder to add for now. */ if (!ossl_decoder_fast_is_a(decoder, - OSSL_DECODER_INSTANCE_get_input_type(di), - &di->input_type_id)) { + OSSL_DECODER_INSTANCE_get_input_type(di), + &di->input_type_id)) { ossl_decoder_instance_free(di); - OSSL_TRACE_BEGIN(DECODER) { + OSSL_TRACE_BEGIN(DECODER) + { BIO_printf(trc_out, - " REJECTED: input type doesn't match output type\n"); - } OSSL_TRACE_END(DECODER); + " REJECTED: input type doesn't match output type\n"); + } + OSSL_TRACE_END(DECODER); return; } break; case IS_DIFFERENT: /* If it's the same, this is not a decoder to add for now. */ if (ossl_decoder_fast_is_a(decoder, - OSSL_DECODER_INSTANCE_get_input_type(di), - &di->input_type_id)) { + OSSL_DECODER_INSTANCE_get_input_type(di), + &di->input_type_id)) { ossl_decoder_instance_free(di); - OSSL_TRACE_BEGIN(DECODER) { + OSSL_TRACE_BEGIN(DECODER) + { BIO_printf(trc_out, - " REJECTED: input type matches output type\n"); - } OSSL_TRACE_END(DECODER); + " REJECTED: input type matches output type\n"); + } + OSSL_TRACE_END(DECODER); return; } break; @@ -538,7 +546,7 @@ static void collect_extra_decoder(OSSL_DECODER *decoder, void *arg) } static int decoder_sk_cmp(const OSSL_DECODER_INSTANCE *const *a, - const OSSL_DECODER_INSTANCE *const *b) + const OSSL_DECODER_INSTANCE *const *b) { if ((*a)->score == (*b)->score) return (*a)->order - (*b)->order; @@ -546,7 +554,7 @@ static int decoder_sk_cmp(const OSSL_DECODER_INSTANCE *const *a, } int OSSL_DECODER_CTX_add_extra(OSSL_DECODER_CTX *ctx, - OSSL_LIB_CTX *libctx, const char *propq) + OSSL_LIB_CTX *libctx, const char *propq) { /* * This function goes through existing decoder methods in @@ -589,11 +597,12 @@ int OSSL_DECODER_CTX_add_extra(OSSL_DECODER_CTX *ctx, if (ctx->decoder_insts == NULL) return 1; - OSSL_TRACE_BEGIN(DECODER) { + OSSL_TRACE_BEGIN(DECODER) + { BIO_printf(trc_out, "(ctx %p) Looking for extra decoders\n", - (void *)ctx); - } OSSL_TRACE_END(DECODER); - + (void *)ctx); + } + OSSL_TRACE_END(DECODER); skdecoders = sk_OSSL_DECODER_new_null(); if (skdecoders == NULL) { @@ -612,8 +621,7 @@ int OSSL_DECODER_CTX_add_extra(OSSL_DECODER_CTX *ctx, int num_decoder_insts = sk_OSSL_DECODER_INSTANCE_num(ctx->decoder_insts); int i; OSSL_DECODER_INSTANCE *di; - sk_OSSL_DECODER_INSTANCE_compfunc old_cmp = - sk_OSSL_DECODER_INSTANCE_set_cmp_func(ctx->decoder_insts, decoder_sk_cmp); + sk_OSSL_DECODER_INSTANCE_compfunc old_cmp = sk_OSSL_DECODER_INSTANCE_set_cmp_func(ctx->decoder_insts, decoder_sk_cmp); for (i = 0; i < num_decoder_insts; i++) { di = sk_OSSL_DECODER_INSTANCE_value(ctx->decoder_insts, i); @@ -640,11 +648,10 @@ int OSSL_DECODER_CTX_add_extra(OSSL_DECODER_CTX *ctx, * 1. All decoders that a different name than their input type. */ for (data.type_check = IS_SAME; - data.type_check <= IS_DIFFERENT; - data.type_check++) { + data.type_check <= IS_DIFFERENT; + data.type_check++) { for (i = data.w_prev_start; i < data.w_prev_end; i++) { - OSSL_DECODER_INSTANCE *decoder_inst = - sk_OSSL_DECODER_INSTANCE_value(ctx->decoder_insts, i); + OSSL_DECODER_INSTANCE *decoder_inst = sk_OSSL_DECODER_INSTANCE_value(ctx->decoder_insts, i); data.output_type = OSSL_DECODER_INSTANCE_get_input_type(decoder_inst); @@ -653,7 +660,7 @@ int OSSL_DECODER_CTX_add_extra(OSSL_DECODER_CTX *ctx, for (j = 0; j < numdecoders; j++) collect_extra_decoder(sk_OSSL_DECODER_value(skdecoders, j), - &data); + &data); } } /* How many were added in this iteration */ @@ -678,7 +685,7 @@ int OSSL_DECODER_CTX_get_num_decoders(OSSL_DECODER_CTX *ctx) } int OSSL_DECODER_CTX_set_construct(OSSL_DECODER_CTX *ctx, - OSSL_DECODER_CONSTRUCT *construct) + OSSL_DECODER_CONSTRUCT *construct) { if (!ossl_assert(ctx != NULL)) { ERR_raise(ERR_LIB_OSSL_DECODER, ERR_R_PASSED_NULL_PARAMETER); @@ -689,7 +696,7 @@ int OSSL_DECODER_CTX_set_construct(OSSL_DECODER_CTX *ctx, } int OSSL_DECODER_CTX_set_construct_data(OSSL_DECODER_CTX *ctx, - void *construct_data) + void *construct_data) { if (!ossl_assert(ctx != NULL)) { ERR_raise(ERR_LIB_OSSL_DECODER, ERR_R_PASSED_NULL_PARAMETER); @@ -700,7 +707,7 @@ int OSSL_DECODER_CTX_set_construct_data(OSSL_DECODER_CTX *ctx, } int OSSL_DECODER_CTX_set_cleanup(OSSL_DECODER_CTX *ctx, - OSSL_DECODER_CLEANUP *cleanup) + OSSL_DECODER_CLEANUP *cleanup) { if (!ossl_assert(ctx != NULL)) { ERR_raise(ERR_LIB_OSSL_DECODER, ERR_R_PASSED_NULL_PARAMETER); @@ -734,16 +741,16 @@ OSSL_DECODER_CTX_get_cleanup(OSSL_DECODER_CTX *ctx) } int OSSL_DECODER_export(OSSL_DECODER_INSTANCE *decoder_inst, - void *reference, size_t reference_sz, - OSSL_CALLBACK *export_cb, void *export_cbarg) + void *reference, size_t reference_sz, + OSSL_CALLBACK *export_cb, void *export_cbarg) { OSSL_DECODER *decoder = NULL; void *decoderctx = NULL; if (!(ossl_assert(decoder_inst != NULL) - && ossl_assert(reference != NULL) - && ossl_assert(export_cb != NULL) - && ossl_assert(export_cbarg != NULL))) { + && ossl_assert(reference != NULL) + && ossl_assert(export_cb != NULL) + && ossl_assert(export_cbarg != NULL))) { ERR_raise(ERR_LIB_OSSL_DECODER, ERR_R_PASSED_NULL_PARAMETER); return 0; } @@ -751,7 +758,7 @@ int OSSL_DECODER_export(OSSL_DECODER_INSTANCE *decoder_inst, decoder = OSSL_DECODER_INSTANCE_get_decoder(decoder_inst); decoderctx = OSSL_DECODER_INSTANCE_get_decoder_ctx(decoder_inst); return decoder->export_object(decoderctx, reference, reference_sz, - export_cb, export_cbarg); + export_cb, export_cbarg); } OSSL_DECODER * @@ -780,7 +787,7 @@ OSSL_DECODER_INSTANCE_get_input_type(OSSL_DECODER_INSTANCE *decoder_inst) const char * OSSL_DECODER_INSTANCE_get_input_structure(OSSL_DECODER_INSTANCE *decoder_inst, - int *was_set) + int *was_set) { if (decoder_inst == NULL) return NULL; @@ -817,49 +824,53 @@ static int decoder_process(const OSSL_PARAM params[], void *arg) new_data.recursion = data->recursion + 1; #define LEVEL_STR ">>>>>>>>>>>>>>>>" -#define LEVEL (new_data.recursion < sizeof(LEVEL_STR) \ - ? &LEVEL_STR[sizeof(LEVEL_STR) - new_data.recursion - 1] \ - : LEVEL_STR "...") +#define LEVEL (new_data.recursion < sizeof(LEVEL_STR) \ + ? &LEVEL_STR[sizeof(LEVEL_STR) - new_data.recursion - 1] \ + : LEVEL_STR "...") if (params == NULL) { /* First iteration, where we prepare for what is to come */ - OSSL_TRACE_BEGIN(DECODER) { + OSSL_TRACE_BEGIN(DECODER) + { BIO_printf(trc_out, - "(ctx %p) starting to walk the decoder chain\n", - (void *)new_data.ctx); - } OSSL_TRACE_END(DECODER); + "(ctx %p) starting to walk the decoder chain\n", + (void *)new_data.ctx); + } + OSSL_TRACE_END(DECODER); - data->current_decoder_inst_index = - OSSL_DECODER_CTX_get_num_decoders(ctx); + data->current_decoder_inst_index = OSSL_DECODER_CTX_get_num_decoders(ctx); bio = data->bio; } else { const OSSL_PARAM *p; const char *trace_data_structure; - decoder_inst = - sk_OSSL_DECODER_INSTANCE_value(ctx->decoder_insts, - data->current_decoder_inst_index); + decoder_inst = sk_OSSL_DECODER_INSTANCE_value(ctx->decoder_insts, + data->current_decoder_inst_index); decoder = OSSL_DECODER_INSTANCE_get_decoder(decoder_inst); data->flag_construct_called = 0; if (ctx->construct != NULL) { int rv; - OSSL_TRACE_BEGIN(DECODER) { + OSSL_TRACE_BEGIN(DECODER) + { BIO_printf(trc_out, - "(ctx %p) %s Running constructor\n", - (void *)new_data.ctx, LEVEL); - } OSSL_TRACE_END(DECODER); + "(ctx %p) %s Running constructor\n", + (void *)new_data.ctx, LEVEL); + } + OSSL_TRACE_END(DECODER); rv = ctx->construct(decoder_inst, params, ctx->construct_data); - OSSL_TRACE_BEGIN(DECODER) { + OSSL_TRACE_BEGIN(DECODER) + { BIO_printf(trc_out, - "(ctx %p) %s Running constructor => %d\n", - (void *)new_data.ctx, LEVEL, rv); - } OSSL_TRACE_END(DECODER); + "(ctx %p) %s Running constructor => %d\n", + (void *)new_data.ctx, LEVEL, rv); + } + OSSL_TRACE_END(DECODER); ok = (rv > 0); if (ok) { @@ -929,15 +940,18 @@ static int decoder_process(const OSSL_PARAM params[], void *arg) && OPENSSL_strcasecmp(data_structure, "type-specific") == 0) data_structure = NULL; - OSSL_TRACE_BEGIN(DECODER) { + OSSL_TRACE_BEGIN(DECODER) + { BIO_printf(trc_out, - "(ctx %p) %s incoming from previous decoder (%p):\n" - " data type: %s, data structure: %s%s\n", - (void *)new_data.ctx, LEVEL, (void *)decoder, - data_type, trace_data_structure, - (trace_data_structure == data_structure - ? "" : " (dropped)")); - } OSSL_TRACE_END(DECODER); + "(ctx %p) %s incoming from previous decoder (%p):\n" + " data type: %s, data structure: %s%s\n", + (void *)new_data.ctx, LEVEL, (void *)decoder, + data_type, trace_data_structure, + (trace_data_structure == data_structure + ? "" + : " (dropped)")); + } + OSSL_TRACE_END(DECODER); } /* @@ -958,30 +972,27 @@ static int decoder_process(const OSSL_PARAM params[], void *arg) } for (i = data->current_decoder_inst_index; i-- > 0;) { - OSSL_DECODER_INSTANCE *new_decoder_inst = - sk_OSSL_DECODER_INSTANCE_value(ctx->decoder_insts, i); - OSSL_DECODER *new_decoder = - OSSL_DECODER_INSTANCE_get_decoder(new_decoder_inst); + OSSL_DECODER_INSTANCE *new_decoder_inst = sk_OSSL_DECODER_INSTANCE_value(ctx->decoder_insts, i); + OSSL_DECODER *new_decoder = OSSL_DECODER_INSTANCE_get_decoder(new_decoder_inst); const char *new_decoder_name = NULL; - void *new_decoderctx = - OSSL_DECODER_INSTANCE_get_decoder_ctx(new_decoder_inst); - const char *new_input_type = - OSSL_DECODER_INSTANCE_get_input_type(new_decoder_inst); - int n_i_s_was_set = 0; /* We don't care here */ - const char *new_input_structure = - OSSL_DECODER_INSTANCE_get_input_structure(new_decoder_inst, - &n_i_s_was_set); + void *new_decoderctx = OSSL_DECODER_INSTANCE_get_decoder_ctx(new_decoder_inst); + const char *new_input_type = OSSL_DECODER_INSTANCE_get_input_type(new_decoder_inst); + int n_i_s_was_set = 0; /* We don't care here */ + const char *new_input_structure = OSSL_DECODER_INSTANCE_get_input_structure(new_decoder_inst, + &n_i_s_was_set); - OSSL_TRACE_BEGIN(DECODER) { + OSSL_TRACE_BEGIN(DECODER) + { new_decoder_name = OSSL_DECODER_get0_name(new_decoder); BIO_printf(trc_out, - "(ctx %p) %s [%u] Considering decoder instance %p (decoder %p):\n" - " %s with %s\n", - (void *)new_data.ctx, LEVEL, (unsigned int)i, - (void *)new_decoder_inst, (void *)new_decoder, - new_decoder_name, - OSSL_DECODER_get0_properties(new_decoder)); - } OSSL_TRACE_END(DECODER); + "(ctx %p) %s [%u] Considering decoder instance %p (decoder %p):\n" + " %s with %s\n", + (void *)new_data.ctx, LEVEL, (unsigned int)i, + (void *)new_decoder_inst, (void *)new_decoder, + new_decoder_name, + OSSL_DECODER_get0_properties(new_decoder)); + } + OSSL_TRACE_END(DECODER); /* * If |decoder| is NULL, it means we've just started, and the caller @@ -990,12 +1001,14 @@ static int decoder_process(const OSSL_PARAM params[], void *arg) */ if (decoder == NULL && ctx->start_input_type != NULL && OPENSSL_strcasecmp(ctx->start_input_type, new_input_type) != 0) { - OSSL_TRACE_BEGIN(DECODER) { + OSSL_TRACE_BEGIN(DECODER) + { BIO_printf(trc_out, - "(ctx %p) %s [%u] the start input type '%s' doesn't match the input type of the considered decoder, skipping...\n", - (void *)new_data.ctx, LEVEL, (unsigned int)i, - ctx->start_input_type); - } OSSL_TRACE_END(DECODER); + "(ctx %p) %s [%u] the start input type '%s' doesn't match the input type of the considered decoder, skipping...\n", + (void *)new_data.ctx, LEVEL, (unsigned int)i, + ctx->start_input_type); + } + OSSL_TRACE_END(DECODER); continue; } @@ -1005,14 +1018,15 @@ static int decoder_process(const OSSL_PARAM params[], void *arg) * |new_input_type| holds the value of the "input-type" parameter * for the decoder we're currently considering. */ - if (decoder != NULL && !ossl_decoder_fast_is_a(decoder, new_input_type, - &new_decoder_inst->input_type_id)) { - OSSL_TRACE_BEGIN(DECODER) { + if (decoder != NULL && !ossl_decoder_fast_is_a(decoder, new_input_type, &new_decoder_inst->input_type_id)) { + OSSL_TRACE_BEGIN(DECODER) + { BIO_printf(trc_out, - "(ctx %p) %s [%u] the input type doesn't match the name of the previous decoder (%p), skipping...\n", - (void *)new_data.ctx, LEVEL, (unsigned int)i, - (void *)decoder); - } OSSL_TRACE_END(DECODER); + "(ctx %p) %s [%u] the input type doesn't match the name of the previous decoder (%p), skipping...\n", + (void *)new_data.ctx, LEVEL, (unsigned int)i, + (void *)decoder); + } + OSSL_TRACE_END(DECODER); continue; } @@ -1021,11 +1035,13 @@ static int decoder_process(const OSSL_PARAM params[], void *arg) * if that matches the decoder we're currently considering. */ if (data_type != NULL && !OSSL_DECODER_is_a(new_decoder, data_type)) { - OSSL_TRACE_BEGIN(DECODER) { + OSSL_TRACE_BEGIN(DECODER) + { BIO_printf(trc_out, - "(ctx %p) %s [%u] the previous decoder's data type doesn't match the name of the considered decoder, skipping...\n", - (void *)new_data.ctx, LEVEL, (unsigned int)i); - } OSSL_TRACE_END(DECODER); + "(ctx %p) %s [%u] the previous decoder's data type doesn't match the name of the considered decoder, skipping...\n", + (void *)new_data.ctx, LEVEL, (unsigned int)i); + } + OSSL_TRACE_END(DECODER); continue; } @@ -1037,12 +1053,15 @@ static int decoder_process(const OSSL_PARAM params[], void *arg) if (data_structure != NULL && (new_input_structure == NULL || OPENSSL_strcasecmp(data_structure, - new_input_structure) != 0)) { - OSSL_TRACE_BEGIN(DECODER) { + new_input_structure) + != 0)) { + OSSL_TRACE_BEGIN(DECODER) + { BIO_printf(trc_out, - "(ctx %p) %s [%u] the previous decoder's data structure doesn't match the input structure of the considered decoder, skipping...\n", - (void *)new_data.ctx, LEVEL, (unsigned int)i); - } OSSL_TRACE_END(DECODER); + "(ctx %p) %s [%u] the previous decoder's data structure doesn't match the input structure of the considered decoder, skipping...\n", + (void *)new_data.ctx, LEVEL, (unsigned int)i); + } + OSSL_TRACE_END(DECODER); continue; } @@ -1057,12 +1076,15 @@ static int decoder_process(const OSSL_PARAM params[], void *arg) && new_input_structure != NULL) { data->flag_input_structure_checked = 1; if (OPENSSL_strcasecmp(new_input_structure, - ctx->input_structure) != 0) { - OSSL_TRACE_BEGIN(DECODER) { + ctx->input_structure) + != 0) { + OSSL_TRACE_BEGIN(DECODER) + { BIO_printf(trc_out, - "(ctx %p) %s [%u] the previous decoder's data structure doesn't match the input structure given by the user, skipping...\n", - (void *)new_data.ctx, LEVEL, (unsigned int)i); - } OSSL_TRACE_END(DECODER); + "(ctx %p) %s [%u] the previous decoder's data structure doesn't match the input structure given by the user, skipping...\n", + (void *)new_data.ctx, LEVEL, (unsigned int)i); + } + OSSL_TRACE_END(DECODER); continue; } } @@ -1082,12 +1104,14 @@ static int decoder_process(const OSSL_PARAM params[], void *arg) goto end; /* Recurse */ - OSSL_TRACE_BEGIN(DECODER) { + OSSL_TRACE_BEGIN(DECODER) + { BIO_printf(trc_out, - "(ctx %p) %s [%u] Running decoder instance %s (%p)\n", - (void *)new_data.ctx, LEVEL, (unsigned int)i, - new_decoder_name, (void *)new_decoder_inst); - } OSSL_TRACE_END(DECODER); + "(ctx %p) %s [%u] Running decoder instance %s (%p)\n", + (void *)new_data.ctx, LEVEL, (unsigned int)i, + new_decoder_name, (void *)new_decoder_inst); + } + OSSL_TRACE_END(DECODER); /* * We only care about errors reported from decoder implementations @@ -1099,20 +1123,22 @@ static int decoder_process(const OSSL_PARAM params[], void *arg) new_data.flag_input_structure_checked = data->flag_input_structure_checked; ok = new_decoder->decode(new_decoderctx, cbio, - new_data.ctx->selection, - decoder_process, &new_data, - ossl_pw_passphrase_callback_dec, - &new_data.ctx->pwdata); + new_data.ctx->selection, + decoder_process, &new_data, + ossl_pw_passphrase_callback_dec, + &new_data.ctx->pwdata); - OSSL_TRACE_BEGIN(DECODER) { + OSSL_TRACE_BEGIN(DECODER) + { BIO_printf(trc_out, - "(ctx %p) %s [%u] Running decoder instance %s (%p) => %d" - " (recursed further: %s, construct called: %s)\n", - (void *)new_data.ctx, LEVEL, (unsigned int)i, - new_decoder_name, (void *)new_decoder_inst, ok, - new_data.flag_next_level_called ? "yes" : "no", - new_data.flag_construct_called ? "yes" : "no"); - } OSSL_TRACE_END(DECODER); + "(ctx %p) %s [%u] Running decoder instance %s (%p) => %d" + " (recursed further: %s, construct called: %s)\n", + (void *)new_data.ctx, LEVEL, (unsigned int)i, + new_decoder_name, (void *)new_decoder_inst, ok, + new_data.flag_next_level_called ? "yes" : "no", + new_data.flag_construct_called ? "yes" : "no"); + } + OSSL_TRACE_END(DECODER); data->flag_construct_called = new_data.flag_construct_called; @@ -1131,7 +1157,7 @@ static int decoder_process(const OSSL_PARAM params[], void *arg) break; } - end: +end: ossl_core_bio_free(cbio); BIO_free(new_data.bio); ctx->start_input_type = start_input_type; |
