2023-05-04 00:38:05 +00:00
|
|
|
use crate::pki::EpfPkiCertificateValidationError;
|
2023-05-03 16:31:57 +00:00
|
|
|
use std::error::Error;
|
|
|
|
use std::fmt::{Display, Formatter};
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum EpfHandshakeError {
|
|
|
|
AlreadyTunnelled,
|
|
|
|
UnsupportedProtocolVersion(usize),
|
|
|
|
InvalidCertificate(EpfPkiCertificateValidationError),
|
|
|
|
UntrustedCertificate,
|
|
|
|
EncryptionError,
|
2023-05-04 00:38:05 +00:00
|
|
|
MissingKeyProof,
|
2023-05-03 16:31:57 +00:00
|
|
|
}
|
|
|
|
impl Display for EpfHandshakeError {
|
|
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
|
|
match self {
|
|
|
|
EpfHandshakeError::AlreadyTunnelled => write!(f, "Already tunneled"),
|
2023-05-04 00:38:05 +00:00
|
|
|
EpfHandshakeError::UnsupportedProtocolVersion(v) => {
|
|
|
|
write!(f, "Unsupported protocol version {}", v)
|
|
|
|
}
|
2023-05-03 16:31:57 +00:00
|
|
|
EpfHandshakeError::InvalidCertificate(e) => write!(f, "Invalid certificate: {}", e),
|
2023-05-04 00:38:05 +00:00
|
|
|
EpfHandshakeError::UntrustedCertificate => {
|
|
|
|
write!(f, "Certificate valid but not trusted")
|
|
|
|
}
|
2023-05-03 16:31:57 +00:00
|
|
|
EpfHandshakeError::EncryptionError => write!(f, "Encryption error"),
|
2023-05-04 00:38:05 +00:00
|
|
|
EpfHandshakeError::MissingKeyProof => write!(f, "Missing key proof"),
|
2023-05-03 16:31:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-05-04 00:38:05 +00:00
|
|
|
impl Error for EpfHandshakeError {}
|
2023-05-04 01:02:25 +00:00
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use crate::error::EpfHandshakeError;
|
|
|
|
use crate::pki::EpfPkiCertificateValidationError;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
pub fn error_display_test() {
|
|
|
|
println!("{}", EpfHandshakeError::AlreadyTunnelled);
|
|
|
|
println!("{}", EpfHandshakeError::UnsupportedProtocolVersion(0));
|
|
|
|
println!("{}", EpfHandshakeError::InvalidCertificate(EpfPkiCertificateValidationError::ValidAfterSigner));
|
|
|
|
println!("{}", EpfHandshakeError::UntrustedCertificate);
|
|
|
|
println!("{}", EpfHandshakeError::EncryptionError);
|
|
|
|
println!("{}", EpfHandshakeError::MissingKeyProof);
|
|
|
|
}
|
|
|
|
}
|