ASN1\_BIT\_STRING\_GET\_LENGTH(3ossl) OpenSSL ASN1\_BIT\_STRING\_GET\_LENGTH(3ossl)

# [NAME](#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 - ASN1\_BIT\_STRING accessors

# [SYNOPSIS](#SYNOPSIS)

```
  #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](#DESCRIPTION)

The ASN.1 BIT STRING type holds a bit string of arbitrary bit length. In the distinguished encoding rules DER, its bits are encoded in groups of eight, leaving between zero and seven bits of the last octet unused. If there are unused bits, they must all be set to zero.

**ASN1\_BIT\_STRING\_set\_bit()** sets the *n*th bit (counted from 0 as the least significant bit) of a bit string *a* to *value* which is interpreted as a boolean.

**ASN1\_BIT\_STRING\_get\_bit()** returns the bit value of the *n*th bit in the bit string *a*.

**ASN1\_BIT\_STRING\_check()** checks if the *a* bit string contains only bits specified by the *flags* vector. *flags\_len* is the length of *flags* in bytes.

**ASN1\_BIT\_STRING\_name\_print()** prints the corresponding bit name specified in *tbl* to *out* based on the bit string *bs*. *indent* might be specified for a number of spaces to indent the line.

**ASN1\_BIT\_STRING\_num\_asc()** searches for the provided *name* in *lname* and *sname* fields of *tbl*'s elements and returns the corresponding *bitnum* field value in case there is a match found.

**ASN1\_BIT\_STRING\_set\_asc()** sets the corresponding bit to *name* in *bs* based on the conversion table *tbl*.

**ASN1\_BIT\_STRING\_get\_length()** returns the number of octets in *bitstr* containing bit values in *length* and the number of unused bits in the last octet in *unused\_bits*. The value returned in *unused\_bits* is guaranteed to be between 0 and 7, inclusive.

**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.

# [RETURN VALUES](#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 not available for the requested arguments.

**ASN1\_BIT\_STRING\_check()** returns 0 if there is at least one bit set in *a* which is not specified in *flags*, 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.

**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.

# [HISTORY](#HISTORY)

Functions **ASN1\_BIT\_STRING\_get\_length()** and **ASN1\_BIT\_STRING\_set1()** were added in OpenSSL version 4.0.

# [COPYRIGHT](#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 &lt;https://www.openssl.org/source/license.html&gt;.

2026-09-29 4.0.3

---

Document: ASN1_BIT_STRING_name_print(3ossl) from openssl-4.0 4.0.3-r0 (Chainguard OS)
