From 8ce1155a1eb490625a7e949a10c4283b4b773d30 Mon Sep 17 00:00:00 2001 From: Kim Altintop Date: Thu, 13 Apr 2023 16:50:24 +0200 Subject: 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 --- src/bundle/fetch.rs | 10 +++------- src/bundle/header.rs | 6 ++---- src/bundle/list.rs | 6 ++---- 3 files changed, 7 insertions(+), 15 deletions(-) (limited to 'src/bundle') 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)?; diff --git a/src/bundle/header.rs b/src/bundle/header.rs index 6f3dfe3..d296af1 100644 --- a/src/bundle/header.rs +++ b/src/bundle/header.rs @@ -12,15 +12,13 @@ use std::{ str::FromStr, }; +use digest::Digest; use hex::{ FromHex, FromHexError, }; use refs::Refname; -use sha2::{ - Digest, - Sha256, -}; +use sha2::Sha256; use super::error; use crate::{ diff --git a/src/bundle/list.rs b/src/bundle/list.rs index 21753fa..ea6296f 100644 --- a/src/bundle/list.rs +++ b/src/bundle/list.rs @@ -19,11 +19,9 @@ use std::{ }; use anyhow::anyhow; +use digest::Digest; use once_cell::sync::Lazy; -use sha2::{ - Digest, - Sha256, -}; +use sha2::Sha256; use url::Url; use crate::git::{ -- cgit v1.2.3