Slice

Struct Slice 

Source
pub struct Slice<'s, SZ> { /* private fields */ }
Expand description

A Salt with runtime flexibility.

The Salt trait, with its associated constraints, is implemented for most common types which meet the marker constraint for pure compile-time checks. However, this can be limiting, this type moves these compile-time checks to runtime.

Implementations§

Source§

impl<'s> Slice<'s, Empty>

Source

pub const fn new(slice: &'s [u8]) -> Result<Self, Infallible>

Create a new SaltSlice instance.

§Arguments
  • slice - The Salt (if any) to use.
§Errors

This is infallible, the only reason this returns a result is to keep this new implementation in sync with other Salt constraints (this being the weakest / most permissive constraint).

Source§

impl<'s> Slice<'s, NonEmpty>

Source

pub const fn new(slice: &'s [u8]) -> Result<Self, InvalidSize>

Create a new SaltSlice instance.

§Arguments
  • slice - The Salt, which must be non-empty.
§Errors

This requires the provided slice to be non-empty, this is the second-weakest constraint, and only leveraged with allow-non-fips enabled. In general, for KDFs such as PBKDF it is strongly recommended to use at least a 128 bit (16 byte) salt generated from a valid CSPRNG.

Source§

impl<'s> Slice<'s, Min16>

Source

pub const fn new(slice: &'s [u8]) -> Result<Self, InvalidSize>

Create a new SaltSlice instance.

§Arguments
  • slice - The Salt, which must be at least 128 bits (16 bytes).
§Errors

This requires that the provided slice is at least 128 bits (16 bytes), this is the strongest constraint as it enforces this best practice (as well as FIPS requirement). Regardless if the interface requires this constraint it is strongly recommended to use a 128 bit salt generated from a valid CSPRNG.

Trait Implementations§

Source§

impl<'s, SZ: MinSize> AsRef<[u8]> for Slice<'s, SZ>

Source§

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

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

impl<'s, SZ: MinSize> Clone for Slice<'s, SZ>

Source§

fn clone(&self) -> Self

Returns a duplicate 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<'s, SZ: MinSize> Debug for Slice<'s, SZ>

Source§

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

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

impl<'s> From<&'s [u8]> for Slice<'s, Empty>

Source§

fn from(value: &'s [u8]) -> Self

Converts to this type from the input type.
Source§

impl<'s> From<&'s [u8; 16]> for Slice<'s, Min16>

Source§

fn from(value: &'s [u8; 16]) -> Self

Converts to this type from the input type.
Source§

impl<'s> TryFrom<&'s [u8]> for Slice<'s, Min16>

Source§

type Error = <Min16 as MinSize>::CreateError

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

fn try_from(value: &'s [u8]) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'s> TryFrom<&'s [u8]> for Slice<'s, NonEmpty>

Source§

type Error = <NonEmpty as MinSize>::CreateError

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

fn try_from(value: &'s [u8]) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'s> Salt<Empty> for Slice<'s, Empty>

Source§

impl<'s> Salt<Empty> for Slice<'s, Min16>

Source§

impl<'s> Salt<Empty> for Slice<'s, NonEmpty>

Source§

impl<'s> Salt<Min16> for Slice<'s, Min16>

Source§

impl<'s> Salt<NonEmpty> for Slice<'s, NonEmpty>

Auto Trait Implementations§

§

impl<'s, SZ> Freeze for Slice<'s, SZ>

§

impl<'s, SZ> RefUnwindSafe for Slice<'s, SZ>
where SZ: RefUnwindSafe,

§

impl<'s, SZ> Send for Slice<'s, SZ>
where SZ: Send,

§

impl<'s, SZ> Sync for Slice<'s, SZ>
where SZ: Sync,

§

impl<'s, SZ> Unpin for Slice<'s, SZ>
where SZ: Unpin,

§

impl<'s, SZ> UnwindSafe for Slice<'s, SZ>
where SZ: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Salt<NonEmpty> for T
where T: Salt<Min16>,

Source§

fn size(&self) -> u32

Source§

fn is_valid_size(&self) -> bool

Source§

fn i_size(&self) -> i32

Source§

fn i_is_valid_size(&self) -> bool

Source§

fn ptr(&self) -> *const u8

Source§

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

Source§

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>,

Source§

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>,

Source§

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.
Source§

impl<T> Fips for T
where T: Salt<Min16>,

Source§

impl<S> NonEmptySize<Min16> for S
where S: Salt<Min16>,

Source§

impl<S> NonEmptySize<NonEmpty> for S
where S: Salt<NonEmpty>,