Skip to main content

Hkdf

Struct Hkdf 

Source
pub struct Hkdf<Variant, Prk, const PRK_LENGTH: usize>
where Variant: HkdfVariant<PRK_LENGTH>, Prk: ByteArray<PRK_LENGTH> + Zeroize + ZeroizeOnDrop,
{ /* private fields */ }
Expand description

HKDF expander for a specific HkdfVariant.

Implementations§

Source§

impl<Variant, Prk, const PRK_LENGTH: usize> Hkdf<Variant, Prk, PRK_LENGTH>
where Variant: HkdfVariant<PRK_LENGTH>, Prk: NewByteArray<PRK_LENGTH> + Zeroize + ZeroizeOnDrop,

Source

pub fn generate() -> Self

Randomly generates a new PRK for HKDF expand.

Source

pub fn gen() -> Self

👎Deprecated:

use generate() instead

Randomly generates a new PRK for HKDF expand.

Prefer generate. gen is retained for compatibility with older Rust editions.

Source

pub fn extract<Salt: Bytes + ?Sized, Ikm: Bytes + ?Sized>( salt: Option<&Salt>, ikm: &Ikm, ) -> Self

Extracts a PRK from input keying material and optional salt.

Source

pub fn extract_and_expand<const OUTPUT_LENGTH: usize, Salt: Bytes + ?Sized, Ikm: Bytes + ?Sized, Context: Bytes + ?Sized, Output: NewByteArray<OUTPUT_LENGTH>>( salt: Option<&Salt>, ikm: &Ikm, context: &Context, ) -> Result<Output, Error>

One-shot HKDF extract-and-expand into a fixed-size output type.

§Errors

Returns an error if OUTPUT_LENGTH is outside the range supported by the selected HKDF variant.

Source

pub fn extract_and_expand_to_vec<Salt: Bytes + ?Sized, Ikm: Bytes + ?Sized, Context: Bytes + ?Sized>( output_len: usize, salt: Option<&Salt>, ikm: &Ikm, context: &Context, ) -> Result<Vec<u8>, Error>

One-shot HKDF extract-and-expand into a Vec.

§Errors

Returns an error if output_len is outside the range supported by the selected HKDF variant.

Source

pub fn extract_and_expand_to_bytes<Salt: Bytes + ?Sized, Ikm: Bytes + ?Sized, Context: Bytes + ?Sized, Output: NewBytes + ResizableBytes>( output_len: usize, salt: Option<&Salt>, ikm: &Ikm, context: &Context, ) -> Result<Output, Error>

One-shot HKDF extract-and-expand into a runtime-sized byte container.

§Errors

Returns an error if output_len is outside the range supported by the selected HKDF variant.

Source§

impl<Variant, Prk, const PRK_LENGTH: usize> Hkdf<Variant, Prk, PRK_LENGTH>
where Variant: HkdfVariant<PRK_LENGTH>, Prk: ByteArray<PRK_LENGTH> + Zeroize + ZeroizeOnDrop,

Source

pub fn from_prk(prk: Prk) -> Self

Constructs an HKDF expander from a PRK, consuming it.

Source

pub fn into_prk(self) -> Prk

Moves the PRK out of this expander.

Source

pub fn expand<const OUTPUT_LENGTH: usize, Context: Bytes + ?Sized, Output>( &self, context: &Context, ) -> Result<Output, Error>
where Output: NewByteArray<OUTPUT_LENGTH>,

Expands this PRK into a fixed-size output type.

§Errors

Returns an error if OUTPUT_LENGTH is outside the range supported by the selected HKDF variant.

Source

pub fn expand_to_vec<Context: Bytes + ?Sized>( &self, output_len: usize, context: &Context, ) -> Result<Vec<u8>, Error>

Expands this PRK into a Vec of output_len bytes.

§Errors

Returns an error if output_len is outside the range supported by the selected HKDF variant.

Source

pub fn expand_to_bytes<Context: Bytes + ?Sized, Output: NewBytes + ResizableBytes>( &self, output_len: usize, context: &Context, ) -> Result<Output, Error>

Expands this PRK into a runtime-sized byte container.

§Errors

Returns an error if output_len is outside the range supported by the selected HKDF variant.

Source§

impl<Variant, const PRK_LENGTH: usize> Hkdf<Variant, Variant::Prk, PRK_LENGTH>
where Variant: HkdfVariant<PRK_LENGTH>,

Source

pub fn generate_with_defaults() -> Self

Randomly generates a new PRK using the default stack-allocated type.

Source

pub fn gen_with_defaults() -> Self

👎Deprecated:

use generate_with_defaults() instead

Randomly generates a new PRK using the default stack-allocated type.

Prefer generate_with_defaults. This method is retained for compatibility.

Trait Implementations§

Source§

impl<Variant, Prk, const PRK_LENGTH: usize> Clone for Hkdf<Variant, Prk, PRK_LENGTH>
where Variant: HkdfVariant<PRK_LENGTH> + Clone, Prk: ByteArray<PRK_LENGTH> + Zeroize + ZeroizeOnDrop + Clone,

Source§

fn clone(&self) -> Hkdf<Variant, Prk, PRK_LENGTH>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<Variant, Prk, const PRK_LENGTH: usize> Debug for Hkdf<Variant, Prk, PRK_LENGTH>
where Variant: HkdfVariant<PRK_LENGTH> + Debug, Prk: ByteArray<PRK_LENGTH> + Zeroize + ZeroizeOnDrop + Debug,

Source§

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

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

impl<'de, Variant, Prk, const PRK_LENGTH: usize> Deserialize<'de> for Hkdf<Variant, Prk, PRK_LENGTH>
where Variant: HkdfVariant<PRK_LENGTH>, Prk: ByteArray<PRK_LENGTH> + Zeroize + ZeroizeOnDrop + Deserialize<'de>,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<Variant, Prk, const PRK_LENGTH: usize> Serialize for Hkdf<Variant, Prk, PRK_LENGTH>
where Variant: HkdfVariant<PRK_LENGTH>, Prk: ByteArray<PRK_LENGTH> + Zeroize + ZeroizeOnDrop + Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<Variant, Prk, const PRK_LENGTH: usize> Zeroize for Hkdf<Variant, Prk, PRK_LENGTH>
where Variant: HkdfVariant<PRK_LENGTH>, Prk: ByteArray<PRK_LENGTH> + Zeroize + ZeroizeOnDrop,

Source§

fn zeroize(&mut self)

Zero out this object from memory using Rust intrinsics which ensure the zeroization operation is not “optimized away” by the compiler.

Auto Trait Implementations§

§

impl<Variant, Prk, const PRK_LENGTH: usize> Freeze for Hkdf<Variant, Prk, PRK_LENGTH>
where Prk: Freeze,

§

impl<Variant, Prk, const PRK_LENGTH: usize> RefUnwindSafe for Hkdf<Variant, Prk, PRK_LENGTH>
where Prk: RefUnwindSafe, Variant: RefUnwindSafe,

§

impl<Variant, Prk, const PRK_LENGTH: usize> Send for Hkdf<Variant, Prk, PRK_LENGTH>
where Prk: Send, Variant: Send,

§

impl<Variant, Prk, const PRK_LENGTH: usize> Sync for Hkdf<Variant, Prk, PRK_LENGTH>
where Prk: Sync, Variant: Sync,

§

impl<Variant, Prk, const PRK_LENGTH: usize> Unpin for Hkdf<Variant, Prk, PRK_LENGTH>
where Prk: Unpin, Variant: Unpin,

§

impl<Variant, Prk, const PRK_LENGTH: usize> UnsafeUnpin for Hkdf<Variant, Prk, PRK_LENGTH>
where Prk: UnsafeUnpin,

§

impl<Variant, Prk, const PRK_LENGTH: usize> UnwindSafe for Hkdf<Variant, Prk, PRK_LENGTH>
where Prk: UnwindSafe, Variant: 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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> Same for T

Source§

type Output = T

Should always be Self
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.