···1818sha2 = "0.10.9" # note: hmac-sha256 is simpler, smaller, benches ~15ns slower
1919thiserror = "2.0.17"
2020tokio = { version = "1.47.1", features = ["rt", "sync"] }
2121+multihash-codetable = { version = "0.1.4", features = ["sha2"] }
21222223[dev-dependencies]
2324clap = { version = "4.5.48", features = ["derive"] }
+21
src/drive.rs
···1919pub enum DriveError {
2020 #[error("Error from iroh_car: {0}")]
2121 CarReader(#[from] iroh_car::Error),
2222+ #[error("Block did not match its CID")]
2323+ BadCID,
2224 #[error("Failed to decode commit block: {0}")]
2325 BadBlock(#[from] serde_ipld_dagcbor::DecodeError<Infallible>),
2426 #[error("The Commit block reference by the root was not found")]
···196198 // try to load all the blocks into memory
197199 let mut mem_size = 0;
198200 while let Some((cid, data)) = car.next_block().await? {
201201+202202+ // lkasdjflkajdsflkajsfdlkjasdf
203203+ if !verify_block(cid, &data) {
204204+ return Err(DriveError::BadCID);
205205+ }
206206+199207 // the root commit is a Special Third Kind of block that we need to make
200208 // sure not to optimistically send to the processing function
201209 if cid == root {
···295303 pub commit: Option<Commit>,
296304}
297305306306+fn verify_block(given: Cid, block: &[u8]) -> bool {
307307+ use multihash_codetable::{Code, MultihashDigest};
308308+ const RAW: u64 = 0x71;
309309+ let calculated = cid::Cid::new_v1(RAW, Code::Sha2_256.digest(block));
310310+ calculated == given
311311+}
312312+298313impl<R: AsyncRead + Unpin> NeedDisk<R> {
299314 pub async fn finish_loading(
300315 mut self,
···334349 let Some((cid, data)) = self.car.next_block().await? else {
335350 break;
336351 };
352352+353353+ // lkasdjflkajdsflkajsfdlkjasdf
354354+ if !verify_block(cid, &data) {
355355+ return Err(DriveError::BadCID);
356356+ }
357357+337358 // we still gotta keep checking for the root since we might not have it
338359 if cid == self.root {
339360 let c: Commit = serde_ipld_dagcbor::from_slice(&data)?;