OSSL_ENCODER_CTX(3ossl)
π¦ OSSL_ENCODER_CTX π β Encoder context routines
okay so this is the 3ossl page for the OSSL_ENCODER_CTX fam β the encoder context routines. yes, we're getting into the OpenSSL guts, but bestie, it's giving β¨plumbingβ¨ and honestly it's iconic.
β¨ NAME β¨
OSSL_ENCODER_CTX, OSSL_ENCODER_CTX_new, OSSL_ENCODER_settable_ctx_params, OSSL_ENCODER_CTX_set_params, OSSL_ENCODER_CTX_free, OSSL_ENCODER_CTX_set_selection, OSSL_ENCODER_CTX_set_output_type, OSSL_ENCODER_CTX_set_output_structure, OSSL_ENCODER_CTX_add_encoder, OSSL_ENCODER_CTX_add_extra, OSSL_ENCODER_CTX_get_num_encoders, OSSL_ENCODER_INSTANCE, OSSL_ENCODER_INSTANCE_get_encoder, OSSL_ENCODER_INSTANCE_get_encoder_ctx, OSSL_ENCODER_INSTANCE_get_output_type, OSSL_ENCODER_INSTANCE_get_output_structure, OSSL_ENCODER_CONSTRUCT, OSSL_ENCODER_CLEANUP, OSSL_ENCODER_CTX_set_construct, OSSL_ENCODER_CTX_set_construct_data, OSSL_ENCODER_CTX_set_cleanup β all of those, and they're all about Encoder context routines. periodt π
πΈ SYNOPSIS πΈ
#include <openssl/encoder.h>
typedef struct ossl_encoder_ctx_st OSSL_ENCODER_CTX;
OSSL_ENCODER_CTX *OSSL_ENCODER_CTX_new();
const OSSL_PARAM *OSSL_ENCODER_settable_ctx_params(OSSL_ENCODER *encoder);
int OSSL_ENCODER_CTX_set_params(OSSL_ENCODER_CTX *ctx,
const OSSL_PARAM params[]);
void OSSL_ENCODER_CTX_free(OSSL_ENCODER_CTX *ctx);
int OSSL_ENCODER_CTX_set_selection(OSSL_ENCODER_CTX *ctx, int selection);
int OSSL_ENCODER_CTX_set_output_type(OSSL_ENCODER_CTX *ctx,
const char *output_type);
int OSSL_ENCODER_CTX_set_output_structure(OSSL_ENCODER_CTX *ctx,
const char *output_structure);
int OSSL_ENCODER_CTX_add_encoder(OSSL_ENCODER_CTX *ctx, OSSL_ENCODER *encoder);
int OSSL_ENCODER_CTX_add_extra(OSSL_ENCODER_CTX *ctx,
OSSL_LIB_CTX *libctx, const char *propq);
int OSSL_ENCODER_CTX_get_num_encoders(OSSL_ENCODER_CTX *ctx);
typedef struct ossl_encoder_instance_st OSSL_ENCODER_INSTANCE;
OSSL_ENCODER *
OSSL_ENCODER_INSTANCE_get_encoder(OSSL_ENCODER_INSTANCE *encoder_inst);
void *
OSSL_ENCODER_INSTANCE_get_encoder_ctx(OSSL_ENCODER_INSTANCE *encoder_inst);
const char *
OSSL_ENCODER_INSTANCE_get_output_type(OSSL_ENCODER_INSTANCE *encoder_inst);
const char *
OSSL_ENCODER_INSTANCE_get_output_structure(OSSL_ENCODER_INSTANCE *encoder_inst);
typedef const void *OSSL_ENCODER_CONSTRUCT(OSSL_ENCODER_INSTANCE *encoder_inst,
void *construct_data);
typedef void OSSL_ENCODER_CLEANUP(void *construct_data);
int OSSL_ENCODER_CTX_set_construct(OSSL_ENCODER_CTX *ctx,
OSSL_ENCODER_CONSTRUCT *construct);
int OSSL_ENCODER_CTX_set_construct_data(OSSL_ENCODER_CTX *ctx,
void *construct_data);
int OSSL_ENCODER_CTX_set_cleanup(OSSL_ENCODER_CTX *ctx,
OSSL_ENCODER_CLEANUP *cleanup);
π DESCRIPTION π
so here's the vibe: encoding an input object into the encoding you actually want can be done with a chain of encoder implementations. and yes, that means the output from one encoder can absolutely be the input for the next one in the chain β it's giving relay race πββοΈπ¨. The OSSL_ENCODER_CTX holds all the data about these encoders. this is what lets us have generic format encoders like DER to PEM, and more specialized encoders like RSA to DER. versatile queen behavior π.
the final output type must be given, and a chain of encoders must end with an implementation that produces that output type. no vibes-based guessing allowed π₯.
at the beginning of the encoding process, a constructor provided by you (the caller) gets called, to make sure there's an appropriate provider-side object to start with. you set that constructor with OSSL_ENCODER_CTX_set_construct().
OSSL_ENCODER_INSTANCE is an opaque structure containing data about the encoder that's going to be used, and that data may be useful for the constructor. there are some functions to extract data from this type, and they're described in "Constructor" below π.
π Functions π
OSSL_ENCODER_CTX_new()β creates anOSSL_ENCODER_CTX. new context, who dis πOSSL_ENCODER_settable_ctx_params()β returns anOSSL_PARAM(3)array of parameter descriptors.OSSL_ENCODER_CTX_set_params()β attempts to set parameters specified with anOSSL_PARAM(3)arrayparams. Parameters that the implementation doesn't recognise should be ignored. (not a rejection, just an ignore, we're being chill π«Ά)OSSL_ENCODER_CTX_free()β frees the given contextctx. If the argument isNULL, nothing is done. iconic minimal effort.OSSL_ENCODER_CTX_add_encoder()β populates theOSSL_ENCODER_CTXctxwith a encoder, to be used to encode an input object. (yes the page says "a encoder", we don't gatekeep grammar here π)OSSL_ENCODER_CTX_add_extra()β finds encoders that further encodes output from already added encoders, and adds them as well. this is literally how encoder chains get built, bestie πOSSL_ENCODER_CTX_set_output_type()β sets the ending output type. this must be specified, and it determines if a complete encoder chain is available.OSSL_ENCODER_CTX_set_output_structure()β sets the desired output structure. this may be used to determines what encoder implementations may be used. depending on the type of object being encoded, the output structure may not be relevant π€·ββοΈOSSL_ENCODER_CTX_get_num_encoders()β gets the number of encoders currently added to the contextctx.OSSL_ENCODER_CTX_set_construct()β sets the constructorconstruct.OSSL_ENCODER_CTX_set_construct_data()β sets the constructor data that is passed to the constructor every time it's called.OSSL_ENCODER_CTX_set_cleanup()β sets the constructor data cleanup function. this is called byOSSL_ENCODER_CTX_free(3).
β οΈ okay listen up, this part matters:OSSL_ENCODER_CTX_set_selection(),OSSL_ENCODER_CTX_set_output_type(),OSSL_ENCODER_CTX_set_output_structure(),OSSL_ENCODER_CTX_add_encoder(),OSSL_ENCODER_CTX_add_extra(),OSSL_ENCODER_CTX_set_construct(),OSSL_ENCODER_CTX_set_construct_data(), andOSSL_ENCODER_CTX_set_cleanup()shouldn't be used after the context is finalised β in particular after calling the functionOSSL_ENCODER_CTX_new_for_pkey(). finalised means finalised, bestie, don't be out here editing after the deadline π
π§ Constructor π§
a OSSL_ENCODER_CONSTRUCT gets the following arguments:
encoder_instβ theOSSL_ENCODER_INSTANCEfor the encoder from which the constructor gets its data.construct_dataβ the pointer that was set withOSSL_ENCODE_CTX_set_construct_data().
the constructor is expected to return a valid (non-NULL) pointer to a provider-native object that can be used as first input of an encoding chain, or NULL to indicate that an error has occurred. no pressure or anything π
these utility functions may be used by a constructor:
OSSL_ENCODER_INSTANCE_get_encoder()β can be used to get the encoder implementation of the encoder instanceencoder_inst.OSSL_ENCODER_INSTANCE_get_encoder_ctx()β can be used to get the encoder implementation's provider context of the encoder instanceencoder_inst.OSSL_ENCODER_INSTANCE_get_output_type()β can be used to get the output type for the encoder implementation of the encoder instanceencoder_inst. this will never beNULL. πOSSL_ENCODER_INSTANCE_get_output_structure()β can be used to get the output structure for the encoder implementation of the encoder instanceencoder_inst. this may beNULL.
π₯ RETURN VALUES π₯
OSSL_ENCODER_CTX_new()β returns a pointer to anOSSL_ENCODER_CTX, orNULLif the context structure couldn't be allocated. πOSSL_ENCODER_settable_ctx_params()β returns anOSSL_PARAM(3)array, orNULLif none is available.OSSL_ENCODER_CTX_set_params()β returns1if all recognised parameters were valid, or0if one of them was invalid or caused some other failure in the implementation.OSSL_ENCODER_CTX_add_encoder(),OSSL_ENCODER_CTX_add_extra(),OSSL_ENCODER_CTX_set_construct(),OSSL_ENCODER_CTX_set_construct_data()andOSSL_ENCODER_CTX_set_cleanup()β return1on success, or0on failure.OSSL_ENCODER_CTX_get_num_encoders()β returns the current number of encoders. it returns0ifctxisNULL. (zero, not a crash β we love a graceful zero π«Ά)OSSL_ENCODER_INSTANCE_get_encoder()β returns anOSSL_ENCODERpointer on success, orNULLon failure.OSSL_ENCODER_INSTANCE_get_encoder_ctx()β returns a provider context pointer on success, orNULLon failure.OSSL_ENCODER_INSTANCE_get_output_type()β returns a string with the name of the input type, if relevant.NULLis a valid returned value.OSSL_ENCODER_INSTANCE_get_output_type()β returns a string with the name of the output type. (and yes, the page literally listsOSSL_ENCODER_INSTANCE_get_output_type()twice here β I'm just faithfully repeating it, don't come for me π)OSSL_ENCODER_INSTANCE_get_output_structure()β returns a string with the name of the output structure.
π NOTES AND BUGS π
the chain mechanism in ENCODE is not yet completely implemented. it affects functions such as OSSL_ENCODER_CTX_add_extra and the inner processing loop. so likeβ¦ it's a work in progress, ngl, but we stan an honest manpage π
β SEE ALSO β
πΈ HISTORY πΈ
the functions described here were added in OpenSSL 3.0.
π COPYRIGHT π
Copyright 2019-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>.
okay that's the whole page bestie, you ate that π β¨ this was OpenSSL 3.5.6, dated 2026-04-07 β go forth and encode responsibly, mwah π«Άπ
π¦ 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