Allow customisation of alert sent for InvalidMessage

Use this to send the correct alert for InvalidMessage::PreSharedKeyIsNotFinalExtension
This commit is contained in:
Joseph Birr-Pixton 2023-09-14 16:21:17 +01:00
parent 823e46c1b0
commit dc957ece89
3 changed files with 13 additions and 4 deletions

View File

@ -892,7 +892,7 @@ impl<Data> ConnectionCore<Data> {
Err(err) => {
return Err(self
.common_state
.send_fatal_alert(AlertDescription::DecodeError, err));
.send_fatal_alert(err.into(), err));
}
};

View File

@ -162,6 +162,15 @@ impl From<InvalidMessage> for Error {
}
}
impl From<InvalidMessage> for AlertDescription {
fn from(e: InvalidMessage) -> Self {
match e {
InvalidMessage::PreSharedKeyIsNotFinalExtension => Self::IllegalParameter,
_ => Self::DecodeError,
}
}
}
#[non_exhaustive]
#[allow(missing_docs)]
#[derive(Debug, PartialEq, Clone)]

View File

@ -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<PlainMessage> for Message<'static> {
type Error = Error;
type Error = InvalidMessage;
fn try_from(plain: PlainMessage) -> Result<Self, Self::Error> {
Ok(Self {
@ -206,7 +206,7 @@ impl TryFrom<PlainMessage> 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<InboundPlainMessage<'a>> for Message<'a> {
type Error = Error;
type Error = InvalidMessage;
fn try_from(plain: InboundPlainMessage<'a>) -> Result<Self, Self::Error> {
Ok(Self {