Struct picky_asn1::wrapper::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

§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method 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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method 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§

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

🔬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<T> ToOwned for T
where T: Clone,

§

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

§

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

§

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