pub struct Unsigned(/* private fields */);
Expand description
A BER encoded unsigned integer.
As integers are variable length in BER, this type is just a simple wrapper
atop the underlying Bytes
value containing the raw content. It
guarantees that the wrapped integer is greater or equal to 0. This equals
an integer defined as INTEGER (0..MAX)
in ASN.1.
If you need a integer without any restrictions, you can use Integer
. If
you have even stricter range restrictions, you can also use the methods
provided on the content types to decode into Rust’s primitive integer
types such as u16
.
BER Encoding
In BER, an INTEGER is encoded as a primitive value with the content octets providing a variable-length, big-endian, two‘s complement byte sequence of that integer. Thus, the most-significant bit of the first octet serves as the sign bit and, for an unsigned integer, has to be unset.
Implementations§
source§impl Unsigned
impl Unsigned
sourcepub fn from_slice(slice: &[u8]) -> Result<Self, InvalidInteger>
pub fn from_slice(slice: &[u8]) -> Result<Self, InvalidInteger>
Constructs Unsigned
by copying from a &[u8]
.
Errors
Will return a malformed error if the given slice is empty.
sourcepub fn from_bytes(bytes: Bytes) -> Result<Self, InvalidInteger>
pub fn from_bytes(bytes: Bytes) -> Result<Self, InvalidInteger>
Constructs Unsigned
from Bytes
, copying only if needed.
Errors
Will return a malformed error if the given slice is empty.
pub fn take_from<S: Source>( cons: &mut Constructed<'_, S> ) -> Result<Self, DecodeError<S::Error>>
pub fn from_primitive<S: Source>( prim: &mut Primitive<'_, S> ) -> Result<Self, DecodeError<S::Error>>
pub fn u8_from_primitive<S: Source>( prim: &mut Primitive<'_, S> ) -> Result<u8, DecodeError<S::Error>>
pub fn u16_from_primitive<S: Source>( prim: &mut Primitive<'_, S> ) -> Result<u16, DecodeError<S::Error>>
pub fn u32_from_primitive<S: Source>( prim: &mut Primitive<'_, S> ) -> Result<u32, DecodeError<S::Error>>
pub fn u64_from_primitive<S: Source>( prim: &mut Primitive<'_, S> ) -> Result<u64, DecodeError<S::Error>>
pub fn u128_from_primitive<S: Source>( prim: &mut Primitive<'_, S> ) -> Result<u128, DecodeError<S::Error>>
sourcepub fn into_bytes(self) -> Bytes
pub fn into_bytes(self) -> Bytes
Trades the integer into a bytes value with the raw content octets.
Trait Implementations§
source§impl Ord for Unsigned
impl Ord for Unsigned
source§impl PartialEq<Unsigned> for Integer
impl PartialEq<Unsigned> for Integer
source§impl PartialEq for Unsigned
impl PartialEq for Unsigned
source§impl PartialOrd for Unsigned
impl PartialOrd for Unsigned
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 more