[][src]Struct bcder::BitString

pub struct BitString { /* fields omitted */ }

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 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]

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.

Trait Implementations

impl PrimitiveContent for BitString[src]

fn to_encoded_bytes(&self, mode: Mode) -> Bytes[src]

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

fn encode(self) -> Primitive<Self>[src]

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

fn encode_as(self, tag: Tag) -> Primitive<Self>[src]

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

fn encode_ref(&self) -> Primitive<&Self>[src]

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

fn encode_ref_as(&self, tag: Tag) -> Primitive<&Self>[src]

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

impl Clone for BitString[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl Eq for BitString[src]

impl PartialEq<BitString> for BitString[src]

impl Debug for BitString[src]

Auto Trait Implementations

impl Send for BitString

impl Sync for BitString

Blanket Implementations

impl<T> From for T[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = !

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

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

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

The type returned in the event of a conversion error.