use rusqlite::params; use crate::{ database::{Database, now}, error::Result, }; impl Database { /// Atomically consume a one-time token or proof identifier. pub(crate) fn consume_space_auth_jti( &self, kind: &str, issuer: &str, jti: &str, expires_at: i64, ) -> Result { self.transaction(|transaction| { transaction.execute( "DELETE FROM space_auth_replays WHERE expires_at < ?1", params![now()], )?; let inserted = transaction.execute( "INSERT OR IGNORE INTO space_auth_replays (kind, issuer, jti, expires_at) VALUES (?1, ?2, ?3, ?4)", params![kind, issuer, jti, expires_at], )?; Ok(inserted == 1) }) } }