Skip to content

ASN1_BIT_STRING_get_length

NAME

ASN1_BIT_STRING_set1, ASN1_BIT_STRING_get_length - ASN1_BIT_STRING accessors

SYNOPSIS

#include <openssl/asn1.h>

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

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_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

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.

Copyright 2025 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.