OSSL_DECODER_FROM_BIO(3SSL)
π OSSL_DECODER_FROM_BIO(3SSL) π
okay bestie, welcome to the OpenSSL manual, section 3SSL β and today's main character is OSSL_DECODER_from_data, OSSL_DECODER_from_bio and OSSL_DECODER_from_fp. it's giving "routines to perform a decoding" and honestly? slay. πΈ
β¨ NAME β¨
OSSL_DECODER_from_data, OSSL_DECODER_from_bio, OSSL_DECODER_from_fp β the routines that actually do the decoding. like, the whole point. the moment. π
β¨ SYNOPSIS β¨
#include <openssl/decoder.h>
int OSSL_DECODER_from_bio(OSSL_DECODER_CTX *ctx, BIO *in);
int OSSL_DECODER_from_fp(OSSL_DECODER_CTX *ctx, FILE *fp);
int OSSL_DECODER_from_data(OSSL_DECODER_CTX *ctx, const unsigned char **pdata,
size_t *pdata_len);
Feature availability macros, bestie β read this part, it matters: β οΈ
OSSL_DECODER_from_fp()is only available whenOPENSSL_NO_STDIOis undefined.
β¨ DESCRIPTION β¨
so here's the tea on each one π«β¨
π OSSL_DECODER_from_data()
this one runs the decoding process for the context ctx, with the input coming from *pdata, which is *pdata_len bytes long. both *pdata and *pdata_len must be non-NULL β no cap, that's just how it is.
and then the β¨glow-upβ¨ moment: when OSSL_DECODER_from_data() returns, *pdata gets updated to point at the location after what has been decoded, and *pdata_len gets updated to hold the number of remaining bytes. so it's lowkey also a progress bar. iconic. π
π OSSL_DECODER_from_bio()
this one runs the decoding process for the context ctx, with the input coming from the BIO in.
should it make a difference, it's recommended to have the BIO set in binary mode rather than text mode. so like, binary mode is the vibe. π
π OSSL_DECODER_from_fp()
does the same thing as OSSL_DECODER_from_bio(), except the input is coming from the FILE fp. same energy, different source. fr fr.
β¨ RETURN VALUES β¨
OSSL_DECODER_from_bio(), OSSL_DECODER_from_data() and OSSL_DECODER_from_fp() return 1 on success, or 0 on failure. that's it. no mysterious third option, no in-between, no "it depends". π
β¨ EXAMPLES β¨
π¦ decoding an RSA key encoded with PEM from a bio
OSSL_DECODER_CTX *dctx;
EVP_PKEY *pkey = NULL;
const char *format = "PEM"; /* NULL for any format */
const char *structure = NULL; /* any structure */
const char *keytype = "RSA"; /* NULL for any key */
const unsigned char *pass = "my password";
dctx = OSSL_DECODER_CTX_new_for_pkey(&pkey, format, structure,
keytype,
OSSL_KEYMGMT_SELECT_KEYPAIR,
NULL, NULL);
if (dctx == NULL) {
/* error: no suitable potential decoders found */
}
if (pass != NULL)
OSSL_DECODER_CTX_set_passphrase(dctx, pass, strlen(pass));
if (OSSL_DECODER_from_bio(dctx, bio)) {
/* pkey is created with the decoded data from the bio */
} else {
/* decoding failure */
}
OSSL_DECODER_CTX_free(dctx);
π¦ decoding an EC key encoded with DER from a buffer
OSSL_DECODER_CTX *dctx;
EVP_PKEY *pkey = NULL;
const char *format = "DER"; /* NULL for any format */
const char *structure = NULL; /* any structure */
const char *keytype = "EC"; /* NULL for any key */
const unsigned char *pass = NULL
const unsigned char *data = buffer;
size_t datalen = sizeof(buffer);
dctx = OSSL_DECODER_CTX_new_for_pkey(&pkey, format, structure,
keytype,
OSSL_KEYMGMT_SELECT_KEYPAIR
| OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS,
NULL, NULL);
if (dctx == NULL) {
/* error: no suitable potential decoders found */
}
if (pass != NULL)
OSSL_DECODER_CTX_set_passphrase(dctx, pass, strlen(pass));
if (OSSL_DECODER_from_data(dctx, &data, &datalen)) {
/* pkey is created with the decoded data from the buffer */
} else {
/* decoding failure */
}
OSSL_DECODER_CTX_free(dctx);
β¨ SEE ALSO β¨
provider(7), OSSL_DECODER_CTX(3)
go read those too, bestie, they're part of the lore ππ
β¨ HISTORY β¨
the functions described here were added in OpenSSL 3.0. so they're not ancient, they're just β¨establishedβ¨.
β¨ COPYRIGHT β¨
Copyright 2020-2023 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>.
real talk bestie: none of this is optional. the license said what it said. π
that's the whole page!! this was version 4.0.3, dated 2026-09-29, and it's the OSSL_DECODER_FROM_BIO(3SSL) page from the OpenSSL manual. thank u for coming to my ted talk, go decode something, ily, periodt π
β¨π
π¦ 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