File
Blob: firmware/vendor/str0m/src/rtp/error.rs
| 1 | use crate::crypto::CryptoError; |
| 2 | use std::error::Error; |
| 3 | use std::fmt; |
| 4 | use std::io; |
| 5 | |
| 6 | /// Errors from parsing and decrypting RTP. |
| 7 | #[derive(Debug)] |
| 8 | pub enum RtpError { |
| 9 | /// Error arising in the crypto |
| 10 | CryptoError(CryptoError), |
| 11 | |
| 12 | /// Other io error |
| 13 | Io(io::Error), |
| 14 | |
| 15 | /// Failed to parse RTP header. |
| 16 | ParseHeader, |
| 17 | } |
| 18 | |
| 19 | impl fmt::Display for RtpError { |
| 20 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 21 | match self { |
| 22 | RtpError::CryptoError(err) => write!(f, "{}", err), |
| 23 | RtpError::Io(err) => write!(f, "{}", err), |
| 24 | RtpError::ParseHeader => write!(f, "Failed to parse RTP header"), |
| 25 | } |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | impl Error for RtpError { |
| 30 | fn source(&self) -> Option<&(dyn Error + 'static)> { |
| 31 | match self { |
| 32 | RtpError::CryptoError(err) => Some(err), |
| 33 | RtpError::Io(err) => Some(err), |
| 34 | _ => None, |
| 35 | } |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | impl From<io::Error> for RtpError { |
| 40 | fn from(err: io::Error) -> Self { |
| 41 | RtpError::Io(err) |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | impl From<CryptoError> for RtpError { |
| 46 | fn from(err: CryptoError) -> Self { |
| 47 | RtpError::CryptoError(err) |
| 48 | } |
| 49 | } |