macro_rules! circular_lshift32 (
($shift:expr, $w:expr) => (($w << $shift) | ($w >> (32 - $shift)))
);
macro_rules! circular_lshift64 (
($shift:expr, $w:expr) => (($w << $shift) | ($w >> (64 - $shift)))
);
macro_rules! hex_fmt_impl(
($imp:ident, $ty:ident) => (
impl ::std::fmt::$imp for $ty {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
use hex::{format_hex, format_hex_reverse};
if $ty::display_backward() {
format_hex_reverse(&self.0, f)
} else {
format_hex(&self.0, f)
}
}
}
)
);
macro_rules! index_impl(
($ty:ty) => (
impl ::std::ops::Index<usize> for $ty {
type Output = u8;
fn index(&self, index: usize) -> &u8 {
&self.0[index]
}
}
impl ::std::ops::Index<::std::ops::Range<usize>> for $ty {
type Output = [u8];
fn index(&self, index: ::std::ops::Range<usize>) -> &[u8] {
&self.0[index]
}
}
impl ::std::ops::Index<::std::ops::RangeFrom<usize>> for $ty {
type Output = [u8];
fn index(&self, index: ::std::ops::RangeFrom<usize>) -> &[u8] {
&self.0[index]
}
}
impl ::std::ops::Index<::std::ops::RangeTo<usize>> for $ty {
type Output = [u8];
fn index(&self, index: ::std::ops::RangeTo<usize>) -> &[u8] {
&self.0[index]
}
}
impl ::std::ops::Index<::std::ops::RangeFull> for $ty {
type Output = [u8];
fn index(&self, index: ::std::ops::RangeFull) -> &[u8] {
&self.0[index]
}
}
)
);
macro_rules! borrow_slice_impl(
($ty:ty) => (
impl ::std::borrow::Borrow<[u8]> for $ty {
fn borrow(&self) -> &[u8] {
&self[..]
}
}
)
);
macro_rules! write_impl(
($ty:ty) => (
impl ::std::io::Write for $ty {
fn flush(&mut self) -> ::std::io::Result<()> {
Ok(())
}
#[cfg(not(feature = "fuzztarget"))]
fn write(&mut self, inp: &[u8]) -> ::std::io::Result<usize> {
let buf_idx = self.length % <Self as ::HashEngine>::block_size();
let rem_len = <Self as ::HashEngine>::block_size() - buf_idx;
let write_len = ::std::cmp::min(rem_len, inp.len());
self.buffer[buf_idx..buf_idx + write_len].copy_from_slice(&inp[..write_len]);
self.length += write_len;
if self.length % <Self as ::HashEngine>::block_size() == 0 {
self.process_block();
}
Ok(write_len)
}
#[cfg(feature = "fuzztarget")]
fn write(&mut self, inp: &[u8]) -> ::std::io::Result<usize> {
for c in inp {
self.buffer[0] ^= *c;
}
self.length += inp.len();
Ok(inp.len())
}
}
)
);