What changed, and why it matters
This commit simply adds the ability to duplicate (clone) several decoder helper objects in the Rust Bitcoin library. It is a routine feature addition with no security relevance visible in the code or commit message.
No security action required. Treat as a normal feature/maintenance commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch adds manual Clone implementations for Decoder2, Decoder3, Decoder4, and Decoder6 composite decoder types in consensus_encoding/src/decode/decoders.rs. The implementations mirror the existing manual Debug implementations and require the underlying decoder types and their outputs to implement Clone. No behavioral logic changes; no unsafe code, input parsing, cryptography, or resource management is modified.
Changed components
consensus_encoding/src/decode/decoders.rsInspect captured patch +57 / −0
diff --git a/consensus_encoding/src/decode/decoders.rs b/consensus_encoding/src/decode/decoders.rs
index a0ebdfd3..16db3f4a 100644
--- a/consensus_encoding/src/decode/decoders.rs
+++ b/consensus_encoding/src/decode/decoders.rs
@@ -392,6 +392,22 @@ where
}
}
+impl<A, B> Clone for Decoder2<A, B>
+where
+ A: Decoder + Clone,
+ B: Decoder + Clone,
+ A::Output: Clone,
+{
+ fn clone(&self) -> Self {
+ let state = match &self.state {
+ Decoder2State::First(a, b) => Decoder2State::First(a.clone(), b.clone()),
+ Decoder2State::Second(out, b) => Decoder2State::Second(out.clone(), b.clone()),
+ Decoder2State::Errored => Decoder2State::Errored,
+ };
+ Self { state }
+ }
+}
+
impl<A, B> Decoder for Decoder2<A, B>
where
A: Decoder,
@@ -498,6 +514,17 @@ where
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.inner.fmt(f) }
}
+impl<A, B, C> Clone for Decoder3<A, B, C>
+where
+ A: Decoder + Clone,
+ B: Decoder + Clone,
+ C: Decoder + Clone,
+ A::Output: Clone,
+ B::Output: Clone,
+{
+ fn clone(&self) -> Self { Self { inner: self.inner.clone() } }
+}
+
impl<A, B, C> Decoder for Decoder3<A, B, C>
where
A: Decoder,
@@ -569,6 +596,19 @@ where
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.inner.fmt(f) }
}
+impl<A, B, C, D> Clone for Decoder4<A, B, C, D>
+where
+ A: Decoder + Clone,
+ B: Decoder + Clone,
+ C: Decoder + Clone,
+ D: Decoder + Clone,
+ A::Output: Clone,
+ B::Output: Clone,
+ C::Output: Clone,
+{
+ fn clone(&self) -> Self { Self { inner: self.inner.clone() } }
+}
+
impl<A, B, C, D> Decoder for Decoder4<A, B, C, D>
where
A: Decoder,
@@ -657,6 +697,23 @@ where
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.inner.fmt(f) }
}
+impl<A, B, C, D, E, F> Clone for Decoder6<A, B, C, D, E, F>
+where
+ A: Decoder + Clone,
+ B: Decoder + Clone,
+ C: Decoder + Clone,
+ D: Decoder + Clone,
+ E: Decoder + Clone,
+ F: Decoder + Clone,
+ A::Output: Clone,
+ B::Output: Clone,
+ C::Output: Clone,
+ D::Output: Clone,
+ E::Output: Clone,
+{
+ fn clone(&self) -> Self { Self { inner: self.inner.clone() } }
+}
+
impl<A, B, C, D, E, F> Decoder for Decoder6<A, B, C, D, E, F>
where
A: Decoder,
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.