picky_asn1::wrapper

Struct BitStringAsn1

Source
pub struct BitStringAsn1(pub BitString);
Expand description

Wrapper type

Tuple Fields§

§0: BitString

Methods from Deref<Target = BitString>§

Source

pub fn as_bytes(&self) -> &[u8]

Returns inner bytes slice

Source

pub fn get_num_bits(&self) -> usize

Get the number of available bits in the BitString

Source

pub fn set_num_bits(&mut self, num_bits: usize)

Set the length of a BitString with each additional slot filled with 0.

§Examples
use picky_asn1::bit_string::BitString;

let v: Vec<u8> = vec![0x01, 0x01];
let mut b = BitString::with_bytes_and_len(v, 16);
assert_eq!(b.is_set(7), true);
assert_eq!(b.is_set(15), true);

b.set_num_bits(8);
assert_eq!(b.is_set(7), true);
b.set(15, true); // attempts to set a value out of the bounds are ignored
assert_eq!(b.is_set(15), false);

b.set_num_bits(16);
assert_eq!(b.is_set(7), true);
assert_eq!(b.is_set(15), false);
b.set(15, true);
assert_eq!(b.is_set(15), true);
Source

pub fn is_set(&self, i: usize) -> bool

Check if bit i is set.

§Examples
use picky_asn1::bit_string::BitString;

let mut b = BitString::with_len(10);
assert_eq!(b.is_set(7), false);
b.set(7, true);
assert_eq!(b.is_set(7), true);
Source

pub fn set(&mut self, i: usize, val: bool)

Set bit i to val.

Source

pub fn get_num_unused_bits(&self) -> u8

Source

pub fn get_num_buckets(&self) -> usize

Source

pub fn get_bucket(&self, i: usize) -> u8

Source

pub fn get_bucket_mut(&mut self, i: usize) -> &mut u8

Source

pub fn set_bucket(&mut self, i: usize, value: u8)

Source

pub fn payload_view(&self) -> &[u8]

Returns an immutabe view on the payload.

§Examples
use picky_asn1::bit_string::BitString;

let v: Vec<u8> = vec![0x01, 0x00];
let mut b = BitString::with_bytes_and_len(v, 15);
b.set(14, true);
let payload = b.payload_view();
assert_eq!(payload, &[0x01, 0x02]);
Source

pub fn payload_view_mut(&mut self) -> &mut [u8]

Returns a mutabe view on the payload.

§Examples
use picky_asn1::bit_string::BitString;

let v: Vec<u8> = vec![0x01, 0x00];
let mut b = BitString::with_bytes_and_len(v, 15);
b.set(14, true);
let payload = b.payload_view_mut();
payload[0] = 0x20;
assert_eq!(payload, &[0x20, 0x02]);

Trait Implementations§

Source§

impl Asn1Type for BitStringAsn1

Source§

const TAG: Tag = Tag::BIT_STRING

Source§

const NAME: &'static str = "BitStringAsn1"

Source§

impl Clone for BitStringAsn1

Source§

fn clone(&self) -> BitStringAsn1

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BitStringAsn1

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for BitStringAsn1

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Deref for BitStringAsn1

Source§

type Target = BitString

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl DerefMut for BitStringAsn1

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<'de> Deserialize<'de> for BitStringAsn1

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<BitString> for BitStringAsn1

Source§

fn from(wrapped: BitString) -> Self

Converts to this type from the input type.
Source§

impl From<BitStringAsn1> for BitString

Source§

fn from(wrapper: BitStringAsn1) -> BitString

Converts to this type from the input type.
Source§

impl PartialEq<BitString> for BitStringAsn1

Source§

fn eq(&self, other: &BitString) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq for BitStringAsn1

Source§

fn eq(&self, other: &BitStringAsn1) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for BitStringAsn1

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for BitStringAsn1

Source§

impl StructuralPartialEq for BitStringAsn1

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,