use std::time::Duration;
use async_trait::async_trait;
pub mod memory;
#[async_trait]
pub trait SessionStore: Send + Sync + 'static {
async fn load(&self, id: &str) -> Option<Vec<u8>>;
async fn store(&self, id: &str, data: Vec<u8>, ttl: Duration);
async fn remove(&self, id: &str) -> bool;
async fn sweep(&self) {}
}
#[async_trait]
pub trait RateLimitStore: Send + Sync + 'static {
async fn consume(&self, key: &str, cost: u32) -> Result<RateLimitSnapshot, RateLimitSnapshot>;
}
#[derive(Debug, Clone)]
pub struct RateLimitSnapshot {
pub limit: u32,
pub remaining: u32,
pub reset_secs: u64,
pub retry_after_secs: u64,
}
#[async_trait]
pub trait IdempotencyStore: Send + Sync + 'static {
async fn get(&self, key: &str) -> Option<IdempotencyEntry>;
async fn begin(&self, key: &str, payload_sig: [u8; 20]) -> IdempotencyEntry;
async fn complete(&self, key: &str, entry: IdempotencyEntry, ttl: Duration);
async fn remove(&self, key: &str);
}
#[derive(Debug, Clone)]
pub struct IdempotencyEntry {
pub status: u16,
pub headers: Vec<(String, Vec<u8>)>,
pub body: Vec<u8>,
pub payload_sig: [u8; 20],
pub completed: bool,
}
#[async_trait]
pub trait JwksProvider: Send + Sync + 'static {
async fn keys_for(&self, kid: &str) -> Vec<Vec<u8>>;
}
#[async_trait]
pub trait CsrfTokenStore: Send + Sync + 'static {
async fn issue(&self, session_id: &str, ttl: Duration) -> String;
async fn validate(&self, session_id: &str, token: &str, single_use: bool) -> bool;
}