gix_pack/data/file/
verify.rs

1use std::sync::atomic::AtomicBool;
2
3use gix_features::progress::Progress;
4
5use crate::data::File;
6
7///
8pub mod checksum {
9    /// Returned by [`data::File::verify_checksum()`][crate::data::File::verify_checksum()].
10    pub type Error = crate::verify::checksum::Error;
11}
12
13/// Checksums and verify checksums
14impl File {
15    /// The checksum in the trailer of this pack data file
16    pub fn checksum(&self) -> gix_hash::ObjectId {
17        gix_hash::ObjectId::from_bytes_or_panic(&self.data[self.data.len() - self.hash_len..])
18    }
19
20    /// Verifies that the checksum of the packfile over all bytes preceding it indeed matches the actual checksum,
21    /// returning the actual checksum equivalent to the return value of [`checksum()`][File::checksum()] if there
22    /// is no mismatch.
23    ///
24    /// Note that if no `progress` is desired, one can pass [`gix_features::progress::Discard`].
25    ///
26    /// Have a look at [`index::File::verify_integrity(…)`][crate::index::File::verify_integrity()] for an
27    /// even more thorough integrity check.
28    pub fn verify_checksum(
29        &self,
30        progress: &mut dyn Progress,
31        should_interrupt: &AtomicBool,
32    ) -> Result<gix_hash::ObjectId, checksum::Error> {
33        crate::verify::checksum_on_disk_or_mmap(
34            self.path(),
35            &self.data,
36            self.checksum(),
37            self.object_hash,
38            progress,
39            should_interrupt,
40        )
41    }
42}