diff --git a/rustls/src/conn.rs b/rustls/src/conn.rs index 6968cae7..0cff1855 100644 --- a/rustls/src/conn.rs +++ b/rustls/src/conn.rs @@ -892,7 +892,7 @@ impl ConnectionCore { Err(err) => { return Err(self .common_state - .send_fatal_alert(AlertDescription::DecodeError, err)); + .send_fatal_alert(err.into(), err)); } }; diff --git a/rustls/src/error.rs b/rustls/src/error.rs index a8f77ead..20803b78 100644 --- a/rustls/src/error.rs +++ b/rustls/src/error.rs @@ -162,6 +162,15 @@ impl From for Error { } } +impl From for AlertDescription { + fn from(e: InvalidMessage) -> Self { + match e { + InvalidMessage::PreSharedKeyIsNotFinalExtension => Self::IllegalParameter, + _ => Self::DecodeError, + } + } +} + #[non_exhaustive] #[allow(missing_docs)] #[derive(Debug, PartialEq, Clone)] diff --git a/rustls/src/msgs/message/mod.rs b/rustls/src/msgs/message/mod.rs index c37b9868..c091aa98 100644 --- a/rustls/src/msgs/message/mod.rs +++ b/rustls/src/msgs/message/mod.rs @@ -1,5 +1,5 @@ use crate::enums::{AlertDescription, ContentType, HandshakeType, ProtocolVersion}; -use crate::error::{Error, InvalidMessage}; +use crate::error::InvalidMessage; use crate::msgs::alert::AlertMessagePayload; use crate::msgs::base::Payload; use crate::msgs::ccs::ChangeCipherSpecPayload; @@ -190,7 +190,7 @@ impl Message<'_> { } impl TryFrom for Message<'static> { - type Error = Error; + type Error = InvalidMessage; fn try_from(plain: PlainMessage) -> Result { Ok(Self { @@ -206,7 +206,7 @@ impl TryFrom for Message<'static> { /// A [`PlainMessage`] must contain plaintext content. Encrypted content should be stored in an /// [`InboundOpaqueMessage`] and decrypted before being stored into a [`PlainMessage`]. impl<'a> TryFrom> for Message<'a> { - type Error = Error; + type Error = InvalidMessage; fn try_from(plain: InboundPlainMessage<'a>) -> Result { Ok(Self {