BIT STRING

The ASN.1 BIT STRING type is mapped to encoding/asn1.BitString from the Go standard library. Bits are specified in the Bytes field (a []byte) in most-significant bit order. For example, the bit string '1'B (consisting of a single bit which is set) would be represented using BitLength = 1 and Bytes being a slice of 1 byte, set to 0x80.

Named Bits

In the ASN.1 standard, it is possible to define a named bit string that specifies names for different bit positions. ASN1C provides support for this type by generating Go constants and run-time functions that can be used to set, clear, or test these named bits. These constants equate the bit name to the bit number defined in the specification. They can be used with the SetBit, ClearBit, and TestBit run-time functions to set, clear, and test the named bits.

Contents Constraint

It is possible to specify a contents constraint on a BIT STRING type using the CONTAINING keyword. This indicates that the encoded contents of the specified type should be packed within the BIT STRING container. An example of this type of constraint is as follows:

   ContainingBS ::= BIT STRING (CONTAINING INTEGER)

ASN1C will generate a type definition that references the type that is within the containing constraint. In this case, that would be INTEGER; therefore, the Go type for INTEGER would be used, which is int64. This direct use of the containing type can be suppressed through the use of the -noContaining command-line argument. In that case, a normal BIT STRING type will be used and it will be the user's responsibility to do the necessary packing and unpacking operations to encode and decode the variable correctly.