BIO_FIND_TYPE(3ossl)

πŸ“¦ version 3.5.0, in opensuse-leap 16.0

πŸ’… BIO_FIND_TYPE(3ossl) β€” the OpenSSL manual page, bestie edition

Okay so this is BIO_FIND_TYPE(3ossl) from the OpenSSL manual, and it's literally just about walking down a chain of BIOs and finding the one you want. Three little functions, zero drama, maximum slay. Let's go 🌸


✨ SYNOPSIS ✨

#include <openssl/bio.h>

BIO *BIO_find_type(BIO *b, int bio_type);
BIO *BIO_next(BIO *b);
int BIO_method_type(const BIO *b);

πŸ¦‹ DESCRIPTION πŸ¦‹

πŸ” BIO_find_type()

So BIO_find_type() goes digging for a BIO of a given type inside a chain, starting at the BIO called b. And the way it searches depends on what kind of type you hand it:

  • If type is a specific type (think BIO_TYPE_MEM), it searches for a BIO of exactly that type.
  • If type is a general type (think BIO_TYPE_SOURCE_SINK), it searches for the next matching BIO of that general type.

It returns the next matching BIO, or NULL if there isn't one. And bestie, listen: if type is BIO_TYPE_NONE, it will not find a match. Like, ever. Not a vibe, just facts πŸ’€

The general types that are defined are:

  • BIO_TYPE_DESCRIPTOR
  • BIO_TYPE_FILTER
  • BIO_TYPE_SOURCE_SINK

Want the full list of specific types? Go look at the <openssl/bio.h> header file, it's all in there πŸ‘‘

➑️ BIO_next()

BIO_next() hands you the next BIO in a chain. Use it on its own to walk every single BIO in a chain, or team it up with BIO_find_type() to round up all the BIOs of a certain type. Iconic duo behavior, honestly 🫢

🏷️ BIO_method_type()

BIO_method_type() returns the type of a BIO. That's it. That's the function. Simple, effective, ate ✨


πŸŽ€ RETURN VALUES πŸŽ€

  • BIO_find_type() β€” returns a matching BIO, or NULL if there's no match.
  • BIO_next() β€” returns the next BIO in a chain.
  • BIO_method_type() β€” returns the type of the BIO b.

πŸ”₯ EXAMPLES πŸ”₯

Here's the whole move: traverse a chain looking for digest BIOs. Copy it exactly, no cap:

BIO *btmp;

btmp = in_bio; /* in_bio is chain to search through */
do {
    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);
} while (btmp);

See how BIO_find_type() finds the digest BIO and then BIO_next() hops along to keep the loop going? That's the combo, periodt πŸ’œ


Copyright 2000-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>.


That's the whole page, diva πŸ’– This version is 3.5.0, dated 2026-09-25 β€” go forth and traverse those chains 🌈⭐

πŸ“¦ where this page comes from