ASN1_BIT_STRING_GET_LENGTH(3SSL)
โจ NAME โจ
ASN1_BIT_STRING_set1, ASN1_BIT_STRING_set_bit, ASN1_BIT_STRING_get_bit, ASN1_BIT_STRING_check, ASN1_BIT_STRING_name_print, ASN1_BIT_STRING_num_asc, ASN1_BIT_STRING_set_asc, ASN1_BIT_STRING_get_length โ bestie, these are the ASN1_BIT_STRING accessors ๐ (it's the OpenSSL 3SSL manual, periodt)
๐ SYNOPSIS ๐
okay so like, here's the whole squad, exactly as they show up in the wild:
#include <openssl/asn1.h>
typedef struct BIT_STRING_BITNAME_st {
int bitnum;
const char *lname;
const char *sname;
} BIT_STRING_BITNAME;
int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value);
int ASN1_BIT_STRING_get_bit(const ASN1_BIT_STRING *a, int n);
int ASN1_BIT_STRING_check(const ASN1_BIT_STRING *a,
const unsigned char *flags, int flags_len);
int ASN1_BIT_STRING_name_print(BIO *out, ASN1_BIT_STRING *bs,
BIT_STRING_BITNAME *tbl, int indent);
int ASN1_BIT_STRING_num_asc(const char *name, BIT_STRING_BITNAME *tbl);
int ASN1_BIT_STRING_set_asc(ASN1_BIT_STRING *bs, const char *name,
int value, BIT_STRING_BITNAME *tbl);
int ASN1_BIT_STRING_get_length(const ASN1_BIT_STRING *bitstr,
size_t *length, int *unused_bits);
int ASN1_BIT_STRING_set1(ASN1_BIT_STRING *bitstr, const uint8_t *data,
size_t length, int unused_bits);
๐ฆ DESCRIPTION ๐ฆ
So the ASN.1 BIT STRING type is literally just a bit string of arbitrary bit length, no cap ๐
. But here's the tea: in the distinguished encoding rules DER, those bits get encoded in groups of eight, which means the last octet has somewhere between zero and seven bits justโฆ sitting there unused ๐. And if there are unused bits, they must all be set to zero. No exceptions, no cap. ๐จ
ASN1_BIT_STRING_set_bit()โ sets the *n*th bit (counted from0, aka the least significant bit) of a bit stringatovalue, andvaluegets read as a boolean. Yes bestie, purely true/false energy โจASN1_BIT_STRING_get_bit()โ hands you back the bit value of the *n*th bit in the bit stringa. That's it, that's the whole vibe.ASN1_BIT_STRING_check()โ checks whether the bit stringacontains only bits that are specified by theflagsvector.flags_lenis the length offlagsin bytes. ๐ASN1_BIT_STRING_name_print()โ prints the matching bit name fromtblout toout, based on the bit stringbs. Andindentcan be given as a number of spaces to indent the line, cute โจASN1_BIT_STRING_num_asc()โ goes looking for thenameyou handed it in thelnameandsnamefields oftbl's elements, and if there's a match it returns the correspondingbitnumfield value. found him ๐ASN1_BIT_STRING_set_asc()โ sets the corresponding bit tonameinbs, using the conversion tabletbl.ASN1_BIT_STRING_get_length()โ returns the number of octets inbitstrthat contain bit values, intolength, and the number of unused bits in the last octet intounused_bits. And the value returned inunused_bitsis guaranteed to be between0and7, inclusive. No rogue numbers here, she's consistent ๐ASN1_BIT_STRING_set1()โ sets the type ofbitstrtoV_ASN1_BIT_STRINGand its octets to the bits in the byte stringdataof lengthlengthoctets, making sure that the lastunused_bitsbits in the last byte are zero. Tidy queen ๐งน
๐ RETURN VALUES ๐
ASN1_BIT_STRING_set_bit()โ returns1on success, or0on incorrect input values.ASN1_BIT_STRING_get_bit()โ returns the value of the requested bit, or0when data isn't available for the requested arguments. (yes this is lowkey ambiguous, we don't talk about it ๐ญ)ASN1_BIT_STRING_check()โ returns0if there's at least one bit set inathat isn't specified inflags, and1otherwise.ASN1_BIT_STRING_name_print()โ returns1on success, or0when the print functions fail.ASN1_BIT_STRING_num_asc()โ returns the bit number of the requested name, or-1when the name was not found. she said not today ๐ โโ๏ธASN1_BIT_STRING_set_asc()โ returns1on success or0on failure.ASN1_BIT_STRING_get_length()โ returns1on success, or0if the encoding ofbitstris internally inconsistent, or if one ofbitstr,length, orunused_bitsisNULL.ASN1_BIT_STRING_set1()โ returns1on success, or0if memory allocation fails, or ifbitstrisNULL,lengthis too large,lengthis zero andunused_bitsis nonzero,unused_bitsis less than0or greater than7, or any unused bit in the last octet ofdatais nonzero. That's a lot of ways to fail bestie, read the list twice ๐ฎโ๐จ
ngl that last one is giving very strict bouncer at the club.0to7. That's the range. That's the assignment. ๐ซถ
๐ HISTORY ๐
ASN1_BIT_STRING_get_length() and ASN1_BIT_STRING_set1() were added in OpenSSL version 4.0. Fresh out the box, brand new, iconic behavior โจ
๐ธ COPYRIGHT ๐ธ
Copyright 2025-2026 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>.
and that's the whole page bestie, no crumbs left ๐ this was the ASN1_BIT_STRING_GET_LENGTH(3SSL) page, version 4.0.3, dated 2026-09-29 โ go forth and set your bits responsibly ๐๐
๐ฆ
๐ฆ where this page comes from
- ubuntu stonking: libssl-doc 4.0.3-1ubuntu1 ยท Apache-2.0
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms