1
0
Fork 0
mirror of https://github.com/emojisum/emojisum.git synced 2025-08-02 13:20:27 +00:00

add emoji checksum

This commit is contained in:
goldenMetteyya 2018-10-19 20:52:02 -04:00
parent bc8ffd082c
commit 4eed2ebd51

View file

@ -15,6 +15,7 @@
//! Emojisum //! Emojisum
//External Crates //External Crates
extern crate blake2_rfc; extern crate blake2_rfc;
extern crate serde; extern crate serde;
@ -56,13 +57,18 @@ impl Emojisum {
return deserialized; return deserialized;
} }
//given a se //given a series of bytes match emojis
pub fn from_bytes(tosum: &[u8]) -> Option<String> { pub fn from_bytes(&self, tosum: &[u8]) -> Option<String> {
//check that it is 32bytes //check that it is 32bytes
if tosum.len() < 32 { return None } if tosum.len() < 32 { return None }
let mut result = String::new(); let mut result = String::new();
for byte in tosum {
result.push_str(&(self.emojiwords[*byte as usize])[0])
}
return Some(result);
} }
@ -74,6 +80,7 @@ impl Emojisum {
} }
} }
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
@ -82,7 +89,10 @@ mod tests {
fn it_works() { fn it_works() {
let e = Emojisum::init("./src/emojimap.json"); let e = Emojisum::init("./src/emojimap.json");
println!("{:?}", e); //println!("{:?}", e);
println!("{:?}", e.hash_to_emojisum("dog".as_bytes().to_vec()));
println!("{:?}", e.hash_to_emojisum("cat".as_bytes().to_vec()));
assert_eq!(2 + 2, 4); assert_eq!(2 + 2, 4);
} }