pub struct BitString { /* private fields */ }
Expand description
A bit string value.
Bit strings are a sequence of bits. Unlike OctetString
s, 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
method. The from_content
method 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§
source§impl BitString
impl BitString
sourcepub fn octets(&self) -> BitStringIter<'_> ⓘ
pub fn octets(&self) -> BitStringIter<'_> ⓘ
Returns an iterator over the octets in the bit string.
sourcepub fn octet_slice(&self) -> Option<&[u8]>
pub fn octet_slice(&self) -> Option<&[u8]>
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.
sourcepub fn octet_bytes(&self) -> Bytes
pub fn octet_bytes(&self) -> Bytes
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.
source§impl BitString
impl BitString
sourcepub fn take_from<S: Source>(
constructed: &mut Constructed<'_, S>
) -> Result<Self, S::Err>
pub fn take_from<S: Source>(
constructed: &mut Constructed<'_, S>
) -> Result<Self, S::Err>
Takes a single bit string value from constructed content.
sourcepub fn skip_in<S: Source>(cons: &mut Constructed<'_, S>) -> Result<(), S::Err>
pub fn skip_in<S: Source>(cons: &mut Constructed<'_, S>) -> Result<(), S::Err>
Skip over a single bit string value inside constructed content.
sourcepub fn from_content<S: Source>(
content: &mut Content<'_, S>
) -> Result<Self, S::Err>
pub fn from_content<S: Source>(
content: &mut Content<'_, S>
) -> Result<Self, S::Err>
Parses the content octets of a bit string value.
sourcepub fn skip_content<S: Source>(
content: &mut Content<'_, S>
) -> Result<(), S::Err>
pub fn skip_content<S: Source>(
content: &mut Content<'_, S>
) -> Result<(), S::Err>
Skips over the content octets of a bit string value.