OSSL_ENCODER_CTX(3ossl)
π OSSL_ENCODER_CTX π
okay so this is the 3ossl manual page for the encoder context crew β literally the whole squad: 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, and OSSL_ENCODER_CTX_set_cleanup. it's giving "encoder context routines" and honestly? 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[]);
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 by chain i mean the output of one encoder becomes the input for the next one in line. very relay race, very passing the baton. πββοΈ
OSSL_ENCODER_CTX holds all the data about these encoders. this is what lets you have generic format encoders like DER β PEM and more specialized ones like RSA β DER. both. at once. versatile queen behaviour. π
the final output type must be given, and a chain of encoders must end with an implementation that produces that output type. no output type = no chain, i don't make the rules.
at the beginning of the encoding process, a constructor provided by 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 holding data about the encoder that's going to be used β data that may be useful for the constructor. there are functions to pull data out of it, described in the "Constructor" section below. π«Ά
πΈ Functions πΈ
OSSL_ENCODER_CTX_new()β creates anOSSL_ENCODER_CTX. fresh out the box, brand new, main character energy.OSSL_ENCODER_settable_ctx_params()β returns anOSSL_PARAM(3)array of parameter descriptors. it's the menu of what you can set.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 rude, just focused. π )OSSL_ENCODER_CTX_free()β frees the given contextctx. if the argument isNULL, nothing is done. no drama, no crash.OSSL_ENCODER_CTX_add_encoder()β populates theOSSL_ENCODER_CTXctxwith a encoder, to be used to encode an input object. (yes the manpage says "a encoder", we're keeping it, it's canon. π)OSSL_ENCODER_CTX_add_extra()β finds encoders that further encodes output from already added encoders, and adds them as well. this is the one that builds encoder chains. lowkey the glue of the whole operation.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. non-negotiable, bestie.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. (yes, "to determines", it's in the original, we're not touching it π)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 gets passed to the constructor every time it's called. consistent king.OSSL_ENCODER_CTX_set_cleanup()β sets the constructor data cleanup function. this gets 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(). (that's exactly how it's spelled in this doc, don't @ me β)
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 half measures, either it works or it's a whole situation. π
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. she's always showing up. β¨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. sometimes she's off the grid, it's fine.
π₯ 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. binary. no in-between.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. (graceful, love that for her.)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. (yes this line says "input type" and yes the next line has the same function name again β the original doc did a little copy-paste moment, we're preserving it for the culture π)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.
reminder bestie:OSSL_ENCODER_CTX_set_selection(),OSSL_ENCODER_CTX_set_output_type()andOSSL_ENCODER_CTX_set_output_structure()are in the synopsis and the name list but this page's RETURN VALUES section doesn't spell out their return values. don't come for me, i'm just the messenger. π«Ά
π SEE ALSO π
β HISTORY β
the functions described here were added in OpenSSL 3.0. so they're not ancient, they're established. π
π 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, you ate that, go build your encoder chain and slay πβ¨
3.5.0 Β· 2026-09-25 Β· OSSL_ENCODER_CTX(3ossl) β mwah, kiss from your favourite manpage ππ¦πΈ
π¦ where this page comes from
- opensuse-leap 16.0: openssl-3-doc 3.5.0-160000.11.1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms