Struct bcder::int::Unsigned

source ·
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

source

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.

source

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.

source

pub fn take_from<S: Source>( cons: &mut Constructed<'_, S> ) -> Result<Self, DecodeError<S::Error>>

source

pub fn from_primitive<S: Source>( prim: &mut Primitive<'_, S> ) -> Result<Self, DecodeError<S::Error>>

source

pub fn u8_from_primitive<S: Source>( prim: &mut Primitive<'_, S> ) -> Result<u8, DecodeError<S::Error>>

source

pub fn u16_from_primitive<S: Source>( prim: &mut Primitive<'_, S> ) -> Result<u16, DecodeError<S::Error>>

source

pub fn u32_from_primitive<S: Source>( prim: &mut Primitive<'_, S> ) -> Result<u32, DecodeError<S::Error>>

source

pub fn u64_from_primitive<S: Source>( prim: &mut Primitive<'_, S> ) -> Result<u64, DecodeError<S::Error>>

source

pub fn u128_from_primitive<S: Source>( prim: &mut Primitive<'_, S> ) -> Result<u128, DecodeError<S::Error>>

source

pub fn into_bytes(self) -> Bytes

Trades the integer into a bytes value with the raw content octets.

source

pub fn as_slice(&self) -> &[u8]

Returns a bytes slice with the raw content.

source

pub fn is_zero(&self) -> bool

Returns whether the number is zero.

Trait Implementations§

source§

impl AsRef<[u8]> for Unsigned

source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl AsRef<Bytes> for Unsigned

source§

fn as_ref(&self) -> &Bytes

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl AsRef<Integer> for Unsigned

source§

fn as_ref(&self) -> &Integer

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Clone for Unsigned

source§

fn clone(&self) -> Unsigned

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Unsigned

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<u128> for Unsigned

source§

fn from(val: u128) -> Unsigned

Converts to this type from the input type.
source§

impl From<u16> for Unsigned

source§

fn from(val: u16) -> Unsigned

Converts to this type from the input type.
source§

impl From<u32> for Unsigned

source§

fn from(val: u32) -> Unsigned

Converts to this type from the input type.
source§

impl From<u64> for Unsigned

source§

fn from(val: u64) -> Unsigned

Converts to this type from the input type.
source§

impl From<u8> for Unsigned

source§

fn from(val: u8) -> Unsigned

Converts to this type from the input type.
source§

impl Hash for Unsigned

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Ord for Unsigned

source§

fn cmp(&self, other: &Unsigned) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq<Unsigned> for Integer

source§

fn eq(&self, other: &Unsigned) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq for Unsigned

source§

fn eq(&self, other: &Unsigned) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Unsigned

source§

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 · source§

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 · source§

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
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<'a> PrimitiveContent for &'a Unsigned

source§

const TAG: Tag = Tag::INTEGER

The natural tag of an encoded value of this type.
source§

fn encoded_len(&self, mode: Mode) -> usize

Returns the length of the encoded content of this type.
source§

fn write_encoded<W: Write>( &self, mode: Mode, target: &mut W ) -> Result<(), Error>

Writes the encoded content to a writer.
source§

fn to_encoded_bytes(&self, mode: Mode) -> Bytes

Encodes the value to bytes (useful when you need to sign a structure)
source§

fn encode(self) -> Primitive<Self>

Returns a value encoder for this content using the natural tag. Read more
source§

fn encode_as(self, tag: Tag) -> Primitive<Self>

Returns a value encoder for this content using the given tag. Read more
source§

fn encode_ref(&self) -> Primitive<&Self>

Returns a value encoder for a reference using the natural tag.
source§

fn encode_ref_as(&self, tag: Tag) -> Primitive<&Self>

Returns a value encoder for a reference using the given tag.
source§

impl<'a> TryFrom<&'a Unsigned> for i128

§

type Error = OverflowError

The type returned in the event of a conversion error.
source§

fn try_from(val: &'a Unsigned) -> Result<i128, Self::Error>

Performs the conversion.
source§

impl<'a> TryFrom<&'a Unsigned> for i16

§

type Error = OverflowError

The type returned in the event of a conversion error.
source§

fn try_from(val: &'a Unsigned) -> Result<i16, Self::Error>

Performs the conversion.
source§

impl<'a> TryFrom<&'a Unsigned> for i32

§

type Error = OverflowError

The type returned in the event of a conversion error.
source§

fn try_from(val: &'a Unsigned) -> Result<i32, Self::Error>

Performs the conversion.
source§

impl<'a> TryFrom<&'a Unsigned> for i64

§

type Error = OverflowError

The type returned in the event of a conversion error.
source§

fn try_from(val: &'a Unsigned) -> Result<i64, Self::Error>

Performs the conversion.
source§

impl<'a> TryFrom<&'a Unsigned> for i8

§

type Error = OverflowError

The type returned in the event of a conversion error.
source§

fn try_from(val: &'a Unsigned) -> Result<i8, Self::Error>

Performs the conversion.
source§

impl<'a> TryFrom<&'a Unsigned> for u128

§

type Error = OverflowError

The type returned in the event of a conversion error.
source§

fn try_from(val: &'a Unsigned) -> Result<u128, Self::Error>

Performs the conversion.
source§

impl<'a> TryFrom<&'a Unsigned> for u16

§

type Error = OverflowError

The type returned in the event of a conversion error.
source§

fn try_from(val: &'a Unsigned) -> Result<u16, Self::Error>

Performs the conversion.
source§

impl<'a> TryFrom<&'a Unsigned> for u32

§

type Error = OverflowError

The type returned in the event of a conversion error.
source§

fn try_from(val: &'a Unsigned) -> Result<u32, Self::Error>

Performs the conversion.
source§

impl<'a> TryFrom<&'a Unsigned> for u64

§

type Error = OverflowError

The type returned in the event of a conversion error.
source§

fn try_from(val: &'a Unsigned) -> Result<u64, Self::Error>

Performs the conversion.
source§

impl<'a> TryFrom<&'a Unsigned> for u8

§

type Error = OverflowError

The type returned in the event of a conversion error.
source§

fn try_from(val: &'a Unsigned) -> Result<u8, Self::Error>

Performs the conversion.
source§

impl TryFrom<Bytes> for Unsigned

§

type Error = InvalidInteger

The type returned in the event of a conversion error.
source§

fn try_from(value: Bytes) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Unsigned> for i128

§

type Error = OverflowError

The type returned in the event of a conversion error.
source§

fn try_from(val: Unsigned) -> Result<i128, Self::Error>

Performs the conversion.
source§

impl TryFrom<Unsigned> for i16

§

type Error = OverflowError

The type returned in the event of a conversion error.
source§

fn try_from(val: Unsigned) -> Result<i16, Self::Error>

Performs the conversion.
source§

impl TryFrom<Unsigned> for i32

§

type Error = OverflowError

The type returned in the event of a conversion error.
source§

fn try_from(val: Unsigned) -> Result<i32, Self::Error>

Performs the conversion.
source§

impl TryFrom<Unsigned> for i64

§

type Error = OverflowError

The type returned in the event of a conversion error.
source§

fn try_from(val: Unsigned) -> Result<i64, Self::Error>

Performs the conversion.
source§

impl TryFrom<Unsigned> for i8

§

type Error = OverflowError

The type returned in the event of a conversion error.
source§

fn try_from(val: Unsigned) -> Result<i8, Self::Error>

Performs the conversion.
source§

impl TryFrom<Unsigned> for u128

§

type Error = OverflowError

The type returned in the event of a conversion error.
source§

fn try_from(val: Unsigned) -> Result<u128, Self::Error>

Performs the conversion.
source§

impl TryFrom<Unsigned> for u16

§

type Error = OverflowError

The type returned in the event of a conversion error.
source§

fn try_from(val: Unsigned) -> Result<u16, Self::Error>

Performs the conversion.
source§

impl TryFrom<Unsigned> for u32

§

type Error = OverflowError

The type returned in the event of a conversion error.
source§

fn try_from(val: Unsigned) -> Result<u32, Self::Error>

Performs the conversion.
source§

impl TryFrom<Unsigned> for u64

§

type Error = OverflowError

The type returned in the event of a conversion error.
source§

fn try_from(val: Unsigned) -> Result<u64, Self::Error>

Performs the conversion.
source§

impl TryFrom<Unsigned> for u8

§

type Error = OverflowError

The type returned in the event of a conversion error.
source§

fn try_from(val: Unsigned) -> Result<u8, Self::Error>

Performs the conversion.
source§

impl Eq for Unsigned

source§

impl StructuralEq for Unsigned

source§

impl StructuralPartialEq for Unsigned

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.