1use std::fmt;
8
9#[derive(Debug)]
27pub enum VCLError {
28 CryptoError(String),
30 SignatureInvalid,
32 InvalidKey(String),
34 ChainValidationFailed,
36 ReplayDetected(String),
38 InvalidPacket(String),
40 ConnectionClosed,
42 Timeout,
44 NoPeerAddress,
46 NoSharedSecret,
48 HandshakeFailed(String),
50 ExpectedClientHello,
52 ExpectedServerHello,
54 SerializationError(String),
56 IoError(String),
58}
59
60impl fmt::Display for VCLError {
61 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
62 match self {
63 VCLError::CryptoError(msg) => write!(f, "Crypto error: {}", msg),
64 VCLError::SignatureInvalid => write!(f, "Signature validation failed"),
65 VCLError::InvalidKey(msg) => write!(f, "Invalid key: {}", msg),
66 VCLError::ChainValidationFailed => write!(f, "Chain validation failed"),
67 VCLError::ReplayDetected(msg) => write!(f, "Replay detected: {}", msg),
68 VCLError::InvalidPacket(msg) => write!(f, "Invalid packet: {}", msg),
69 VCLError::ConnectionClosed => write!(f, "Connection closed"),
70 VCLError::Timeout => write!(f, "Connection timeout"),
71 VCLError::NoPeerAddress => write!(f, "No peer address"),
72 VCLError::NoSharedSecret => write!(f, "No shared secret"),
73 VCLError::HandshakeFailed(msg) => write!(f, "Handshake failed: {}", msg),
74 VCLError::ExpectedClientHello => write!(f, "Expected ClientHello"),
75 VCLError::ExpectedServerHello => write!(f, "Expected ServerHello"),
76 VCLError::SerializationError(msg) => write!(f, "Serialization error: {}", msg),
77 VCLError::IoError(msg) => write!(f, "IO error: {}", msg),
78 }
79 }
80}
81
82impl std::error::Error for VCLError {}
83
84impl From<std::io::Error> for VCLError {
85 fn from(err: std::io::Error) -> Self {
86 VCLError::IoError(err.to_string())
87 }
88}
89
90impl From<bincode::Error> for VCLError {
91 fn from(err: bincode::Error) -> Self {
92 VCLError::SerializationError(err.to_string())
93 }
94}
95
96impl From<std::net::AddrParseError> for VCLError {
97 fn from(err: std::net::AddrParseError) -> Self {
98 VCLError::IoError(err.to_string())
99 }
100}
101
102impl From<VCLError> for String {
103 fn from(err: VCLError) -> Self {
104 err.to_string()
105 }
106}