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