---
name: "libressl-ASN1_BIT_STRING_set"
section: "3"
platform: "linux"
package: "libressl"
version: "4.4.0-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/libressl-ASN1_BIT_STRING_set"
---

# libressl-ASN1\_BIT\_STRING\_set(3)

ASN.1 BIT STRING accessors

## NAME

**ASN1\_BIT\_STRING\_set**, **ASN1\_BIT\_STRING\_set\_bit**, **ASN1\_BIT\_STRING\_get\_bit** – ASN.1 BIT STRING accessors

## SYNOPSIS

Crypto Library (libcrypto, -lcrypto)

**#include \<openssl/asn1.h\>**

*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

**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, by merely calling ASN1\_STRING\_set(3). This function does no validation whatsoever. In particular, it neither checks that *bitstr* is actually of the type V\_ASN1\_BIT\_STRING nor, even if it is, that the *data* and *len* arguments make sense for this particular bit string.

If the *set* argument is non-zero, **ASN1\_BIT\_STRING\_set\_bit**() sets the bit with the given *bitnumber* in the *bitstr*; otherwise, it clears that bit. A *bitnumber* of 0 addresses the most significant bit in the first data byte of *bitstr*, 7 the least significant bit in the same byte, 8 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*.

## RETURN VALUES

**ASN1\_BIT\_STRING\_set**() returns 1 on success or 0 if memory allocation fails or if *data* is NULL and *len* is -1 in the same call.

**ASN1\_BIT\_STRING\_set\_bit**() returns 1 on success or 0 if *bitstr* is NULL or if memory allocation fails.

**ASN1\_BIT\_STRING\_get\_bit**() returns 1 if the bit with the given *bitnumber* is set in the *bitstr* or 0 if *bitstr* is NULL, if *bitnumber* points beyond the last data byte in *bitstr*, or if the requested bit is not set.

## SEE ALSO

ASN1\_BIT\_STRING\_new(3), ASN1\_STRING\_set(3), d2i\_ASN1\_BIT\_STRING(3), v2i\_ASN1\_BIT\_STRING(3)

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