summaryrefslogtreecommitdiff
path: root/src/bundle/fetch.rs
diff options
context:
space:
mode:
authorKim Altintop <kim@eagain.io>2023-04-13 16:50:24 +0200
committerKim Altintop <kim@eagain.io>2023-04-13 17:10:18 +0200
commit8ce1155a1eb490625a7e949a10c4283b4b773d30 (patch)
tree4ece9c129b032bed209df94ba520f7a3c940e310 /src/bundle/fetch.rs
parent607a5609f858cd707dca3a936d80a7a9539b4b5a (diff)
core: replace bundle checksum with BLAKE3
BLAKE3 has a verified streaming mode (Bao), which allows variable chunk sizes without altering the root hash. This means that a BLAKE3 hash can serve as a long-term stable content address in location-independent storage (as demonstrated by iroh). Signed-off-by: Kim Altintop <kim@eagain.io>
Diffstat (limited to 'src/bundle/fetch.rs')
-rw-r--r--src/bundle/fetch.rs10
1 files changed, 3 insertions, 7 deletions
diff --git a/src/bundle/fetch.rs b/src/bundle/fetch.rs
index 4e58000..ff10e27 100644
--- a/src/bundle/fetch.rs
+++ b/src/bundle/fetch.rs
@@ -22,10 +22,6 @@ use either::Either::{
Left,
Right,
};
-use sha2::{
- Digest,
- Sha256,
-};
use tempfile::NamedTempFile;
use url::Url;
@@ -96,13 +92,13 @@ impl Fetcher {
LockedFile::atomic(&path, true, LockedFile::DEFAULT_PERMISSIONS)?
};
- let mut out = HashWriter::new(Sha256::new(), &mut lck);
+ let mut out = HashWriter::new(blake3::Hasher::new(), &mut lck);
out.write_all(&buf)?;
let len = buf.len() as u64 + io::copy(&mut body.take(expect.len), &mut out)?;
- let checksum = out.hash().into();
+ let checksum = bundle::Checksum::from(out.hasher());
if let Some(chk) = expect.checksum {
- ensure!(chk == checksum, "checksum mismatch");
+ ensure!(chk == &checksum, "checksum mismatch");
}
lck.seek(SeekFrom::Start(0))?;
let header = Header::from_reader(&mut lck)?;