consensus_encoding: rename UnexptectedEof
What changed, and why it matters
This commit is a simple rename of an error type from 'UnexpectedEof' to 'UnexpectedEofError' to follow the project's naming policy. It only moves the type definition to the bottom of the file and updates all references. There is no functional change and no security impact.
No action required; this is a non-functional refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch renames the public error struct UnexpectedEof to UnexpectedEofError in consensus_encoding/src/decode/decoders.rs, re-exports it from lib.rs, and updates all usages in tests. The struct’s fields, derives, Display impl, and std::error::Error impl are unchanged. No logic, bounds checking, or behavior changes.
Changed components
consensus_encoding/src/decode/decoders.rsconsensus_encoding/src/lib.rsconsensus_encoding/tests/composition.rsconsensus_encoding/tests/decode.rsInspect captured patch +33 / −33
diff --git a/consensus_encoding/src/decode/decoders.rs b/consensus_encoding/src/decode/decoders.rs
index a502516c..f3a9d6d7 100644
--- a/consensus_encoding/src/decode/decoders.rs
+++ b/consensus_encoding/src/decode/decoders.rs
@@ -4,22 +4,6 @@
use super::Decoder;
-/// Not enough bytes given to decoder.
-#[derive(Debug, Clone, PartialEq, Eq)]
-pub struct UnexpectedEof {
- /// Number of bytes missing to complete decoder.
- missing: usize,
-}
-
-impl core::fmt::Display for UnexpectedEof {
- fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
- write!(f, "not enough bytes for decoder, {} more bytes required", self.missing)
- }
-}
-
-#[cfg(feature = "std")]
-impl std::error::Error for UnexpectedEof {}
-
/// A decoder that expects exactly N bytes and returns them as an array.
pub struct ArrayDecoder<const N: usize> {
buffer: [u8; N],
@@ -37,7 +21,7 @@ impl<const N: usize> Default for ArrayDecoder<N> {
impl<const N: usize> Decoder for ArrayDecoder<N> {
type Output = [u8; N];
- type Error = UnexpectedEof;
+ type Error = UnexpectedEofError;
fn push_bytes(&mut self, bytes: &mut &[u8]) -> Result<bool, Self::Error> {
let remaining_space = N - self.bytes_written;
@@ -59,7 +43,7 @@ impl<const N: usize> Decoder for ArrayDecoder<N> {
if self.bytes_written == N {
Ok(self.buffer)
} else {
- Err(UnexpectedEof { missing: N - self.bytes_written })
+ Err(UnexpectedEofError { missing: N - self.bytes_written })
}
}
}
@@ -355,3 +339,19 @@ where
Ok((first, second, third, fourth, fifth, sixth))
}
}
+
+/// Not enough bytes given to decoder.
+#[derive(Debug, Clone, PartialEq, Eq)]
+pub struct UnexpectedEofError {
+ /// Number of bytes missing to complete decoder.
+ missing: usize,
+}
+
+impl core::fmt::Display for UnexpectedEofError {
+ fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
+ write!(f, "not enough bytes for decoder, {} more bytes required", self.missing)
+ }
+}
+
+#[cfg(feature = "std")]
+impl std::error::Error for UnexpectedEofError {}
diff --git a/consensus_encoding/src/lib.rs b/consensus_encoding/src/lib.rs
index 723eeae1..7da0716c 100644
--- a/consensus_encoding/src/lib.rs
+++ b/consensus_encoding/src/lib.rs
@@ -23,7 +23,7 @@ mod decode;
mod encode;
pub use self::decode::decoders::{
- ArrayDecoder, Decoder2, Decoder3, Decoder4, Decoder6, UnexpectedEof,
+ ArrayDecoder, Decoder2, Decoder3, Decoder4, Decoder6, UnexpectedEofError,
};
pub use self::decode::{Decodable, Decoder};
#[cfg(feature = "alloc")]
diff --git a/consensus_encoding/tests/composition.rs b/consensus_encoding/tests/composition.rs
index 778073f1..aa055b65 100644
--- a/consensus_encoding/tests/composition.rs
+++ b/consensus_encoding/tests/composition.rs
@@ -4,7 +4,7 @@
use consensus_encoding::{
ArrayDecoder, ArrayEncoder, Decodable, Decoder, Decoder2, Decoder6, Encodable, Encoder,
- Encoder2, Encoder6, UnexpectedEof,
+ Encoder2, Encoder6, UnexpectedEofError,
};
const EMPTY: &[u8] = &[];
@@ -30,11 +30,11 @@ impl Encodable for CompositeData {
/// A unified error type for [`CompositeDataDecoder`].
#[derive(Debug, Clone, PartialEq, Eq)]
enum CompositeError {
- Eof(UnexpectedEof),
+ Eof(UnexpectedEofError),
}
-impl From<UnexpectedEof> for CompositeError {
- fn from(eof: UnexpectedEof) -> Self { CompositeError::Eof(eof) }
+impl From<UnexpectedEofError> for CompositeError {
+ fn from(eof: UnexpectedEofError) -> Self { CompositeError::Eof(eof) }
}
impl core::fmt::Display for CompositeError {
@@ -115,7 +115,7 @@ fn composition_nested() {
}
assert_eq!(encoded_bytes, data);
- let mut decoder6: Decoder6<_, _, _, _, _, _, UnexpectedEof> = Decoder6::new(
+ let mut decoder6: Decoder6<_, _, _, _, _, _, UnexpectedEofError> = Decoder6::new(
ArrayDecoder::<1>::new(),
ArrayDecoder::<1>::new(),
ArrayDecoder::<1>::new(),
@@ -139,7 +139,7 @@ fn composition_nested() {
#[test]
fn composition_extra_bytes() {
// Test that Decoder2 consumes exactly what it needs and leaves extra bytes unconsumed.
- let mut decoder2: Decoder2<_, _, UnexpectedEof> =
+ let mut decoder2: Decoder2<_, _, UnexpectedEofError> =
Decoder2::new(ArrayDecoder::<2>::new(), ArrayDecoder::<3>::new());
let mut bytes = &[0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08][..];
let original_len = bytes.len();
@@ -167,22 +167,22 @@ fn composition_error_unification() {
#[derive(Debug, Clone, PartialEq, Eq)]
enum NestedError {
BadChecksum,
- UnexpectedEof(UnexpectedEof),
+ UnexpectedEof(UnexpectedEofError),
}
- impl From<UnexpectedEof> for NestedError {
- fn from(eof: UnexpectedEof) -> Self { NestedError::UnexpectedEof(eof) }
+ impl From<UnexpectedEofError> for NestedError {
+ fn from(eof: UnexpectedEofError) -> Self { NestedError::UnexpectedEof(eof) }
}
/// Error for top level encoder.
#[derive(Debug, Clone, PartialEq, Eq)]
enum TopLevelError {
- UnexpectedEof(UnexpectedEof),
+ UnexpectedEof(UnexpectedEofError),
Validation(NestedError),
}
- impl From<UnexpectedEof> for TopLevelError {
- fn from(eof: UnexpectedEof) -> Self { TopLevelError::UnexpectedEof(eof) }
+ impl From<UnexpectedEofError> for TopLevelError {
+ fn from(eof: UnexpectedEofError) -> Self { TopLevelError::UnexpectedEof(eof) }
}
impl From<NestedError> for TopLevelError {
diff --git a/consensus_encoding/tests/decode.rs b/consensus_encoding/tests/decode.rs
index d1aaa301..2b34c1a8 100644
--- a/consensus_encoding/tests/decode.rs
+++ b/consensus_encoding/tests/decode.rs
@@ -2,7 +2,7 @@
//! Integration tests for decode module.
-use consensus_encoding::{ArrayDecoder, Decoder, UnexpectedEof};
+use consensus_encoding::{ArrayDecoder, Decoder, UnexpectedEofError};
const EMPTY: &[u8] = &[];
@@ -50,5 +50,5 @@ fn decode_array_insufficient_data_error() {
assert_eq!(data, EMPTY);
let err = decoder.end().unwrap_err();
- assert!(matches!(err, UnexpectedEof { .. }));
+ assert!(matches!(err, UnexpectedEofError { .. }));
}
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.