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:
Tobin C. Harding 2024-10-29 14:04:52 +11:00
parent e4486d07f0
commit baab5e580d
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
6 changed files with 35 additions and 34 deletions

View File

@ -253,3 +253,34 @@ macro_rules! 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;

View File

@ -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.
///
/// The syntax is similar to the usual tuple struct syntax:

View File

@ -85,7 +85,7 @@ impl crate::HashEngine for HashEngine {
fn n_bytes_hashed(&self) -> u64 { self.bytes_hashed }
engine_input_impl!();
crate::internal_macros::engine_input_impl!();
}
#[cfg(feature = "small-hash")]

View File

@ -77,7 +77,7 @@ impl crate::HashEngine for HashEngine {
fn n_bytes_hashed(&self) -> u64 { self.bytes_hashed }
engine_input_impl!();
crate::internal_macros::engine_input_impl!();
}
impl HashEngine {

View File

@ -132,7 +132,7 @@ impl crate::HashEngine for HashEngine {
fn n_bytes_hashed(&self) -> u64 { self.bytes_hashed }
engine_input_impl!();
crate::internal_macros::engine_input_impl!();
}
impl Hash {

View File

@ -118,7 +118,7 @@ impl crate::HashEngine for HashEngine {
fn n_bytes_hashed(&self) -> u64 { self.bytes_hashed }
engine_input_impl!();
crate::internal_macros::engine_input_impl!();
}
#[allow(non_snake_case)]