pub struct Length { /* private fields */ }Expand description
ASN.1-encoded length.
§Examples
use der::{Decode, Length, SliceReader};
let mut reader = SliceReader::new(&[0x82, 0xAA, 0xBB]).unwrap();
let length = Length::decode(&mut reader).expect("valid length");
assert_eq!(length, Length::new(0xAABB));5-byte lengths are supported:
use der::{Encode, Length};
let length = Length::new(0x10000000);
assert_eq!(length.encoded_len(), Ok(Length::new(5)));Invalid lengths produce an error:
use der::{Decode, Length, SliceReader};
let mut reader = SliceReader::new(&[0x81, 0x7F]).unwrap();
Length::decode(&mut reader).expect_err("non-canonical length should be rejected");Implementations§
Source§impl Length
impl Length
Sourcepub fn for_tlv(self, tag: Tag) -> Result<Self>
pub fn for_tlv(self, tag: Tag) -> Result<Self>
Get the length of DER Tag-Length-Value (TLV) encoded data if self
is the length of the inner “value” portion of the message.
§Errors
Returns an error if an overflow occurred computing the length.
Sourcepub fn saturating_add(self, rhs: Self) -> Self
pub fn saturating_add(self, rhs: Self) -> Self
Perform saturating addition of two lengths.
Sourcepub fn saturating_sub(self, rhs: Self) -> Self
pub fn saturating_sub(self, rhs: Self) -> Self
Perform saturating subtraction of two lengths.
Trait Implementations§
Source§impl<'a> Arbitrary<'a> for Length
Available on crate feature arbitrary only.
impl<'a> Arbitrary<'a> for Length
Available on crate feature
arbitrary only.Source§fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
Generate an arbitrary value of
Self from the given unstructured data. Read moreSource§fn size_hint(depth: usize) -> (usize, Option<usize>)
fn size_hint(depth: usize) -> (usize, Option<usize>)
Get a size hint for how many bytes out of an
Unstructured this type
needs to construct itself. Read moreSource§fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
Generate an arbitrary value of
Self from the entirety of the given
unstructured data. Read moreSource§fn try_size_hint(
depth: usize,
) -> Result<(usize, Option<usize>), MaxRecursionReached>
fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>
Get a size hint for how many bytes out of an
Unstructured this type
needs to construct itself. Read moreSource§impl<'a> Decode<'a> for Length
impl<'a> Decode<'a> for Length
Source§fn decode<R: Reader<'a>>(reader: &mut R) -> Result<Length>
fn decode<R: Reader<'a>>(reader: &mut R) -> Result<Length>
Attempt to decode this TLV message using the provided decoder. Read more
Source§fn from_ber(bytes: &'a [u8]) -> Result<Self, Self::Error>
fn from_ber(bytes: &'a [u8]) -> Result<Self, Self::Error>
Available on crate feature
ber only.Parse
Self from the provided BER-encoded byte slice. Read moreSource§impl Encode for Length
impl Encode for Length
Source§fn encoded_len(&self) -> Result<Length>
fn encoded_len(&self) -> Result<Length>
Compute the length of this TLV object in bytes when encoded as ASN.1 DER. Read more
Source§fn encode_to_slice<'a>(&self, buf: &'a mut [u8]) -> Result<&'a [u8]>
fn encode_to_slice<'a>(&self, buf: &'a mut [u8]) -> Result<&'a [u8]>
Encode this TLV object to the provided byte slice, returning a sub-slice
containing the encoded message. Read more
Source§impl Ord for Length
impl Ord for Length
Source§impl PartialOrd for Length
impl PartialOrd for Length
impl Copy for Length
impl Eq for Length
impl StructuralPartialEq for Length
Auto Trait Implementations§
impl Freeze for Length
impl RefUnwindSafe for Length
impl Send for Length
impl Sync for Length
impl Unpin for Length
impl UnwindSafe for Length
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
Mutably borrows from an owned value. Read more