From 71454d438acc3f0bb1f10cf288a1984e8d3f16af Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Fri, 3 Nov 2023 10:18:24 +1100 Subject: [PATCH] Use hash_type macro for sha512::Hash Currently we are defining the `sha512::Hash` type manually instead of using the `hash_type` macro. The generated code using the macro is identical to that without it (although I didn't actually look at the generated code :) --- hashes/src/sha512.rs | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/hashes/src/sha512.rs b/hashes/src/sha512.rs index f93de8b6..f7fff543 100644 --- a/hashes/src/sha512.rs +++ b/hashes/src/sha512.rs @@ -10,7 +10,12 @@ use core::{cmp, str}; use crate::{FromSliceError, HashEngine as _}; -crate::internal_macros::hash_trait_impls!(512, false); +crate::internal_macros::hash_type! { + 512, + false, + "Output of the SHA512 hash function.", + "crate::util::json_hex_string::len_64" +} #[cfg(not(hashes_fuzz))] pub(crate) fn from_engine(mut e: HashEngine) -> Hash { @@ -105,24 +110,6 @@ impl crate::HashEngine for HashEngine { engine_input_impl!(); } -/// Output of the SHA512 hash function. -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -#[repr(transparent)] -pub struct Hash( - #[cfg_attr( - feature = "schemars", - schemars(schema_with = "crate::util::json_hex_string::len_64") - )] - [u8; 64], -); - -impl Hash { - fn internal_new(arr: [u8; 64]) -> Self { Hash(arr) } - - fn internal_engine() -> HashEngine { Default::default() } -} - #[allow(non_snake_case)] fn Ch(x: u64, y: u64, z: u64) -> u64 { z ^ (x & (y ^ z)) } #[allow(non_snake_case)]