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
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
sourceimpl BitString
impl BitString
sourcepub fn octets(&self) -> BitStringIter<'_>ⓘNotable traits for BitStringIter<'a>impl<'a> Iterator for BitStringIter<'a> type Item = u8;
pub fn octets(&self) -> BitStringIter<'_>ⓘNotable traits for BitStringIter<'a>impl<'a> Iterator for BitStringIter<'a> type Item = u8;
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.
sourceimpl BitString
impl BitString
sourcepub fn take_from<S: Source>(
constructed: &mut Constructed<'_, S>
) -> Result<Self, DecodeError<S::Error>>
pub fn take_from<S: Source>(
constructed: &mut Constructed<'_, S>
) -> Result<Self, DecodeError<S::Error>>
Takes a single bit string value from constructed content.
sourcepub fn skip_in<S: Source>(
cons: &mut Constructed<'_, S>
) -> Result<(), DecodeError<S::Error>>
pub fn skip_in<S: Source>(
cons: &mut Constructed<'_, S>
) -> Result<(), DecodeError<S::Error>>
Skip over a single bit string value inside constructed content.
sourcepub fn from_content<S: Source>(
content: &mut Content<'_, S>
) -> Result<Self, DecodeError<S::Error>>
pub fn from_content<S: Source>(
content: &mut Content<'_, S>
) -> Result<Self, DecodeError<S::Error>>
Parses the content octets of a bit string value.
sourcepub fn skip_content<S: Source>(
content: &mut Content<'_, S>
) -> Result<(), DecodeError<S::Error>>
pub fn skip_content<S: Source>(
content: &mut Content<'_, S>
) -> Result<(), DecodeError<S::Error>>
Skips over the content octets of a bit string value.
sourcepub fn encode_slice<T>(value: T, unused: u8) -> BitSliceEncoder<T>
pub fn encode_slice<T>(value: T, unused: u8) -> BitSliceEncoder<T>
Returns a value encoder that encodes a bytes slice as an octet string.
sourcepub fn encode_slice_as<T>(value: T, unused: u8, tag: Tag) -> BitSliceEncoder<T>
pub fn encode_slice_as<T>(value: T, unused: u8, tag: Tag) -> BitSliceEncoder<T>
Returns a value encoder that encodes a bytes slice as an octet string.
Trait Implementations
sourceimpl PrimitiveContent for BitString
impl PrimitiveContent for BitString
sourcefn encoded_len(&self, _: Mode) -> usize
fn encoded_len(&self, _: Mode) -> usize
Returns the length of the encoded content of this type.
sourcefn write_encoded<W: Write>(&self, _: Mode, target: &mut W) -> Result<(), Error>
fn write_encoded<W: Write>(&self, _: Mode, target: &mut W) -> Result<(), Error>
Writes the encoded content to a writer.
sourcefn to_encoded_bytes(&self, mode: Mode) -> Bytes
fn to_encoded_bytes(&self, mode: Mode) -> Bytes
Encodes the value to bytes (useful when you need to sign a structure)
sourcefn encode(self) -> Primitive<Self>
fn encode(self) -> Primitive<Self>
Returns a value encoder for this content using the natural tag. Read more
sourcefn encode_as(self, tag: Tag) -> Primitive<Self>
fn encode_as(self, tag: Tag) -> Primitive<Self>
Returns a value encoder for this content using the given tag. Read more
sourcefn encode_ref(&self) -> Primitive<&Self>
fn encode_ref(&self) -> Primitive<&Self>
Returns a value encoder for a reference using the natural tag.
sourcefn encode_ref_as(&self, tag: Tag) -> Primitive<&Self>
fn encode_ref_as(&self, tag: Tag) -> Primitive<&Self>
Returns a value encoder for a reference using the given tag.
impl Eq for BitString
impl StructuralEq for BitString
impl StructuralPartialEq for BitString
Auto Trait Implementations
impl RefUnwindSafe for BitString
impl Send for BitString
impl Sync for BitString
impl Unpin for BitString
impl UnwindSafe for BitString
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more