pub struct Unsigned(_);
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
sourceimpl 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
sourceimpl Ord for Unsigned
impl Ord for Unsigned
sourceimpl PartialOrd<Unsigned> for Unsigned
impl PartialOrd<Unsigned> for Unsigned
sourcefn partial_cmp(&self, other: &Unsigned) -> Option<Ordering>
fn partial_cmp(&self, other: &Unsigned) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl<'a> PrimitiveContent for &'a Unsigned
impl<'a> PrimitiveContent for &'a Unsigned
sourcefn encoded_len(&self, mode: Mode) -> usize
fn encoded_len(&self, mode: Mode) -> usize
Returns the length of the encoded content of this type.
sourcefn write_encoded<W: Write>(&self, mode: Mode, target: &mut W) -> Result<(), Error>
fn write_encoded<W: Write>(&self, mode: Mode, target: &mut W) -> Result<(), Error>
Writes the encoded content to a writer.
sourcefn to_encoded_bytes(&self, mode: Mode) -> Bytes
fn to_encoded_bytes(&self, mode: Mode) -> Bytes
Encodes the value to bytes (useful when you need to sign a structure)
sourcefn encode(self) -> Primitive<Self>
fn encode(self) -> Primitive<Self>
Returns a value encoder for this content using the natural tag. Read more
sourcefn encode_as(self, tag: Tag) -> Primitive<Self>
fn encode_as(self, tag: Tag) -> Primitive<Self>
Returns a value encoder for this content using the given tag. Read more
sourcefn encode_ref(&self) -> Primitive<&Self>
fn encode_ref(&self) -> Primitive<&Self>
Returns a value encoder for a reference using the natural tag.
sourcefn encode_ref_as(&self, tag: Tag) -> Primitive<&Self>
fn encode_ref_as(&self, tag: Tag) -> Primitive<&Self>
Returns a value encoder for a reference using the given tag.
impl Eq for Unsigned
impl StructuralEq for Unsigned
impl StructuralPartialEq for Unsigned
Auto Trait Implementations
impl RefUnwindSafe for Unsigned
impl Send for Unsigned
impl Sync for Unsigned
impl Unpin for Unsigned
impl UnwindSafe for Unsigned
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more