Skip to main content

PrfKeyInit

Trait PrfKeyInit 

Source
pub trait PrfKeyInit: Prf {
    type Key: Controlled;
    type KeyError: Error + Send + Sync + 'static;

    // Required methods
    fn new(key: Self::Key) -> Self;
    fn try_from_bytes(key: Protected<Vec<u8>>) -> Result<Self, Self::KeyError>;
}
Expand description

Construction of a Prf backend from key material.

This is the one place the key changes hands. Both constructors take the key by value, so the material moves into the backend rather than being copied at the boundary, and the backend owns it for the rest of its life: when the backend drops, the key is wiped. Backends must not hand out shared handles to the key (for example behind an Arc), because that turns “wiped when this backend drops” into “wiped when the last outstanding handle drops”, which no call site can see.

The shape mirrors RustCrypto’s KeyInit, with the deliberate difference that the key is owned rather than borrowed and copied in.

Prf is a supertrait, so P: PrfKeyInit alone says “a PRF I can build from a key”; generic code does not need to spell out P: Prf as well.

Required Associated Types§

Source

type Key: Controlled

Fixed-size key type whose length is guaranteed by construction, so new cannot fail. Always a controlled type; a bare array cannot key a backend.

Source

type KeyError: Error + Send + Sync + 'static

Reason try_from_bytes can reject key material, typically because it is too short.

Required Methods§

Source

fn new(key: Self::Key) -> Self

Key the backend with a full-strength key of the statically known length.

Source

fn try_from_bytes(key: Protected<Vec<u8>>) -> Result<Self, Self::KeyError>

Key the backend with material whose length is only known at runtime, such as a KMS response or an environment variable.

§Errors

Returns KeyError if the material is not acceptable as a key.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§