Skip to content
File

Blob: firmware/vendor/str0m/src/rtp/error.rs

rust50 lines
1use crate::crypto::CryptoError;
2use std::error::Error;
3use std::fmt;
4use std::io;
5 
6/// Errors from parsing and decrypting RTP.
7#[derive(Debug)]
8pub 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 
19impl 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 
29impl 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 
39impl From<io::Error> for RtpError {
40 fn from(err: io::Error) -> Self {
41 RtpError::Io(err)
42 }
43}
44 
45impl From<CryptoError> for RtpError {
46 fn from(err: CryptoError) -> Self {
47 RtpError::CryptoError(err)
48 }
49}