Skip to main content

HmacFactoryExt

Trait HmacFactoryExt 

Source
pub trait HmacFactoryExt {
    // Required method
    fn hmac(&self, label: impl AsRef<str>, spec: HmacSpec) -> HmacSecret;
}
Expand description

Extension trait to hang HMAC helpers off the core Factory.

Required Methods§

Source

fn hmac(&self, label: impl AsRef<str>, spec: HmacSpec) -> HmacSecret

Generate (or retrieve from cache) an HMAC secret fixture.

The label identifies this secret within your test suite. In deterministic mode, seed + label + spec always produces the same secret.

§Examples
use uselesskey_core::{Factory, Seed};
use uselesskey_hmac::{HmacFactoryExt, HmacSpec};

let seed = Seed::from_env_value("test-seed").unwrap();
let fx = Factory::deterministic(seed);
let secret = fx.hmac("jwt-signing", HmacSpec::hs256());

// Same seed + label + spec = same secret
let secret2 = fx.hmac("jwt-signing", HmacSpec::hs256());
assert_eq!(secret.secret_bytes(), secret2.secret_bytes());

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl HmacFactoryExt for Factory

Source§

fn hmac(&self, label: impl AsRef<str>, spec: HmacSpec) -> HmacSecret

Implementors§