Skip to main content

AuditChain

Struct AuditChain 

Source
pub struct AuditChain { /* private fields */ }
Expand description

An append-only audit chain with hash-linked entries.

Implementations§

Source§

impl AuditChain

Source

pub fn new() -> Self

Source

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.

Source

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.

Source

pub fn len(&self) -> usize

Number of entries in the chain.

Source

pub fn is_empty(&self) -> bool

Source

pub fn entries(&self) -> &[AuditEntry]

Get all entries.

Source

pub fn head_hash(&self) -> Option<&str>

Get the last entry’s hash (chain head).

Source

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.

Source

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.

Source

pub fn by_source(&self, source: &str) -> Vec<&AuditEntry>

Query entries by source.

Source

pub fn by_severity(&self, severity: EventSeverity) -> Vec<&AuditEntry>

Query entries by severity.

Source

pub fn by_agent(&self, agent_id: &str) -> Vec<&AuditEntry>

Query entries by agent ID.

Source

pub fn page(&self, offset: usize, limit: usize) -> &[AuditEntry]

Return a page of entries: offset entries skipped, up to limit returned.

Source

pub fn query(&self, filter: &QueryFilter) -> Vec<&AuditEntry>

Query entries using a composable QueryFilter.

Source

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.

Source

pub fn from_entries(entries: Vec<AuditEntry>) -> Self

Restore a chain from an archive (e.g. for verification of historical data).

Source

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

Source

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.

Trait Implementations§

Source§

impl Debug for AuditChain

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for AuditChain

Source§

fn default() -> AuditChain

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more