1use std::io;
2
3use thiserror::Error;
4use tokio::sync::mpsc::error::SendError as MpscSendError;
5
6pub type Result<T> = std::result::Result<T, Error>;
7
8#[derive(Error, Debug, PartialEq)]
9#[non_exhaustive]
10pub enum Error {
11 #[error("duplicated packet")]
12 ErrDuplicated,
13 #[error("SRTP master key is not long enough")]
14 ErrShortSrtpMasterKey,
15 #[error("SRTP master salt is not long enough")]
16 ErrShortSrtpMasterSalt,
17 #[error("no such SRTP Profile")]
18 ErrNoSuchSrtpProfile,
19 #[error("indexOverKdr > 0 is not supported yet")]
20 ErrNonZeroKdrNotSupported,
21 #[error("exporter called with wrong label")]
22 ErrExporterWrongLabel,
23 #[error("no config provided")]
24 ErrNoConfig,
25 #[error("no conn provided")]
26 ErrNoConn,
27 #[error("failed to verify auth tag")]
28 ErrFailedToVerifyAuthTag,
29 #[error("packet is too short to be RTP packet")]
30 ErrTooShortRtp,
31 #[error("packet is too short to be RTCP packet")]
32 ErrTooShortRtcp,
33 #[error("payload differs")]
34 ErrPayloadDiffers,
35 #[error("started channel used incorrectly, should only be closed")]
36 ErrStartedChannelUsedIncorrectly,
37 #[error("exceeded the maximum number of packets")]
38 ErrExceededMaxPackets,
39
40 #[error("stream has not been inited, unable to close")]
41 ErrStreamNotInited,
42 #[error("stream is already closed")]
43 ErrStreamAlreadyClosed,
44 #[error("stream is already inited")]
45 ErrStreamAlreadyInited,
46 #[error("failed to cast child")]
47 ErrFailedTypeAssertion,
48
49 #[error("index_over_kdr > 0 is not supported yet")]
50 UnsupportedIndexOverKdr,
51 #[error("invalid master key length for aes_256_cm")]
52 InvalidMasterKeyLength,
53 #[error("invalid master salt length for aes_256_cm")]
54 InvalidMasterSaltLength,
55 #[error("out_len > 32 is not supported for aes_256_cm")]
56 UnsupportedOutLength,
57 #[error("SRTP Master Key must be len {0}, got {1}")]
58 SrtpMasterKeyLength(usize, usize),
59 #[error("SRTP Salt must be len {0}, got {1}")]
60 SrtpSaltLength(usize, usize),
61 #[error("SyntaxError: {0}")]
62 ExtMapParse(String),
63 #[error("srtp ssrc={0} index={1}: duplicated")]
64 SrtpSsrcDuplicated(u32, u16),
65 #[error("srtcp ssrc={0} index={1}: duplicated")]
66 SrtcpSsrcDuplicated(u32, usize),
67 #[error("ssrc {0} not exist in srtcp_ssrc_state")]
68 SsrcMissingFromSrtcp(u32),
69 #[error("Stream with ssrc {0} exists")]
70 StreamWithSsrcExists(u32),
71 #[error("Session RTP/RTCP type must be same as input buffer")]
72 SessionRtpRtcpTypeMismatch,
73 #[error("Session EOF")]
74 SessionEof,
75 #[error("too short SRTP packet: only {0} bytes, expected > {1} bytes")]
76 SrtpTooSmall(usize, usize),
77 #[error("too short SRTCP packet: only {0} bytes, expected > {1} bytes")]
78 SrtcpTooSmall(usize, usize),
79 #[error("failed to verify rtp auth tag")]
80 RtpFailedToVerifyAuthTag,
81 #[error("too short auth tag: only {0} bytes, expected > {1} bytes")]
82 RtcpInvalidLengthAuthTag(usize, usize),
83 #[error("failed to verify rtcp auth tag")]
84 RtcpFailedToVerifyAuthTag,
85 #[error("SessionSRTP has been closed")]
86 SessionSrtpAlreadyClosed,
87 #[error("this stream is not a RTPStream")]
88 InvalidRtpStream,
89 #[error("this stream is not a RTCPStream")]
90 InvalidRtcpStream,
91
92 #[error("{0}")]
93 Io(#[source] IoError),
94 #[error("{0}")]
95 KeyingMaterial(#[from] util::KeyingMaterialExporterError),
96 #[error("mpsc send: {0}")]
97 MpscSend(String),
98 #[error("{0}")]
99 Util(#[from] util::Error),
100 #[error("{0}")]
101 Rtcp(#[from] rtcp::Error),
102 #[error("aes gcm: {0}")]
103 AesGcm(#[from] aes_gcm::Error),
104
105 #[error("{0}")]
106 Other(String),
107}
108
109#[derive(Debug, Error)]
110#[error("io error: {0}")]
111pub struct IoError(#[from] pub io::Error);
112
113impl PartialEq for IoError {
115 fn eq(&self, other: &Self) -> bool {
116 self.0.kind() == other.0.kind()
117 }
118}
119
120impl From<io::Error> for Error {
121 fn from(e: io::Error) -> Self {
122 Error::Io(IoError(e))
123 }
124}
125
126impl<T> From<MpscSendError<T>> for Error {
128 fn from(e: MpscSendError<T>) -> Self {
129 Error::MpscSend(e.to_string())
130 }
131}