What changed, and why it matters
This commit adds a new public helper function called drain_to_engine in the rust-bitcoin hashes crate. It simply refactors existing code so that the logic for feeding an encoder's output into a hash engine can be called independently. There is no indication of a bug fix or security issue in the commit message or diff.
No security action required. This is a routine API refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change extracts the loop that drains an encoding::Encoder into a HashEngine from encode_to_engine into a new public function drain_to_engine. The original encode_to_engine now creates the encoder and delegates to the new function. The only functional change is increased API surface; behavior of encode_to_engine is unchanged. The import of encoding::Encoder at module scope was removed because the new function uses a fully-qualified path.
Changed components
hashes/src/lib.rsencode_to_enginedrain_to_engineInspect captured patch +9 / −2
diff --git a/hashes/src/lib.rs b/hashes/src/lib.rs
index 6cfa673e..5818ca43 100644
--- a/hashes/src/lib.rs
+++ b/hashes/src/lib.rs
@@ -117,8 +117,6 @@ pub mod siphash24;
use core::fmt::{self, Write as _};
use core::{convert, hash};
-use encoding::Encoder;
-
#[rustfmt::skip] // Keep public re-exports separate.
#[doc(inline)]
pub use self::{
@@ -205,6 +203,15 @@ where
H: HashEngine,
{
let mut encoder = object.encoder();
+ drain_to_engine(&mut encoder, engine);
+}
+
+/// Drain the output of an [`encoding::Encoder`] into a hash engine.
+pub fn drain_to_engine<T, H>(encoder: &mut T, engine: &mut H)
+where
+ T: encoding::Encoder + ?Sized,
+ H: HashEngine,
+{
loop {
engine.input(encoder.current_chunk());
if !encoder.advance() {
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.