Skip to main content

pakery_core/
error.rs

1//! Common error types for PAKE protocols.
2
3use core::fmt;
4
5/// Errors that can occur during PAKE protocol execution.
6#[derive(Debug)]
7pub enum PakeError {
8    /// A received point could not be decoded as a valid group element.
9    InvalidPoint,
10    /// A computed or received point is the group identity element.
11    IdentityPoint,
12    /// Invalid input was provided.
13    InvalidInput(&'static str),
14    /// A protocol-level error occurred.
15    ProtocolError(&'static str),
16}
17
18impl fmt::Display for PakeError {
19    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
20        match self {
21            PakeError::InvalidPoint => write!(f, "invalid point encoding"),
22            PakeError::IdentityPoint => write!(f, "identity point encountered"),
23            PakeError::InvalidInput(msg) => write!(f, "invalid input: {msg}"),
24            PakeError::ProtocolError(msg) => write!(f, "protocol error: {msg}"),
25        }
26    }
27}
28
29#[cfg(feature = "std")]
30impl std::error::Error for PakeError {}