hyper_util/client/legacy/connect/proxy/socks/v5/
errors.rs

1use super::Status;
2
3#[derive(Debug)]
4pub enum SocksV5Error {
5    HostTooLong,
6    Auth(AuthError),
7    Command(Status),
8}
9
10#[derive(Debug)]
11pub enum AuthError {
12    Unsupported,
13    MethodMismatch,
14    Failed,
15}
16
17impl From<Status> for SocksV5Error {
18    fn from(err: Status) -> Self {
19        Self::Command(err)
20    }
21}
22
23impl From<AuthError> for SocksV5Error {
24    fn from(err: AuthError) -> Self {
25        Self::Auth(err)
26    }
27}
28
29impl std::fmt::Display for SocksV5Error {
30    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
31        match self {
32            Self::HostTooLong => f.write_str("host address is more than 255 characters"),
33            Self::Command(e) => e.fmt(f),
34            Self::Auth(e) => e.fmt(f),
35        }
36    }
37}
38
39impl std::fmt::Display for AuthError {
40    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
41        f.write_str(match self {
42            Self::Unsupported => "server does not support user/pass authentication",
43            Self::MethodMismatch => "server implements authentication incorrectly",
44            Self::Failed => "credentials not accepted",
45        })
46    }
47}