use {Blake2b, Blake2xb};
use blake2xb;
use hash::{Hash};
use slice_ext::{SliceExt};
pub trait Digest {
type Output;
fn len(&self) -> usize;
fn write_u8(&mut self, data: &[u8]);
fn finish(self) -> Self::Output;
fn write_i8(&mut self, data: &[i8]) {
self.write_u8(data.as_bytes());
}
fn write_i16(&mut self, data: &[i16]) {
self.write_u8(data.as_bytes());
}
fn write_u16(&mut self, data: &[u16]) {
self.write_u8(data.as_bytes());
}
fn write_i32(&mut self, data: &[i32]) {
self.write_u8(data.as_bytes());
}
fn write_u32(&mut self, data: &[u32]) {
self.write_u8(data.as_bytes());
}
fn write_i64(&mut self, data: &[i64]) {
self.write_u8(data.as_bytes());
}
fn write_u64(&mut self, data: &[u64]) {
self.write_u8(data.as_bytes());
}
fn write_isize(&mut self, data: &[isize]) {
self.write_u8(data.as_bytes());
}
fn write_usize(&mut self, data: &[usize]) {
self.write_u8(data.as_bytes());
}
}
impl Digest for Blake2b {
type Output = Hash;
fn len(&self) -> usize {
self.len() as usize
}
fn write_u8(&mut self, data: &[u8]) {
self.update(data);
}
fn finish(self) -> Self::Output {
self.finish()
}
}
impl Digest for Blake2xb {
type Output = blake2xb::Iter;
fn len(&self) -> usize {
self.len() as usize
}
fn write_u8(&mut self, data: &[u8]) {
self.update(data);
}
fn finish(self) -> Self::Output {
self.finish()
}
}