Move SerializeBytesAsHex to primitives
What changed, and why it matters
This commit simply moves an existing helper type used for serializing bytes as hexadecimal from one internal module to another. The code is copied verbatim and made private to the module that uses it. There is no functional change, no bug fix, and no security relevance.
No action required. This is a non-security refactoring change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The SerializeBytesAsHex type is relocated from internals::serde (public under the hex feature) to primitives::witness (private under the serde feature). The implementation is unchanged: it still serializes a byte slice as lowercase hex via hex::DisplayHex. The only call site in Witness::serialize is updated to use the local private type. This is a pure refactoring with identical runtime behavior.
Changed components
internals/src/serde.rsprimitives/src/witness.rsInspect captured patch +17 / −17
diff --git a/internals/src/serde.rs b/internals/src/serde.rs
index bf54774f..b6619b6c 100644
--- a/internals/src/serde.rs
+++ b/internals/src/serde.rs
@@ -296,19 +296,3 @@ macro_rules! serde_struct_human_string_impl {
}
)
}
-
-#[cfg(feature = "hex")]
-/// Serializes a byte slice using the `hex` crate.
-pub struct SerializeBytesAsHex<'a>(pub &'a [u8]);
-
-#[cfg(feature = "hex")]
-impl serde::Serialize for SerializeBytesAsHex<'_> {
- fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
- where
- S: serde::Serializer,
- {
- use hex::DisplayHex;
-
- serializer.collect_str(&format_args!("{:x}", self.0.as_hex()))
- }
-}
diff --git a/primitives/src/witness.rs b/primitives/src/witness.rs
index 4653860c..fec5a058 100644
--- a/primitives/src/witness.rs
+++ b/primitives/src/witness.rs
@@ -745,7 +745,7 @@ impl serde::Serialize for Witness {
// Note that the `Iter` strips the varints out when iterating.
for elem in self {
if human_readable {
- seq.serialize_element(&internals::serde::SerializeBytesAsHex(elem))?;
+ seq.serialize_element(&SerializeBytesAsHex(elem))?;
} else {
seq.serialize_element(&elem)?;
}
@@ -955,6 +955,22 @@ impl<F: Fn(&mut fmt::Formatter) -> fmt::Result> fmt::Debug for WrapDebug<F> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { (self.0)(f) }
}
+/// Serializes a byte slice using the `hex` crate.
+#[cfg(feature = "serde")]
+struct SerializeBytesAsHex<'a>(pub &'a [u8]);
+
+#[cfg(feature = "serde")]
+impl serde::Serialize for SerializeBytesAsHex<'_> {
+ fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
+ where
+ S: serde::Serializer,
+ {
+ use hex::DisplayHex;
+
+ serializer.collect_str(&format_args!("{:x}", self.0.as_hex()))
+ }
+}
+
/// Error types for witness data.
pub mod error {
use core::convert::Infallible;
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.