pub struct HashVerifier { /* private fields */ }Expand description
Build up a set of (path, expected_hash) pairs, then Self::execute to
hash the on-disk files and compare against the expected values.
The verifier never writes — it opens each registered file read-only, hashes
it (whole-file or per-block), and produces a HashVerifyReport. Missing
files and I/O errors during read are recorded as per-file outcomes rather
than aborting the run — consumers want the full picture in a single pass.
§Error semantics
execute returns Err only for programmer errors detected up front
(e.g. a zero block_size, or a digest whose length does not match its
declared algorithm). Filesystem errors against the registered paths are
captured per-file in FileVerifyOutcome::IoError / FileVerifyOutcome::Missing.
§Security
Files are opened via std::fs::File::open, which follows symbolic
links on every platform zipatch-rs supports. The verifier itself never
writes — the worst-case outcome of a hostile symlink pointed at a file
outside the install root is an information-disclosure-via-hash: the
target file’s SHA1 would appear in the report’s
FileVerifyOutcome::WholeMismatch actual field.
If the caller derives registered paths from untrusted input (e.g. a
patch-list response from a server that could be tampered with), it is
the caller’s responsibility to canonicalize the install root and
reject paths that escape it before passing them to Self::expect.
zipatch-rs does not canonicalize or symlink-fence on the caller’s
behalf, because the appropriate root depends on the consumer’s install
layout.
Implementations§
Source§impl HashVerifier
impl HashVerifier
Sourcepub fn expect(self, path: impl Into<PathBuf>, expected: ExpectedHash) -> Self
pub fn expect(self, path: impl Into<PathBuf>, expected: ExpectedHash) -> Self
Register path with expected.
Registering the same path twice with identical ExpectedHash
values is a no-op (the second registration is silently absorbed at
Self::execute time). Registering the same path twice with
different ExpectedHash values is a programmer error and causes
Self::execute to return crate::ZiPatchError::InvalidField.
The check fires at execute-time rather than here so the builder API
stays infallible.
Sourcepub fn execute(self) -> Result<HashVerifyReport>
pub fn execute(self) -> Result<HashVerifyReport>
Hash each registered file and compare against its expected hash.
Returns a HashVerifyReport describing every file. The report is
always populated for every registered task — is_clean() distinguishes
a fully-passing run from a failing one. See the struct docs for the
error policy.
§Errors
Returns crate::ZiPatchError::InvalidField if any registered
ExpectedHash is malformed (wrong digest length, zero block_size).
Filesystem errors are not returned here — they appear as
FileVerifyOutcome::IoError / FileVerifyOutcome::Missing entries
in the report.
Trait Implementations§
Source§impl Debug for HashVerifier
impl Debug for HashVerifier
Source§impl Default for HashVerifier
impl Default for HashVerifier
Source§fn default() -> HashVerifier
fn default() -> HashVerifier
Auto Trait Implementations§
impl Freeze for HashVerifier
impl RefUnwindSafe for HashVerifier
impl Send for HashVerifier
impl Sync for HashVerifier
impl Unpin for HashVerifier
impl UnsafeUnpin for HashVerifier
impl UnwindSafe for HashVerifier
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
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