use core::fmt;
pub type Result<T> = core::result::Result<T, Error>;
#[non_exhaustive]
#[derive(Debug)]
pub enum Error {
Format(&'static str),
NoCommonAlgorithm(&'static str),
Protocol(&'static str),
BadMac,
BadTag,
BadPadding,
BadSignature,
HostKeyRejected,
AuthFailed,
BadChannelState,
Unsupported(&'static str),
#[cfg(feature = "std")]
Io(std::io::Error),
Crypto(&'static str),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::Format(s) => write!(f, "ssh wire format: {s}"),
Error::NoCommonAlgorithm(s) => write!(f, "no common {s}"),
Error::Protocol(s) => write!(f, "protocol error: {s}"),
Error::BadMac => f.write_str("bad MAC"),
Error::BadTag => f.write_str("bad AEAD tag"),
Error::BadPadding => f.write_str("bad padding"),
Error::BadSignature => f.write_str("bad signature"),
Error::HostKeyRejected => f.write_str("host key rejected"),
Error::AuthFailed => f.write_str("authentication failed"),
Error::BadChannelState => f.write_str("bad channel state"),
Error::Unsupported(s) => write!(f, "unsupported: {s}"),
#[cfg(feature = "std")]
Error::Io(e) => write!(f, "io: {e}"),
Error::Crypto(s) => write!(f, "crypto: {s}"),
}
}
}
#[cfg(feature = "std")]
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Error::Io(e) => Some(e),
_ => None,
}
}
}
#[cfg(feature = "std")]
impl From<std::io::Error> for Error {
fn from(e: std::io::Error) -> Self {
Error::Io(e)
}
}