OSSL_ENCODER_CTX(3SSL)
π OSSL_ENCODER_CTX β encoder context routines π
hey bestie, welcome to the OSSL_ENCODER_CTX(3SSL) page, aka your group chat for making encoders behave. grab a snack, we're going through everything.
β¨ NAME β¨
It's the whole squad of encoder-context routines, and here's every single one of them, no cap:
OSSL_ENCODER_CTXOSSL_ENCODER_CTX_newOSSL_ENCODER_settable_ctx_paramsOSSL_ENCODER_CTX_set_paramsOSSL_ENCODER_CTX_ctrl_stringOSSL_ENCODER_CTX_freeOSSL_ENCODER_CTX_set_selectionOSSL_ENCODER_CTX_set_output_typeOSSL_ENCODER_CTX_set_output_structureOSSL_ENCODER_CTX_add_encoderOSSL_ENCODER_CTX_add_extraOSSL_ENCODER_CTX_get_num_encodersOSSL_ENCODER_INSTANCEOSSL_ENCODER_INSTANCE_get_encoderOSSL_ENCODER_INSTANCE_get_encoder_ctxOSSL_ENCODER_INSTANCE_get_output_typeOSSL_ENCODER_INSTANCE_get_output_structureOSSL_ENCODER_CONSTRUCTOSSL_ENCODER_CLEANUPOSSL_ENCODER_CTX_set_constructOSSL_ENCODER_CTX_set_construct_dataOSSL_ENCODER_CTX_set_cleanup
and what are they, as a collective? Encoder context routines. iconic. π
π¦ 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[]);
int OSSL_ENCODER_CTX_ctrl_string(OSSL_ENCODER_CTX *ctx,
const char *name, const char *val);
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 πΈ
okay so here's the vibe. you want to encode an input object into whatever encoding you're dreaming of, and you don't have to do it alone β you do it with a chain of encoder implementations. that means the output from one encoder can literally be the input for the next one in the chain. a relay race, but for bytes. πβοΈβ¨
The OSSL_ENCODER_CTX is the main character here β it holds all the data about these encoders. Which is what lets you have generic format encoders like DER to PEM, AND also more specialized ones like RSA to DER. both. we can have both. π
You must give the final output type, and a chain of encoders must end with an implementation that produces that output type. no notes.
At the beginning of the encoding process, a constructor that you (the caller) provided 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 holding 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 down in "Constructor". π«Ά
π Functions π
OSSL_ENCODER_CTX_new()β creates aOSSL_ENCODER_CTX. fresh out the box, bestie.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. (like, they get the silent treatment. respectfully.)OSSL_ENCODER_CTX_ctrl_string()β attempts to set a single parameter namednameby parsing the specified string value to the type of a settable parameter associated with one of the underlying encoders. An error is reported if no parameter namednameis a settable in any of the underlying encoders, the value fails to parse, or the encoder implementation rejects the parsed value. so many ways to fail π but it will tell you.OSSL_ENCODER_CTX_free()β frees the given contextctx. If the argument isNULL, nothing is done. (it's giving "if they're not there, we don't speak.")OSSL_ENCODER_CTX_add_encoder()β populates theOSSL_ENCODER_CTXctxwith a encoder, to be used to encode an input object.OSSL_ENCODER_CTX_add_extra()β finds encoders that further encodes output from already added encoders, and adds them as well. This is used to build encoder chains. chain-building behaviour fr fr. πOSSL_ENCODER_CTX_set_selection()β sets what should be included in the output.OSSL_ENCODER_CTX_set_output_type()β sets the ending output type. This must be specified, and 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. (iykyk, it's a vibe-dependent situation.)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).
π§ 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 NULL shenanigans unless something went wrong, bestie.
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. periodt.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. ok so this one's allowed to ghost you.
π₯ RETURN VALUES π₯
OSSL_ENCODER_CTX_new()returns a pointer to aOSSL_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_ctrl_string()returns1on success and0on error.OSSL_ENCODER_CTX_add_encoder(),OSSL_ENCODER_CTX_add_extra(),OSSL_ENCODER_CTX_set_cleanup(),OSSL_ENCODER_CTX_set_construct(),OSSL_ENCODER_CTX_set_construct_data(),OSSL_ENCODER_CTX_set_output_structure(),OSSL_ENCODER_CTX_set_output_type()andOSSL_ENCODER_CTX_set_selection()return1on success, or0on failure.
β οΈ heads up bestie: they always fail for encoder contexts created in a frozen state via OSSL_ENCODER_CTX_new_for_pkey(3). frozen means frozen. π§
OSSL_ENCODER_CTX_get_num_encoders()returns the current number of encoders. It returns0ifctxisNULL.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.OSSL_ENCODER_INSTANCE_get_output_structure()returns a string with the name of the output structure.
(yes, OSSL_ENCODER_INSTANCE_get_output_type() really is listed twice up there, once for the input type and once for the output type. the manpage said it, so I said it. π)
π 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 not finished yet, don't be shocked.
π SEE ALSO π
β HISTORY β
The functions described here were added in OpenSSL 3.0. a classic, honestly.
π 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>.
and that's the whole page, bestie!! this was OpenSSL 4.0.3, dated 2026-09-29, and it's genuinely been a pleasure. go encode something gorgeous. mwah. πβ¨π
π¦ where this page comes from
- ubuntu stonking: libssl-doc 4.0.3-1ubuntu1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms