#![deny(non_upper_case_globals)]
#![deny(non_camel_case_types)]
#![deny(non_snake_case)]
#![deny(unused_mut)]
#![deny(missing_docs)]
#![cfg_attr(all(test, feature = "unstable"), feature(test))]
#[cfg(all(test, feature = "unstable"))] extern crate test;
#[cfg(feature="serde")] extern crate serde;
#[cfg(all(test,feature="serde"))] extern crate serde_test;
extern crate byteorder;
#[macro_use] mod util;
#[macro_use] mod serde_macros;
pub mod error;
pub mod hex;
pub mod hash160;
pub mod hmac;
pub mod ripemd160;
pub mod sha1;
pub mod sha256;
pub mod sha512;
pub mod sha256d;
pub mod cmp;
use std::{borrow, fmt, hash, io, ops};
pub use hmac::{Hmac, HmacEngine};
pub use error::Error;
pub trait HashEngine: Clone + io::Write {
type MidState;
fn midstate(&self) -> Self::MidState;
fn block_size() -> usize;
#[inline(always)]
fn input(&mut self, data: &[u8]) {
self.write_all(data).expect("hash returned error");
}
}
pub trait Hash: Copy + Clone + PartialEq + Eq + Default + PartialOrd + Ord +
hash::Hash + fmt::Debug + fmt::Display + fmt::LowerHex +
ops::Index<ops::RangeFull, Output = [u8]> +
ops::Index<ops::RangeFrom<usize>, Output = [u8]> +
ops::Index<ops::RangeTo<usize>, Output = [u8]> +
ops::Index<ops::Range<usize>, Output = [u8]> +
ops::Index<usize, Output = u8> +
hex::ToHex + borrow::Borrow<[u8]>
{
type Engine: HashEngine;
type Inner;
fn engine() -> Self::Engine;
fn from_engine(e: Self::Engine) -> Self;
fn len() -> usize;
fn block_size() -> usize { Self::Engine::block_size() }
fn from_slice(sl: &[u8]) -> Result<Self, Error>;
fn hash(data: &[u8]) -> Self {
use std::io::Write;
let mut engine = Self::engine();
engine.write_all(data).unwrap();
Self::from_engine(engine)
}
fn display_backward() -> bool { false }
fn into_inner(self) -> Self::Inner;
}