From 39fbabcbbed235c5c7427d67586a52907c612a0a Mon Sep 17 00:00:00 2001 From: ennucore Date: Thu, 19 Mar 2020 18:05:48 +0300 Subject: [PATCH] Tests --- src/lib.rs | 15 ++++++++++++++- src/message.rs | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 583d3f4..401b1c6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -38,7 +38,20 @@ mod tests { let msg = Message::new( MsgType::MultiCast, Vec::::new(), &KeyPack::gen() ); - assert!(msg.verify()); + assert!(&msg.verify()); + } + + #[test] + fn test_invalid_sign() { + let key_pack = KeyPack::gen(); + let mut msg = Message::new( + MsgType::MultiCast, Vec::::new(), &key_pack + ); + msg.sign = [0;64].to_vec(); + assert!(!&msg.verify()); + msg.hash = [0;64].to_vec(); + msg.sign = key_pack.sign(&msg); + assert!(!&msg.verify()); } #[test] diff --git a/src/message.rs b/src/message.rs index 42ea111..1d35cf9 100644 --- a/src/message.rs +++ b/src/message.rs @@ -42,7 +42,7 @@ impl Message { msg } - pub fn verify(self) -> bool { + pub fn verify(&self) -> bool { self.hash == self.get_hash() && self.source.verify_sign(&self) }