ASN1_BIT_STRING_GET_LENGTH(3SSL)

๐Ÿ“ฆ
version 4.0.3 ยท 2 versions
, in ubuntu stonking

โœจ 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 from 0, aka the least significant bit) of a bit string a to value, and value gets 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 string a. That's it, that's the whole vibe.
  • ASN1_BIT_STRING_check() โ€” checks whether the bit string a contains only bits that are specified by the flags vector. flags_len is the length of flags in bytes. ๐Ÿ”
  • ASN1_BIT_STRING_name_print() โ€” prints the matching bit name from tbl out to out, based on the bit string bs. And indent can be given as a number of spaces to indent the line, cute โœจ
  • ASN1_BIT_STRING_num_asc() โ€” goes looking for the name you handed it in the lname and sname fields of tbl's elements, and if there's a match it returns the corresponding bitnum field value. found him ๐Ÿ”Ž
  • ASN1_BIT_STRING_set_asc() โ€” sets the corresponding bit to name in bs, using the conversion table tbl.
  • ASN1_BIT_STRING_get_length() โ€” returns the number of octets in bitstr that contain bit values, into length, and the number of unused bits in the last octet into unused_bits. And the value returned in unused_bits is guaranteed to be between 0 and 7, inclusive. No rogue numbers here, she's consistent ๐Ÿ’…
  • ASN1_BIT_STRING_set1() โ€” sets the type of bitstr to V_ASN1_BIT_STRING and its octets to the bits in the byte string data of length length octets, making sure that the last unused_bits bits in the last byte are zero. Tidy queen ๐Ÿงน

๐Ÿ’€ RETURN VALUES ๐Ÿ’€

  • ASN1_BIT_STRING_set_bit() โ€” returns 1 on success, or 0 on incorrect input values.
  • ASN1_BIT_STRING_get_bit() โ€” returns the value of the requested bit, or 0 when data isn't available for the requested arguments. (yes this is lowkey ambiguous, we don't talk about it ๐Ÿ˜ญ)
  • ASN1_BIT_STRING_check() โ€” returns 0 if there's at least one bit set in a that isn't specified in flags, and 1 otherwise.
  • ASN1_BIT_STRING_name_print() โ€” returns 1 on success, or 0 when the print functions fail.
  • ASN1_BIT_STRING_num_asc() โ€” returns the bit number of the requested name, or -1 when the name was not found. she said not today ๐Ÿ™…โ€โ™€๏ธ
  • ASN1_BIT_STRING_set_asc() โ€” returns 1 on success or 0 on failure.
  • ASN1_BIT_STRING_get_length() โ€” returns 1 on success, or 0 if the encoding of bitstr is internally inconsistent, or if one of bitstr, length, or unused_bits is NULL.
  • ASN1_BIT_STRING_set1() โ€” returns 1 on success, or 0 if memory allocation fails, or if bitstr is NULL, length is too large, length is zero and unused_bits is nonzero, unused_bits is less than 0 or greater than 7, or any unused bit in the last octet of data is 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. 0 to 7. 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 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