1use crate::CommandReply;
2use std::io;
3use thiserror::Error;
4
5#[derive(Debug, Error)]
7pub enum Error {
8 #[error("Invalid version: {0}")]
10 InvalidVersion(u8),
11
12 #[error("Too many methods")]
14 TooManyMethods,
15
16 #[error("Invalid handshake")]
18 InvalidHandshake,
19
20 #[error("Invalid command: {0}")]
22 InvalidCommand(u8),
23
24 #[error("Invalid command reply: {0}")]
26 InvalidCommandReply(u8),
27
28 #[error("Command reply with error: {0:?}")]
30 CommandReply(CommandReply),
31
32 #[error("Domain too long {0}")]
34 DomainTooLong(usize),
35
36 #[error("Invalid domain {0:?}")]
38 InvalidDomain(Vec<u8>),
39
40 #[error("Invalid address type {0}")]
42 InvalidAddressType(u8),
43
44 #[error("IO error: {0:?}")]
46 Io(#[from] io::Error),
47}
48
49pub type Result<T, E = Error> = ::std::result::Result<T, E>;
51
52impl Error {
53 pub fn to_io_err(self) -> io::Error {
55 match self {
56 Error::Io(e) => e,
57 e => io::Error::new(io::ErrorKind::Other, e),
58 }
59 }
60}