#![deny(missing_docs)]
extern crate blake2_rfc;
extern crate byteorder;
use std::hash::{Hash, Hasher};
mod blake2b;
mod hashwrap;
pub use blake2b::Blake2b;
pub use hashwrap::Wrapped;
pub trait ByteHash: 'static + Sized + Clone + Default {
type Digest: AsRef<[u8]>
+ AsMut<[u8]>
+ Copy
+ Clone
+ Eq
+ Hash
+ Default
+ Send;
type State: State<Self::Digest> + Hasher;
fn state() -> Self::State;
fn hash<T: Hash + ?Sized>(t: &T) -> Self::Digest {
let mut state = Self::state();
t.hash(&mut state);
state.fin()
}
}
pub trait State<D> {
fn fin(self) -> D;
}
#[cfg(test)]
mod tests {
use super::*;
use hashwrap::Wrapped;
use std::collections::hash_map::DefaultHasher;
#[test]
fn default() {
let mut state = Wrapped::<DefaultHasher>::state();
state.write(b"hello world");
state.fin();
}
#[test]
fn blake2b() {
let mut state = Blake2b::state();
state.write(b"hello world");
state.fin();
}
#[test]
fn oneshot_hash() {
let _hash_a = Blake2b::hash(&42u64);
let _hash_b = Blake2b::hash("hello");
}
}