1use core::fmt;
4
5#[derive(Debug)]
21pub enum OpaqueError {
22 ServerAuthenticationError,
24 ClientAuthenticationError,
26 EnvelopeRecoveryError,
28 InvalidMac,
30 DeserializationError,
32 InternalError(&'static str),
34 InvalidInput(&'static str),
36}
37
38impl fmt::Display for OpaqueError {
39 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
40 match self {
41 Self::ServerAuthenticationError => write!(f, "server authentication failed"),
42 Self::ClientAuthenticationError => write!(f, "client authentication failed"),
43 Self::EnvelopeRecoveryError => write!(f, "envelope recovery failed"),
44 Self::InvalidMac => write!(f, "invalid MAC"),
45 Self::DeserializationError => write!(f, "deserialization error"),
46 Self::InternalError(msg) => write!(f, "internal error: {msg}"),
47 Self::InvalidInput(msg) => write!(f, "invalid input: {msg}"),
48 }
49 }
50}
51
52#[cfg(feature = "std")]
53impl std::error::Error for OpaqueError {}
54
55impl From<pakery_core::PakeError> for OpaqueError {
56 fn from(e: pakery_core::PakeError) -> Self {
57 match e {
58 pakery_core::PakeError::InvalidInput(msg) => OpaqueError::InvalidInput(msg),
59 pakery_core::PakeError::InvalidPoint => OpaqueError::InternalError("invalid point"),
60 pakery_core::PakeError::IdentityPoint => OpaqueError::InternalError("identity point"),
61 pakery_core::PakeError::ProtocolError(msg) => OpaqueError::InternalError(msg),
62 }
63 }
64}
65
66impl From<OpaqueError> for pakery_core::PakeError {
67 fn from(e: OpaqueError) -> Self {
68 match e {
69 OpaqueError::InvalidInput(msg) => pakery_core::PakeError::InvalidInput(msg),
70 _ => pakery_core::PakeError::ProtocolError("OPAQUE error"),
71 }
72 }
73}