Move impl blocks to below struct definition
What changed, and why it matters
This commit only moves existing code around in the same file. It takes several implementation blocks for the Hmac type and places them directly below the Hmac struct definition instead of further down after another struct. No code behavior, logic, or public interface was changed.
No action needed; this is a non-functional code organization change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff is a pure relocation of impl blocks for Hmac
Changed components
hashes/src/hmac/mod.rsInspect captured patch +42 / −42
diff --git a/hashes/src/hmac/mod.rs b/hashes/src/hmac/mod.rs
index c8ccdf14..af7a09ac 100644
--- a/hashes/src/hmac/mod.rs
+++ b/hashes/src/hmac/mod.rs
@@ -31,6 +31,48 @@ impl<T: Hash> PartialEq for Hmac<T> {
impl<T: Hash> Eq for Hmac<T> {}
+impl<T: Hash + fmt::Debug> fmt::Debug for Hmac<T> {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::Debug::fmt(&self.0, f) }
+}
+
+impl<T: Hash + fmt::Display> fmt::Display for Hmac<T> {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::Display::fmt(&self.0, f) }
+}
+
+impl<T: Hash + fmt::LowerHex> fmt::LowerHex for Hmac<T> {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::LowerHex::fmt(&self.0, f) }
+}
+
+impl<T: Hash> convert::AsRef<[u8]> for Hmac<T> {
+ // Calling as_byte_array is more reliable
+ fn as_ref(&self) -> &[u8] { self.0.as_byte_array().as_ref() }
+}
+
+impl<T: Hash> Hash for Hmac<T> {
+ type Bytes = T::Bytes;
+
+ fn from_byte_array(bytes: T::Bytes) -> Self { Self(T::from_byte_array(bytes)) }
+
+ fn to_byte_array(self) -> Self::Bytes { self.0.to_byte_array() }
+
+ fn as_byte_array(&self) -> &Self::Bytes { self.0.as_byte_array() }
+}
+
+#[cfg(feature = "serde")]
+impl<T: Hash + Serialize> Serialize for Hmac<T> {
+ fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
+ Serialize::serialize(&self.0, s)
+ }
+}
+
+#[cfg(feature = "serde")]
+impl<'de, T: Hash + Deserialize<'de>> Deserialize<'de> for Hmac<T> {
+ fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
+ let bytes = Deserialize::deserialize(d)?;
+ Ok(Self(bytes))
+ }
+}
+
/// Pair of underlying hash engines, used for the inner and outer hash of HMAC.
#[derive(Debug, Clone)]
pub struct HmacEngine<T: HashEngine> {
@@ -115,48 +157,6 @@ impl<T: HashEngine> HashEngine for HmacEngine<T> {
}
}
-impl<T: Hash + fmt::Debug> fmt::Debug for Hmac<T> {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::Debug::fmt(&self.0, f) }
-}
-
-impl<T: Hash + fmt::Display> fmt::Display for Hmac<T> {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::Display::fmt(&self.0, f) }
-}
-
-impl<T: Hash + fmt::LowerHex> fmt::LowerHex for Hmac<T> {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::LowerHex::fmt(&self.0, f) }
-}
-
-impl<T: Hash> convert::AsRef<[u8]> for Hmac<T> {
- // Calling as_byte_array is more reliable
- fn as_ref(&self) -> &[u8] { self.0.as_byte_array().as_ref() }
-}
-
-impl<T: Hash> Hash for Hmac<T> {
- type Bytes = T::Bytes;
-
- fn from_byte_array(bytes: T::Bytes) -> Self { Self(T::from_byte_array(bytes)) }
-
- fn to_byte_array(self) -> Self::Bytes { self.0.to_byte_array() }
-
- fn as_byte_array(&self) -> &Self::Bytes { self.0.as_byte_array() }
-}
-
-#[cfg(feature = "serde")]
-impl<T: Hash + Serialize> Serialize for Hmac<T> {
- fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
- Serialize::serialize(&self.0, s)
- }
-}
-
-#[cfg(feature = "serde")]
-impl<'de, T: Hash + Deserialize<'de>> Deserialize<'de> for Hmac<T> {
- fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
- let bytes = Deserialize::deserialize(d)?;
- Ok(Self(bytes))
- }
-}
-
#[cfg(feature = "std")]
crate::internal_macros::impl_write!(
HmacEngine<T>,
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.