OSSL_DECODER_CTX(3ossl)
β¨ NAME β¨
okay so welcome to OSSL_DECODER_CTX(3ossl), straight outta the OpenSSL manual bestie π β it's the decoder context routines, and there's a LOT of them, so buckle up.
The whole squad, no one left behind:
OSSL_DECODER_CTXOSSL_DECODER_CTX_newOSSL_DECODER_settable_ctx_paramsOSSL_DECODER_CTX_set_paramsOSSL_DECODER_CTX_freeOSSL_DECODER_CTX_set_selectionOSSL_DECODER_CTX_set_input_typeOSSL_DECODER_CTX_set_input_structureOSSL_DECODER_CTX_add_decoderOSSL_DECODER_CTX_add_extraOSSL_DECODER_CTX_get_num_decodersOSSL_DECODER_INSTANCEOSSL_DECODER_CONSTRUCTOSSL_DECODER_CLEANUPOSSL_DECODER_CTX_set_constructOSSL_DECODER_CTX_set_construct_dataOSSL_DECODER_CTX_set_cleanupOSSL_DECODER_CTX_get_constructOSSL_DECODER_CTX_get_construct_dataOSSL_DECODER_CTX_get_cleanupOSSL_DECODER_exportOSSL_DECODER_INSTANCE_get_decoderOSSL_DECODER_INSTANCE_get_decoder_ctxOSSL_DECODER_INSTANCE_get_input_typeOSSL_DECODER_INSTANCE_get_input_structure
πΈ 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 π¦
So like. The OSSL_DECODER_CTX is holding all the tea about multiple decoders at once β everything you need to (a) figure out what your input data even is, and (b) try to unpack it into one of several possible related results. It also does chaining of decoders, so the output from one can become the input for another. Which is iconic because it means you get the generic format decoders (like PEM to DER) and the more specialised ones (like DER to RSA). slay. π
The chains can be limited by setting an input type, and that's basically the starting point. Two things care about it:
OSSL_DECODER_CTX_add_extra(), which stops adding more decoder implementations once it's already added the ones that take the specified input type, and- functions like
OSSL_DECODER_from_bio(3), which will only kick off the decoding process with the decoder implementations that take that input type.
Example bestie: if the input type is set to "DER", then a PEM to DER decoder is getting ignored. periodt.
The input type can also be NULL, and that means the caller doesn't know what type of input they've got. In that case, OSSL_DECODER_from_bio() will just try one decoder implementation after the other and thereby discover what kind of input the caller gave it. main character energy fr fr β¨
For every decoding done β even an intermediary one β a constructor provided by the caller gets called, to attempt to construct an appropriate type / structure that the caller knows how to handle, from the current decoding result. You set that constructor with OSSL_DECODER_CTX_set_construct().
OSSL_DECODER_INSTANCE is an opaque structure containing 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, and they're described further down. π«Ά
π Functions π
OSSL_DECODER_CTX_new()β creates a new, emptyOSSL_DECODER_CTX. a whole new baby.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 get passed to all decoders that have been added to thectxso far. And if an implementation doesn't recognise a parameter? It should just ignore it. no drama.OSSL_DECODER_CTX_free()β frees the given contextctx. If the argument isNULL, nothing is done. (nothing. zero. zilch.)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 the decoders you already added, and adds them too. This is literally how you build decoder chains. πOSSL_DECODER_CTX_set_input_type()β sets the starting input type. This limits which decoder chains get considered, as explained up in the general description.OSSL_DECODER_CTX_set_input_structure()β sets the name of the structure that the input is expected to have. This may be used to determine 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 themselves.OSSL_DECODER_CTX_get_num_decoders()β gets the number of decoders currently added to the contextctx.OSSL_DECODER_CTX_set_construct()β sets the constructorconstruct.OSSL_DECODER_CTX_set_construct_data()β sets the constructor data that gets passed to the constructor every single time it's called.OSSL_DECODER_CTX_set_cleanup()β sets the constructor data cleanup function. This one 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. getters gonna get. πOSSL_DECODER_export()β a fallback function for constructors that can't use the data they get directly, for diverse reasons. It takes the same decode instancedecoder_instthat the constructor got, plus 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.
okay so this next bit is a BIG DEAL β οΈ β 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(). don't do it bestie, it's giving chaos π
π§ Constructor π§
A 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 info on the provider-native object abstraction lives 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. simple as that π
These utility functions may be used by a constructor:
OSSL_DECODER_INSTANCE_get_decoder()β get the decoder implementation from a decoder instancedecoder_inst.OSSL_DECODER_INSTANCE_get_decoder_ctx()β get the decoder implementation's provider context from a decoder instancedecoder_inst.OSSL_DECODER_INSTANCE_get_input_type()β get the decoder implementation's input type from a decoder instancedecoder_inst.OSSL_DECODER_INSTANCE_get_input_structure()β get the input structure for the decoder implementation from a decoder instancedecoder_inst. This may beNULL.
β RETURN VALUES β
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)
π HISTORY π
The functions described here were added in OpenSSL 3.0. β¨
π COPYRIGHT π
okay bestie, legal era incoming, but it's short and sweet so we're fine π
Copyright 2020-2024 The OpenSSL Project Authors. All Rights Reserved.
that's the whole vibe. every single right, reserved, no cap. π«Ά
π the license bit (iykyk) π
so this file is Licensed under the Apache License 2.0 (the "License"). and like, read carefully bestie:
- you may not use this file except in compliance with the License β
- you can grab a copy of the License in the file
LICENSEin the source distribution, or over at:
<https://www.openssl.org/source/license.html>
fr fr, unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, without warranties or conditions of any kind β that part is in the License itself, so go read it, it's giving very important β¨
and that's a wrap on OSSL_DECODER_CTX(3ossl), bestie π this one's from OpenSSL version 3.5.9, dated 2026-09-29, and honestly? iconic. go decode something. slay π
β¨π¦
π¦ where this page comes from
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms