Skip to main content

AuditStore

Trait AuditStore 

Source
pub trait AuditStore:
    Send
    + Sync
    + 'static {
Show 23 methods // Required methods fn head<'a>( &'a self, chain: &'a str, ) -> Pin<Box<dyn Future<Output = Result<Option<(u64, String)>, A2aError>> + Send + 'a>>; fn append<'a>( &'a self, record: &'a AuditRecord, ) -> Pin<Box<dyn Future<Output = Result<Appended, A2aError>> + Send + 'a>>; fn read<'a>( &'a self, chain: &'a str, after: u64, limit: usize, ) -> Pin<Box<dyn Future<Output = Result<Vec<AuditRecord>, A2aError>> + Send + 'a>>; fn chains( &self, ) -> Pin<Box<dyn Future<Output = Result<Vec<String>, A2aError>> + Send + '_>>; fn put_checkpoint<'a>( &'a self, checkpoint: &'a Checkpoint, ) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>>; fn checkpoints<'a>( &'a self, chain: &'a str, ) -> Pin<Box<dyn Future<Output = Result<Vec<Checkpoint>, A2aError>> + Send + 'a>>; fn last_before<'a>( &'a self, chain: &'a str, cutoff_ms: i64, ) -> Pin<Box<dyn Future<Output = Result<Option<(u64, String)>, A2aError>> + Send + 'a>>; fn delete_through<'a>( &'a self, chain: &'a str, seq: u64, ) -> Pin<Box<dyn Future<Output = Result<u64, A2aError>> + Send + 'a>>; fn place_hold<'a>( &'a self, hold: &'a LegalHold, ) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>>; fn release_hold<'a>( &'a self, chain: &'a str, ) -> Pin<Box<dyn Future<Output = Result<bool, A2aError>> + Send + 'a>>; fn holds( &self, ) -> Pin<Box<dyn Future<Output = Result<Vec<LegalHold>, A2aError>> + Send + '_>>; // Provided methods fn is_process_local(&self) -> bool { ... } fn append_next<'a>( &'a self, chain: &'a str, seal: &'a (dyn Fn(Option<(u64, String)>, Option<i64>) -> Pin<Box<dyn Future<Output = Result<AuditRecord, A2aError>> + Send + 'a>> + Send + Sync), ) -> Pin<Box<dyn Future<Output = Result<Option<AuditRecord>, A2aError>> + Send + 'a>> { ... } fn delete_through_unless_held<'a>( &'a self, chain: &'a str, seq: u64, ) -> Pin<Box<dyn Future<Output = Result<Option<u64>, A2aError>> + Send + 'a>> { ... } fn supports_subject_keys(&self) -> bool { ... } fn subject_key<'a>( &'a self, chain: &'a str, lookup: &'a str, ) -> Pin<Box<dyn Future<Output = Result<Option<SubjectKey>, A2aError>> + Send + 'a>> { ... } fn subject_key_by_sid<'a>( &'a self, chain: &'a str, sid: &'a str, ) -> Pin<Box<dyn Future<Output = Result<Option<SubjectKey>, A2aError>> + Send + 'a>> { ... } fn subject_keys<'a>( &'a self, chain: &'a str, ) -> Pin<Box<dyn Future<Output = Result<Vec<SubjectKey>, A2aError>> + Send + 'a>> { ... } fn put_subject_key<'a>( &'a self, chain: &'a str, key: &'a SubjectKey, ) -> Pin<Box<dyn Future<Output = Result<bool, A2aError>> + Send + 'a>> { ... } fn delete_subject_key<'a>( &'a self, chain: &'a str, lookup: &'a str, ) -> Pin<Box<dyn Future<Output = Result<Option<String>, A2aError>> + Send + 'a>> { ... } fn append_next_naming<'a>( &'a self, chain: &'a str, sids: &'a [String], seal: &'a (dyn Fn(Option<(u64, String)>, Option<i64>) -> Pin<Box<dyn Future<Output = Result<AuditRecord, A2aError>> + Send + 'a>> + Send + Sync), ) -> Pin<Box<dyn Future<Output = Result<NamedAppend, A2aError>> + Send + 'a>> { ... } fn delete_subject_key_unless_named<'a>( &'a self, chain: &'a str, lookup: &'a str, sid: &'a str, scanned_through: u64, ) -> Pin<Box<dyn Future<Output = Result<bool, A2aError>> + Send + 'a>> { ... } fn delete_subject_keys_unless_held<'a>( &'a self, chain: &'a str, lookups: &'a [String], ) -> Pin<Box<dyn Future<Output = Result<Option<Vec<String>>, A2aError>> + Send + 'a>> { ... }
}
Available on crate feature audit only.
Expand description

Durable storage for audit chains.

Implementations store; they do not chain. Sealing a record — choosing its seq, linking its prev, computing its hash — is AuditLog’s job, so every store gets it right in one place. What a store must guarantee is that a (chain, seq) is written at most once (Appended::Conflict otherwise), which is what keeps two replicas appending to one chain from forking it.

Records are returned exactly as they were appended: a store that normalises a field (reorders object keys is fine; drops an empty map is not) changes the record’s hash and makes the chain fail to verify.

Required Methods§

Source

fn head<'a>( &'a self, chain: &'a str, ) -> Pin<Box<dyn Future<Output = Result<Option<(u64, String)>, A2aError>> + Send + 'a>>

The highest seq stored in chain and that record’s hash.

Source

fn append<'a>( &'a self, record: &'a AuditRecord, ) -> Pin<Box<dyn Future<Output = Result<Appended, A2aError>> + Send + 'a>>

Stores a sealed record, unless its (chain, seq) is already taken.

Source

fn read<'a>( &'a self, chain: &'a str, after: u64, limit: usize, ) -> Pin<Box<dyn Future<Output = Result<Vec<AuditRecord>, A2aError>> + Send + 'a>>

Up to limit records of chain with seq above after, in order.

Source

fn chains( &self, ) -> Pin<Box<dyn Future<Output = Result<Vec<String>, A2aError>> + Send + '_>>

Every chain that holds a record or a checkpoint.

Source

fn put_checkpoint<'a>( &'a self, checkpoint: &'a Checkpoint, ) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>>

Stores a checkpoint, replacing one of the same chain, seq and kind.

Source

fn checkpoints<'a>( &'a self, chain: &'a str, ) -> Pin<Box<dyn Future<Output = Result<Vec<Checkpoint>, A2aError>> + Send + 'a>>

Every checkpoint of chain, in seq order.

Source

fn last_before<'a>( &'a self, chain: &'a str, cutoff_ms: i64, ) -> Pin<Box<dyn Future<Output = Result<Option<(u64, String)>, A2aError>> + Send + 'a>>

The last record of chain sealed before cutoff_ms (Unix milliseconds), as (seq, hash).

Source

fn delete_through<'a>( &'a self, chain: &'a str, seq: u64, ) -> Pin<Box<dyn Future<Output = Result<u64, A2aError>> + Send + 'a>>

Deletes the records of chain up to and including seq, and the checkpoints below seq (an anchor at seq itself is kept). Returns how many records went.

Source

fn place_hold<'a>( &'a self, hold: &'a LegalHold, ) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>>

Places a hold on chain, replacing any reason already given.

Source

fn release_hold<'a>( &'a self, chain: &'a str, ) -> Pin<Box<dyn Future<Output = Result<bool, A2aError>> + Send + 'a>>

Lifts the hold on chain; returns whether there was one.

Source

fn holds( &self, ) -> Pin<Box<dyn Future<Output = Result<Vec<LegalHold>, A2aError>> + Send + '_>>

Every hold in place.

Provided Methods§

Source

fn is_process_local(&self) -> bool

Whether this store keeps its state in this process alone.

The default is false: a store this crate cannot see into (yours, over Redis, say) is taken to be shared. The in-memory ones answer true. Profile::Production reads it: on a task store that is shared between processes, a store that only this process can see makes the fleet behave as if it had no store (audit E-F13).

Source

fn append_next<'a>( &'a self, chain: &'a str, seal: &'a (dyn Fn(Option<(u64, String)>, Option<i64>) -> Pin<Box<dyn Future<Output = Result<AuditRecord, A2aError>> + Send + 'a>> + Send + Sync), ) -> Pin<Box<dyn Future<Output = Result<Option<AuditRecord>, A2aError>> + Send + 'a>>

Appends the next record of chain: reads its head, has seal build the record that follows it, and stores that. Ok(None) when another writer took the position first: nothing was stored, and the caller asks again.

The default does it optimistically, as head then append: replicas sharing the store interleave on one chain because the loser of a position is refused it and asks again, and with many of them the same few lose again and again. The default passes seal no clock, so the record is timed by the writer’s.

A store that can serialise writers across processes overrides this and holds the head fixed from the read to the store, so no one loses, and may pass its own clock, so that records in one chain are timed by one clock whatever the writers’ are. PostgresAuditStore (the postgres feature) does both. An override must call seal exactly once, after reading the head and before storing, and must not retry on its own.

§Errors

When the store cannot be read or written, or seal fails.

Source

fn delete_through_unless_held<'a>( &'a self, chain: &'a str, seq: u64, ) -> Pin<Box<dyn Future<Output = Result<Option<u64>, A2aError>> + Send + 'a>>

delete_through, unless a hold is placed on chain: None when one is, with nothing deleted.

The hold is read atomically with the deletion. A hold whose place_hold returned before this call began is always seen by it, and one placed while it runs is either seen or placed after the deletion, never in between. Retention reads the holds before it decides what to delete and deletes some time later, so a hold placed in between must still stop it (adversarial review A1, 2026-11-12).

The default reads holds and then deletes, which is not atomic: a store shared between processes must override it with a check and a deletion that no hold can come between (a transaction that holds the lock place_hold takes, as PostgresAuditStore does). AuditLog::purge serialises the two within one log; only the store can do it across replicas.

§Errors

When the store cannot be read or written.

Source

fn supports_subject_keys(&self) -> bool

Whether this store keeps subject keys. AuditLog::with_privacy refuses a store that answers false.

Source

fn subject_key<'a>( &'a self, chain: &'a str, lookup: &'a str, ) -> Pin<Box<dyn Future<Output = Result<Option<SubjectKey>, A2aError>> + Send + 'a>>

The key of chain whose lookup is lookup.

§Errors

When the store fails, or keeps no subject keys.

Source

fn subject_key_by_sid<'a>( &'a self, chain: &'a str, sid: &'a str, ) -> Pin<Box<dyn Future<Output = Result<Option<SubjectKey>, A2aError>> + Send + 'a>>

The key of chain whose handle is sid.

§Errors

When the store fails, or keeps no subject keys.

Source

fn subject_keys<'a>( &'a self, chain: &'a str, ) -> Pin<Box<dyn Future<Output = Result<Vec<SubjectKey>, A2aError>> + Send + 'a>>

Every subject key of chain, for dropping those no record names.

§Errors

When the store fails, or keeps no subject keys.

Source

fn put_subject_key<'a>( &'a self, chain: &'a str, key: &'a SubjectKey, ) -> Pin<Box<dyn Future<Output = Result<bool, A2aError>> + Send + 'a>>

Stores key for chain unless a key with its lookup is there; false when one was, and nothing was stored. Atomic: of two writers racing on one lookup, exactly one stores.

§Errors

When the store fails, or keeps no subject keys.

Source

fn delete_subject_key<'a>( &'a self, chain: &'a str, lookup: &'a str, ) -> Pin<Box<dyn Future<Output = Result<Option<String>, A2aError>> + Send + 'a>>

Deletes the key of chain whose lookup is lookup, returning its sid, or None when there was none. Must not leave a copy: what it deletes is what erasure destroys.

§Errors

When the store fails, or keeps no subject keys.

Source

fn append_next_naming<'a>( &'a self, chain: &'a str, sids: &'a [String], seal: &'a (dyn Fn(Option<(u64, String)>, Option<i64>) -> Pin<Box<dyn Future<Output = Result<AuditRecord, A2aError>> + Send + 'a>> + Send + Sync), ) -> Pin<Box<dyn Future<Output = Result<NamedAppend, A2aError>> + Send + 'a>>

append_next for a record sealed under the keys whose handles are sids: stores it only if every one of those keys is still in the store, checked atomically with the store’s write, so that delete_subject_key_unless_named either sees this record or deleted the key before it, which this then sees. The same contract as append_next otherwise.

§Errors

When the store cannot be read or written, or seal fails.

Source

fn delete_subject_key_unless_named<'a>( &'a self, chain: &'a str, lookup: &'a str, sid: &'a str, scanned_through: u64, ) -> Pin<Box<dyn Future<Output = Result<bool, A2aError>> + Send + 'a>>

Deletes the key of chain whose lookup is lookup and handle sid, unless a record with seq above scanned_through references sid (sid_marker); true when it was deleted. For dropping keys no record names: the caller has read the chain through scanned_through, found no record naming sid, and this checks the records stored since, atomically with the deletion (see append_next_naming).

§Errors

When the store fails, or keeps no subject keys.

Source

fn delete_subject_keys_unless_held<'a>( &'a self, chain: &'a str, lookups: &'a [String], ) -> Pin<Box<dyn Future<Output = Result<Option<Vec<String>>, A2aError>> + Send + 'a>>

Deletes every key of chain whose lookup is in lookups, unless a legal hold is placed on chain: None when one is, with nothing deleted; otherwise the sid of each key deleted. All or nothing, and the hold is read atomically with the deletion, as delete_through_unless_held reads it.

§Errors

When the store fails, or keeps no subject keys.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§