Browse Source

Tests

master
ennucore 5 years ago
parent
commit
39fbabcbbe
  1. 15
      src/lib.rs
  2. 2
      src/message.rs

15
src/lib.rs

@ -38,7 +38,20 @@ mod tests {
let msg = Message::new( let msg = Message::new(
MsgType::MultiCast, Vec::<u8>::new(), &KeyPack::gen() MsgType::MultiCast, Vec::<u8>::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::<u8>::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] #[test]

2
src/message.rs

@ -42,7 +42,7 @@ impl Message {
msg msg
} }
pub fn verify(self) -> bool { pub fn verify(&self) -> bool {
self.hash == self.get_hash() && self.source.verify_sign(&self) self.hash == self.get_hash() && self.source.verify_sign(&self)
} }

Loading…
Cancel
Save