hashes: Move errors in hkdf to error submodule
What changed, and why it matters
This commit is a routine code reorganization. It moves an existing error type (MaxLengthError) from the main HKDF module into a new 'error' submodule and re-exports it publicly. There is no functional change to how the code behaves, no bug fix, and no security improvement or regression.
No security action required. Treat as normal maintenance/refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors the MaxLengthError struct in hashes/src/hkdf/mod.rs by relocating its definition into a new error submodule and adding a pub use self::error::MaxLengthError; re-export at the top level. The struct’s fields, derives, Display implementation, and std::error::Error implementation remain identical. The max field visibility changes from private (default) to pub(super), which is a visibility relaxation within the same module hierarchy and does not expose it to external callers. No logic, bounds, or API behavior changes.
Changed components
hashes/src/hkdf/mod.rsInspect captured patch +24 / −15
diff --git a/hashes/src/hkdf/mod.rs b/hashes/src/hkdf/mod.rs
index 98c4d1f5..9e7fbf12 100644
--- a/hashes/src/hkdf/mod.rs
+++ b/hashes/src/hkdf/mod.rs
@@ -12,24 +12,13 @@ use core::fmt;
use crate::{HashEngine, Hmac, HmacEngine, IsByteArray};
+#[rustfmt::skip] // Keep public re-exports separate.
+#[doc(no_inline)]
+pub use self::error::MaxLengthError;
+
/// Output keying material max length multiple.
const MAX_OUTPUT_BLOCKS: usize = 255;
-/// Size of output exceeds maximum length allowed.
-#[derive(Copy, Clone, Debug, PartialEq, Eq)]
-pub struct MaxLengthError {
- max: usize,
-}
-
-impl fmt::Display for MaxLengthError {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "exceeds {} byte max output material limit", self.max)
- }
-}
-
-#[cfg(feature = "std")]
-impl std::error::Error for MaxLengthError {}
-
/// HMAC-based Extract-and-Expand Key Derivation Function (HKDF).
#[derive(Clone)]
pub struct Hkdf<T: HashEngine> {
@@ -150,6 +139,26 @@ impl<T: HashEngine> fmt::Debug for Hkdf<T> {
}
}
+/// Error types for the HKDF hash.
+pub mod error {
+ use core::fmt;
+
+ /// Size of output exceeds maximum length allowed.
+ #[derive(Copy, Clone, Debug, PartialEq, Eq)]
+ pub struct MaxLengthError {
+ pub(super) max: usize,
+ }
+
+ impl fmt::Display for MaxLengthError {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ write!(f, "exceeds {} byte max output material limit", self.max)
+ }
+ }
+
+ #[cfg(feature = "std")]
+ impl std::error::Error for MaxLengthError {}
+}
+
#[cfg(test)]
#[cfg(feature = "alloc")]
#[cfg(feature = "hex")]
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.