pub struct StorageBlockValidator { /* private fields */ }Expand description
Block integrity validator with configurable rules.
Validates blocks against a set of ValidationRules, tracking
cumulative statistics across invocations.
Implementations§
Source§impl StorageBlockValidator
impl StorageBlockValidator
Sourcepub fn add_rule(&mut self, rule: ValidationRule)
pub fn add_rule(&mut self, rule: ValidationRule)
Register a validation rule.
Sourcepub fn remove_rule(&mut self, name: &str) -> bool
pub fn remove_rule(&mut self, name: &str) -> bool
Remove a rule by name. Returns true if a rule was removed.
Sourcepub fn rule_count(&self) -> usize
pub fn rule_count(&self) -> usize
Number of registered rules.
Sourcepub fn validate(&mut self, block_cid: &str, data: &[u8]) -> ValidationReport
pub fn validate(&mut self, block_cid: &str, data: &[u8]) -> ValidationReport
Validate a single block against all registered rules.
Every rule is evaluated; a block is considered valid only if it
passes all checks across all rules. When more than one
check fails the result is ValidationResult::Corrupted.
Sourcepub fn validate_size(data: &[u8], min: Option<u64>, max: Option<u64>) -> bool
pub fn validate_size(data: &[u8], min: Option<u64>, max: Option<u64>) -> bool
Check whether data length is within [min, max].
Sourcepub fn validate_prefix(data: &[u8], prefix: &[u8]) -> bool
pub fn validate_prefix(data: &[u8], prefix: &[u8]) -> bool
Check whether data starts with the given prefix.
Sourcepub fn validate_hash(data: &[u8], expected: u64) -> bool
pub fn validate_hash(data: &[u8], expected: u64) -> bool
Check whether the FNV-1a hash of data equals expected.
Sourcepub fn fnv1a_hash(data: &[u8]) -> u64
pub fn fnv1a_hash(data: &[u8]) -> u64
Compute the FNV-1a 64-bit hash of data.
Sourcepub fn batch_validate(
&mut self,
blocks: &[(&str, &[u8])],
) -> Vec<ValidationReport>
pub fn batch_validate( &mut self, blocks: &[(&str, &[u8])], ) -> Vec<ValidationReport>
Validate multiple blocks, returning a report for each.
Sourcepub fn stats(&self) -> ValidatorStats
pub fn stats(&self) -> ValidatorStats
Return aggregate validation statistics.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for StorageBlockValidator
impl RefUnwindSafe for StorageBlockValidator
impl Send for StorageBlockValidator
impl Sync for StorageBlockValidator
impl Unpin for StorageBlockValidator
impl UnsafeUnpin for StorageBlockValidator
impl UnwindSafe for StorageBlockValidator
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> 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