pub struct AuditChain { /* private fields */ }Expand description
An append-only audit chain with hash-linked entries.
Implementations§
Source§impl AuditChain
impl AuditChain
pub fn new() -> Self
Sourcepub fn append(
&mut self,
severity: EventSeverity,
source: impl Into<String>,
action: impl Into<String>,
details: Value,
) -> &AuditEntry
pub fn append( &mut self, severity: EventSeverity, source: impl Into<String>, action: impl Into<String>, details: Value, ) -> &AuditEntry
Append an event to the chain. Automatically links to the previous entry’s hash.
Sourcepub fn append_with_agent(
&mut self,
severity: EventSeverity,
source: impl Into<String>,
action: impl Into<String>,
details: Value,
agent_id: impl Into<String>,
) -> &AuditEntry
pub fn append_with_agent( &mut self, severity: EventSeverity, source: impl Into<String>, action: impl Into<String>, details: Value, agent_id: impl Into<String>, ) -> &AuditEntry
Append an event with an agent ID to the chain.
pub fn is_empty(&self) -> bool
Sourcepub fn entries(&self) -> &[AuditEntry]
pub fn entries(&self) -> &[AuditEntry]
Get all entries.
Sourcepub fn verify(&self) -> Result<()>
pub fn verify(&self) -> Result<()>
Verify the entire chain’s integrity.
Checks the genesis entry links to the expected previous chain hash
(empty string for a fresh chain, or the archived head after rotation),
then delegates entry-level hash and linkage verification to verify_chain.
Sourcepub fn append_batch(
&mut self,
events: impl IntoIterator<Item = (EventSeverity, String, String, Value)>,
) -> &[AuditEntry]
pub fn append_batch( &mut self, events: impl IntoIterator<Item = (EventSeverity, String, String, Value)>, ) -> &[AuditEntry]
Append multiple events in one call. Each entry is chained to the previous. Returns a slice of the newly appended entries.
Sourcepub fn by_source(&self, source: &str) -> Vec<&AuditEntry>
pub fn by_source(&self, source: &str) -> Vec<&AuditEntry>
Query entries by source.
Sourcepub fn by_severity(&self, severity: EventSeverity) -> Vec<&AuditEntry>
pub fn by_severity(&self, severity: EventSeverity) -> Vec<&AuditEntry>
Query entries by severity.
Sourcepub fn by_agent(&self, agent_id: &str) -> Vec<&AuditEntry>
pub fn by_agent(&self, agent_id: &str) -> Vec<&AuditEntry>
Query entries by agent ID.
Sourcepub fn page(&self, offset: usize, limit: usize) -> &[AuditEntry]
pub fn page(&self, offset: usize, limit: usize) -> &[AuditEntry]
Return a page of entries: offset entries skipped, up to limit returned.
Sourcepub fn query(&self, filter: &QueryFilter) -> Vec<&AuditEntry>
pub fn query(&self, filter: &QueryFilter) -> Vec<&AuditEntry>
Query entries using a composable QueryFilter.
Sourcepub fn rotate(&mut self) -> ChainArchive
pub fn rotate(&mut self) -> ChainArchive
Rotate the chain: drain all current entries and return them as an archive. The next entry appended will link to the previous chain’s head hash, preserving continuity across rotations.
Sourcepub fn from_entries(entries: Vec<AuditEntry>) -> Self
pub fn from_entries(entries: Vec<AuditEntry>) -> Self
Restore a chain from an archive (e.g. for verification of historical data).
Sourcepub fn apply_retention(
&mut self,
policy: &RetentionPolicy,
) -> Option<ChainArchive>
pub fn apply_retention( &mut self, policy: &RetentionPolicy, ) -> Option<ChainArchive>
Apply a retention policy, archiving entries that fall outside the retention window. Returns the archived entries (if any).
The chain maintains integrity: the first retained entry links to
the last archived entry’s hash via prev_chain_hash.
Returns None if no entries need archiving.
Source§impl AuditChain
impl AuditChain
Sourcepub fn review(&self) -> ChainReview
pub fn review(&self) -> ChainReview
Produce a structured review of the chain.
Verifies integrity and summarizes contents: entry count, time range, source/severity/agent distributions, and head hash.