[−][src]Struct bcder::BitString
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.
Methods
impl BitString
[src]
pub fn new(unused: u8, bits: Bytes) -> Self
[src]
Creates a new bit string.
pub fn bit(&self, bit: usize) -> bool
[src]
Returns the value of the given bit.
pub fn bit_len(&self) -> usize
[src]
Returns the number of bits in the bit string.
pub fn unused(&self) -> u8
[src]
Returns the number of unused bits in the last octet.
pub fn octet_len(&self) -> usize
[src]
Returns the number of octets in the bit string.
ⓘImportant traits for BitStringIter<'a>pub fn octets(&self) -> BitStringIter
[src]
Returns an iterator over the octets in the bit string.
pub fn octet_slice(&self) -> Option<&[u8]>
[src]
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.
pub fn octet_bytes(&self) -> Bytes
[src]
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.
impl BitString
[src]
pub fn take_from<S: Source>(
constructed: &mut Constructed<S>
) -> Result<Self, S::Err>
[src]
constructed: &mut Constructed<S>
) -> Result<Self, S::Err>
Takes a single bit string value from constructed content.
pub fn skip_in<S: Source>(cons: &mut Constructed<S>) -> Result<(), S::Err>
[src]
Skip over a single bit string value inside constructed content.
pub fn from_content<S: Source>(content: &mut Content<S>) -> Result<Self, S::Err>
[src]
Parses the content octets of a bit string value.
pub fn skip_content<S: Source>(content: &mut Content<S>) -> Result<(), S::Err>
[src]
Skips over the content octets of a bit string value.
pub fn encode_slice<T>(value: T, unused: u8) -> BitSliceEncoder<T>
[src]
Returns a value encoder that encodes a bytes slice as an octet string.
pub fn encode_slice_as<T>(value: T, unused: u8, tag: Tag) -> BitSliceEncoder<T>
[src]
Returns a value encoder that encodes a bytes slice as an octet string.
Trait Implementations
impl Clone for BitString
[src]
impl Debug for BitString
[src]
impl Eq for BitString
[src]
impl PartialEq<BitString> for BitString
[src]
impl PrimitiveContent for BitString
[src]
const TAG: Tag
[src]
fn encoded_len(&self, _: Mode) -> usize
[src]
fn write_encoded<W: Write>(&self, _: Mode, target: &mut W) -> Result<(), Error>
[src]
fn to_encoded_bytes(&self, mode: Mode) -> Bytes
[src]
fn encode(self) -> Primitive<Self>
[src]
fn encode_as(self, tag: Tag) -> Primitive<Self>
[src]
fn encode_ref(&self) -> Primitive<&Self>
[src]
fn encode_ref_as(&self, tag: Tag) -> Primitive<&Self>
[src]
impl StructuralEq for BitString
[src]
impl StructuralPartialEq for BitString
[src]
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
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,