From 496beab75a980709dc203168b7d6590d92ad5866 Mon Sep 17 00:00:00 2001 From: ennucore Date: Thu, 19 Mar 2020 15:52:32 +0300 Subject: [PATCH] hashing --- src/lib.rs | 19 ++++++++++++++++--- src/message.rs | 2 +- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 7b8f344..f42cc07 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,6 +14,7 @@ mod error; mod tests { use crate::ironforce::IronForce; use crate::message::{MsgType, Message}; + use crate::crypto::KeyPack; use alloc::vec::Vec; #[test] @@ -23,8 +24,20 @@ mod tests { #[test] fn serialization() { - let msg = crate::message::Message::new(MsgType::MultiCast, Vec::::new(), crate::crypto::KeyPack::gen()); - let serialized = msg.ser(); - let msg2 = Message::deserialize(serialized); + let key_pack = KeyPack::gen(); + let msg = Message::new( + MsgType::MultiCast, Vec::::new(), key_pack + ); + let serialized = &msg.ser(); + let msg2 = Message::deserialize(serialized.to_vec()); + assert_eq!(msg2.msg_type, MsgType::MultiCast); + } + + #[test] + fn test_hash() { + let msg = Message::new( + MsgType::MultiCast, Vec::::new(), crate::crypto::KeyPack::gen() + ); + msg.get_hash(); } } diff --git a/src/message.rs b/src/message.rs index d46daf1..dcd4d67 100644 --- a/src/message.rs +++ b/src/message.rs @@ -22,7 +22,7 @@ pub struct Message { } impl Message { - fn get_hash(self) -> Vec { + pub fn get_hash(self) -> Vec { let mut hasher = sha2::Sha256::new(); hasher.input(self.ser()); hasher.result().to_vec()