hashes: add one-shot hash method to HashEngine
What changed, and why it matters
This commit adds a small convenience method that lets any hash type compute a hash from a chunk of data in a single call. It is a pure API addition with no changes to existing behavior, no bug fixes, and no security-related content.
No security action needed. Treat as a routine API enhancement.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch adds a default-implemented hash(&[u8]) -> Self::Hash method to the HashEngine trait in hashes/src/lib.rs. The implementation creates a default engine, feeds the input bytes, and finalizes. It is a generic, one-shot hashing helper and does not alter any existing code paths or cryptographic logic.
Changed components
hashes/src/lib.rsHashEngine traitInspect captured patch +10 / −0
diff --git a/hashes/src/lib.rs b/hashes/src/lib.rs
index 2c61758b..2412be24 100644
--- a/hashes/src/lib.rs
+++ b/hashes/src/lib.rs
@@ -180,6 +180,16 @@ pub trait HashEngine: Clone {
/// Finalizes this engine.
fn finalize(self) -> Self::Hash;
+
+ /// Hashes bytes in one shot.
+ fn hash(data: &[u8]) -> Self::Hash
+ where
+ Self: Default,
+ {
+ let mut engine = Self::default();
+ engine.input(data);
+ engine.finalize()
+ }
}
/// Encodes an object into a hash engine.
Why this scored 16/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.