Browse Source

hashing

master
ennucore 5 years ago
parent
commit
496beab75a
  1. 19
      src/lib.rs
  2. 2
      src/message.rs

19
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::<u8>::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::<u8>::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::<u8>::new(), crate::crypto::KeyPack::gen()
);
msg.get_hash();
}
}

2
src/message.rs

@ -22,7 +22,7 @@ pub struct Message {
}
impl Message {
fn get_hash(self) -> Vec<u8> {
pub fn get_hash(self) -> Vec<u8> {
let mut hasher = sha2::Sha256::new();
hasher.input(self.ser());
hasher.result().to_vec()

Loading…
Cancel
Save