OSSL_DECODER_CTX(3ossl)
π
OSSL_DECODER_CTX β Decoder context routines (from 3ossl, the OpenSSL girlies β¨)
okay bestie, grab a strawberry π and sit down, because this one's a whole thing and it's honestly kind of iconic. This is OSSL_DECODER_CTX(3ossl) β the page about how OpenSSL figures out what the heck your input data even is, and then unpacks it. no cap, it's a lot, but we're gonna get through it together π«Ά
πΈ NAME πΈ
ok so like, a lot of things live here. All of these, periodt:
OSSL_DECODER_CTX,OSSL_DECODER_CTX_new,OSSL_DECODER_settable_ctx_params,OSSL_DECODER_CTX_set_params,OSSL_DECODER_CTX_freeOSSL_DECODER_CTX_set_selection,OSSL_DECODER_CTX_set_input_type,OSSL_DECODER_CTX_set_input_structureOSSL_DECODER_CTX_add_decoder,OSSL_DECODER_CTX_add_extra,OSSL_DECODER_CTX_get_num_decodersOSSL_DECODER_INSTANCE,OSSL_DECODER_CONSTRUCT,OSSL_DECODER_CLEANUPOSSL_DECODER_CTX_set_construct,OSSL_DECODER_CTX_set_construct_data,OSSL_DECODER_CTX_set_cleanupOSSL_DECODER_CTX_get_construct,OSSL_DECODER_CTX_get_construct_data,OSSL_DECODER_CTX_get_cleanupOSSL_DECODER_exportOSSL_DECODER_INSTANCE_get_decoder,OSSL_DECODER_INSTANCE_get_decoder_ctx,OSSL_DECODER_INSTANCE_get_input_type,OSSL_DECODER_INSTANCE_get_input_structure
and the collective vibe name for all of it? Decoder context routines. slay π
β¨ SYNOPSIS β¨
#include <openssl/decoder.h>
typedef struct ossl_decoder_ctx_st OSSL_DECODER_CTX;
OSSL_DECODER_CTX *OSSL_DECODER_CTX_new(void);
const OSSL_PARAM *OSSL_DECODER_settable_ctx_params(OSSL_DECODER *decoder);
int OSSL_DECODER_CTX_set_params(OSSL_DECODER_CTX *ctx,
const OSSL_PARAM params[]);
void OSSL_DECODER_CTX_free(OSSL_DECODER_CTX *ctx);
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);
int OSSL_DECODER_CTX_set_input_structure(OSSL_DECODER_CTX *ctx,
const char *input_structure);
int OSSL_DECODER_CTX_add_decoder(OSSL_DECODER_CTX *ctx, OSSL_DECODER *decoder);
int OSSL_DECODER_CTX_add_extra(OSSL_DECODER_CTX *ctx,
OSSL_LIB_CTX *libctx,
const char *propq);
int OSSL_DECODER_CTX_get_num_decoders(OSSL_DECODER_CTX *ctx);
typedef struct ossl_decoder_instance_st OSSL_DECODER_INSTANCE;
OSSL_DECODER *
OSSL_DECODER_INSTANCE_get_decoder(OSSL_DECODER_INSTANCE *decoder_inst);
void *
OSSL_DECODER_INSTANCE_get_decoder_ctx(OSSL_DECODER_INSTANCE *decoder_inst);
const char *
OSSL_DECODER_INSTANCE_get_input_type(OSSL_DECODER_INSTANCE *decoder_inst);
OSSL_DECODER_INSTANCE_get_input_structure(OSSL_DECODER_INSTANCE *decoder_inst,
int *was_set);
typedef int OSSL_DECODER_CONSTRUCT(OSSL_DECODER_INSTANCE *decoder_inst,
const OSSL_PARAM *object,
void *construct_data);
typedef void OSSL_DECODER_CLEANUP(void *construct_data);
int OSSL_DECODER_CTX_set_construct(OSSL_DECODER_CTX *ctx,
OSSL_DECODER_CONSTRUCT *construct);
int OSSL_DECODER_CTX_set_construct_data(OSSL_DECODER_CTX *ctx,
void *construct_data);
int OSSL_DECODER_CTX_set_cleanup(OSSL_DECODER_CTX *ctx,
OSSL_DECODER_CLEANUP *cleanup);
OSSL_DECODER_CONSTRUCT *OSSL_DECODER_CTX_get_construct(OSSL_DECODER_CTX *ctx);
void *OSSL_DECODER_CTX_get_construct_data(OSSL_DECODER_CTX *ctx);
OSSL_DECODER_CLEANUP *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);
π¦ DESCRIPTION π¦
okay so the whole concept: OSSL_DECODER_CTX is like the group chat of decoders π. It holds all the data about multiple decoders at once β because you need a squad to figure out what your input data actually is, and then to attempt to unpack it into one of several possible related results.
and yes, that includes chaining decoders, so the output from one becomes the input for the next. literally passing the aux. π₯ that's how you get generic format decoders like PEM to DER, and also the more specialized ones like DER to RSA.
the chains can be limited by specifying an input type, which counts as a starting point. two things care about this:
OSSL_DECODER_CTX_add_extra(), which will stop adding one more decoder implementations once it's already added the ones that take the specified input type- functions like
OSSL_DECODER_from_bio(3), which will only start the decoding process with the decoder implementations that take that input type
so like, fr fr: if the input type is set to "DER", a PEM to DER decoder gets ignored. not invited to the party π
the input type can also be NULL, which means the caller has no idea what type of input they have. relatable tbh π in that case, OSSL_DECODER_from_bio() will simply try one decoder implementation after the other, and thereby discover what kind of input the caller gave it. main character energy: it just figures it out.
every single time a decoding happens β even an intermediary one β a constructor provided by the caller gets called. its job? attempt to construct an appropriate type / structure that the caller knows how to handle from the current decoding result π
the constructor is set with OSSL_DECODER_CTX_set_construct().
OSSL_DECODER_INSTANCE is an opaque structure holding data about the decoder that was just used, and that may be useful for the constructor. there are some functions to extract data from this type, described further down π
π Functions π
OSSL_DECODER_CTX_new()β creates a new emptyOSSL_DECODER_CTX. fresh start, blank slate, no baggage β¨OSSL_DECODER_settable_ctx_params()β returns anOSSL_PARAM(3)array of parameter descriptors.OSSL_DECODER_CTX_set_params()β attempts to set parameters specified with anOSSL_PARAM(3)arrayparams. These parameters are passed to all decoders that have been added to the ctx so far. Parameters that an implementation doesn't recognise should be ignored by it. (not me ignoring things I don't understand π)OSSL_DECODER_CTX_free()β frees the given contextctx. If the argument isNULL, nothing is done. no drama.OSSL_DECODER_CTX_add_decoder()β populates theOSSL_DECODER_CTXctxwith a decoder, to be used to attempt to decode some encoded input.OSSL_DECODER_CTX_add_extra()β finds decoders that generate input for already added decoders, and adds them as well. This is used to build decoder chains. π¦ matching matching.OSSL_DECODER_CTX_set_input_type()β sets the starting input type. This limits the decoder chains to be considered, as explained in the general description above.OSSL_DECODER_CTX_set_input_structure()β sets the name of the structure that the input is expected to have. This may be used to determines what decoder implementations may be used.NULLis a valid input structure, when it's not relevant, or when the decoder implementations are expected to figure it out.OSSL_DECODER_CTX_get_num_decoders()β gets the number of decoders currently added to the contextctx. (a headcount, basically π )OSSL_DECODER_CTX_set_construct()β sets the constructorconstruct.OSSL_DECODER_CTX_set_construct_data()β sets the constructor data that is passed to the constructor every time it's called.OSSL_DECODER_CTX_set_cleanup()β sets the constructor data cleanup function. This is called byOSSL_DECODER_CTX_free(3).OSSL_DECODER_CTX_get_construct(),OSSL_DECODER_CTX_get_construct_data()andOSSL_DECODER_CTX_get_cleanup()β return the values that have been set byOSSL_DECODER_CTX_set_construct(),OSSL_DECODER_CTX_set_construct_data()andOSSL_DECODER_CTX_set_cleanup()respectively.OSSL_DECODER_export()β a fallback function for constructors that cannot use the data they get directly for diverse reasons. It takes the same decode instancedecoder_instthat the constructor got and an objectreference, unpacks the object which it refers to, and exports it by creating anOSSL_PARAM(3)array that it then passes toexport_cb, along withexport_arg. the backup plan that still ate π₯
β οΈ attention bestie, this part matters: note that functionsOSSL_DECODER_CTX_set_selection(),OSSL_DECODER_CTX_set_output_type(),OSSL_DECODER_CTX_set_output_structure(),OSSL_DECODER_CTX_add_encoder(),OSSL_DECODER_CTX_add_extra(),OSSL_DECODER_CTX_set_construct(),OSSL_DECODER_CTX_set_construct_data(), andOSSL_DECODER_CTX_set_cleanup()shouldn't be used after the context is finalised, in particular after calling the functionOSSL_DECODER_CTX_new_for_pkey(). like, the glow-up is done, stop touching it π
π Constructor π
an OSSL_DECODER_CONSTRUCT gets the following arguments:
decoder_instβ theOSSL_DECODER_INSTANCEfor the decoder from which the constructor gets its data.objectβ a provider-native object abstraction produced by the decoder. Further information on the provider-native object abstraction can be found inprovider-object(7).construct_dataβ the pointer that was set withOSSL_DECODE_CTX_set_construct_data().
the constructor is expected to return 1 when the data it receives can be constructed, otherwise 0. yes/no, icon behaviour only β¨
these utility functions may be used by a constructor:
OSSL_DECODER_INSTANCE_get_decoder()β can be used to get the decoder implementation from a decoder instancedecoder_inst.OSSL_DECODER_INSTANCE_get_decoder_ctx()β can be used to get the decoder implementation's provider context from a decoder instancedecoder_inst.OSSL_DECODER_INSTANCE_get_input_type()β can be used to get the decoder implementation's input type from a decoder instancedecoder_inst.OSSL_DECODER_INSTANCE_get_input_structure()β can be used to get the input structure for the decoder implementation from a decoder instancedecoder_inst. This may beNULL.
π RETURN VALUES π
okay, scoreboard time π:
OSSL_DECODER_CTX_new()β returns a pointer to aOSSL_DECODER_CTX, orNULLif the context structure couldn't be allocated.OSSL_DECODER_settable_ctx_params()β returns anOSSL_PARAM(3)array, orNULLif none is available.OSSL_DECODER_CTX_set_params()β returns1if all recognised parameters were valid, or0if one of them was invalid or caused some other failure in the implementation.OSSL_DECODER_CTX_add_decoder(),OSSL_DECODER_CTX_add_extra(),OSSL_DECODER_CTX_set_construct(),OSSL_DECODER_CTX_set_construct_data()andOSSL_DECODER_CTX_set_cleanup()β return1on success, or0on failure.OSSL_DECODER_CTX_get_construct(),OSSL_DECODER_CTX_get_construct_data()andOSSL_DECODER_CTX_get_cleanup()β return the current pointers to the constructor, the constructor data and the cleanup functions, respectively.OSSL_DECODER_CTX_num_decoders()β returns the current number of decoders. It returns0ifctxisNULL.OSSL_DECODER_export()β returns1on success, or0on failure.OSSL_DECODER_INSTANCE_decoder()β returns anOSSL_DECODERpointer on success, orNULLon failure.OSSL_DECODER_INSTANCE_decoder_ctx()β returns a provider context pointer on success, orNULLon failure.
π§ SEE ALSO π§
provider(7), OSSL_DECODER(3), OSSL_DECODER_from_bio(3) β go read those next, bestie, iykyk π
β HISTORY β
the functions described here were added in OpenSSL 3.0. vintage-ish but still cute π
π COPYRIGHT π
okay so legally we gotta do this part and honestly? respect the paperwork bestie π
Copyright 2020-2024 The OpenSSL Project Authors. All Rights Reserved.
This whole thing is licensed under the Apache License 2.0 (that's "the License" btw, capital L, main character energy π). You may not use this file except in compliance with the License β like, fr fr, it's not a suggestion π«Ά
You can obtain a copy of the License in the file LICENSE in the source distribution, or at:
https://www.openssl.org/source/license.html
and that's the whole page, bestie!! πΈ no cap, you now know OSSL_DECODER_CTX inside and out. this diva is documented as OpenSSL 3.5.6, dated 2026-04-07, filed under OSSL_DECODER_CTX(3ossl) β go forth and decode slayfully πβ¨π¦
π¦ where this page comes from
- freebsd 15.1: base 15.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms