Type Alias FixedBitString

Source
pub type FixedBitString<const N: usize> = BitArray<[u8; N], Msb0>;
Expand description

A fixed length BIT STRING type.

IMPORTANT: While N describes the number of bits, also the internal size is for N amount of bytes. When accessing the bits, use &array[..N] to get the correct bits, for example. Also when setting the bits, you should use the big-endian ordering. See example. Constraints are checked for N amount of bits and encoding operation will drop extra bits since the underlying container is larger.

§Example

use rasn::prelude::*;
use bitvec::prelude::*;

let bool_array = [true, false, true];
let mut bit_array: FixedBitString<3> = BitArray::ZERO;
for (i, &value) in bool_array.iter().enumerate() {
   bit_array.set(i, value);
}
// Also works: (note that the first byte can hold the whole bit array, since N = 3)
let second_array = FixedBitString::<3>::new([0b10100000, 0, 0]);
assert_eq!(bit_array, second_array);

Aliased Type§

struct FixedBitString<const N: usize> {
    pub _ord: PhantomData<Msb0>,
    pub data: [u8; N],
}

Fields§

§_ord: PhantomData<Msb0>

The ordering of bits within an A::Store element.

§data: [u8; N]

The wrapped data buffer.

Trait Implementations§

Source§

impl<const N: usize> AsnType for FixedBitString<N>

Source§

const TAG: Tag = Tag::BIT_STRING

The associated tag for the type. Read more
Source§

const CONSTRAINTS: Constraints

The set of constraints for values of the given type.
Source§

const IDENTIFIER: Identifier = Identifier::BIT_STRING

Identifier of an ASN.1 type as specified in the original specification if not identical with the identifier of Self
Source§

const TAG_TREE: TagTree = _

The root of this type’s tree of tag’s if it a CHOICE type, otherwise its Leaf that points Self::TAG.
Source§

fn is_present(&self) -> bool

Whether the type is present with value. OPTIONAL fields are common in SEQUENCE or SET. Read more
Source§

impl<const N: usize> Decode for FixedBitString<N>

Source§

fn decode_with_tag_and_constraints<D: Decoder>( decoder: &mut D, tag: Tag, constraints: Constraints, ) -> Result<Self, D::Error>

Decode this value implicitly tagged with tag from a given ASN.1 decoder with a set of constraints on what values of that type are allowed. Read more
Source§

fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, D::Error>

Decode this value from a given ASN.1 decoder. Read more
Source§

fn decode_with_tag<D: Decoder>( decoder: &mut D, tag: Tag, ) -> Result<Self, D::Error>

Decode this value implicitly tagged with tag from a given ASN.1 decoder. Read more
Source§

fn decode_with_constraints<D: Decoder>( decoder: &mut D, constraints: Constraints, ) -> Result<Self, D::Error>

Decode this value from a given ASN.1 decoder with a set of constraints on what values of that type are allowed. Read more
Source§

impl<const N: usize> Encode for FixedBitString<N>

Source§

fn encode_with_tag_and_constraints<'b, E: Encoder<'b>>( &self, encoder: &mut E, tag: Tag, constraints: Constraints, identifier: Identifier, ) -> Result<(), E::Error>

Encode this value with tag into the given crate::Encoder with the constraints the values this is allowed to encode into. Read more
Source§

fn encode<'b, E: Encoder<'b>>(&self, encoder: &mut E) -> Result<(), E::Error>

Encodes self’s data into the given crate::Encoder. Read more
Source§

fn encode_with_tag<'b, E: Encoder<'b>>( &self, encoder: &mut E, tag: Tag, ) -> Result<(), E::Error>

Encode this value with tag into the given crate::Encoder. Read more
Source§

fn encode_with_identifier<'b, E: Encoder<'b>>( &self, encoder: &mut E, identifier: Identifier, ) -> Result<(), E::Error>

Encode this value with identifier into the given crate::Encoder. Read more
Source§

fn encode_with_tag_and_identifier<'b, E: Encoder<'b>>( &self, encoder: &mut E, tag: Tag, identifier: Identifier, ) -> Result<(), E::Error>

Encode this value with tag and identifier into the given crate::Encoder. Read more
Source§

fn encode_with_constraints<'b, E: Encoder<'b>>( &self, encoder: &mut E, constraints: Constraints, ) -> Result<(), E::Error>

Encode this value into the given crate::Encoder with the constraints the values this is allowed to encode into. Read more
Source§

fn encode_with_constraints_and_identifier<'b, E: Encoder<'b>>( &self, encoder: &mut E, constraints: Constraints, identifier: Identifier, ) -> Result<(), E::Error>

Encode this value into the given crate::Encoder with identifier and the constraints the values this is allowed to encode into. Read more