hashes: Convert debug_hex to take u8 iterator
What changed, and why it matters
This is a small, safe API refactor. A helper function that writes bytes as hexadecimal text was changed to accept any iterator over bytes instead of only a fixed slice. This does not fix a vulnerability and does not change runtime behavior for existing callers.
No security action needed. Treat as a normal API ergonomics change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The public function bitcoin_hashes::debug_hex changes its parameter from &[u8] to impl IntoIterator<Item = &'a u8>. The body still iterates over &b in bytes and writes each byte as two hex characters. The change is source-compatible for slice callers (slices implement IntoIterator<Item = &u8>) and only broadens the accepted input types. No security-sensitive logic is modified.
Changed components
hashes/src/lib.rspublic API surface files (api/hashes/*.txt)Inspect captured patch +4 / −4
diff --git a/api/hashes/all-features.txt b/api/hashes/all-features.txt
index b231619b..ddfba970 100644
--- a/api/hashes/all-features.txt
+++ b/api/hashes/all-features.txt
@@ -659,7 +659,7 @@ pub fn bitcoin_hashes::HashEngine::finalize(self) -> Self::Hash
pub fn bitcoin_hashes::HashEngine::input(&mut self, data: &[u8])
pub fn bitcoin_hashes::HashEngine::n_bytes_hashed(&self) -> u64
pub fn bitcoin_hashes::cmp::fixed_time_eq(a: &[u8], b: &[u8]) -> bool
-pub fn bitcoin_hashes::debug_hex(bytes: &[u8], f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
+pub fn bitcoin_hashes::debug_hex<'a>(bytes: impl core::iter::traits::collect::IntoIterator<Item = &'a u8>, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
pub fn bitcoin_hashes::encode_to_engine<T, H>(object: &T, engine: H) -> H where T: bitcoin_consensus_encoding::encode::Encodable + ?core::marker::Sized, H: bitcoin_hashes::HashEngine
pub fn bitcoin_hashes::hash160::Hash::as_byte_array(&self) -> &Self::Bytes
pub fn bitcoin_hashes::hash160::Hash::as_ref(&self) -> &[u8; 20]
diff --git a/api/hashes/alloc-only.txt b/api/hashes/alloc-only.txt
index b187154a..f95cdb9c 100644
--- a/api/hashes/alloc-only.txt
+++ b/api/hashes/alloc-only.txt
@@ -559,7 +559,7 @@ pub fn bitcoin_hashes::HashEngine::finalize(self) -> Self::Hash
pub fn bitcoin_hashes::HashEngine::input(&mut self, data: &[u8])
pub fn bitcoin_hashes::HashEngine::n_bytes_hashed(&self) -> u64
pub fn bitcoin_hashes::cmp::fixed_time_eq(a: &[u8], b: &[u8]) -> bool
-pub fn bitcoin_hashes::debug_hex(bytes: &[u8], f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
+pub fn bitcoin_hashes::debug_hex<'a>(bytes: impl core::iter::traits::collect::IntoIterator<Item = &'a u8>, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
pub fn bitcoin_hashes::encode_to_engine<T, H>(object: &T, engine: H) -> H where T: bitcoin_consensus_encoding::encode::Encodable + ?core::marker::Sized, H: bitcoin_hashes::HashEngine
pub fn bitcoin_hashes::hash160::Hash::as_byte_array(&self) -> &Self::Bytes
pub fn bitcoin_hashes::hash160::Hash::as_ref(&self) -> &[u8; 20]
diff --git a/api/hashes/no-features.txt b/api/hashes/no-features.txt
index ad8375ec..0b5c54ab 100644
--- a/api/hashes/no-features.txt
+++ b/api/hashes/no-features.txt
@@ -559,7 +559,7 @@ pub fn bitcoin_hashes::HashEngine::finalize(self) -> Self::Hash
pub fn bitcoin_hashes::HashEngine::input(&mut self, data: &[u8])
pub fn bitcoin_hashes::HashEngine::n_bytes_hashed(&self) -> u64
pub fn bitcoin_hashes::cmp::fixed_time_eq(a: &[u8], b: &[u8]) -> bool
-pub fn bitcoin_hashes::debug_hex(bytes: &[u8], f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
+pub fn bitcoin_hashes::debug_hex<'a>(bytes: impl core::iter::traits::collect::IntoIterator<Item = &'a u8>, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
pub fn bitcoin_hashes::encode_to_engine<T, H>(object: &T, engine: H) -> H where T: bitcoin_consensus_encoding::encode::Encodable + ?core::marker::Sized, H: bitcoin_hashes::HashEngine
pub fn bitcoin_hashes::hash160::Hash::as_byte_array(&self) -> &Self::Bytes
pub fn bitcoin_hashes::hash160::Hash::as_ref(&self) -> &[u8; 20]
diff --git a/hashes/src/lib.rs b/hashes/src/lib.rs
index 1ec86ffd..0411fe66 100644
--- a/hashes/src/lib.rs
+++ b/hashes/src/lib.rs
@@ -261,7 +261,7 @@ fn incomplete_block_len<H: HashEngine>(eng: &H) -> usize {
///
/// For when we cannot rely on having the `hex` feature enabled. Ignores formatter options and just
/// writes with plain old `f.write_char()`.
-pub fn debug_hex(bytes: &[u8], f: &mut fmt::Formatter) -> fmt::Result {
+pub fn debug_hex<'a>(bytes: impl IntoIterator<Item = &'a u8>, f: &mut fmt::Formatter) -> fmt::Result {
const HEX_TABLE: [u8; 16] = *b"0123456789abcdef";
for &b in bytes {
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.