e3pf/libepf/src/error.rs

46 lines
1.7 KiB
Rust
Raw Normal View History

2023-05-04 00:38:05 +00:00
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,
2023-05-04 00:38:05 +00:00
MissingKeyProof,
}
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)
}
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")
}
EpfHandshakeError::EncryptionError => write!(f, "Encryption error"),
2023-05-04 00:38:05 +00:00
EpfHandshakeError::MissingKeyProof => write!(f, "Missing key proof"),
}
}
}
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);
}
}