Skip to content

Commit

Permalink
improve ecies error fatal types
Browse files Browse the repository at this point in the history
  • Loading branch information
caglaryucekaya committed Sep 27, 2024
1 parent 5b585eb commit 59382a4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
5 changes: 5 additions & 0 deletions crates/net/ecies/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ impl ECIESError {
pub fn into_inner(self) -> ECIESErrorImpl {
*self.inner
}

/// Returns a reference to the inner error
pub const fn inner(&self) -> &ECIESErrorImpl {
&self.inner
}
}

impl fmt::Display for ECIESError {
Expand Down
15 changes: 14 additions & 1 deletion crates/net/network/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use std::{fmt, io, io::ErrorKind, net::SocketAddr};

use reth_dns_discovery::resolver::ResolveError;
use reth_ecies::ECIESErrorImpl;
use reth_eth_wire::{
errors::{EthHandshakeError, EthStreamError, P2PHandshakeError, P2PStreamError},
DisconnectReason,
Expand Down Expand Up @@ -214,7 +215,19 @@ impl SessionError for PendingSessionHandshakeError {
fn is_fatal_protocol_error(&self) -> bool {
match self {
Self::Eth(eth) => eth.is_fatal_protocol_error(),
Self::Ecies(_) => true,
Self::Ecies(err) => matches!(
err.inner(),
ECIESErrorImpl::TagCheckDecryptFailed |
ECIESErrorImpl::TagCheckHeaderFailed |
ECIESErrorImpl::TagCheckBodyFailed |
ECIESErrorImpl::InvalidAuthData |
ECIESErrorImpl::InvalidAckData |
ECIESErrorImpl::InvalidHeader |
ECIESErrorImpl::Secp256k1(_) |
ECIESErrorImpl::InvalidHandshake { .. } |
ECIESErrorImpl::UnreadableStream |
ECIESErrorImpl::StreamTimeout
),
Self::Timeout => false,
}
}
Expand Down

0 comments on commit 59382a4

Please sign in to comment.