pub struct ApiKey {
pub id: String,
pub name: String,
pub key: String,
pub secret_hash: Option<String>,
pub salt: Option<Salt>,
pub role: Role,
pub created_at: DateTime<Utc>,
pub expires_at: Option<DateTime<Utc>>,
pub last_used: Option<DateTime<Utc>>,
pub ip_whitelist: Vec<String>,
pub active: bool,
pub usage_count: u64,
}
Expand description
API key for authentication with comprehensive metadata
Fields§
§id: String
Unique key identifier (format: lmcp_{role}{timestamp}{random})
name: String
Human-readable name/description
key: String
The actual secret token used for authentication
secret_hash: Option<String>
Secure hash of the secret token (for storage)
salt: Option<Salt>
Salt used for hashing the secret token
role: Role
Role-based permissions
created_at: DateTime<Utc>
Creation timestamp
expires_at: Option<DateTime<Utc>>
Optional expiration timestamp
last_used: Option<DateTime<Utc>>
Last time this key was used
ip_whitelist: Vec<String>
IP address whitelist (empty = all IPs allowed)
active: bool
Is the key currently active
usage_count: u64
Usage count
Implementations§
Source§impl ApiKey
impl ApiKey
Sourcepub fn new(
name: String,
role: Role,
expires_at: Option<DateTime<Utc>>,
ip_whitelist: Vec<String>,
) -> Self
pub fn new( name: String, role: Role, expires_at: Option<DateTime<Utc>>, ip_whitelist: Vec<String>, ) -> Self
Create a new API key with secure random generation
Sourcepub fn is_expired(&self) -> bool
pub fn is_expired(&self) -> bool
Check if the key is expired
Sourcepub fn verify_key(&self, provided_key: &str) -> Result<bool, HashingError>
pub fn verify_key(&self, provided_key: &str) -> Result<bool, HashingError>
Verify if the provided key matches the stored hash
Sourcepub fn to_secure_storage(&self) -> SecureApiKey
pub fn to_secure_storage(&self) -> SecureApiKey
Convert to secure storage format (without plain text key)
Trait Implementations§
Source§impl<'de> Deserialize<'de> for ApiKey
impl<'de> Deserialize<'de> for ApiKey
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for ApiKey
impl RefUnwindSafe for ApiKey
impl Send for ApiKey
impl Sync for ApiKey
impl Unpin for ApiKey
impl UnwindSafe for ApiKey
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