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)
| 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 | /// |