1 use std::array::TryFromSliceError; 2 use std::string::FromUtf8Error; 3 use std::time::SystemTimeError; 4 use std::{fmt, num}; 5 6 use tokio::sync::mpsc::error::SendError; 7 8 use url::ParseError; 9 10 #[derive(Default, Debug, Clone, PartialEq)] 11 pub struct Error { 12 message: String, 13 } 14 15 impl fmt::Display for Error { 16 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { 17 write!(f, "{}", self.message) 18 } 19 } 20 21 impl std::error::Error for Error { 22 fn description(&self) -> &str { 23 &self.message 24 } 25 } 26 27 impl From<std::io::Error> for Error { 28 fn from(error: std::io::Error) -> Self { 29 Error { 30 message: error.to_string(), 31 } 32 } 33 } 34 35 impl From<num::ParseIntError> for Error { 36 fn from(error: num::ParseIntError) -> Self { 37 Error { 38 message: error.to_string(), 39 } 40 } 41 } 42 43 impl From<ParseError> for Error { 44 fn from(error: ParseError) -> Self { 45 Error { 46 message: error.to_string(), 47 } 48 } 49 } 50 51 impl From<FromUtf8Error> for Error { 52 fn from(error: FromUtf8Error) -> Self { 53 Error { 54 message: error.to_string(), 55 } 56 } 57 } 58 59 impl From<TryFromSliceError> for Error { 60 fn from(error: TryFromSliceError) -> Self { 61 Error { 62 message: error.to_string(), 63 } 64 } 65 } 66 67 impl From<SystemTimeError> for Error { 68 fn from(error: SystemTimeError) -> Self { 69 Error { 70 message: error.to_string(), 71 } 72 } 73 } 74 75 impl<T> From<SendError<T>> for Error { 76 fn from(error: SendError<T>) -> Self { 77 Error { 78 message: error.to_string(), 79 } 80 } 81 } 82 83 impl From<aes_gcm::Error> for Error { 84 fn from(error: aes_gcm::Error) -> Self { 85 Error { 86 message: error.to_string(), 87 } 88 } 89 } 90 91 impl From<hmac::crypto_mac::InvalidKeyLength> for Error { 92 fn from(error: hmac::crypto_mac::InvalidKeyLength) -> Self { 93 Error { 94 message: error.to_string(), 95 } 96 } 97 } 98 99 impl From<p256::elliptic_curve::Error> for Error { 100 fn from(error: p256::elliptic_curve::Error) -> Self { 101 Error { 102 message: error.to_string(), 103 } 104 } 105 } 106 107 impl From<block_modes::InvalidKeyIvLength> for Error { 108 fn from(error: block_modes::InvalidKeyIvLength) -> Self { 109 Error { 110 message: error.to_string(), 111 } 112 } 113 } 114 impl From<block_modes::BlockModeError> for Error { 115 fn from(error: block_modes::BlockModeError) -> Self { 116 Error { 117 message: error.to_string(), 118 } 119 } 120 } 121 122 impl From<der_parser::nom::Err<x509_parser::error::X509Error>> for Error { 123 fn from(error: der_parser::nom::Err<x509_parser::error::X509Error>) -> Self { 124 Error { 125 message: error.to_string(), 126 } 127 } 128 } 129 130 impl From<x509_parser::error::X509Error> for Error { 131 fn from(error: x509_parser::error::X509Error) -> Self { 132 Error { 133 message: error.to_string(), 134 } 135 } 136 } 137 138 impl From<rcgen::RcgenError> for Error { 139 fn from(error: rcgen::RcgenError) -> Self { 140 Error { 141 message: error.to_string(), 142 } 143 } 144 } 145 146 impl From<ring::error::KeyRejected> for Error { 147 fn from(error: ring::error::KeyRejected) -> Self { 148 Error { 149 message: error.to_string(), 150 } 151 } 152 } 153 154 impl From<ring::error::Unspecified> for Error { 155 fn from(error: ring::error::Unspecified) -> Self { 156 Error { 157 message: error.to_string(), 158 } 159 } 160 } 161 162 impl Error { 163 pub fn new(message: String) -> Self { 164 Error { message } 165 } 166 } 167