hashes: Move private macro
We have two files one for public macros and one for private macros. Move the `engine_input_impl` macro to the private macros file. Requires change to call sites because we do not have `use_macros` attribute on the `internal_macros` file.
This commit is contained in:
parent
e4486d07f0
commit
baab5e580d
|
@ -253,3 +253,34 @@ macro_rules! impl_io_write {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub(crate) use impl_io_write;
|
pub(crate) use impl_io_write;
|
||||||
|
|
||||||
|
macro_rules! engine_input_impl(
|
||||||
|
() => (
|
||||||
|
#[cfg(not(hashes_fuzz))]
|
||||||
|
fn input(&mut self, mut inp: &[u8]) {
|
||||||
|
|
||||||
|
while !inp.is_empty() {
|
||||||
|
let buf_idx = $crate::incomplete_block_len(self);
|
||||||
|
let rem_len = <Self as crate::HashEngine>::BLOCK_SIZE - buf_idx;
|
||||||
|
let write_len = cmp::min(rem_len, inp.len());
|
||||||
|
|
||||||
|
self.buffer[buf_idx..buf_idx + write_len]
|
||||||
|
.copy_from_slice(&inp[..write_len]);
|
||||||
|
self.bytes_hashed += write_len as u64;
|
||||||
|
if $crate::incomplete_block_len(self) == 0 {
|
||||||
|
self.process_block();
|
||||||
|
}
|
||||||
|
inp = &inp[write_len..];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(hashes_fuzz)]
|
||||||
|
fn input(&mut self, inp: &[u8]) {
|
||||||
|
for c in inp {
|
||||||
|
self.buffer[0] ^= *c;
|
||||||
|
}
|
||||||
|
self.bytes_hashed += inp.len() as u64;
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
pub(crate) use engine_input_impl;
|
||||||
|
|
|
@ -70,36 +70,6 @@ macro_rules! borrow_slice_impl(
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
macro_rules! engine_input_impl(
|
|
||||||
() => (
|
|
||||||
#[cfg(not(hashes_fuzz))]
|
|
||||||
fn input(&mut self, mut inp: &[u8]) {
|
|
||||||
|
|
||||||
while !inp.is_empty() {
|
|
||||||
let buf_idx = $crate::incomplete_block_len(self);
|
|
||||||
let rem_len = <Self as crate::HashEngine>::BLOCK_SIZE - buf_idx;
|
|
||||||
let write_len = cmp::min(rem_len, inp.len());
|
|
||||||
|
|
||||||
self.buffer[buf_idx..buf_idx + write_len]
|
|
||||||
.copy_from_slice(&inp[..write_len]);
|
|
||||||
self.bytes_hashed += write_len as u64;
|
|
||||||
if $crate::incomplete_block_len(self) == 0 {
|
|
||||||
self.process_block();
|
|
||||||
}
|
|
||||||
inp = &inp[write_len..];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(hashes_fuzz)]
|
|
||||||
fn input(&mut self, inp: &[u8]) {
|
|
||||||
for c in inp {
|
|
||||||
self.buffer[0] ^= *c;
|
|
||||||
}
|
|
||||||
self.bytes_hashed += inp.len() as u64;
|
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
/// Creates a new newtype around a [`Hash`] type.
|
/// Creates a new newtype around a [`Hash`] type.
|
||||||
///
|
///
|
||||||
/// The syntax is similar to the usual tuple struct syntax:
|
/// The syntax is similar to the usual tuple struct syntax:
|
||||||
|
|
|
@ -85,7 +85,7 @@ impl crate::HashEngine for HashEngine {
|
||||||
|
|
||||||
fn n_bytes_hashed(&self) -> u64 { self.bytes_hashed }
|
fn n_bytes_hashed(&self) -> u64 { self.bytes_hashed }
|
||||||
|
|
||||||
engine_input_impl!();
|
crate::internal_macros::engine_input_impl!();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "small-hash")]
|
#[cfg(feature = "small-hash")]
|
||||||
|
|
|
@ -77,7 +77,7 @@ impl crate::HashEngine for HashEngine {
|
||||||
|
|
||||||
fn n_bytes_hashed(&self) -> u64 { self.bytes_hashed }
|
fn n_bytes_hashed(&self) -> u64 { self.bytes_hashed }
|
||||||
|
|
||||||
engine_input_impl!();
|
crate::internal_macros::engine_input_impl!();
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HashEngine {
|
impl HashEngine {
|
||||||
|
|
|
@ -132,7 +132,7 @@ impl crate::HashEngine for HashEngine {
|
||||||
|
|
||||||
fn n_bytes_hashed(&self) -> u64 { self.bytes_hashed }
|
fn n_bytes_hashed(&self) -> u64 { self.bytes_hashed }
|
||||||
|
|
||||||
engine_input_impl!();
|
crate::internal_macros::engine_input_impl!();
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Hash {
|
impl Hash {
|
||||||
|
|
|
@ -118,7 +118,7 @@ impl crate::HashEngine for HashEngine {
|
||||||
|
|
||||||
fn n_bytes_hashed(&self) -> u64 { self.bytes_hashed }
|
fn n_bytes_hashed(&self) -> u64 { self.bytes_hashed }
|
||||||
|
|
||||||
engine_input_impl!();
|
crate::internal_macros::engine_input_impl!();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
|
|
Loading…
Reference in New Issue