[][src]Struct bcder::int::Integer

pub struct Integer(_);

A BER encoded integer.

As integers are variable length in BER, this type is just a simple wrapper atop the underlying Bytes value containing the raw content. A value of this type is a signed integer. If a value is defined as an unsigned integer, i.e., as INTEGER (0..MAX), you should use the sibling type Unsigned instead.

In addition to these two generic types, the content decoders also provide methods to parse integers into native integer types such as i8. If the range of such a type is obviously enough, you might want to consider using these methods instead.

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.

Methods

impl Integer[src]

pub fn take_from<S: Source>(cons: &mut Constructed<S>) -> Result<Self, S::Err>[src]

Takes a single signed integer from the beginning of an encoded value.

This requires the next value in cons to be a primitive value with a correctly encoded signed integer.

pub fn from_primitive<S: Source>(
    prim: &mut Primitive<S>
) -> Result<Self, S::Err>
[src]

Constructs a signed integer from the content of a primitive value.

pub fn i8_from_primitive<S: Source>(
    prim: &mut Primitive<S>
) -> Result<i8, S::Err>
[src]

Constructs an i8 from the content of a primitive value.

pub fn i16_from_primitive<S: Source>(
    prim: &mut Primitive<S>
) -> Result<i16, S::Err>
[src]

Constructs an i16 from the content of a primitive value.

pub fn i32_from_primitive<S: Source>(
    prim: &mut Primitive<S>
) -> Result<i32, S::Err>
[src]

Constructs an i32 from the content of a primitive value.

pub fn i64_from_primitive<S: Source>(
    prim: &mut Primitive<S>
) -> Result<i64, S::Err>
[src]

Constructs an i64 from the content of a primitive value.

pub fn i128_from_primitive<S: Source>(
    prim: &mut Primitive<S>
) -> Result<i128, S::Err>
[src]

Constructs an i128 from the content of a primitive value.

pub fn into_bytes(self) -> Bytes[src]

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

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

Returns a bytes slice with the raw content.

pub fn is_zero(&self) -> bool[src]

Returns whether the number is zero.

pub fn is_positive(&self) -> bool[src]

Returns whether the integer is positive.

Also returns false if the number is zero.

pub fn is_negative(&self) -> bool[src]

Returns whether the integer is negative.

Also returns false if the number is zero.

Trait Implementations

impl<'a> PrimitiveContent for &'a Integer[src]

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

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

fn encode(self) -> Primitive<Self>[src]

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

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

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

fn encode_ref(&self) -> Primitive<&Self>[src]

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

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

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

impl Clone for Integer[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl Ord for Integer[src]

fn max(self, other: Self) -> Self
1.21.0
[src]

Compares and returns the maximum of two values. Read more

fn min(self, other: Self) -> Self
1.21.0
[src]

Compares and returns the minimum of two values. Read more

impl From<i8> for Integer[src]

impl From<i16> for Integer[src]

impl From<i32> for Integer[src]

impl From<i64> for Integer[src]

impl From<i128> for Integer[src]

impl From<u8> for Integer[src]

impl From<u16> for Integer[src]

impl From<u32> for Integer[src]

impl From<u64> for Integer[src]

impl From<u128> for Integer[src]

impl Eq for Integer[src]

impl PartialOrd<Integer> for Integer[src]

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests less than (for self and other) and is used by the < operator. Read more

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0
[src]

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

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0
[src]

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

impl PartialEq<Integer> for Integer[src]

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests for !=.

impl PartialEq<Unsigned> for Integer[src]

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests for !=.

impl AsRef<Bytes> for Integer[src]

impl AsRef<[u8]> for Integer[src]

impl AsRef<Integer> for Unsigned[src]

impl Hash for Integer[src]

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

Feeds a slice of this type into the given [Hasher]. Read more

impl Debug for Integer[src]

Auto Trait Implementations

impl Send for Integer

impl Sync for Integer

Blanket Implementations

impl<T> From for T[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.