From ba5c0a2f1e85cc01c22cf6403779582c27e99619 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Mon, 30 Oct 2017 22:25:10 -0700 Subject: fix off-by-one bug with verification code --- src/sleep_register.rs | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/sleep_register.rs b/src/sleep_register.rs index 0687b3d..7d2d38e 100644 --- a/src/sleep_register.rs +++ b/src/sleep_register.rs @@ -39,7 +39,7 @@ pub trait HyperRegister { /// Total size of this register in bytes. fn len_bytes(&mut self) -> Result; - /// [UNIMPLEMENTED] Intended to do a deeper merkel-tree verification of all stored data + /// Intended to do a deeper merkel-tree verification of all stored data fn verify(&mut self) -> Result<()>; /// Quick sanity checks on register store robust-ness @@ -86,7 +86,7 @@ impl HyperRegister { let mut hash = Blake2b::new(32); let mut index_buf = [0; 8]; hash.input(&[2; 1]); - for ri in HyperRegister::tree_root_nodes(entry_index) { + for ri in HyperRegister::tree_root_nodes(entry_index + 1) { u64::to_be(ri).encode_fixed(&mut index_buf); let node = reg.get_tree_entry(ri)?; hash.input(&node[0..32]); @@ -542,12 +542,13 @@ impl HyperRegister for SleepDirRegister { #[test] fn test_sdr_open() { + let mut sdr = SleepDirRegister::open(Path::new("test-data/dat/simple/.dat/"), "metadata", false).unwrap(); // Values from 'dat log' assert!(sdr.check().is_ok()); - // XXX: assert!(sdr.verify().is_ok()); + assert!(sdr.verify().is_ok()); assert_eq!(sdr.len().unwrap(), 3); assert_eq!(sdr.len_bytes().unwrap(), 145); @@ -556,9 +557,28 @@ fn test_sdr_open() { // Values from 'dat log' assert!(sdr.check().is_ok()); - // XXX: assert!(sdr.verify().is_ok()); + assert!(sdr.verify().is_ok()); assert_eq!(sdr.len().unwrap(), 2); assert_eq!(sdr.len_bytes().unwrap(), 204); + + let mut sdr = + SleepDirRegister::open(Path::new("test-data/dat/alphabet/.dat/"), "metadata", false).unwrap(); + + // Values from 'dat log' + assert!(sdr.check().is_ok()); + assert!(sdr.verify().is_ok()); + assert_eq!(sdr.len().unwrap(), 7); + assert_eq!(sdr.len_bytes().unwrap(), 307); + + let mut sdr = + SleepDirRegister::open(Path::new("test-data/dat/alphabet/.dat/"), "content", false).unwrap(); + + // Values from 'dat log' + assert!(sdr.check().is_ok()); + assert!(sdr.verify().is_ok()); + assert_eq!(sdr.len().unwrap(), 6); + assert_eq!(sdr.len_bytes().unwrap(), 6); + } #[test] -- cgit v1.2.3