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 = 7u8
pub const MAX_UNUSED_BITS: u8 = 7u8
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.
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.
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
.
Trait Implementations§
source§impl<'a> DecodeValue<'a> for BitString
impl<'a> DecodeValue<'a> for BitString
source§impl EncodeValue for BitString
impl EncodeValue for BitString
source§impl<'a> From<&'a BitString> for BitStringRef<'a>
impl<'a> From<&'a BitString> for BitStringRef<'a>
source§fn from(bit_string: &'a BitString) -> BitStringRef<'a>
fn from(bit_string: &'a BitString) -> BitStringRef<'a>
source§impl Ord for BitString
impl Ord for BitString
source§impl PartialEq<BitString> for BitString
impl PartialEq<BitString> for BitString
source§impl PartialOrd<BitString> for BitString
impl PartialOrd<BitString> for BitString
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 moreimpl Eq for BitString
impl StructuralEq for BitString
impl StructuralPartialEq for BitString
Auto Trait Implementations§
impl RefUnwindSafe for BitString
impl Send for BitString
impl Sync for BitString
impl Unpin for BitString
impl UnwindSafe for BitString
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<'a, T> Decode<'a> for Twhere
T: DecodeValue<'a> + FixedTag,
impl<'a, T> Decode<'a> for Twhere T: DecodeValue<'a> + FixedTag,
source§impl<T> Encode for Twhere
T: EncodeValue + Tagged,
impl<T> Encode for Twhere T: EncodeValue + Tagged,
source§fn encoded_len(&self) -> Result<Length, Error>
fn encoded_len(&self) -> Result<Length, Error>
Compute the length of this value in bytes when encoded as ASN.1 DER.
source§fn encode(&self, writer: &mut dyn Writer) -> Result<(), Error>
fn encode(&self, writer: &mut dyn Writer) -> Result<(), Error>
Encode this value as ASN.1 DER using the provided Writer
.