From 1c923d2f9ec88af7dbbe0e46c19d10f186cd28c7 Mon Sep 17 00:00:00 2001 From: Greg Fitzgerald Date: Mon, 16 Apr 2018 16:38:31 -0400 Subject: [PATCH] Fix entry hash when no events and num_hashes is one --- src/entry.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/entry.rs b/src/entry.rs index e672e71c0..cd2327635 100644 --- a/src/entry.rs +++ b/src/entry.rs @@ -61,7 +61,7 @@ fn add_event_data(hash_data: &mut Vec, event: &Event) { } /// Creates the hash `num_hashes` after `start_hash`. If the event contains -/// signature, the final hash will be a hash of both the previous ID and +/// a signature, the final hash will be a hash of both the previous ID and /// the signature. pub fn next_hash(start_hash: &Hash, num_hashes: u64, events: &[Event]) -> Hash { let mut id = *start_hash; @@ -76,10 +76,12 @@ pub fn next_hash(start_hash: &Hash, num_hashes: u64, events: &[Event]) -> Hash { } if !hash_data.is_empty() { - return extend_and_hash(&id, &hash_data); + extend_and_hash(&id, &hash_data) + } else if num_hashes != 0 { + hash(&id) + } else { + id } - - id } /// Creates the next Entry `num_hashes` after `start_hash`. @@ -167,6 +169,8 @@ mod tests { #[test] fn test_next_tick() { let zero = Hash::default(); - assert_eq!(next_tick(&zero, 1).num_hashes, 1) + let tick = next_tick(&zero, 1); + assert_eq!(tick.num_hashes, 1); + assert_ne!(tick.id, zero); } }