1#[derive(Debug, thiserror::Error)]
3pub enum Error {
4 #[error("{0}")]
5 Io(#[from] std::io::Error),
6
7 #[error("{0}")]
8 FromUtf8(#[from] std::string::FromUtf8Error),
9
10 #[error("Invalid SOCKS version: {0:x}")]
11 InvalidVersion(u8),
12 #[error("Invalid command: {0:x}")]
13 InvalidCommand(u8),
14 #[error("Invalid address type: {0:x}")]
15 InvalidAtyp(u8),
16 #[error("Invalid reserved bytes: {0:x}")]
17 InvalidReserved(u8),
18 #[error("Invalid authentication status: {0:x}")]
19 InvalidAuthStatus(u8),
20 #[error("Invalid authentication version of subnegotiation: {0:x}")]
21 InvalidAuthSubnegotiation(u8),
22 #[error("Invalid fragment id: {0:x}")]
23 InvalidFragmentId(u8),
24
25 #[error("Invalid authentication method: {0:?}")]
26 InvalidAuthMethod(crate::protocol::AuthMethod),
27
28 #[error("SOCKS version is 4 when 5 is expected")]
29 WrongVersion,
30
31 #[error("AddrParseError: {0}")]
32 AddrParseError(#[from] std::net::AddrParseError),
33
34 #[error("ParseIntError: {0}")]
35 ParseIntError(#[from] std::num::ParseIntError),
36
37 #[error("Utf8Error: {0}")]
38 Utf8Error(#[from] std::str::Utf8Error),
39
40 #[error("Invalid address: {0}")]
41 InvalidAddress(String),
42
43 #[error("Domain name too long: {0}")]
44 DomainTooLong(usize),
45
46 #[error("{0}")]
47 String(String),
48}
49
50impl From<&str> for Error {
51 fn from(s: &str) -> Self {
52 Error::String(s.to_string())
53 }
54}
55
56impl From<String> for Error {
57 fn from(s: String) -> Self {
58 Error::String(s)
59 }
60}
61
62impl From<&String> for Error {
63 fn from(s: &String) -> Self {
64 Error::String(s.to_string())
65 }
66}
67
68impl From<Error> for std::io::Error {
69 fn from(e: Error) -> Self {
70 match e {
71 Error::Io(e) => e,
72 _ => std::io::Error::other(e),
73 }
74 }
75}
76
77#[cfg(feature = "tokio")]
78impl From<tokio::time::error::Elapsed> for Error {
79 fn from(e: tokio::time::error::Elapsed) -> Self {
80 Error::Io(e.into())
81 }
82}
83
84pub type Result<T, E = Error> = std::result::Result<T, E>;