pub struct Keys { /* private fields */ }Expand description
Keys derived from the configured secrets. The first secret signs, verifies and encrypts.
Every secret decrypts, so encrypted columns stay readable after a rotation, and every
secret verifies a signed session token (Keys::verify_token), which is only a
pointer to a session row, so rotating signs nobody out. A retired secret can’t sign
anything self-contained (the cookie cache, plugin cookies) that is accepted.
Implementations§
Source§impl Keys
impl Keys
Sourcepub fn sign(&self, purpose: SignPurpose, value: &str) -> String
pub fn sign(&self, purpose: SignPurpose, value: &str) -> String
value.signature, signature base64url. With CookieSigning::BetterAuth, a
SignPurpose::Cookie value is signed in Better Auth’s format instead.
Sourcepub fn verify<'a>(
&self,
purpose: SignPurpose,
signed: &'a str,
) -> Option<&'a str>
pub fn verify<'a>( &self, purpose: SignPurpose, signed: &'a str, ) -> Option<&'a str>
The value, when the current (first) secret signed it. For values that carry their own meaning, like the cookie cache or a plugin’s signed cookie.
signed is the value after Keys::decode_cookie: with CookieSigning::BetterAuth,
a cookie as the browser sent it may be percent-encoded.
Sourcepub fn verify_token<'a>(&self, signed: &'a str) -> Option<&'a str>
pub fn verify_token<'a>(&self, signed: &'a str) -> Option<&'a str>
A session token signed with SignPurpose::Cookie by any configured secret. Only
for raw session tokens, and for markers that only restrict the session they come
with (the rememberMe: false flag): a token means nothing until its session row is
found, and a forged marker only shortens a session, so a retired secret can’t gain
anything, and values signed before a rotation keep working.
With CookieSigning::BetterAuth, only its one secret verifies, as in Better Auth.
A signed cookie’s value as Keys::verify and Keys::verify_token take it. With
CookieSigning::BetterAuth, a value holding a % is percent-decoded the way
better-call does (kept as it came when it isn’t valid); otherwise it’s returned as it is.