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 :)
This commit is contained in:
Tobin C. Harding 2023-11-03 10:18:24 +11:00
parent d51c1857fd
commit 71454d438a
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
1 changed files with 6 additions and 19 deletions

View File

@ -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)]