Struct Length Copy item path Source pub struct Length {
inner: u32 ,
}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" );Inner length as a u32. Note that the decoder and encoder also support a maximum length
of 32-bits.
Maximum length (u32::MAX).
Create a new Length for any value which fits inside of a u16 .
This function is const-safe and therefore useful for Length constants.
Create a new Length for any value which fits inside the length type.
This function is const-safe and therefore useful for Length constants.
Is this length equal to zero?
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.
Perform saturating addition of two lengths.
Perform saturating subtraction of two lengths.
Get initial octet of the encoded length (if one is required).
From X.690 Section 8.1.3.5:
In the long form, the length octets shall consist of an initial octet
and one or more subsequent octets. The initial octet shall be encoded
as follows:
a) bit 8 shall be one;
b) bits 7 to 1 shall encode the number of subsequent octets in the
length octets, as an unsigned binary integer with bit 7 as the
most significant bit;
c) the value 11111111₂ shall not be used.
The resulting type after applying the + operator.
The resulting type after applying the + operator.
The resulting type after applying the + operator.
The resulting type after applying the + operator.
The resulting type after applying the + operator.
The resulting type after applying the + operator.
Performs copy-assignment from
source.
Read more Formats the value using the given formatter.
Read more Type returned in the event of a decoding error.
Attempt to decode this TLV message using the provided decoder.
Read more Parse
Self from the provided DER-encoded byte slice.
Read more Parse
Self from the provided DER-encoded byte slice.
Read more Returns the “default value” for a type.
Read more Formats the value using the given formatter.
Read more Compute the length of this TLV object in bytes when encoded as ASN.1 DER.
Read more Encode this TLV object to the provided byte slice, returning a sub-slice
containing the encoded message.
Read more Encode this TLV object as ASN.1 DER, appending it to the provided
byte vector.
Read more Encode this TLV object as ASN.1 DER, returning a byte vector.
Read more Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Compares and returns the maximum of two values.
Read more Compares and returns the minimum of two values.
Read more Restrict a value to a certain interval.
Read more Tests for self and other values to be equal, and is used by ==.
Tests for !=. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
This method returns an ordering between
self and
other values if one exists.
Read more Tests less than (for
self and
other) and is used by the
< operator.
Read more Tests less than or equal to (for
self and
other) and is used by the
<= operator.
Read more Tests greater than (for
self and
other) and is used by the
>
operator.
Read more Tests greater than or equal to (for
self and
other) and is used by
the
>= operator.
Read more The resulting type after applying the - operator.
The resulting type after applying the - operator.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Immutably borrows from an owned value.
Read more Mutably borrows from an owned value.
Read more 🔬 This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from
self to
dest.
Read more Returns the argument unchanged.
Calls U::from(self).
That is, this conversion is whatever the implementation of
From <T> for U chooses to do.
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning.
Read more Uses borrowed data to replace owned data, usually by cloning.
Read more Converts the given value to a
String.
Read more The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.