Skip to main content

SizedBytes

Trait SizedBytes 

Source
pub trait SizedBytes: Sized {
    type Len: ArrayLength<u8> + 'static;

    // Required methods
    fn to_arr(&self) -> GenericArray<u8, Self::Len>;
    fn from_arr(
        arr: &GenericArray<u8, Self::Len>,
    ) -> Result<Self, TryFromSizedBytesError>;
}
Expand description

A trait for sized key material that can be represented within a fixed byte array size, used to represent our DH key types. This trait being implemented with Error = SomeError allows you to derive TryFrom<&[u8], Error = SomeError>.

Required Associated Types§

Source

type Len: ArrayLength<u8> + 'static

The typed representation of the byte length

Required Methods§

Source

fn to_arr(&self) -> GenericArray<u8, Self::Len>

Converts this sized key material to a GenericArray of the same size. One can convert this to a &[u8] with GenericArray::as_slice() but the size information is then lost from the type.

Source

fn from_arr( arr: &GenericArray<u8, Self::Len>, ) -> Result<Self, TryFromSizedBytesError>

How to parse such sized material from a correctly-sized byte slice.

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<N: ArrayLength<u8> + 'static> SizedBytes for GenericArray<u8, N>

The blanket implementation of SizedBytes for GenericArray

Source§

type Len = N

Source§

fn to_arr(&self) -> GenericArray<u8, Self::Len>

Source§

fn from_arr( arr: &GenericArray<u8, Self::Len>, ) -> Result<Self, TryFromSizedBytesError>

Implementors§