1use sctp_proto::Error as ProtoError;
2use std::error::Error;
3use std::fmt;
4
5#[derive(Debug, Eq, Clone, PartialEq)]
7pub enum SctpError {
8 Proto(ProtoError),
10
11 WriteBeforeEstablished,
13
14 DcepOpenTooSmall,
16
17 DcepIncorrectMessageType,
19
20 DcepBadUtf8,
22
23 InvalidSnap,
25}
26
27impl fmt::Display for SctpError {
28 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
29 match self {
30 SctpError::Proto(err) => write!(f, "{}", err),
31 SctpError::WriteBeforeEstablished => {
32 write!(f, "Write on a stream before it was established")
33 }
34 SctpError::DcepOpenTooSmall => write!(f, "DCEP open message too small"),
35 SctpError::DcepIncorrectMessageType => write!(f, "DCEP incorrect message type"),
36 SctpError::DcepBadUtf8 => write!(f, "DCEP bad UTF-8 string"),
37 SctpError::InvalidSnap => write!(f, "Invalid SNAP token"),
38 }
39 }
40}
41
42impl Error for SctpError {
43 fn source(&self) -> Option<&(dyn Error + 'static)> {
44 match self {
45 SctpError::Proto(err) => Some(err),
46 _ => None,
47 }
48 }
49}
50
51impl From<ProtoError> for SctpError {
52 fn from(err: ProtoError) -> Self {
53 SctpError::Proto(err)
54 }
55}