refactor: remove From<UnexpectedEof> impls for decoder errors
What changed, and why it matters
This is a code cleanup change in the rust-bitcoin library. It removes automatic error conversions (From trait implementations) for certain decoder errors and replaces them with explicit .map_err() calls. The behavior of the code appears functionally identical—errors are still propagated the same way. There is no indication this fixes a security vulnerability.
No security action required. Treat as a normal API-breaking refactor. Downstream users relying on From<UnexpectedEofError> conversions will need to update their code, but functionality is preserved via .map_err().
Security signals we found
No security-relevant behavioral change: error wrapping and propagation remain identical
Public API surface reduction: removes From trait implementations (breaking change, not a vulnerability)
No new bounds checks, no new validation, no change to parsing logic
No mention of security, vulnerability, CVE, or attacker in commit message or changelog
Evidence from the diff
The commit removes impl From
Changed components
primitives/src/block.rs (VersionDecoder)primitives/src/hash_types/block_hash.rs (BlockHashDecoder)primitives/src/hash_types/transaction_merkle_node.rs (TxMerkleNodeDecoder)primitives/src/hash_types/witness_merkle_node.rs (WitnessMerkleNodeDecoder)primitives/src/pow.rs (CompactTargetDecoder)Inspect captured patch +13 / −54
diff --git a/api/primitives/all-features.txt b/api/primitives/all-features.txt
index 323d71d9..a33b0773 100644
--- a/api/primitives/all-features.txt
+++ b/api/primitives/all-features.txt
@@ -316,10 +316,6 @@ impl core::convert::From<&bitcoin_primitives::transaction::Transaction> for bitc
impl core::convert::From<alloc::vec::Vec<&[u8]>> for bitcoin_primitives::witness::Witness
impl core::convert::From<alloc::vec::Vec<alloc::vec::Vec<u8>>> for bitcoin_primitives::witness::Witness
impl core::convert::From<bitcoin_consensus_encoding::decode::decoders::ByteVecDecoderError> for bitcoin_primitives::script::ScriptBufDecoderError
-impl core::convert::From<bitcoin_consensus_encoding::decode::decoders::UnexpectedEofError> for bitcoin_primitives::block::BlockHashDecoderError
-impl core::convert::From<bitcoin_consensus_encoding::decode::decoders::UnexpectedEofError> for bitcoin_primitives::block::VersionDecoderError
-impl core::convert::From<bitcoin_consensus_encoding::decode::decoders::UnexpectedEofError> for bitcoin_primitives::pow::CompactTargetDecoderError
-impl core::convert::From<bitcoin_consensus_encoding::decode::decoders::UnexpectedEofError> for bitcoin_primitives::transaction::TxMerkleNodeDecoderError
impl core::convert::From<bitcoin_consensus_encoding::decode::decoders::VecDecoderError<bitcoin_primitives::transaction::TxInDecoderError>> for bitcoin_primitives::transaction::TransactionDecoderError
impl core::convert::From<bitcoin_consensus_encoding::decode::decoders::VecDecoderError<bitcoin_primitives::transaction::TxOutDecoderError>> for bitcoin_primitives::transaction::TransactionDecoderError
impl core::convert::From<bitcoin_primitives::block::Block> for bitcoin_primitives::BlockHash
@@ -1498,7 +1494,6 @@ pub fn bitcoin_primitives::block::BlockHashDecoder::read_limit(&self) -> usize
pub fn bitcoin_primitives::block::BlockHashDecoderError::clone(&self) -> bitcoin_primitives::block::BlockHashDecoderError
pub fn bitcoin_primitives::block::BlockHashDecoderError::eq(&self, other: &bitcoin_primitives::block::BlockHashDecoderError) -> bool
pub fn bitcoin_primitives::block::BlockHashDecoderError::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
-pub fn bitcoin_primitives::block::BlockHashDecoderError::from(e: bitcoin_consensus_encoding::decode::decoders::UnexpectedEofError) -> Self
pub fn bitcoin_primitives::block::BlockHashDecoderError::from(never: core::convert::Infallible) -> Self
pub fn bitcoin_primitives::block::BlockHashDecoderError::source(&self) -> core::option::Option<&(dyn core::error::Error + 'static)>
pub fn bitcoin_primitives::block::BlockHashEncoder::advance(&mut self) -> bool
@@ -1564,7 +1559,6 @@ pub fn bitcoin_primitives::block::VersionDecoder::read_limit(&self) -> usize
pub fn bitcoin_primitives::block::VersionDecoderError::clone(&self) -> bitcoin_primitives::block::VersionDecoderError
pub fn bitcoin_primitives::block::VersionDecoderError::eq(&self, other: &bitcoin_primitives::block::VersionDecoderError) -> bool
pub fn bitcoin_primitives::block::VersionDecoderError::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
-pub fn bitcoin_primitives::block::VersionDecoderError::from(e: bitcoin_consensus_encoding::decode::decoders::UnexpectedEofError) -> Self
pub fn bitcoin_primitives::block::VersionDecoderError::from(never: core::convert::Infallible) -> Self
pub fn bitcoin_primitives::block::VersionDecoderError::source(&self) -> core::option::Option<&(dyn core::error::Error + 'static)>
pub fn bitcoin_primitives::block::VersionEncoder::advance(&mut self) -> bool
@@ -1594,7 +1588,6 @@ pub fn bitcoin_primitives::pow::CompactTargetDecoder::read_limit(&self) -> usize
pub fn bitcoin_primitives::pow::CompactTargetDecoderError::clone(&self) -> bitcoin_primitives::pow::CompactTargetDecoderError
pub fn bitcoin_primitives::pow::CompactTargetDecoderError::eq(&self, other: &bitcoin_primitives::pow::CompactTargetDecoderError) -> bool
pub fn bitcoin_primitives::pow::CompactTargetDecoderError::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
-pub fn bitcoin_primitives::pow::CompactTargetDecoderError::from(e: bitcoin_consensus_encoding::decode::decoders::UnexpectedEofError) -> Self
pub fn bitcoin_primitives::pow::CompactTargetDecoderError::from(never: core::convert::Infallible) -> Self
pub fn bitcoin_primitives::pow::CompactTargetDecoderError::source(&self) -> core::option::Option<&(dyn core::error::Error + 'static)>
pub fn bitcoin_primitives::pow::CompactTargetEncoder::advance(&mut self) -> bool
@@ -1832,7 +1825,6 @@ pub fn bitcoin_primitives::transaction::TxMerkleNodeDecoder::read_limit(&self) -
pub fn bitcoin_primitives::transaction::TxMerkleNodeDecoderError::clone(&self) -> bitcoin_primitives::transaction::TxMerkleNodeDecoderError
pub fn bitcoin_primitives::transaction::TxMerkleNodeDecoderError::eq(&self, other: &bitcoin_primitives::transaction::TxMerkleNodeDecoderError) -> bool
pub fn bitcoin_primitives::transaction::TxMerkleNodeDecoderError::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
-pub fn bitcoin_primitives::transaction::TxMerkleNodeDecoderError::from(e: bitcoin_consensus_encoding::decode::decoders::UnexpectedEofError) -> Self
pub fn bitcoin_primitives::transaction::TxMerkleNodeDecoderError::from(never: core::convert::Infallible) -> Self
pub fn bitcoin_primitives::transaction::TxMerkleNodeDecoderError::source(&self) -> core::option::Option<&(dyn core::error::Error + 'static)>
pub fn bitcoin_primitives::transaction::TxOut::arbitrary(u: &mut arbitrary::unstructured::Unstructured<'a>) -> arbitrary::error::Result<Self>
diff --git a/api/primitives/alloc-only.txt b/api/primitives/alloc-only.txt
index f6b7bd2d..ea104c4e 100644
--- a/api/primitives/alloc-only.txt
+++ b/api/primitives/alloc-only.txt
@@ -312,10 +312,6 @@ impl core::convert::From<&bitcoin_primitives::transaction::Transaction> for bitc
impl core::convert::From<alloc::vec::Vec<&[u8]>> for bitcoin_primitives::witness::Witness
impl core::convert::From<alloc::vec::Vec<alloc::vec::Vec<u8>>> for bitcoin_primitives::witness::Witness
impl core::convert::From<bitcoin_consensus_encoding::decode::decoders::ByteVecDecoderError> for bitcoin_primitives::script::ScriptBufDecoderError
-impl core::convert::From<bitcoin_consensus_encoding::decode::decoders::UnexpectedEofError> for bitcoin_primitives::block::BlockHashDecoderError
-impl core::convert::From<bitcoin_consensus_encoding::decode::decoders::UnexpectedEofError> for bitcoin_primitives::block::VersionDecoderError
-impl core::convert::From<bitcoin_consensus_encoding::decode::decoders::UnexpectedEofError> for bitcoin_primitives::pow::CompactTargetDecoderError
-impl core::convert::From<bitcoin_consensus_encoding::decode::decoders::UnexpectedEofError> for bitcoin_primitives::transaction::TxMerkleNodeDecoderError
impl core::convert::From<bitcoin_consensus_encoding::decode::decoders::VecDecoderError<bitcoin_primitives::transaction::TxInDecoderError>> for bitcoin_primitives::transaction::TransactionDecoderError
impl core::convert::From<bitcoin_consensus_encoding::decode::decoders::VecDecoderError<bitcoin_primitives::transaction::TxOutDecoderError>> for bitcoin_primitives::transaction::TransactionDecoderError
impl core::convert::From<bitcoin_primitives::block::Block> for bitcoin_primitives::BlockHash
@@ -1308,7 +1304,6 @@ pub fn bitcoin_primitives::block::BlockHashDecoder::read_limit(&self) -> usize
pub fn bitcoin_primitives::block::BlockHashDecoderError::clone(&self) -> bitcoin_primitives::block::BlockHashDecoderError
pub fn bitcoin_primitives::block::BlockHashDecoderError::eq(&self, other: &bitcoin_primitives::block::BlockHashDecoderError) -> bool
pub fn bitcoin_primitives::block::BlockHashDecoderError::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
-pub fn bitcoin_primitives::block::BlockHashDecoderError::from(e: bitcoin_consensus_encoding::decode::decoders::UnexpectedEofError) -> Self
pub fn bitcoin_primitives::block::BlockHashDecoderError::from(never: core::convert::Infallible) -> Self
pub fn bitcoin_primitives::block::BlockHashEncoder::advance(&mut self) -> bool
pub fn bitcoin_primitives::block::BlockHashEncoder::current_chunk(&self) -> &[u8]
@@ -1365,7 +1360,6 @@ pub fn bitcoin_primitives::block::VersionDecoder::read_limit(&self) -> usize
pub fn bitcoin_primitives::block::VersionDecoderError::clone(&self) -> bitcoin_primitives::block::VersionDecoderError
pub fn bitcoin_primitives::block::VersionDecoderError::eq(&self, other: &bitcoin_primitives::block::VersionDecoderError) -> bool
pub fn bitcoin_primitives::block::VersionDecoderError::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
-pub fn bitcoin_primitives::block::VersionDecoderError::from(e: bitcoin_consensus_encoding::decode::decoders::UnexpectedEofError) -> Self
pub fn bitcoin_primitives::block::VersionDecoderError::from(never: core::convert::Infallible) -> Self
pub fn bitcoin_primitives::block::VersionEncoder::advance(&mut self) -> bool
pub fn bitcoin_primitives::block::VersionEncoder::current_chunk(&self) -> &[u8]
@@ -1392,7 +1386,6 @@ pub fn bitcoin_primitives::pow::CompactTargetDecoder::read_limit(&self) -> usize
pub fn bitcoin_primitives::pow::CompactTargetDecoderError::clone(&self) -> bitcoin_primitives::pow::CompactTargetDecoderError
pub fn bitcoin_primitives::pow::CompactTargetDecoderError::eq(&self, other: &bitcoin_primitives::pow::CompactTargetDecoderError) -> bool
pub fn bitcoin_primitives::pow::CompactTargetDecoderError::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
-pub fn bitcoin_primitives::pow::CompactTargetDecoderError::from(e: bitcoin_consensus_encoding::decode::decoders::UnexpectedEofError) -> Self
pub fn bitcoin_primitives::pow::CompactTargetDecoderError::from(never: core::convert::Infallible) -> Self
pub fn bitcoin_primitives::pow::CompactTargetEncoder::advance(&mut self) -> bool
pub fn bitcoin_primitives::pow::CompactTargetEncoder::current_chunk(&self) -> &[u8]
@@ -1597,7 +1590,6 @@ pub fn bitcoin_primitives::transaction::TxMerkleNodeDecoder::read_limit(&self) -
pub fn bitcoin_primitives::transaction::TxMerkleNodeDecoderError::clone(&self) -> bitcoin_primitives::transaction::TxMerkleNodeDecoderError
pub fn bitcoin_primitives::transaction::TxMerkleNodeDecoderError::eq(&self, other: &bitcoin_primitives::transaction::TxMerkleNodeDecoderError) -> bool
pub fn bitcoin_primitives::transaction::TxMerkleNodeDecoderError::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
-pub fn bitcoin_primitives::transaction::TxMerkleNodeDecoderError::from(e: bitcoin_consensus_encoding::decode::decoders::UnexpectedEofError) -> Self
pub fn bitcoin_primitives::transaction::TxMerkleNodeDecoderError::from(never: core::convert::Infallible) -> Self
pub fn bitcoin_primitives::transaction::TxOut::clone(&self) -> bitcoin_primitives::transaction::TxOut
pub fn bitcoin_primitives::transaction::TxOut::cmp(&self, other: &bitcoin_primitives::transaction::TxOut) -> core::cmp::Ordering
diff --git a/api/primitives/no-features.txt b/api/primitives/no-features.txt
index 26e73edd..8736c659 100644
--- a/api/primitives/no-features.txt
+++ b/api/primitives/no-features.txt
@@ -156,10 +156,6 @@ impl core::convert::AsRef<[u8]> for bitcoin_primitives::WitnessCommitment
impl core::convert::AsRef<[u8]> for bitcoin_primitives::WitnessMerkleNode
impl core::convert::AsRef<[u8]> for bitcoin_primitives::Wtxid
impl core::convert::From<&bitcoin_primitives::block::Header> for bitcoin_primitives::BlockHash
-impl core::convert::From<bitcoin_consensus_encoding::decode::decoders::UnexpectedEofError> for bitcoin_primitives::block::BlockHashDecoderError
-impl core::convert::From<bitcoin_consensus_encoding::decode::decoders::UnexpectedEofError> for bitcoin_primitives::block::VersionDecoderError
-impl core::convert::From<bitcoin_consensus_encoding::decode::decoders::UnexpectedEofError> for bitcoin_primitives::pow::CompactTargetDecoderError
-impl core::convert::From<bitcoin_consensus_encoding::decode::decoders::UnexpectedEofError> for bitcoin_primitives::transaction::TxMerkleNodeDecoderError
impl core::convert::From<bitcoin_primitives::block::Header> for bitcoin_primitives::BlockHash
impl core::convert::From<bitcoin_primitives::transaction::Version> for u32
impl core::convert::From<core::convert::Infallible> for bitcoin_primitives::block::BlockHashDecoderError
@@ -584,7 +580,6 @@ pub fn bitcoin_primitives::block::BlockHashDecoder::read_limit(&self) -> usize
pub fn bitcoin_primitives::block::BlockHashDecoderError::clone(&self) -> bitcoin_primitives::block::BlockHashDecoderError
pub fn bitcoin_primitives::block::BlockHashDecoderError::eq(&self, other: &bitcoin_primitives::block::BlockHashDecoderError) -> bool
pub fn bitcoin_primitives::block::BlockHashDecoderError::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
-pub fn bitcoin_primitives::block::BlockHashDecoderError::from(e: bitcoin_consensus_encoding::decode::decoders::UnexpectedEofError) -> Self
pub fn bitcoin_primitives::block::BlockHashDecoderError::from(never: core::convert::Infallible) -> Self
pub fn bitcoin_primitives::block::BlockHashEncoder::advance(&mut self) -> bool
pub fn bitcoin_primitives::block::BlockHashEncoder::current_chunk(&self) -> &[u8]
@@ -617,7 +612,6 @@ pub fn bitcoin_primitives::block::VersionDecoder::read_limit(&self) -> usize
pub fn bitcoin_primitives::block::VersionDecoderError::clone(&self) -> bitcoin_primitives::block::VersionDecoderError
pub fn bitcoin_primitives::block::VersionDecoderError::eq(&self, other: &bitcoin_primitives::block::VersionDecoderError) -> bool
pub fn bitcoin_primitives::block::VersionDecoderError::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
-pub fn bitcoin_primitives::block::VersionDecoderError::from(e: bitcoin_consensus_encoding::decode::decoders::UnexpectedEofError) -> Self
pub fn bitcoin_primitives::block::VersionDecoderError::from(never: core::convert::Infallible) -> Self
pub fn bitcoin_primitives::block::VersionEncoder::advance(&mut self) -> bool
pub fn bitcoin_primitives::block::VersionEncoder::current_chunk(&self) -> &[u8]
@@ -641,7 +635,6 @@ pub fn bitcoin_primitives::pow::CompactTargetDecoder::read_limit(&self) -> usize
pub fn bitcoin_primitives::pow::CompactTargetDecoderError::clone(&self) -> bitcoin_primitives::pow::CompactTargetDecoderError
pub fn bitcoin_primitives::pow::CompactTargetDecoderError::eq(&self, other: &bitcoin_primitives::pow::CompactTargetDecoderError) -> bool
pub fn bitcoin_primitives::pow::CompactTargetDecoderError::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
-pub fn bitcoin_primitives::pow::CompactTargetDecoderError::from(e: bitcoin_consensus_encoding::decode::decoders::UnexpectedEofError) -> Self
pub fn bitcoin_primitives::pow::CompactTargetDecoderError::from(never: core::convert::Infallible) -> Self
pub fn bitcoin_primitives::pow::CompactTargetEncoder::advance(&mut self) -> bool
pub fn bitcoin_primitives::pow::CompactTargetEncoder::current_chunk(&self) -> &[u8]
@@ -671,7 +664,6 @@ pub fn bitcoin_primitives::transaction::TxMerkleNodeDecoder::read_limit(&self) -
pub fn bitcoin_primitives::transaction::TxMerkleNodeDecoderError::clone(&self) -> bitcoin_primitives::transaction::TxMerkleNodeDecoderError
pub fn bitcoin_primitives::transaction::TxMerkleNodeDecoderError::eq(&self, other: &bitcoin_primitives::transaction::TxMerkleNodeDecoderError) -> bool
pub fn bitcoin_primitives::transaction::TxMerkleNodeDecoderError::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
-pub fn bitcoin_primitives::transaction::TxMerkleNodeDecoderError::from(e: bitcoin_consensus_encoding::decode::decoders::UnexpectedEofError) -> Self
pub fn bitcoin_primitives::transaction::TxMerkleNodeDecoderError::from(never: core::convert::Infallible) -> Self
pub fn bitcoin_primitives::transaction::Version::clone(&self) -> bitcoin_primitives::transaction::Version
pub fn bitcoin_primitives::transaction::Version::cmp(&self, other: &bitcoin_primitives::transaction::Version) -> core::cmp::Ordering
diff --git a/primitives/CHANGELOG.md b/primitives/CHANGELOG.md
index 5184c49e..df314f0a 100644
--- a/primitives/CHANGELOG.md
+++ b/primitives/CHANGELOG.md
@@ -1,3 +1,6 @@
+# TBD
+- Remove `From<UnexpectedEof>` for primitive decoder error types [#5606](https://github.com/rust-bitcoin/rust-bitcoin/pull/5606)
+
# 1.0.0 - 2025-10-18
This changelog is a rolling description of everything that will eventually end up in `v1.0`.
diff --git a/primitives/src/block.rs b/primitives/src/block.rs
index 052ac10b..7369f9ee 100644
--- a/primitives/src/block.rs
+++ b/primitives/src/block.rs
@@ -837,12 +837,12 @@ impl encoding::Decoder for VersionDecoder {
#[inline]
fn push_bytes(&mut self, bytes: &mut &[u8]) -> Result<bool, Self::Error> {
- Ok(self.0.push_bytes(bytes)?)
+ self.0.push_bytes(bytes).map_err(VersionDecoderError)
}
#[inline]
fn end(self) -> Result<Self::Output, Self::Error> {
- let n = i32::from_le_bytes(self.0.end()?);
+ let n = i32::from_le_bytes(self.0.end().map_err(VersionDecoderError)?);
Ok(Version::from_consensus(n))
}
@@ -863,10 +863,6 @@ impl From<Infallible> for VersionDecoderError {
fn from(never: Infallible) -> Self { match never {} }
}
-impl From<encoding::UnexpectedEofError> for VersionDecoderError {
- fn from(e: encoding::UnexpectedEofError) -> Self { Self(e) }
-}
-
impl fmt::Display for VersionDecoderError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write_err!(f, "version decoder error"; self.0)
diff --git a/primitives/src/hash_types/block_hash.rs b/primitives/src/hash_types/block_hash.rs
index f92ffa9b..8c313280 100644
--- a/primitives/src/hash_types/block_hash.rs
+++ b/primitives/src/hash_types/block_hash.rs
@@ -59,12 +59,12 @@ impl encoding::Decoder for BlockHashDecoder {
#[inline]
fn push_bytes(&mut self, bytes: &mut &[u8]) -> Result<bool, Self::Error> {
- Ok(self.0.push_bytes(bytes)?)
+ self.0.push_bytes(bytes).map_err(BlockHashDecoderError)
}
#[inline]
fn end(self) -> Result<Self::Output, Self::Error> {
- let a = self.0.end()?;
+ let a = self.0.end().map_err(BlockHashDecoderError)?;
Ok(BlockHash::from_byte_array(a))
}
@@ -85,10 +85,6 @@ impl From<Infallible> for BlockHashDecoderError {
fn from(never: Infallible) -> Self { match never {} }
}
-impl From<encoding::UnexpectedEofError> for BlockHashDecoderError {
- fn from(e: encoding::UnexpectedEofError) -> Self { Self(e) }
-}
-
impl fmt::Display for BlockHashDecoderError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write_err!(f, "sequence decoder error"; self.0)
diff --git a/primitives/src/hash_types/transaction_merkle_node.rs b/primitives/src/hash_types/transaction_merkle_node.rs
index 42e8c485..38e15570 100644
--- a/primitives/src/hash_types/transaction_merkle_node.rs
+++ b/primitives/src/hash_types/transaction_merkle_node.rs
@@ -78,12 +78,12 @@ impl encoding::Decoder for TxMerkleNodeDecoder {
#[inline]
fn push_bytes(&mut self, bytes: &mut &[u8]) -> Result<bool, Self::Error> {
- Ok(self.0.push_bytes(bytes)?)
+ self.0.push_bytes(bytes).map_err(TxMerkleNodeDecoderError)
}
#[inline]
fn end(self) -> Result<Self::Output, Self::Error> {
- let a = self.0.end()?;
+ let a = self.0.end().map_err(TxMerkleNodeDecoderError)?;
Ok(TxMerkleNode::from_byte_array(a))
}
@@ -104,10 +104,6 @@ impl From<Infallible> for TxMerkleNodeDecoderError {
fn from(never: Infallible) -> Self { match never {} }
}
-impl From<encoding::UnexpectedEofError> for TxMerkleNodeDecoderError {
- fn from(e: encoding::UnexpectedEofError) -> Self { Self(e) }
-}
-
impl fmt::Display for TxMerkleNodeDecoderError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write_err!(f, "sequence decoder error"; self.0)
diff --git a/primitives/src/hash_types/witness_merkle_node.rs b/primitives/src/hash_types/witness_merkle_node.rs
index 7cc59e5b..7e25fc56 100644
--- a/primitives/src/hash_types/witness_merkle_node.rs
+++ b/primitives/src/hash_types/witness_merkle_node.rs
@@ -80,12 +80,12 @@ impl encoding::Decoder for WitnessMerkleNodeDecoder {
#[inline]
fn push_bytes(&mut self, bytes: &mut &[u8]) -> Result<bool, Self::Error> {
- Ok(self.0.push_bytes(bytes)?)
+ self.0.push_bytes(bytes).map_err(WitnessMerkleNodeDecoderError)
}
#[inline]
fn end(self) -> Result<Self::Output, Self::Error> {
- let a = self.0.end()?;
+ let a = self.0.end().map_err(WitnessMerkleNodeDecoderError)?;
Ok(WitnessMerkleNode::from_byte_array(a))
}
@@ -106,10 +106,6 @@ impl From<Infallible> for WitnessMerkleNodeDecoderError {
fn from(never: Infallible) -> Self { match never {} }
}
-impl From<encoding::UnexpectedEofError> for WitnessMerkleNodeDecoderError {
- fn from(e: encoding::UnexpectedEofError) -> Self { Self(e) }
-}
-
impl fmt::Display for WitnessMerkleNodeDecoderError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write_err!(f, "sequence decoder error"; self.0)
diff --git a/primitives/src/pow.rs b/primitives/src/pow.rs
index a7f1c813..1f7ce3c5 100644
--- a/primitives/src/pow.rs
+++ b/primitives/src/pow.rs
@@ -83,12 +83,12 @@ impl encoding::Decoder for CompactTargetDecoder {
#[inline]
fn push_bytes(&mut self, bytes: &mut &[u8]) -> Result<bool, Self::Error> {
- Ok(self.0.push_bytes(bytes)?)
+ self.0.push_bytes(bytes).map_err(CompactTargetDecoderError)
}
#[inline]
fn end(self) -> Result<Self::Output, Self::Error> {
- let n = u32::from_le_bytes(self.0.end()?);
+ let n = u32::from_le_bytes(self.0.end().map_err(CompactTargetDecoderError)?);
Ok(CompactTarget::from_consensus(n))
}
@@ -109,10 +109,6 @@ impl From<Infallible> for CompactTargetDecoderError {
fn from(never: Infallible) -> Self { match never {} }
}
-impl From<encoding::UnexpectedEofError> for CompactTargetDecoderError {
- fn from(e: encoding::UnexpectedEofError) -> Self { Self(e) }
-}
-
impl fmt::Display for CompactTargetDecoderError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write_err!(f, "sequence decoder error"; self.0)
Why this scored 17/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.