#[non_exhaustive]pub struct ApiKeyEntry {
pub name: String,
pub hash: String,
pub role: String,
pub expires_at: Option<RfcTimestamp>,
}Expand description
A single API key entry (stored as Argon2id hash in config).
The Debug impl is manually written to redact the Argon2id hash.
Although the hash is not directly reversible, treating it as a secret
prevents offline brute-force attempts from leaked logs and matches the
defense-in-depth posture used for AuthIdentity.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.name: StringHuman-readable key label (used in logs and audit records).
hash: StringArgon2id hash of the token (PHC string format).
role: StringRBAC role granted when this key authenticates successfully.
expires_at: Option<RfcTimestamp>Optional expiry, parsed from an RFC 3339 string at deserialization
time. Construction from a raw string is fallible (see
RfcTimestamp::parse and ApiKeyEntry::try_with_expiry),
which guarantees verify_bearer_token never sees a malformed value.
Implementations§
Source§impl ApiKeyEntry
impl ApiKeyEntry
Sourcepub fn new(
name: impl Into<String>,
hash: impl Into<String>,
role: impl Into<String>,
) -> Self
pub fn new( name: impl Into<String>, hash: impl Into<String>, role: impl Into<String>, ) -> Self
Create a new API key entry (no expiry).
Sourcepub fn with_expiry(self, expires_at: RfcTimestamp) -> Self
pub fn with_expiry(self, expires_at: RfcTimestamp) -> Self
Set an RFC 3339 expiry on this key.
Takes an already-parsed RfcTimestamp; for ergonomic construction
from a raw string see Self::try_with_expiry.
Sourcepub fn try_with_expiry(
self,
expires_at: impl AsRef<str>,
) -> Result<Self, ParseError>
pub fn try_with_expiry( self, expires_at: impl AsRef<str>, ) -> Result<Self, ParseError>
Set an RFC 3339 expiry on this key from a raw string.
§Errors
Returns the underlying chrono::ParseError when expires_at is
not a valid RFC 3339 timestamp. This is the fallible counterpart to
Self::with_expiry.
Trait Implementations§
Source§impl Clone for ApiKeyEntry
impl Clone for ApiKeyEntry
Source§fn clone(&self) -> ApiKeyEntry
fn clone(&self) -> ApiKeyEntry
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more