pub struct BitString { /* private fields */ }Expand description
Owned form of ASN.1 BIT STRING type.
This type provides the same functionality as BitStringRef but owns the
backing data.
Implementations§
Source§impl BitString
impl BitString
Sourcepub const MAX_UNUSED_BITS: u8 = 7
pub const MAX_UNUSED_BITS: u8 = 7
Maximum number of unused bits allowed.
Sourcepub fn new(unused_bits: u8, bytes: impl Into<Vec<u8>>) -> Result<Self>
pub fn new(unused_bits: u8, bytes: impl Into<Vec<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.
§Errors
Returns Error if any of the following occur:
unused_bitsis invalidbytesis too long- an overflow occurred calculating the bit length
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self>
pub fn from_bytes(bytes: &[u8]) -> Result<Self>
Create a new ASN.1 BIT STRING from the given bytes.
The “unused bits” are set to 0.
§Errors
If bytes is too long.
Sourcepub fn unused_bits(&self) -> u8
pub fn unused_bits(&self) -> u8
Get the number of unused bits in the octet serialization of this
BIT STRING.
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 as_bytes(&self) -> Option<&[u8]>
pub fn as_bytes(&self) -> Option<&[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 bits(&self) -> BitStringIter<'_> ⓘ
pub fn bits(&self) -> BitStringIter<'_> ⓘ
Iterator over the bits of this BIT STRING.