vitaminc-prf
vitaminc-prf provides a serde-style API for deriving structured,
domain-separated pseudorandom values. Inputs cross backend boundaries in
Protected containers, maps bind their keys into the derivation context, and
backend output is always awaitable so local and remote batched implementations
share one interface.
This crate defines only the abstraction: the PrfValue,
Prf, and
PrfKeyInit
traits, context and encoding domains, and the visitor machinery. It contains
no cryptography. Concrete backends live in their own crates; the local
HMAC-SHA256 backend is vitaminc-hmac,
and its documentation carries runnable end-to-end examples.
Key ownership lives in exactly one place. PrfKeyInit constructs a backend
from key material taken by value, so the key moves into the backend and is
wiped when the backend drops. Every Prf derivation method then borrows the
backend (&self): a derivation is a pure function of the key and the input,
so nothing is consumed and one instance serves any number of derivations
without being cloned.
Every protected leaf carries an explicit PrfEncoding
domain. Built-in text, bytes, and fixed-width integers are separated even when
their byte representations happen to match. Custom leaf implementations must
provide a stable, namespaced encoding identifier, preventing accidental
untagged derivation.
Implementing PrfValue for a struct
Struct implementations describe their fields with a map driver. The final visitor receives resolved child nodes, so each field can produce a different owned output while a deferred backend still executes the structure as one batch.
use ;
;
;
Executing the derivation requires a backend; with vitaminc-hmac in
scope the value above resolves through
user.prf_visit_with_context(&prf, "tenant/acme/users/v1", UserTermsVisitor).await.