use core::fmt;
#[derive(Debug)]
pub enum Spake2PlusError {
InvalidPoint,
IdentityPoint,
ConfirmationFailed,
InternalError(&'static str),
}
impl fmt::Display for Spake2PlusError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Spake2PlusError::InvalidPoint => write!(f, "invalid point encoding"),
Spake2PlusError::IdentityPoint => write!(f, "identity point encountered"),
Spake2PlusError::ConfirmationFailed => write!(f, "key confirmation failed"),
Spake2PlusError::InternalError(msg) => write!(f, "internal error: {msg}"),
}
}
}
#[cfg(feature = "std")]
impl std::error::Error for Spake2PlusError {}
impl From<pakery_core::PakeError> for Spake2PlusError {
fn from(e: pakery_core::PakeError) -> Self {
match e {
pakery_core::PakeError::InvalidPoint => Spake2PlusError::InvalidPoint,
pakery_core::PakeError::IdentityPoint => Spake2PlusError::IdentityPoint,
pakery_core::PakeError::ProtocolError(msg) => Spake2PlusError::InternalError(msg),
pakery_core::PakeError::InvalidInput(msg) => Spake2PlusError::InternalError(msg),
}
}
}
impl From<Spake2PlusError> for pakery_core::PakeError {
fn from(e: Spake2PlusError) -> Self {
match e {
Spake2PlusError::InvalidPoint => pakery_core::PakeError::InvalidPoint,
Spake2PlusError::IdentityPoint => pakery_core::PakeError::IdentityPoint,
Spake2PlusError::ConfirmationFailed => {
pakery_core::PakeError::ProtocolError("key confirmation failed")
}
Spake2PlusError::InternalError(msg) => pakery_core::PakeError::ProtocolError(msg),
}
}
}