BIO_FIND_TYPE(3)
π BIO_FIND_TYPE(3) β like, the whole BIO chain traversal moment
okay bestie, so this is the libcrypto page β the Library Functions Manual one β and it's literally all about walking through a chain of BIOs and finding the one you want. it's giving scavenger hunt but make it β¨cryptographicβ¨. let's get into it π«Ά
β¨ SYNOPSIS β¨
library βlibcryptoβ #include <openssl/bio.h>
BIO *
BIO_find_type(BIO *bio, int type);
BIO *
BIO_next(BIO *bio);
int
BIO_method_type(const BIO *bio);
const char *
BIO_method_name(const BIO *bio);
#define BIO_TYPE_NONE 0
#define BIO_TYPE_START 128
like, yes, that's a lot of BIO * up there, don't panic π
πΈ DESCRIPTION πΈ
So BIO_find_type() goes searching through the chain starting at bio, looking for a BIO that matches the type you passed in. Here's the tea on how matching works, because it's lowkey the whole plot twist:
- if the least significant byte of the type argument is non-zero, only exact matches of the type get accepted. no vibes-based matching, periodt.
- otherwise, a match just requires that any of the bits set in the type argument is also set in the candidate BIO. bitwise bestie behavior π
Types whose least significant byte is in the range from 0 to BIO_TYPE_START, inclusive, are reserved for BIO types built into the library. Types whose least significant byte is greater than BIO_TYPE_START are available for user-defined BIO types β see BIO_get_new_index(3) for the details, iykyk π₯
BIO_next() returns the next BIO in the chain after bio. use this to traverse all the BIOs in a chain, or team it up with BIO_find_type() to find all the BIOs of a certain type. dynamic duo energy fr fr π¦
BIO_method_type() returns the type of the given bio.
BIO_method_name() returns an ASCII string representing the type of the bio.
π the built-in source/sink BIO types that operate on file descriptors
bestie these all have both the bits BIO_TYPE_SOURCE_SINK and BIO_TYPE_DESCRIPTOR set in their type constant β but not the bit BIO_TYPE_FILTER. noted! π
BIO_TYPE_ACCEPTβ name stringsocket acceptβBIO_s_accept(3)BIO_TYPE_CONNECTβ name stringsocket connectβBIO_s_connect(3)BIO_TYPE_DGRAMβ name stringdatagram socketβBIO_s_datagram(3)BIO_TYPE_FDβ name stringfile descriptorβBIO_s_fd(3)BIO_TYPE_SOCKETβ name stringsocketβBIO_s_socket(3)
π the built-in source/sink BIO types that don't directly operate on file descriptors
these all have the bit BIO_TYPE_SOURCE_SINK set β but not BIO_TYPE_DESCRIPTOR and not BIO_TYPE_FILTER. different flavor, same source/sink slay β
BIO_TYPE_BIOβ name stringBIO pairβBIO_s_bio(3)BIO_TYPE_FILEβ name stringFILE pointerβBIO_s_file(3)BIO_TYPE_MEMβ name stringmemory bufferβBIO_s_mem(3)BIO_TYPE_NULLβ name stringNULLβBIO_s_null(3)
π§ the built-in filter BIO types
these all have the bit BIO_TYPE_FILTER set β and not BIO_TYPE_SOURCE_SINK or BIO_TYPE_DESCRIPTOR. filter era π
BIO_TYPE_BASE64β name stringbase64 encodingβBIO_f_base64(3)BIO_TYPE_BUFFERβ name stringbufferβBIO_f_buffer(3)BIO_TYPE_CIPHERβ name stringcipherβBIO_f_cipher(3)BIO_TYPE_MDβ name stringmessage digestβBIO_f_md(3)BIO_TYPE_NULL_FILTERβ name stringNULL filterβBIO_f_null(3)BIO_TYPE_SSLβ name stringsslβBIO_f_ssl(3)
β οΈ okay important caveat time, don't skip this: the constantsBIO_TYPE_BER,BIO_TYPE_PROXY_CLIENT, andBIO_TYPE_PROXY_SERVERdo not correspond to any BIO types implemented by the library, and they are not intended to be used for application-defined types either. so like... don't. π
also: the constantsBIO_TYPE_COMP,BIO_TYPE_LINEBUFFER, andBIO_TYPE_NBIO_TESTcorrespond to deprecated BIO types that are intentionally undocumented. they're the mysterious exes of the BIO world π
And a cute little life tip: if a variable in your application program is intended to store a BIO type but temporarily doesn't refer to any BIO, or refers to a BIO of an unknown type, setting that variable to BIO_TYPE_NONE is recommended. do it for the plot π
π RETURN VALUES π
BIO_find_type()returns the next matching BIO β orNULLif bio is aNULLpointer, or if no matching BIO is found. πBIO_next()returns the next BIO β orNULLif bio is aNULLpointer, or if it points to the last BIO in a chain.BIO_method_type()returns one of theBIO_TYPE_*constants.BIO_method_name()returns an internal pointer to a string.
π₯ EXAMPLES π₯
Traverse a chain looking for digest BIOs β this is the moment, bestie, study it:
BIO *btmp;
btmp = in_bio; /* in_bio is the chain to search through */
while (btmp != NULL) {
btmp = BIO_find_type(btmp, BIO_TYPE_MD);
if (btmp == NULL)
break; /* Not found */
/* btmp is a digest BIO, do something with it ... */
...
btmp = BIO_next(btmp);
}
πΈ SEE ALSO πΈ
π HISTORY π
BIO_method_type() and BIO_method_name() first appeared in SSLeay 0.6.0. BIO_find_type() first appeared in SSLeay 0.6.6. these functions have been available since OpenBSD 2.4. vintage icons only π
BIO_next() first appeared in OpenSSL 0.9.6 and has been available since OpenBSD 2.9. late bloomer, still iconic πΈ
k bye bestie, go traverse that chain π¦β¨ β this page came from Debian, dated June 8, 2025, and yeah that's the whole BIO_FIND_TYPE(3) situation, no cap π
π¦ where this page comes from
- alpine 3.24: libressl-doc 4.3.1-r0 Β· custom
- arch rolling: libressl 4.4.0-1 Β· ISC AND custom:OpenSSL
- Copyright (c) 2021, 2023 Ingo Schwarze <schwarze@openbsd.org>
- Copyright (c) 2000, 2013, 2016 The OpenSSL Project. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms