1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
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() } }