use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use crate::secrets::error::{Result, SecretsError};
pub const PUBLIC_KEY_LEN: usize = 32;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum ActorKind {
User,
ApiKey,
}
impl ActorKind {
#[must_use]
pub fn as_str(&self) -> &'static str {
match self {
Self::User => "user",
Self::ApiKey => "api_key",
}
}
#[allow(clippy::should_implement_trait)]
pub fn from_str(s: &str) -> Result<Self> {
match s {
"user" => Ok(Self::User),
"api_key" => Ok(Self::ApiKey),
other => Err(SecretsError::Storage(format!(
"invalid actor_kind in client_public_keys row: {other:?}"
))),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ClientPublicKey {
pub key_id: String,
pub actor_kind: ActorKind,
pub actor_id: String,
pub public_key: Vec<u8>,
pub label: Option<String>,
pub created_at: DateTime<Utc>,
pub last_used_at: Option<DateTime<Utc>>,
pub revoked_at: Option<DateTime<Utc>>,
}