From 4c784b0b1562d7465908fcb671c4f48ce299d272 Mon Sep 17 00:00:00 2001 From: edef Date: Tue, 19 Apr 2022 15:08:23 +0000 Subject: ripple/fossil: use bao to one-shot verify hashes Change-Id: I77ace8ee9f69ccb92afaa0a41d69538d28f11583 --- ripple/Cargo.lock | 12 ++++++++++++ ripple/fossil/Cargo.toml | 1 + ripple/fossil/src/lib.rs | 11 ++++++----- 3 files changed, 19 insertions(+), 5 deletions(-) (limited to 'ripple') diff --git a/ripple/Cargo.lock b/ripple/Cargo.lock index b857ee0..359d48d 100644 --- a/ripple/Cargo.lock +++ b/ripple/Cargo.lock @@ -46,6 +46,17 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" +[[package]] +name = "bao" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50f51ef7e16e840728c95d71045a7f67fb0c17e0c03560b0aa99ae607bd31a3c" +dependencies = [ + "arrayref", + "arrayvec", + "blake3", +] + [[package]] name = "bitflags" version = "1.3.2" @@ -209,6 +220,7 @@ checksum = "37ab347416e802de484e4d03c7316c48f1ecb56574dfd4a46a80f173ce1de04d" name = "fossil" version = "0.1.0" dependencies = [ + "bao", "blake3", "byteorder", "bytes", diff --git a/ripple/fossil/Cargo.toml b/ripple/fossil/Cargo.toml index 70554ea..ecfa5b4 100644 --- a/ripple/fossil/Cargo.toml +++ b/ripple/fossil/Cargo.toml @@ -17,6 +17,7 @@ log = "0.4.14" libc = "0.2.112" env_logger = "0.9.0" lazy_static = "1.4.0" +bao = "0.12.0" [build-dependencies] prost-build = "0.8.0" diff --git a/ripple/fossil/src/lib.rs b/ripple/fossil/src/lib.rs index 3492789..9e380f2 100644 --- a/ripple/fossil/src/lib.rs +++ b/ripple/fossil/src/lib.rs @@ -7,7 +7,7 @@ use { std::{ collections::BTreeMap, fs, - io::{self, BufRead, Read}, + io::{self, BufRead, Read, Write}, os::unix::fs::PermissionsExt, path::Path, }, @@ -107,10 +107,11 @@ impl Store { let mut buffer = Vec::new(); self.raw_blob(ident).read_to_end(&mut buffer).unwrap(); - let computed_ident = { - let mut h = blake3::Hasher::new(); - h.update_rayon(&buffer); - h.finalize() + let mut outboard = Vec::new(); + let computed_ident: blake3::Hash = { + let mut encoder = bao::encode::Encoder::new_outboard(io::Cursor::new(&mut outboard)); + encoder.write_all(&buffer).unwrap(); + encoder.finalize().unwrap() }; if computed_ident != ident { -- cgit 1.4.1