BIO_METH_NEW(3)

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

πŸ’… BIO_METH_NEW(3) β€” custom BIO_METHOD era πŸ’…

okay bestie, this is the BIO_METH_NEW(3) page from the Library Functions Manual, and it’s genuinely iconic: we’re manipulating BIO_METHOD structures, aka the little function-pointer tables that give a BIO its whole personality. custom-BIO main character energy, no cap πŸ¦‹βœ¨


πŸ’– NAME πŸ’–

BIO_get_new_index, BIO_meth_new, BIO_meth_free, BIO_meth_get_write, BIO_meth_set_write, BIO_meth_get_read, BIO_meth_set_read, BIO_meth_get_puts, BIO_meth_set_puts, BIO_meth_get_gets, BIO_meth_set_gets, BIO_meth_get_ctrl, BIO_meth_set_ctrl, BIO_meth_get_create, BIO_meth_set_create, BIO_meth_get_destroy, BIO_meth_set_destroy, BIO_meth_get_callback_ctrl, BIO_meth_set_callback_ctrl β€” manipulate BIO_METHOD structures πŸ’…


✨ SYNOPSIS ✨

the synopsis says library β€œlibcrypto” and #include <openssl/bio.h>, so that’s your include + lib situation, bestie. the signatures go exactly like this:

int
BIO_get_new_index(void);

BIO_METHOD *
BIO_meth_new(int type, const char *name);

void
BIO_meth_free(BIO_METHOD *biom);

int
(*BIO_meth_get_write(const BIO_METHOD *biom))(BIO *, const char *, int);

int
BIO_meth_set_write(BIO_METHOD *biom,
    int (*write)(BIO *, const char *, int));

int
(*BIO_meth_get_read(const BIO_METHOD *biom))(BIO *, char *, int);

int
BIO_meth_set_read(BIO_METHOD *biom, int (*read)(BIO *, char *, int));

int
(*BIO_meth_get_puts(const BIO_METHOD *biom))(BIO *, const char *);

int
BIO_meth_set_puts(BIO_METHOD *biom, int (*puts)(BIO *, const char *));

int
(*BIO_meth_get_gets(const BIO_METHOD *biom))(BIO *, char *, int);

int
BIO_meth_set_gets(BIO_METHOD *biom, int (*gets)(BIO *, char *, int));

long
(*BIO_meth_get_ctrl(const BIO_METHOD *biom))(BIO *, int, long, void *);

int
BIO_meth_set_ctrl(BIO_METHOD *biom,
    long (*ctrl)(BIO *, int, long, void *));

int
(*BIO_meth_get_create(const BIO_METHOD *biom))(BIO *);

int
BIO_meth_set_create(BIO_METHOD *biom, int (*create)(BIO *));

int
(*BIO_meth_get_destroy(const BIO_METHOD *biom))(BIO *);

int
BIO_meth_set_destroy(BIO_METHOD *biom, int (*destroy)(BIO *));

long
(*BIO_meth_get_callback_ctrl(const BIO_METHOD *biom))(BIO *, int,
    BIO_info_cb *);

int
BIO_meth_set_callback_ctrl(BIO_METHOD *biom,
    long (*callback_ctrl)(BIO *, int, BIO_info_cb *));

πŸ¦‹ DESCRIPTION πŸ¦‹

the BIO_METHOD structure stores function pointers that implement a BIO type. if you want the whole lore on BIO objects, see BIO_new(3) πŸ’–

  • BIO_meth_new() β€” creates a new BIO_METHOD structure. it needs a unique integer type, and you use BIO_get_new_index() to get that value for type. currently, the user can only create up to 127 different BIO types, and type is limited to the range 129–255. the name pointer is stored in the structure and will not be freed by BIO_meth_free() β€” so don’t expect it to clean that up for you, bestie 🫢
  • the standard BIO types are listed in <openssl/bio.h>. some examples include BIO_TYPE_BUFFER and BIO_TYPE_CIPHER. the type of filter BIOs should have the BIO_TYPE_FILTER bit set. source/sink BIOs should have the BIO_TYPE_SOURCE_SINK bit set. file descriptor based BIOs (e.g. socket, fd, connect, accept etc.) should additionally have the BIO_TYPE_DESCRIPTOR bit set. see BIO_find_type(3) for more information 🌈
  • BIO_meth_free() β€” is an alias for free(3). literally that. πŸ’€
  • BIO_meth_get_write(), BIO_meth_set_write(), BIO_meth_get_read(), and BIO_meth_set_read() β€” get and set the functions write and read used for writing and reading arbitrary length data to and from the BIO. these functions are called from BIO_write(3) and BIO_read(3), respectively. the parameters and return values of write and read have the same meaning as for BIO_write(3) and BIO_read(3) ✨
  • BIO_meth_get_puts() and BIO_meth_set_puts() β€” get and set the function puts used for writing a NUL-terminated string to the BIO. this function is called from BIO_puts(3). the parameters and the return value of puts have the same meaning as for BIO_puts(3) πŸŽ€
  • BIO_meth_get_gets() and BIO_meth_set_gets() β€” get and set the function gets used for reading a line of data from the BIO. this function is called from BIO_gets(3). the parameters and the return value of gets have the same meaning as for BIO_gets(3) 🌸
  • BIO_meth_get_ctrl() and BIO_meth_set_ctrl() β€” get and set the function ctrl used for processing control messages in the BIO. this function is called from BIO_ctrl(3). the parameters and return value of ctrl have the same meaning as for BIO_ctrl(3) πŸ”₯
  • BIO_meth_get_create() and BIO_meth_set_create() β€” get and set a function create used while initializing a new instance of the BIO. this function is called from BIO_new(3). BIO_new(3) allocates the memory for the new BIO, and a pointer to this newly allocated structure is passed as the parameter to create πŸ‘‘
  • BIO_meth_get_destroy() and BIO_meth_set_destroy() β€” get and set a function destroy used while destroying an instance of a BIO. this function is called from BIO_free(3). a pointer to the BIO to be destroyed is passed as the parameter. the destroy function is intended to perform clean-up specific to the BIO type. the memory for the BIO itself must not be freed by this function β€” don’t do it, bestie, that’s not your moment 😭
  • BIO_meth_get_callback_ctrl() and BIO_meth_set_callback_ctrl() β€” get and set the function callback_ctrl used for processing callback control messages in the BIO. this function is called from BIO_callback_ctrl(3). the parameters and return value of callback_ctrl have the same meaning as for BIO_callback_ctrl(3) πŸ’œ

🌈 RETURN VALUES 🌈

  • BIO_get_new_index() β€” returns the new BIO type value or -1 if an error occurs.
  • BIO_meth_new() β€” returns the new BIO_METHOD structure or NULL if an error occurs.
  • BIO_meth_set_*() β€” return 1 on success or 0 on error. currently, they cannot fail. slay, no notes πŸ’…
  • BIO_meth_get_*() β€” return function pointers.

πŸ”₯ SEE ALSO πŸ”₯

BIO_ctrl(3), BIO_find_type(3), BIO_new(3), BIO_read(3) 🫢


πŸŽ€ HISTORY πŸŽ€

these functions first appeared in OpenSSL 1.1.0 and have been available since OpenBSD 6.3. periodt πŸ’–


mwah πŸ’‹ β€” this cutie is from the Debian source, dated June 8, 2025, and the manual page is BIO_METH_NEW(3) πŸŽ€βœ¨

πŸ“¦ where this page comes from