OSSL_DECODER_CTX(3SSL)

πŸ’… OSSL_DECODER_CTX(3SSL) β€” decoder context routines πŸ’…

okay bestie, sit down, hydrate, and let me tell you about OSSL_DECODER_CTX β€” yes that's the manual page name, OSSL_DECODER_CTX(3SSL), and it's lowkey the whole backstage pass to OpenSSL's decoder machinery. it's giving orchestra conductor energy, fr fr. ✨


🌸 NAME 🌸

OSSL_DECODER_CTX, OSSL_DECODER_CTX_new, OSSL_DECODER_settable_ctx_params, OSSL_DECODER_CTX_set_params, OSSL_DECODER_CTX_free, OSSL_DECODER_CTX_set_selection, OSSL_DECODER_CTX_set_input_type, OSSL_DECODER_CTX_set_input_structure, OSSL_DECODER_CTX_add_decoder, OSSL_DECODER_CTX_add_extra, OSSL_DECODER_CTX_get_num_decoders, OSSL_DECODER_INSTANCE, OSSL_DECODER_CONSTRUCT, OSSL_DECODER_CLEANUP, OSSL_DECODER_CTX_set_construct, OSSL_DECODER_CTX_set_construct_data, OSSL_DECODER_CTX_set_cleanup, OSSL_DECODER_CTX_get_construct, OSSL_DECODER_CTX_get_construct_data, OSSL_DECODER_CTX_get_cleanup, OSSL_DECODER_export, OSSL_DECODER_INSTANCE_get_decoder, OSSL_DECODER_INSTANCE_get_decoder_ctx, OSSL_DECODER_INSTANCE_get_input_type, OSSL_DECODER_INSTANCE_get_input_structure β€” decoder context routines 🫢


πŸŽ€ 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. the OSSL_DECODER_CTX holds data about multiple decoders, which is exactly what you need to figure out what your input data even is and then try to unpack it into one of several possible related results. it also handles chaining decoders β€” meaning the output from one becomes the input for another. iconic behaviour honestly. that's how you get generic format decoders like PEM to DER, plus the more specialized girlies like DER to RSA. πŸ’–

the chains may be limited by specifying an input type, which counts as a starting point. this is both considered by OSSL_DECODER_CTX_add_extra(), which will stop adding one more decoder implementations when it has already added those that take the specified input type, and by functions like OSSL_DECODER_from_bio(3), which will only start the decoding process with the decoder implementations that take that input type. for example, if the input type is set to "DER", a PEM to DER decoder will be ignored. bye bestie πŸ‘‹

the input type can also be NULL, which means the caller doesn't know what type of input they have. (relatable.) in this case, OSSL_DECODER_from_bio() will simply try with one decoder implementation after the other, and thereby discover what kind of input the caller gave it. it's giving detective energy πŸ”

for every decoding done, even an intermediary one, a constructor provided by the caller is called to 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 that contains 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 empty OSSL_DECODER_CTX. blank slate, main character moment. ✨
  • OSSL_DECODER_settable_ctx_params() β€” returns an OSSL_PARAM(3) array of parameter descriptors.
  • OSSL_DECODER_CTX_set_params() β€” attempts to set parameters specified with an OSSL_PARAM(3) array params. 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 context ctx. if the argument is NULL, nothing is done. graceful exit, we love to see it. πŸ’…
  • OSSL_DECODER_CTX_add_decoder() β€” populates the OSSL_DECODER_CTX ctx with 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. πŸ”—
  • OSSL_DECODER_CTX_set_selection() β€” sets what the input is expected to contain.
  • 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. NULL is 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 context ctx.
  • OSSL_DECODER_CTX_set_construct() β€” sets the constructor construct.
  • 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 by OSSL_DECODER_CTX_free(3).
  • OSSL_DECODER_CTX_get_construct(), OSSL_DECODER_CTX_get_construct_data() and OSSL_DECODER_CTX_get_cleanup() β€” return the values that have been set by OSSL_DECODER_CTX_set_construct(), OSSL_DECODER_CTX_set_construct_data() and OSSL_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 instance decoder_inst that the constructor got and an object reference, unpacks the object which it refers to, and exports it by creating an OSSL_PARAM(3) array that it then passes to export_cb, along with export_arg.

🧚 Constructor 🧚

a OSSL_DECODER_CONSTRUCT gets the following arguments:

  • decoder_inst β€” the OSSL_DECODER_INSTANCE for 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 in provider-object(7).
  • construct_data β€” the pointer that was set with OSSL_DECODE_CTX_set_construct_data().

the constructor is expected to return 1 when the data it receives can be constructed, otherwise 0. (a yes-or-no girlie. πŸŽ€)

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 instance decoder_inst.
  • OSSL_DECODER_INSTANCE_get_decoder_ctx() β€” can be used to get the decoder implementation's provider context from a decoder instance decoder_inst.
  • OSSL_DECODER_INSTANCE_get_input_type() β€” can be used to get the decoder implementation's input type from a decoder instance decoder_inst.
  • OSSL_DECODER_INSTANCE_get_input_structure() β€” can be used to get the input structure for the decoder implementation from a decoder instance decoder_inst. this may be NULL.

πŸ”₯ RETURN VALUES πŸ”₯

  • OSSL_DECODER_CTX_new() returns a pointer to a OSSL_DECODER_CTX, or NULL if the context structure couldn't be allocated.
  • OSSL_DECODER_settable_ctx_params() returns an OSSL_PARAM(3) array, or NULL if none is available.
  • OSSL_DECODER_CTX_set_params() returns 1 if all recognised parameters were valid, or 0 if 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_cleanup(), OSSL_DECODER_CTX_set_construct(), OSSL_DECODER_CTX_set_construct_data(), OSSL_DECODER_CTX_set_input_structure(), OSSL_DECODER_CTX_set_input_type(), OSSL_DECODER_CTX_set_params(), and OSSL_DECODER_CTX_set_selection() return 1 on success, or 0 on failure. they always fail for decoder contexts created in a frozen state via OSSL_DECODER_CTX_new_for_pkey(3). πŸ₯Ά yes, frozen means frozen.
  • OSSL_DECODER_CTX_get_construct(), OSSL_DECODER_CTX_get_construct_data() and OSSL_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 returns 0 if ctx is NULL.
  • OSSL_DECODER_export() returns 1 on success, or 0 on failure.
  • OSSL_DECODER_INSTANCE_decoder() returns an OSSL_DECODER pointer on success, or NULL on failure.
  • OSSL_DECODER_INSTANCE_decoder_ctx() returns a provider context pointer on success, or NULL on failure.

🌈 SEE ALSO 🌈

provider(7), OSSL_DECODER(3), OSSL_DECODER_from_bio(3)


⭐ HISTORY ⭐

the functions described here were added in OpenSSL 3.0. vintage-ish but make it iconic. 🫢


Copyright 2020-2024 The OpenSSL Project Authors. All Rights Reserved.

Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.


and that's the whole page, bestie πŸ’– this was version 4.0.3, dated 2026-09-29, and you've been reading OSSL_DECODER_CTX(3SSL). go forth and decode, no cap. 🌸✨

πŸ“¦ where this page comes from