pub struct ApiKey(/* private fields */);Expand description
An Agent Assembly API key in aa_<32-hex-chars> format.
Implementations§
Source§impl ApiKey
impl ApiKey
Sourcepub fn parse(raw: &str) -> Result<Self, ApiKeyError>
pub fn parse(raw: &str) -> Result<Self, ApiKeyError>
Parse and validate a raw API key string.
Returns an error if the key doesn’t match aa_<32-hex-chars>.
Sourcepub fn generate() -> Self
pub fn generate() -> Self
Generate a new cryptographically random API key.
Returns the ApiKey and the plaintext string (for display to the user).
Sourcepub fn hash(&self) -> Result<String, ApiKeyError>
pub fn hash(&self) -> Result<String, ApiKeyError>
Hash this key using argon2 for secure storage.
Sourcepub fn lookup(&self) -> String
pub fn lookup(&self) -> String
Derive the fast, non-secret lookup index for this key (AAASM-4075).
A truncated SHA-256 of the raw key. Because SHA-256 is preimage-resistant,
persisting this alongside the argon2 hash leaks nothing about the key even
if the key store is exfiltrated, yet it lets ApiKeyStore::validate_detailed
select the single candidate entry in O(1) and run the expensive argon2
verification only on that candidate — never once per stored key. argon2
remains the sole authority for the final match.