summaryrefslogtreecommitdiff
path: root/src/patches
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/patches
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/patches')
-rw-r--r--src/patches/bundle.rs18
-rw-r--r--src/patches/record.rs8
2 files changed, 10 insertions, 16 deletions
diff --git a/src/patches/bundle.rs b/src/patches/bundle.rs
index 296b24a..52397a1 100644
--- a/src/patches/bundle.rs
+++ b/src/patches/bundle.rs
@@ -21,11 +21,9 @@ use anyhow::{
ensure,
Context,
};
+use digest::Digest;
use multipart::client::lazy::Multipart;
-use sha2::{
- Digest,
- Sha256,
-};
+use sha2::Sha256;
use tempfile::NamedTempFile;
use url::Url;
@@ -105,14 +103,14 @@ impl Bundle {
let encryption = pack.encryption()?;
drop(pack);
let mut file = File::open(&path)?;
- let mut sha2 = Sha256::new();
+ let mut hasher = blake3::Hasher::new();
- let len = io::copy(&mut file, &mut sha2)?;
+ let len = io::copy(&mut file, &mut hasher)?;
let hash = header.hash();
ensure!(expect.hash == &hash, "header hash mismatch");
- let checksum = sha2.finalize().into();
+ let checksum = bundle::Checksum::from(&hasher);
if let Some(expect) = expect.checksum {
- ensure!(expect == checksum, "claimed and actual hash differ");
+ ensure!(expect == &checksum, "claimed and actual hash differ");
}
let info = bundle::Info {
@@ -138,10 +136,10 @@ impl Bundle {
{
std::fs::create_dir_all(&to)?;
let mut tmp = NamedTempFile::new_in(&to)?;
- let mut out = HashWriter::new(Sha256::new(), &mut tmp);
+ let mut out = HashWriter::new(blake3::Hasher::new(), &mut tmp);
let len = io::copy(&mut from, &mut out)?;
- let checksum = out.hash().into();
+ let checksum = bundle::Checksum::from(out.hasher());
let (header, mut pack) = split(tmp.path())?;
let hash = header.hash();
diff --git a/src/patches/record.rs b/src/patches/record.rs
index 6a95973..9bf7856 100644
--- a/src/patches/record.rs
+++ b/src/patches/record.rs
@@ -25,16 +25,12 @@ use anyhow::{
ensure,
Context,
};
-
+use digest::Digest;
use hex::{
FromHex,
ToHex,
};
-
-use sha2::{
- Digest,
- Sha256,
-};
+use sha2::Sha256;
use signature::{
Signature as _,
Verifier,