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
impl HmacSecret
Sourcepub fn secret_bytes(&self) -> &[u8] ⓘ
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);Sourcepub fn kid(&self) -> String
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());Sourcepub fn jwk(&self) -> PrivateJwk
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");Trait Implementations§
Source§impl Clone for HmacSecret
impl Clone for HmacSecret
Source§fn clone(&self) -> HmacSecret
fn clone(&self) -> HmacSecret
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for HmacSecret
impl !RefUnwindSafe for HmacSecret
impl Send for HmacSecret
impl Sync for HmacSecret
impl Unpin for HmacSecret
impl UnsafeUnpin for HmacSecret
impl !UnwindSafe for HmacSecret
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more