pub struct BitString<'a> { /* private fields */ }
Expand description
ASN.1 BIT STRING
type.
This type contains a sequence of any number of bits, modeled internally as a sequence of bytes with a known number of “unused bits”.
Implementations§
source§impl<'a> BitString<'a>
impl<'a> BitString<'a>
sourcepub const MAX_UNUSED_BITS: u8 = 7u8
pub const MAX_UNUSED_BITS: u8 = 7u8
Maximum number of unused bits allowed.
sourcepub fn new(unused_bits: u8, bytes: &'a [u8]) -> Result<Self>
pub fn new(unused_bits: u8, bytes: &'a [u8]) -> Result<Self>
Create a new ASN.1 BIT STRING
from a byte slice.
Accepts an optional number of “unused bits” (0-7) which are omitted from the final octet. This number is 0 if the value is octet-aligned.
sourcepub fn from_bytes(bytes: &'a [u8]) -> Result<Self>
pub fn from_bytes(bytes: &'a [u8]) -> Result<Self>
Create a new ASN.1 BIT STRING
from the given bytes.
The “unused bits” are set to 0.
sourcepub fn unused_bits(&self) -> u8
pub fn unused_bits(&self) -> u8
Get the number of unused bits in this byte slice.
sourcepub fn has_unused_bits(&self) -> bool
pub fn has_unused_bits(&self) -> bool
Is the number of unused bits a value other than 0?
sourcepub fn byte_len(&self) -> Length
pub fn byte_len(&self) -> Length
Get the number of bytes/octets needed to represent this BIT STRING
when serialized in an octet-aligned manner.
sourcepub fn as_bytes(&self) -> Option<&'a [u8]>
pub fn as_bytes(&self) -> Option<&'a [u8]>
Borrow the inner byte slice.
Returns None
if the number of unused bits is not equal to zero,
i.e. if the BIT STRING
is not octet aligned.
Use BitString::raw_bytes
to obtain access to the raw value
regardless of the presence of unused bits.
sourcepub fn raw_bytes(&self) -> &'a [u8]
pub fn raw_bytes(&self) -> &'a [u8]
Borrow the raw bytes of this BIT STRING
.
Note that the byte string may contain extra unused bits in the final
octet. If the number of unused bits is expected to be 0, the
BitString::as_bytes
function can be used instead.
sourcepub fn bits(self) -> BitStringIter<'a> ⓘ
pub fn bits(self) -> BitStringIter<'a> ⓘ
Iterator over the bits of this BIT STRING
.
Trait Implementations§
source§impl<'a> DecodeValue<'a> for BitString<'a>
impl<'a> DecodeValue<'a> for BitString<'a>
source§impl EncodeValue for BitString<'_>
impl EncodeValue for BitString<'_>
source§impl<'a> Ord for BitString<'a>
impl<'a> Ord for BitString<'a>
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl<'a> PartialEq<BitString<'a>> for BitString<'a>
impl<'a> PartialEq<BitString<'a>> for BitString<'a>
source§impl<'a> PartialOrd<BitString<'a>> for BitString<'a>
impl<'a> PartialOrd<BitString<'a>> for BitString<'a>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl<'a> TryFrom<&&'a [u8]> for BitString<'a>
impl<'a> TryFrom<&&'a [u8]> for BitString<'a>
Hack for simplifying the custom derive use case.