Make `sha256t` obey sanity rules

The comparison functions were accessing the fields directly, so this
changes them to use methods instead.
This commit is contained in:
Martin Habovstiak 2025-03-24 13:17:49 +01:00
parent fb80a94194
commit 8ee088df74
1 changed files with 3 additions and 3 deletions

View File

@ -128,7 +128,7 @@ impl<T: Tag> Clone for Hash<T> {
fn clone(&self) -> Self { *self } fn clone(&self) -> Self { *self }
} }
impl<T: Tag> PartialEq for Hash<T> { impl<T: Tag> PartialEq for Hash<T> {
fn eq(&self, other: &Hash<T>) -> bool { self.0 == other.0 } fn eq(&self, other: &Hash<T>) -> bool { self.as_byte_array() == other.as_byte_array() }
} }
impl<T: Tag> Eq for Hash<T> {} impl<T: Tag> Eq for Hash<T> {}
impl<T: Tag> PartialOrd for Hash<T> { impl<T: Tag> PartialOrd for Hash<T> {
@ -137,10 +137,10 @@ impl<T: Tag> PartialOrd for Hash<T> {
} }
} }
impl<T: Tag> Ord for Hash<T> { impl<T: Tag> Ord for Hash<T> {
fn cmp(&self, other: &Hash<T>) -> cmp::Ordering { cmp::Ord::cmp(&self.0, &other.0) } fn cmp(&self, other: &Hash<T>) -> cmp::Ordering { cmp::Ord::cmp(&self.as_byte_array(), &other.as_byte_array()) }
} }
impl<T: Tag> core::hash::Hash for Hash<T> { impl<T: Tag> core::hash::Hash for Hash<T> {
fn hash<H: core::hash::Hasher>(&self, h: &mut H) { self.0.hash(h) } fn hash<H: core::hash::Hasher>(&self, h: &mut H) { self.as_byte_array().hash(h) }
} }
crate::internal_macros::hash_trait_impls!(256, false, T: Tag); crate::internal_macros::hash_trait_impls!(256, false, T: Tag);