consensus_encoding: Implement Encoder for Option<T>
What changed, and why it matters
This commit adds a small, routine Rust trait implementation that lets optional values be encoded in the same way as the values they wrap. There is no indication of a security bug or fix; it is a straightforward feature addition.
No security action needed. Review as a normal feature addition.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch implements Encoder for Option<T: Encoder> in consensus_encoding/src/encode/mod.rs. When the option is Some, it delegates current_chunk and advance to the wrapped encoder; when None, it returns no data and signals completion. The change is additive only (+16 lines) and contains no logic that handles untrusted input, parsing, cryptography, or resource limits.
Changed components
consensus_encoding/src/encode/mod.rsInspect captured patch +16 / −0
diff --git a/consensus_encoding/src/encode/mod.rs b/consensus_encoding/src/encode/mod.rs
index 4eb43444..ecd34009 100644
--- a/consensus_encoding/src/encode/mod.rs
+++ b/consensus_encoding/src/encode/mod.rs
@@ -122,3 +122,19 @@ where
}
Ok(())
}
+
+impl<T: Encoder> Encoder for Option<T> {
+ fn current_chunk(&self) -> Option<&[u8]> {
+ match self {
+ Some(encoder) => encoder.current_chunk(),
+ None => None,
+ }
+ }
+
+ fn advance(&mut self) -> bool {
+ match self {
+ Some(encoder) => encoder.advance(),
+ None => false,
+ }
+ }
+}
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.