pub struct StorageChecksumEngine {
pub algorithm: ChecksumAlgorithm,
pub verify_on_read: bool,
/* private fields */
}Expand description
Multi-algorithm checksum engine for storage integrity verification.
Stores one ChecksumRecord per object and allows efficient batch
computation and verification.
Fields§
§algorithm: ChecksumAlgorithmDefault algorithm used for new computations.
verify_on_read: boolWhen true, callers are encouraged to verify on every read.
Implementations§
Source§impl StorageChecksumEngine
impl StorageChecksumEngine
Sourcepub fn new(algorithm: ChecksumAlgorithm) -> Self
pub fn new(algorithm: ChecksumAlgorithm) -> Self
Create a new engine with the given default algorithm.
Sourcepub fn compute(&self, data: &[u8]) -> Checksum
pub fn compute(&self, data: &[u8]) -> Checksum
Compute a checksum for data using the engine’s current algorithm.
Sourcepub fn compute_with_algorithm(
algorithm: ChecksumAlgorithm,
data: &[u8],
) -> Checksum
pub fn compute_with_algorithm( algorithm: ChecksumAlgorithm, data: &[u8], ) -> Checksum
Compute a checksum for data using the specified algorithm.
Sourcepub fn compute_for(
&mut self,
object_id: String,
data: &[u8],
now: u64,
) -> ChecksumRecord
pub fn compute_for( &mut self, object_id: String, data: &[u8], now: u64, ) -> ChecksumRecord
Compute a checksum for data, store the resulting record, and return it.
Sourcepub fn verify(
&mut self,
object_id: &str,
data: &[u8],
now: u64,
) -> Option<CeVerificationResult>
pub fn verify( &mut self, object_id: &str, data: &[u8], now: u64, ) -> Option<CeVerificationResult>
Compare the stored checksum for object_id with a freshly computed one.
Returns None when no record exists for object_id.
On a successful match the record’s verified_at is updated to now.
Sourcepub fn record(&self, object_id: &str) -> Option<&ChecksumRecord>
pub fn record(&self, object_id: &str) -> Option<&ChecksumRecord>
Retrieve the stored record for object_id, if any.
Sourcepub fn remove(&mut self, object_id: &str) -> bool
pub fn remove(&mut self, object_id: &str) -> bool
Remove the record for object_id. Returns true if the record existed.
Sourcepub fn verify_all(
&mut self,
data_fn: impl Fn(&str) -> Option<Vec<u8>>,
now: u64,
) -> Vec<CeVerificationResult>
pub fn verify_all( &mut self, data_fn: impl Fn(&str) -> Option<Vec<u8>>, now: u64, ) -> Vec<CeVerificationResult>
Verify all stored records by calling data_fn for each object_id.
If data_fn returns None for a given id the object is skipped.
Sourcepub fn batch_compute(
&mut self,
items: &[(&str, &[u8])],
now: u64,
) -> Vec<ChecksumRecord>
pub fn batch_compute( &mut self, items: &[(&str, &[u8])], now: u64, ) -> Vec<ChecksumRecord>
Compute and store checksums for a batch of (object_id, data) pairs.
Sourcepub fn corruption_count(results: &[CeVerificationResult]) -> usize
pub fn corruption_count(results: &[CeVerificationResult]) -> usize
Count the number of verification results where !matches.
Sourcepub fn object_count(&self) -> usize
pub fn object_count(&self) -> usize
Number of objects currently tracked.
Sourcepub fn stats(&self, results: &[CeVerificationResult]) -> ChecksumStats
pub fn stats(&self, results: &[CeVerificationResult]) -> ChecksumStats
Compute aggregate statistics from the engine’s state and a set of results.
Trait Implementations§
Source§impl Clone for StorageChecksumEngine
impl Clone for StorageChecksumEngine
Source§fn clone(&self) -> StorageChecksumEngine
fn clone(&self) -> StorageChecksumEngine
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for StorageChecksumEngine
impl RefUnwindSafe for StorageChecksumEngine
impl Send for StorageChecksumEngine
impl Sync for StorageChecksumEngine
impl Unpin for StorageChecksumEngine
impl UnsafeUnpin for StorageChecksumEngine
impl UnwindSafe for StorageChecksumEngine
Blanket Implementations§
impl<T> Allocation for T
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more