Skip to main content

Limbs

Trait Limbs 

Source
pub(super) trait Limbs:
    Send
    + Sync
    + Debug
    + Zeroize
    + CtEq
    + CtSelect
    + BitOps
    + Limbs<Wide: Send + Sync + Debug + Zeroize + CtSelect + BitOps + Limbs + Limbs>
    + Limbs {
    type Bytes: AsRef<[u8]> + AsMut<[u8]>;

    // Required methods
    fn max_bits() -> Option<u32>;
    fn truncate(wide: Self::Wide, bits: u32) -> Self;
    fn widen(thin: Self, wide_bits: u32) -> Self::Wide;
    fn to_le_bytes(self) -> Self::Bytes;
    fn wide_to_le_bytes(wide: Self::Wide) -> impl AsRef<[u8]>;
    fn from_le_slice(bytes: &[u8], max_bits: u32) -> Self;
    fn wide_from_le_slice(bytes: &[u8], max_bits: u32) -> Self::Wide;
    fn stitch(
        first: Self::Bytes,
        second: Self::Bytes,
        bytes_per_element: usize,
    ) -> impl AsRef<[u8]>;
}

Required Associated Types§

Source

type Bytes: AsRef<[u8]> + AsMut<[u8]>

Required Methods§

Source

fn max_bits() -> Option<u32>

The maximum amount of bits this value can support.

None signifies this value is unbounded.

Source

fn truncate(wide: Self::Wide, bits: u32) -> Self

Truncate wide to a member of Self.

bits, a bound on the size of the result, is provided. The value in wide MUST be less than $2^{bits}$. bits MUST be less than or equal to Self::max_bits() when Self::max_bits().is_some().

Source

fn widen(thin: Self, wide_bits: u32) -> Self::Wide

Widen thin to a member of Self::Wide.

wide_bits is a bound on how big the widened type should be able to support. The value in thin MUST be less than $2^{wide_bits}$. wide_bits MUST be less than or equal to 2 * Self::max_bits() when Self::max_bits().is_some().

Source

fn to_le_bytes(self) -> Self::Bytes

Convert this number to a sequence of little-endian bytes.

This function MUST run in constant time and yield a result of length constant to the relevant bound.

Source

fn wide_to_le_bytes(wide: Self::Wide) -> impl AsRef<[u8]>

Convert this wide number to a sequence of little-endian bytes.

This function MUST run in constant time and yield a result of length constant to the relevant bound.

Source

fn from_le_slice(bytes: &[u8], max_bits: u32) -> Self

Load this number from a sequence of little-endian bytes.

The slice MAY be of arbitrary length so long as the encoded value has bits less than or equal to max_bits. max_bits MUST be less than or equal to Self::max_bits() when Self::max_bits().is_some().

Source

fn wide_from_le_slice(bytes: &[u8], max_bits: u32) -> Self::Wide

Load a wide number from a sequence of little-endian bytes.

The slice MAY be of arbitrary length so long as the encoded value has bits less than or equal to max_bits.max_bits MUST be less than or equal to 2 * Self::max_bits() when Self::max_bits().is_some().

Source

fn stitch( first: Self::Bytes, second: Self::Bytes, bytes_per_element: usize, ) -> impl AsRef<[u8]>

Stich together two byte sequences into a single container of length 2 * bytes_per_element.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Limbs for BoxedUint

Available on crate feature alloc only.
Source§

type Bytes = Box<[u8]>

Source§

fn max_bits() -> Option<u32>

Source§

fn truncate(wide: Self::Wide, bits: u32) -> Self

Source§

fn widen(thin: Self, wide_bits: u32) -> Self::Wide

Source§

fn to_le_bytes(self) -> Self::Bytes

Source§

fn wide_to_le_bytes(wide: Self::Wide) -> impl AsRef<[u8]>

Source§

fn from_le_slice(bytes: &[u8], max_bits: u32) -> Self

Source§

fn wide_from_le_slice(bytes: &[u8], max_bits: u32) -> Self::Wide

Source§

fn stitch( first: Self::Bytes, second: Self::Bytes, bytes_per_element: usize, ) -> impl AsRef<[u8]>

Source§

impl<const LIMBS: usize, const WIDE_LIMBS: usize> Limbs for Uint<LIMBS>
where Self: Encoding<Repr: Default> + Concat<LIMBS, Output = Uint<WIDE_LIMBS>>, Uint<WIDE_LIMBS>: Encoding<Repr: Default> + SplitEven<Output = Self> + Limbs,

Source§

type Bytes = EncodedUint<LIMBS>

Source§

fn max_bits() -> Option<u32>

Source§

fn truncate(wide: Self::Wide, _bits: u32) -> Self

Source§

fn widen(thin: Self, _wide_bits: u32) -> Self::Wide

Source§

fn to_le_bytes(self) -> Self::Bytes

Source§

fn wide_to_le_bytes(wide: Self::Wide) -> impl AsRef<[u8]>

Source§

fn from_le_slice(bytes: &[u8], max_bits: u32) -> Self

Source§

fn wide_from_le_slice(bytes: &[u8], max_bits: u32) -> Self::Wide

Source§

fn stitch( first: Self::Bytes, second: Self::Bytes, bytes_per_element: usize, ) -> impl AsRef<[u8]>

Implementors§