1use std::fmt;
4
5#[allow(missing_docs)]
7#[derive(Debug, PartialEq)]
8#[non_exhaustive]
9pub enum Error {
10 Pattern(PatternProblem),
12
13 Init(InitStage),
15
16 Prereq(Prerequisite),
18
19 State(StateProblem),
21
22 Input,
24
25 Dh,
27
28 Decrypt,
30
31 #[cfg(feature = "hfs")]
33 Kem,
34}
35
36#[allow(missing_docs)]
39#[derive(Debug, PartialEq)]
40pub enum PatternProblem {
41 TooFewParameters,
42 UnsupportedHandshakeType,
43 UnsupportedBaseType,
44 UnsupportedHashType,
45 UnsupportedDhType,
46 UnsupportedCipherType,
47 InvalidPsk,
48 UnsupportedModifier,
49 #[cfg(feature = "hfs")]
50 UnsupportedKemType,
51}
52
53impl From<PatternProblem> for Error {
54 fn from(reason: PatternProblem) -> Self {
55 Error::Pattern(reason)
56 }
57}
58
59#[allow(missing_docs)]
62#[derive(Debug, PartialEq)]
63pub enum InitStage {
64 ValidateKeyLengths,
65 ValidatePskLengths,
66 ValidateCipherTypes,
67 GetRngImpl,
68 GetDhImpl,
69 GetCipherImpl,
70 GetHashImpl,
71 #[cfg(feature = "hfs")]
72 GetKemImpl,
73 ValidatePskPosition,
74}
75
76impl From<InitStage> for Error {
77 fn from(reason: InitStage) -> Self {
78 Error::Init(reason)
79 }
80}
81
82#[allow(missing_docs)]
84#[derive(Debug, PartialEq)]
85pub enum Prerequisite {
86 LocalPrivateKey,
87 RemotePublicKey,
88}
89
90impl From<Prerequisite> for Error {
91 fn from(reason: Prerequisite) -> Self {
92 Error::Prereq(reason)
93 }
94}
95
96#[allow(missing_docs)]
98#[derive(Debug, PartialEq)]
99pub enum StateProblem {
100 MissingKeyMaterial,
101 MissingPsk,
102 NotTurnToWrite,
103 NotTurnToRead,
104 HandshakeNotFinished,
105 HandshakeAlreadyFinished,
106 OneWay,
107 StatelessTransportMode,
108 Exhausted,
110}
111
112impl From<StateProblem> for Error {
113 fn from(reason: StateProblem) -> Self {
114 Error::State(reason)
115 }
116}
117
118impl fmt::Display for Error {
119 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
120 match self {
121 Error::Pattern(reason) => write!(f, "pattern error: {:?}", reason),
122 Error::Init(reason) => {
123 write!(f, "initialization error: {:?}", reason)
124 },
125 Error::Prereq(reason) => {
126 write!(f, "prerequisite error: {:?}", reason)
127 },
128 Error::State(reason) => write!(f, "state error: {:?}", reason),
129 Error::Input => write!(f, "input error"),
130 Error::Dh => write!(f, "diffie-hellman error"),
131 Error::Decrypt => write!(f, "decrypt error"),
132 #[cfg(feature = "hfs")]
133 Error::Kem => write!(f, "kem error"),
134 }
135 }
136}
137
138impl std::error::Error for Error {}