pub struct AuditTrail { /* private fields */ }Expand description
A tamper-evident audit trail with cryptographic hash chain.
Each entry is cryptographically linked to the previous entry using blake3 hashing. This makes it possible to detect any tampering with historical entries.
Implementations§
Source§impl AuditTrail
impl AuditTrail
Sourcepub fn new(max_entries: usize) -> AuditTrail
pub fn new(max_entries: usize) -> AuditTrail
Create a new audit trail with the given maximum entry count.
Sourcepub fn append(
&self,
actor: String,
action: AuditAction,
resource: String,
) -> String
pub fn append( &self, actor: String, action: AuditAction, resource: String, ) -> String
Append an audit entry. Computes hash chain automatically.
Sourcepub fn append_with_meta(
&self,
actor: String,
action: AuditAction,
resource: String,
metadata: Option<Value>,
) -> String
pub fn append_with_meta( &self, actor: String, action: AuditAction, resource: String, metadata: Option<Value>, ) -> String
Append an audit entry with optional metadata.
Sourcepub fn verify(&self) -> Result<bool, AuditError>
pub fn verify(&self) -> Result<bool, AuditError>
Verify the integrity of the hash chain.
Sourcepub fn entries(&self, from_seq: u64, to_seq: u64) -> Vec<TrailEntry>
pub fn entries(&self, from_seq: u64, to_seq: u64) -> Vec<TrailEntry>
Get entries within a sequence range (inclusive).
Sourcepub fn all_entries(&self) -> Vec<TrailEntry>
pub fn all_entries(&self) -> Vec<TrailEntry>
Get all entries.
Sourcepub fn by_agent(&self, agent_id: &str) -> Vec<TrailEntry>
pub fn by_agent(&self, agent_id: &str) -> Vec<TrailEntry>
Query entries by agent ID.
Sourcepub fn by_action(&self, action: &AuditAction) -> Vec<TrailEntry>
pub fn by_action(&self, action: &AuditAction) -> Vec<TrailEntry>
Query entries by exact action match.
Sourcepub fn by_action_type(&self, type_name: &str) -> Vec<TrailEntry>
pub fn by_action_type(&self, type_name: &str) -> Vec<TrailEntry>
Query entries by action discriminant name (e.g., “ToolCall”, “AgentSpawn”).
Sourcepub fn export_json(&self, from_seq: u64) -> Result<String, AuditError>
pub fn export_json(&self, from_seq: u64) -> Result<String, AuditError>
Export entries from a sequence number as pretty JSON.
Sourcepub fn export_all_json(&self) -> Result<String, AuditError>
pub fn export_all_json(&self) -> Result<String, AuditError>
Export all entries as pretty JSON.
Sourcepub fn flush_to(&self, store: &dyn AuditPersistence) -> Result<(), Error>
pub fn flush_to(&self, store: &dyn AuditPersistence) -> Result<(), Error>
Flush entries to a persistence backend.
Sourcepub fn restore_from_store(
&self,
store: &dyn AuditPersistence,
) -> Result<(), Error>
pub fn restore_from_store( &self, store: &dyn AuditPersistence, ) -> Result<(), Error>
Restore entries from a persistence backend.
Sourcepub fn restore_from(&self, entries: Vec<TrailEntry>)
pub fn restore_from(&self, entries: Vec<TrailEntry>)
Restore previously persisted entries directly.
Sets seq_counter to max(entries.seq) + 1 so new entries
don’t collide with restored ones. Trims to max_entries if needed.