Skip to main content

HmacSecret

Struct HmacSecret 

Source
pub struct HmacSecret { /* private fields */ }
Expand description

An HMAC secret fixture.

Created via HmacFactoryExt::hmac(). Provides access to raw secret bytes and JWK output (with the jwk feature).

§Examples

use uselesskey_core::Factory;
use uselesskey_hmac::{HmacFactoryExt, HmacSpec};

let fx = Factory::random();
let secret = fx.hmac("jwt-signing", HmacSpec::hs256());

assert_eq!(secret.secret_bytes().len(), 32);

Implementations§

Source§

impl HmacSecret

Source

pub fn secret_bytes(&self) -> &[u8]

Access raw secret bytes.

§Examples
let fx = Factory::deterministic(Seed::from_env_value("test-seed").unwrap());
let secret = fx.hmac("jwt-signing", HmacSpec::hs256());
assert_eq!(secret.secret_bytes().len(), 32);

let secret512 = fx.hmac("jwt-signing", HmacSpec::hs512());
assert_eq!(secret512.secret_bytes().len(), 64);
Source

pub fn kid(&self) -> String

A stable key identifier derived from the secret bytes (base64url blake3 hash prefix).

§Examples
let fx = Factory::random();
let secret = fx.hmac("jwt", HmacSpec::hs256());
let kid = secret.kid();
assert!(!kid.is_empty());
Source

pub fn jwk(&self) -> PrivateJwk

HMAC secret as an octet JWK (kty=oct).

Requires the jwk feature.

§Examples
let fx = Factory::random();
let secret = fx.hmac("jwt", HmacSpec::hs256());
let jwk = secret.jwk();
let val = jwk.to_value();
assert_eq!(val["kty"], "oct");
assert_eq!(val["alg"], "HS256");
Source

pub fn jwks(&self) -> Jwks

JWKS containing this HMAC secret as an octet key.

Requires the jwk feature.

§Examples
let fx = Factory::random();
let secret = fx.hmac("jwt", HmacSpec::hs256());
let jwks = secret.jwks();
let val = jwks.to_value();
assert!(val["keys"].is_array());

Trait Implementations§

Source§

impl Clone for HmacSecret

Source§

fn clone(&self) -> HmacSecret

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 Debug for HmacSecret

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V