Skip to main content

pakery_cpace/
error.rs

1//! CPace-specific error types.
2
3use core::fmt;
4
5/// Errors that can occur during CPace protocol execution.
6#[derive(Debug)]
7pub enum CpaceError {
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}
13
14impl fmt::Display for CpaceError {
15    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
16        match self {
17            CpaceError::InvalidPoint => write!(f, "invalid point encoding"),
18            CpaceError::IdentityPoint => write!(f, "identity point encountered"),
19        }
20    }
21}
22
23#[cfg(feature = "std")]
24impl std::error::Error for CpaceError {}
25
26impl From<pakery_core::PakeError> for CpaceError {
27    fn from(e: pakery_core::PakeError) -> Self {
28        match e {
29            pakery_core::PakeError::InvalidPoint => CpaceError::InvalidPoint,
30            pakery_core::PakeError::IdentityPoint => CpaceError::IdentityPoint,
31            _ => CpaceError::InvalidPoint,
32        }
33    }
34}
35
36impl From<CpaceError> for pakery_core::PakeError {
37    fn from(e: CpaceError) -> Self {
38        match e {
39            CpaceError::InvalidPoint => pakery_core::PakeError::InvalidPoint,
40            CpaceError::IdentityPoint => pakery_core::PakeError::IdentityPoint,
41        }
42    }
43}