BIO_FIND_TYPE(3)

πŸ“¦ version 4.4.0, in alpine 3.24, arch rolling

πŸ’… 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! πŸ“

🌈 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 string BIO pair β€” BIO_s_bio(3)
  • BIO_TYPE_FILE β€” name string FILE pointer β€” BIO_s_file(3)
  • BIO_TYPE_MEM β€” name string memory buffer β€” BIO_s_mem(3)
  • BIO_TYPE_NULL β€” name string NULL β€” 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 πŸ’œ


⚠️ okay important caveat time, don't skip this: the constants BIO_TYPE_BER, BIO_TYPE_PROXY_CLIENT, and BIO_TYPE_PROXY_SERVER do 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 constants BIO_TYPE_COMP, BIO_TYPE_LINEBUFFER, and BIO_TYPE_NBIO_TEST correspond 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 β€” or NULL if bio is a NULL pointer, or if no matching BIO is found. 😭
  • BIO_next() returns the next BIO β€” or NULL if bio is a NULL pointer, or if it points to the last BIO in a chain.
  • BIO_method_type() returns one of the BIO_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 🌸

BIO_meth_new(3), BIO_new(3)


πŸ’– 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