pub struct ProofCache { /* private fields */ }Expand description
Secure proof cache with TTL, single-use nonces, and bounded size.
Implements SEC-002 security requirements:
- 100ms TTL for cache entries
- Single-use nonce consumption
- Maximum 64 entries
- Entries scoped to (mutation_hash, nonce) pairs
Implementations§
Source§impl ProofCache
impl ProofCache
Sourcepub fn insert(
&mut self,
mutation_hash: [u8; 32],
nonce: u64,
proof_id: u32,
current_time_ns: u64,
) -> Result<(), CacheError>
pub fn insert( &mut self, mutation_hash: [u8; 32], nonce: u64, proof_id: u32, current_time_ns: u64, ) -> Result<(), CacheError>
Inserts a new proof into the cache.
§Arguments
mutation_hash- Hash of the mutation being authorizednonce- Single-use nonce for this proofproof_id- Unique identifier for this proofcurrent_time_ns- Current time in nanoseconds
§Errors
CacheError::DuplicateEntryif an entry with the same (mutation_hash, nonce) existsCacheError::CacheFullif the cache is at capacity and no expired entries can be evicted
Sourcepub fn verify_and_consume(
&mut self,
mutation_hash: &[u8; 32],
nonce: u64,
current_time_ns: u64,
) -> Result<u32, CacheError>
pub fn verify_and_consume( &mut self, mutation_hash: &[u8; 32], nonce: u64, current_time_ns: u64, ) -> Result<u32, CacheError>
Verifies and consumes a proof from the cache.
This is the primary security-critical function. It:
- Finds the entry matching (mutation_hash, nonce)
- Checks that TTL has not expired
- Marks the entry as consumed (single-use)
- Removes the entry from the cache
- Returns the proof_id
§Arguments
mutation_hash- Hash of the mutation being verifiednonce- Nonce that was used when the proof was createdcurrent_time_ns- Current time in nanoseconds
§Returns
The proof_id if verification succeeds.
§Errors
CacheError::NotFoundif no matching entry existsCacheError::Expiredif the entry’s TTL has passedCacheError::NonceConsumedif the nonce was already used
Sourcepub fn exists(
&self,
mutation_hash: &[u8; 32],
nonce: u64,
current_time_ns: u64,
) -> bool
pub fn exists( &self, mutation_hash: &[u8; 32], nonce: u64, current_time_ns: u64, ) -> bool
Checks if a proof exists in the cache without consuming it.
This is useful for pre-validation before attempting a mutation. Note: This does NOT consume the nonce.
Sourcepub fn evict_expired(&mut self, current_time_ns: u64)
pub fn evict_expired(&mut self, current_time_ns: u64)
Removes all expired entries from the cache.
This can be called periodically to clean up the cache.
Sourcepub fn stats(&self, current_time_ns: u64) -> ProofCacheStats
pub fn stats(&self, current_time_ns: u64) -> ProofCacheStats
Returns statistics about the cache.
Trait Implementations§
Source§impl Debug for ProofCache
impl Debug for ProofCache
Auto Trait Implementations§
impl Freeze for ProofCache
impl RefUnwindSafe for ProofCache
impl Send for ProofCache
impl Sync for ProofCache
impl Unpin for ProofCache
impl UnsafeUnpin for ProofCache
impl UnwindSafe for ProofCache
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more