MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / verify

Method verify

atomic-core/src/change/format_v3/reader/sections.rs:264–282  ·  view source on GitHub ↗

Verify the content hash by reading the trailer. Reads the 32-byte trailer from the source and compares it to the blake3 hash computed incrementally from all hashed sections. This should be called **after** all sections have been read or skipped. Sections that were skipped still contribute to the hash (their compressed bytes are fed through the hasher during skipping). # Returns The verified 32

(&mut self)

Source from the content-addressed store, hash-verified

262 /// println!("Verified content hash: {:02x?}", &content_hash[..8]);
263 /// ```
264 pub fn verify(&mut self) -> FormatResult<[u8; 32]> {
265 // Read the trailer
266 let trailer = Trailer::read_from(self.reader)?;
267 self.stats.total_bytes_read += Trailer::SIZE as u64;
268
269 // Compute the final hash from everything we've fed through the hasher
270 let computed = self.hasher.finalize();
271 let computed_bytes = *computed.as_bytes();
272
273 // Compare
274 if computed_bytes != trailer.content_hash {
275 return Err(FormatError::HashMismatch {
276 expected: format!("{:02x?}", &trailer.content_hash[..8]),
277 computed: format!("{:02x?}", &computed_bytes[..8]),
278 });
279 }
280
281 Ok(computed_bytes)
282 }
283
284 /// Read all remaining sections and verify the content hash in one call.
285 ///

Callers 14

runMethod · 0.45
deserializeMethod · 0.45
read_all_and_verifyMethod · 0.45
test_verify_minimalFunction · 0.45
test_verify_fullFunction · 0.45
test_verify_corrupt_dataFunction · 0.45

Calls 2

finalizeMethod · 0.45
as_bytesMethod · 0.45