#![cfg_attr(not(feature = "std"), no_std)]
pub extern crate generic_array;
#[cfg(feature = "std")]
use std as core;
use generic_array::{GenericArray, ArrayLength};
mod digest;
mod errors;
#[cfg(feature = "dev")]
pub mod dev;
pub use errors::{InvalidOutputSize, InvalidBufferLength};
pub use digest::Digest;
pub trait Input {
fn process(&mut self, input: &[u8]);
}
pub trait BlockInput {
type BlockSize: ArrayLength<u8>;
}
pub trait FixedOutput {
type OutputSize: ArrayLength<u8>;
fn fixed_result(self) -> GenericArray<u8, Self::OutputSize>;
}
#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct InvalidLength;
pub trait VariableOutput: core::marker::Sized {
fn new(output_size: usize) -> Result<Self, InvalidLength>;
fn output_size(&self) -> usize;
fn variable_result(self, buffer: &mut [u8]) -> Result<&[u8], InvalidLength>;
}
pub trait XofReader {
fn read(&mut self, buffer: &mut [u8]);
}
pub trait ExtendableOutput {
type Reader: XofReader;
fn xof_result(self) -> Self::Reader;
}
#[macro_export]
macro_rules! impl_opaque_debug {
($state:ty) => {
impl ::core::fmt::Debug for $state {
fn fmt(&self, f: &mut ::core::fmt::Formatter)
-> Result<(), ::core::fmt::Error>
{
write!(f, concat!(stringify!($state), " {{ ... }}"))
}
}
}
}