pub struct ModelFingerprint {
pub file_size: u64,
pub mtime_secs: i64,
pub head_hash: [u8; 32],
pub tail_hash: [u8; 32],
pub probe_size: u32,
}Expand description
Bounded O(constant) fingerprint of a GGUF model file.
Avoids the O(file-size) cost of hashing the whole file by reading only
probe_size bytes from the head and probe_size bytes from the tail,
then hashing each block independently. The combination of file size,
modification time, and the two content hashes is sufficient to detect
truncation, replacement, or in-place modification of any real GGUF file
while capping I/O at 2 * probe_size bytes regardless of model size.
Fields§
§file_size: u64Total file size in bytes.
mtime_secs: i64File mtime as Unix seconds (best-effort; 0 if unavailable).
head_hash: [u8; 32]Blake3 hash of the first probe_size bytes.
tail_hash: [u8; 32]Blake3 hash of the last probe_size bytes.
probe_size: u32Number of bytes probed from each end of the file.
Implementations§
Source§impl ModelFingerprint
impl ModelFingerprint
Sourcepub fn compute(path: &Path) -> RuntimeResult<Self>
pub fn compute(path: &Path) -> RuntimeResult<Self>
Compute a fingerprint for the file at path.
Reads at most 2 * DEFAULT_PROBE_SIZE bytes in total.
Sourcepub fn compute_with_probe(path: &Path, probe_size: u32) -> RuntimeResult<Self>
pub fn compute_with_probe(path: &Path, probe_size: u32) -> RuntimeResult<Self>
Compute a fingerprint with a custom probe size.
Sourcepub fn verify(&self, path: &Path) -> RuntimeResult<()>
pub fn verify(&self, path: &Path) -> RuntimeResult<()>
Verify that path matches this fingerprint.
Returns Ok(()) if the file matches, or a
RuntimeError::ModelFingerprintMismatch if it does not.
Trait Implementations§
Source§impl Clone for ModelFingerprint
impl Clone for ModelFingerprint
Source§fn clone(&self) -> ModelFingerprint
fn clone(&self) -> ModelFingerprint
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ModelFingerprint
impl Debug for ModelFingerprint
Source§impl Decode for ModelFingerprint
impl Decode for ModelFingerprint
Source§impl Encode for ModelFingerprint
impl Encode for ModelFingerprint
Source§impl PartialEq for ModelFingerprint
impl PartialEq for ModelFingerprint
impl StructuralPartialEq for ModelFingerprint
Auto Trait Implementations§
impl Freeze for ModelFingerprint
impl RefUnwindSafe for ModelFingerprint
impl Send for ModelFingerprint
impl Sync for ModelFingerprint
impl Unpin for ModelFingerprint
impl UnsafeUnpin for ModelFingerprint
impl UnwindSafe for ModelFingerprint
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> 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