mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-05-24 00:21:20 +00:00
feat: properly encapsulate quick_protobuf::Error
I noticed that we also still leak that dependency in several crates by providing a `From` impl so I've removed that one as well. Resolves #3534. Pull-Request: #3894.
This commit is contained in:
parent
6985d72462
commit
1bf6264cbe
@ -47,8 +47,6 @@ mod proto {
|
||||
|
||||
/// Multi-address re-export.
|
||||
pub use multiaddr;
|
||||
use std::fmt;
|
||||
use std::fmt::Formatter;
|
||||
pub type Negotiated<T> = multistream_select::Negotiated<T>;
|
||||
|
||||
#[deprecated(since = "0.39.0", note = "Depend on `libp2p-identity` instead.")]
|
||||
@ -130,16 +128,5 @@ pub use transport::Transport;
|
||||
pub use upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeError, UpgradeInfo};
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub struct DecodeError(String);
|
||||
|
||||
impl From<quick_protobuf::Error> for DecodeError {
|
||||
fn from(e: quick_protobuf::Error) -> Self {
|
||||
Self(e.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for DecodeError {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{}", self.0)
|
||||
}
|
||||
}
|
||||
#[error(transparent)]
|
||||
pub struct DecodeError(quick_protobuf::Error);
|
||||
|
@ -36,8 +36,7 @@ impl PeerRecord {
|
||||
let (payload, signing_key) =
|
||||
envelope.payload_and_signing_key(String::from(DOMAIN_SEP), PAYLOAD_TYPE.as_bytes())?;
|
||||
let mut reader = BytesReader::from_bytes(payload);
|
||||
let record =
|
||||
proto::PeerRecord::from_reader(&mut reader, payload).map_err(DecodeError::from)?;
|
||||
let record = proto::PeerRecord::from_reader(&mut reader, payload).map_err(DecodeError)?;
|
||||
|
||||
let peer_id = PeerId::from_bytes(&record.peer_id)?;
|
||||
|
||||
|
@ -97,8 +97,7 @@ impl SignedEnvelope {
|
||||
use quick_protobuf::MessageRead;
|
||||
|
||||
let mut reader = BytesReader::from_bytes(bytes);
|
||||
let envelope =
|
||||
proto::Envelope::from_reader(&mut reader, bytes).map_err(DecodeError::from)?;
|
||||
let envelope = proto::Envelope::from_reader(&mut reader, bytes).map_err(DecodeError)?;
|
||||
|
||||
Ok(Self {
|
||||
key: PublicKey::try_decode_protobuf(&envelope.public_key)?,
|
||||
|
@ -28,7 +28,7 @@ mod proto {
|
||||
|
||||
use crate::io::{framed::NoiseFramed, Output};
|
||||
use crate::protocol::{KeypairIdentity, STATIC_KEY_DOMAIN};
|
||||
use crate::Error;
|
||||
use crate::{DecodeError, Error};
|
||||
use bytes::Bytes;
|
||||
use futures::prelude::*;
|
||||
use libp2p_identity as identity;
|
||||
@ -140,7 +140,8 @@ where
|
||||
{
|
||||
let msg = recv(state).await?;
|
||||
let mut reader = BytesReader::from_bytes(&msg[..]);
|
||||
let pb = proto::NoiseHandshakePayload::from_reader(&mut reader, &msg[..])?;
|
||||
let pb =
|
||||
proto::NoiseHandshakePayload::from_reader(&mut reader, &msg[..]).map_err(DecodeError)?;
|
||||
|
||||
state.id_remote_pubkey = Some(identity::PublicKey::try_decode_protobuf(&pb.identity_key)?);
|
||||
|
||||
|
@ -69,8 +69,6 @@ use libp2p_core::{InboundUpgrade, OutboundUpgrade, UpgradeInfo};
|
||||
use libp2p_identity as identity;
|
||||
use libp2p_identity::PeerId;
|
||||
use snow::params::NoiseParams;
|
||||
use std::fmt;
|
||||
use std::fmt::Formatter;
|
||||
use std::pin::Pin;
|
||||
|
||||
/// The configuration for the noise handshake.
|
||||
@ -211,29 +209,12 @@ pub enum Error {
|
||||
BadSignature,
|
||||
#[error("Authentication failed")]
|
||||
AuthenticationFailed,
|
||||
#[error(transparent)]
|
||||
InvalidPayload(DecodeError),
|
||||
#[error("failed to decode protobuf ")]
|
||||
InvalidPayload(#[from] DecodeError),
|
||||
#[error(transparent)]
|
||||
SigningError(#[from] libp2p_identity::SigningError),
|
||||
}
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub struct DecodeError(String);
|
||||
|
||||
impl fmt::Display for DecodeError {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{}", self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<quick_protobuf::Error> for DecodeError {
|
||||
fn from(e: quick_protobuf::Error) -> Self {
|
||||
Self(e.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<quick_protobuf::Error> for Error {
|
||||
fn from(e: quick_protobuf::Error) -> Self {
|
||||
Error::InvalidPayload(e.into())
|
||||
}
|
||||
}
|
||||
#[error(transparent)]
|
||||
pub struct DecodeError(quick_protobuf::Error);
|
||||
|
@ -41,7 +41,7 @@ pub enum PlainTextError {
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct DecodeError(quick_protobuf::Error);
|
||||
pub struct DecodeError(pub(crate) quick_protobuf::Error);
|
||||
|
||||
impl fmt::Display for DecodeError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
@ -87,9 +87,9 @@ impl From<IoError> for PlainTextError {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<quick_protobuf::Error> for PlainTextError {
|
||||
fn from(err: quick_protobuf::Error) -> PlainTextError {
|
||||
PlainTextError::InvalidPayload(DecodeError(err))
|
||||
impl From<DecodeError> for PlainTextError {
|
||||
fn from(err: DecodeError) -> PlainTextError {
|
||||
PlainTextError::InvalidPayload(err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
use crate::error::PlainTextError;
|
||||
use crate::error::{DecodeError, PlainTextError};
|
||||
use crate::proto::Exchange;
|
||||
use crate::PlainText2Config;
|
||||
|
||||
@ -74,7 +74,7 @@ impl HandshakeContext<Local> {
|
||||
exchange_bytes: BytesMut,
|
||||
) -> Result<HandshakeContext<Remote>, PlainTextError> {
|
||||
let mut reader = BytesReader::from_bytes(&exchange_bytes);
|
||||
let prop = Exchange::from_reader(&mut reader, &exchange_bytes)?;
|
||||
let prop = Exchange::from_reader(&mut reader, &exchange_bytes).map_err(DecodeError)?;
|
||||
|
||||
let public_key = PublicKey::try_decode_protobuf(&prop.pubkey.unwrap_or_default())?;
|
||||
let peer_id = PeerId::from_bytes(&prop.id.unwrap_or_default())?;
|
||||
|
Loading…
x
Reference in New Issue
Block a user