ASN1_BIT_STRING_SET(3)
πΈ NAME πΈ
okay bestie, welcome to ASN1_BIT_STRING_SET(3) from the Library Functions Manual β yes, itβs the ASN.1 BIT STRING accessors and they are lowkey iconic. The whole crew is ASN1_BIT_STRING_set, ASN1_BIT_STRING_set_bit, and ASN1_BIT_STRING_get_bit. They live in libcrypto, and we are absolutely getting into it π
.
β¨ SYNOPSIS β¨
the library is libcrypto, and the header situation is:
library βlibcryptoβ
#include <openssl/asn1.h>
then the function signatures, exactly:
int
ASN1_BIT_STRING_set(ASN1_BIT_STRING *bitstr, unsigned char *data,
int len);
int
ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *bitstr, int bitnumber,
int set);
int
ASN1_BIT_STRING_get_bit(ASN1_BIT_STRING *bitstr, int bitnumber);
π DESCRIPTION π
okay so ASN1_BIT_STRING_set() sets the length attribute of bitstr to len and copies that number of bytes from data into bitstr, overwriting any previous data β and the way it does this is literally just by calling ASN1_STRING_set(3). Thatβs the whole move. It does no validation whatsoever. none. not a crumb.
π¨ bestie warning:ASN1_BIT_STRING_set()does no validation whatsoever. In particular, it neither checks thatbitstris actually of the typeV_ASN1_BIT_STRINGnor, even if it is, that thedataandlenarguments make sense for this particular bit string.
ASN1_BIT_STRING_set_bit() has a lil set argument, and the vibe check is simple: if set is non-zero, it sets the bit with the given bitnumber in the bitstr; otherwise, it clears that bit.
the bit numbering is giving βmost significant firstβ energy:
bitnumberof0addresses the most significant bit in the first data byte ofbitstr7addresses the least significant bit in the same byte8addresses the most significant bit in the second data byte- and so on β¨
if setting a bit is requested beyond the last existing data byte, additional bytes are added to the bitstr as needed. after clearing a bit, any trailing NUL bytes are removed from the bitstr.
ASN1_BIT_STRING_get_bit() checks that the bit with the given bitnumber is set in bitstr. thatβs it. itβs the bit vibes check π₯.
π«Ά RETURN VALUES π«Ά
ASN1_BIT_STRING_set()β returns1on success or0if memory allocation fails or ifdataisNULLandlenis-1in the same call.ASN1_BIT_STRING_set_bit()β returns1on success or0ifbitstrisNULLor if memory allocation fails.ASN1_BIT_STRING_get_bit()β returns1if the bit with the givenbitnumberis set in thebitstror0ifbitstrisNULL, ifbitnumberpoints beyond the last data byte inbitstr, or if the requested bit is not set.
π₯ SEE ALSO π₯
go read these next, bestie:
π HISTORY π
ASN1_BIT_STRING_set() first appeared in SSLeay 0.6.5. ASN1_BIT_STRING_set_bit() and ASN1_BIT_STRING_get_bit() first appeared in SSLeay 0.9.0. These functions have been available since OpenBSD 2.4.
xoxo, this page comes from Debian, dated June 8, 2025, and itβs the ASN1_BIT_STRING_SET(3) manual β periodt π
π¦ 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 Ingo Schwarze <schwarze@openbsd.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms