From 9a8400f4ce451f430818337993949c59b02efaa8 Mon Sep 17 00:00:00 2001 From: Daniel Sanchez Date: Thu, 2 Feb 2023 09:20:16 +0100 Subject: [PATCH] Use blake 2b instead of 2s for mockpool node TxId (#62) * Use blake 2b instead of 2s * Clippy happy --- nodes/mockpool-node/src/tx.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/nodes/mockpool-node/src/tx.rs b/nodes/mockpool-node/src/tx.rs index 887776d0..607626f4 100644 --- a/nodes/mockpool-node/src/tx.rs +++ b/nodes/mockpool-node/src/tx.rs @@ -1,4 +1,5 @@ -use blake2::{Blake2s256, Digest}; +use blake2::digest::{Update, VariableOutput}; +use blake2::Blake2bVar; use serde::{Deserialize, Serialize}; use std::hash::Hash; @@ -10,10 +11,14 @@ pub struct TxId([u8; 32]); impl From<&Tx> for TxId { fn from(tx: &Tx) -> Self { - let mut hasher = Blake2s256::new(); - hasher.update(bincode::serde::encode_to_vec(tx, bincode::config::standard()).unwrap()); + let mut hasher = Blake2bVar::new(32).unwrap(); + hasher.update( + bincode::serde::encode_to_vec(tx, bincode::config::standard()) + .unwrap() + .as_slice(), + ); let mut id = [0u8; 32]; - id.copy_from_slice(hasher.finalize().as_slice()); + hasher.finalize_variable(&mut id).unwrap(); Self(id) } } @@ -29,8 +34,8 @@ mod test { assert_eq!( txid.0, [ - 26, 113, 217, 35, 178, 18, 65, 215, 30, 117, 195, 9, 189, 146, 124, 78, 66, 91, 97, - 21, 254, 51, 156, 155, 144, 52, 135, 125, 51, 128, 186, 244 + 39, 227, 252, 176, 211, 134, 68, 39, 134, 158, 47, 7, 82, 40, 169, 232, 168, 118, + 240, 103, 84, 146, 127, 64, 60, 196, 126, 142, 172, 156, 124, 78 ] ); }