use std::fmt;
#[allow(missing_docs)]
#[derive(Debug, PartialEq)]
#[non_exhaustive]
pub enum Error {
Pattern(PatternProblem),
Init(InitStage),
Prereq(Prerequisite),
State(StateProblem),
Input,
Dh,
Decrypt,
#[cfg(feature = "hfs")]
Kem,
}
#[allow(missing_docs)]
#[derive(Debug, PartialEq)]
pub enum PatternProblem {
TooFewParameters,
UnsupportedHandshakeType,
UnsupportedBaseType,
UnsupportedHashType,
UnsupportedDhType,
UnsupportedCipherType,
InvalidPsk,
UnsupportedModifier,
#[cfg(feature = "hfs")]
UnsupportedKemType,
}
impl From<PatternProblem> for Error {
fn from(reason: PatternProblem) -> Self {
Error::Pattern(reason)
}
}
#[allow(missing_docs)]
#[derive(Debug, PartialEq)]
pub enum InitStage {
ValidateKeyLengths,
ValidatePskLengths,
ValidateCipherTypes,
GetRngImpl,
GetDhImpl,
GetCipherImpl,
GetHashImpl,
#[cfg(feature = "hfs")]
GetKemImpl,
ValidatePskPosition,
}
impl From<InitStage> for Error {
fn from(reason: InitStage) -> Self {
Error::Init(reason)
}
}
#[allow(missing_docs)]
#[derive(Debug, PartialEq)]
pub enum Prerequisite {
LocalPrivateKey,
RemotePublicKey,
}
impl From<Prerequisite> for Error {
fn from(reason: Prerequisite) -> Self {
Error::Prereq(reason)
}
}
#[allow(missing_docs)]
#[derive(Debug, PartialEq)]
pub enum StateProblem {
MissingKeyMaterial,
MissingPsk,
NotTurnToWrite,
NotTurnToRead,
HandshakeNotFinished,
HandshakeAlreadyFinished,
OneWay,
StatelessTransportMode,
Exhausted,
}
impl From<StateProblem> for Error {
fn from(reason: StateProblem) -> Self {
Error::State(reason)
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::Pattern(reason) => write!(f, "pattern error: {:?}", reason),
Error::Init(reason) => {
write!(f, "initialization error: {:?}", reason)
},
Error::Prereq(reason) => {
write!(f, "prerequisite error: {:?}", reason)
},
Error::State(reason) => write!(f, "state error: {:?}", reason),
Error::Input => write!(f, "input error"),
Error::Dh => write!(f, "diffie-hellman error"),
Error::Decrypt => write!(f, "decrypt error"),
#[cfg(feature = "hfs")]
Error::Kem => write!(f, "kem error"),
}
}
}
impl std::error::Error for Error {}