Skip to main content

HashVerifier

Struct HashVerifier 

Source
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

Source

pub fn new() -> Self

Construct an empty verifier.

Source

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.

Source

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

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for HashVerifier

Source§

fn default() -> HashVerifier

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more