use crate::pki::EpfPkiCertificateValidationError; use std::error::Error; use std::fmt::{Display, Formatter}; #[derive(Debug)] pub enum EpfHandshakeError { AlreadyTunnelled, UnsupportedProtocolVersion(usize), InvalidCertificate(EpfPkiCertificateValidationError), UntrustedCertificate, EncryptionError, MissingKeyProof, } impl Display for EpfHandshakeError { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { match self { EpfHandshakeError::AlreadyTunnelled => write!(f, "Already tunneled"), EpfHandshakeError::UnsupportedProtocolVersion(v) => { write!(f, "Unsupported protocol version {}", v) } EpfHandshakeError::InvalidCertificate(e) => write!(f, "Invalid certificate: {}", e), EpfHandshakeError::UntrustedCertificate => { write!(f, "Certificate valid but not trusted") } EpfHandshakeError::EncryptionError => write!(f, "Encryption error"), EpfHandshakeError::MissingKeyProof => write!(f, "Missing key proof"), } } } impl Error for EpfHandshakeError {}