Struct bcder::BitString[][src]

pub struct BitString { /* fields omitted */ }
Expand description

A bit string value.

Bit strings are a sequence of bits. Unlike OctetStrings, they do not need to contain a multiple of eight bits.

You can parse a bit string value out of a constructed value using the take_from function. The from_content function parses the content octets of a bit string value and can be used of the bit string is implcitely tagged. Alternatively, you can create a new simple bit string via the new method.

There are two types of methods for accessing the data in a bit string. Methods starting with bit operate on the individual bits while those prefixed with octet access entire octets and ignore the fact that there may be unused bits in the final octet.

BER Encoding

When encoded in BER, bit strings can either be a primitive or constructed value.

If encoded as a primitive value, the first octet of the content contains the number of unused bits in the last octet and the following octets contain the bits with the first bit in the most significant bit of the octet.

In the constructed encoding, the bit string is represented as a sequence of bit strings which in turn may either be constructed or primitive encodings. The only limitation in this nesting is that only the last primitively encoded bit string may have a non-zero number of unused bits.

With BER, the sender can choose either form of encoding. With CER, the primitive encoding should be chosen if its length would be no more than 1000 octets long. Otherwise, the constructed encoding is to be chosen which must contain a sequence of primitively encoded bit strings. Each of these except for the last one must have content of exactly 1000 octets. The last one must be a least one and at most 1000 octets of content. With DER, only the primitive form is allowed.

Limitation

At this time, the BitString type does not implement the constructed encoding of a bit string.

Implementations

Creates a new bit string.

Returns the value of the given bit.

Returns the number of bits in the bit string.

Returns the number of unused bits in the last octet.

Returns the number of octets in the bit string.

Returns an iterator over the octets in the bit string.

Returns a slice of the octets in the bit string if available.

The method will return None if the bit string is constructed from several parts.

Returns a bytes value of the octets of the bit string.

This will be cheap for primitively encoded bit strings but requires allocations for complex ones.

Takes a single bit string value from constructed content.

Skip over a single bit string value inside constructed content.

Parses the content octets of a bit string value.

Skips over the content octets of a bit string value.

Returns a value encoder that encodes a bytes slice as an octet string.

Returns a value encoder that encodes a bytes slice as an octet string.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

The natural tag of an encoded value of this type.

Returns the length of the encoded content of this type.

Writes the encoded content to a writer.

Encodes the value to bytes (useful when you need to sign a structure)

Returns a value encoder for this content using the natural tag. Read more

Returns a value encoder for this content using the given tag. Read more

Returns a value encoder for a reference using the natural tag.

Returns a value encoder for a reference using the given tag.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.