1use core::fmt;
4
5#[derive(Debug)]
7pub enum Spake2Error {
8 InvalidPoint,
10 IdentityPoint,
12 ConfirmationFailed,
14 InternalError(&'static str),
16}
17
18impl fmt::Display for Spake2Error {
19 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
20 match self {
21 Spake2Error::InvalidPoint => write!(f, "invalid point encoding"),
22 Spake2Error::IdentityPoint => write!(f, "identity point encountered"),
23 Spake2Error::ConfirmationFailed => write!(f, "key confirmation failed"),
24 Spake2Error::InternalError(msg) => write!(f, "internal error: {msg}"),
25 }
26 }
27}
28
29#[cfg(feature = "std")]
30impl std::error::Error for Spake2Error {}
31
32impl From<pakery_core::PakeError> for Spake2Error {
33 fn from(e: pakery_core::PakeError) -> Self {
34 match e {
35 pakery_core::PakeError::InvalidPoint => Spake2Error::InvalidPoint,
36 pakery_core::PakeError::IdentityPoint => Spake2Error::IdentityPoint,
37 pakery_core::PakeError::ProtocolError(msg) => Spake2Error::InternalError(msg),
38 pakery_core::PakeError::InvalidInput(msg) => Spake2Error::InternalError(msg),
39 }
40 }
41}
42
43impl From<Spake2Error> for pakery_core::PakeError {
44 fn from(e: Spake2Error) -> Self {
45 match e {
46 Spake2Error::InvalidPoint => pakery_core::PakeError::InvalidPoint,
47 Spake2Error::IdentityPoint => pakery_core::PakeError::IdentityPoint,
48 Spake2Error::ConfirmationFailed => {
49 pakery_core::PakeError::ProtocolError("key confirmation failed")
50 }
51 Spake2Error::InternalError(msg) => pakery_core::PakeError::ProtocolError(msg),
52 }
53 }
54}