aucpace_conflux/
errors.rs

1use core::fmt;
2
3/// Errors that can occur during the protocol
4#[non_exhaustive]
5#[derive(Copy, Clone, Debug, PartialEq, Eq)]
6pub enum Error {
7    /// Some points such as the Neutral or Identity point are illegal
8    IllegalPointError,
9    /// Wrapper around `password_hash`'s error type, for propagating errors should they occur
10    PasswordHashing(password_hash::Error),
11    /// Failure in random number generation (entropy unavailable or RNG error)
12    Rng,
13    /// PasswordHasher produced an empty hash.
14    HashEmpty,
15    /// PasswordHasher produced a hash of an invalid size (size was not 32 or 64 bytes)
16    HashSizeInvalid,
17    /// Failure during Explicit Mutual Authentication
18    MutualAuthFail,
19    /// The username:password string would overflow the buffer size allocated for hashing the password
20    /// Note: this error can only occur when using the *_alloc APIs
21    UsernameOrPasswordTooLong,
22    /// The SSID provided is too short to be secure, SSIDs must be at least 16 bytes long
23    /// Note: this error can only occur if the SSID establishment phase is bypassed
24    InsecureSsid,
25    /// This error happens when a long term keypair for a user is stored in a [`PartialAugDatabase`](crate::PartialAugDatabase)
26    /// but the user doesn't exist, this operation has no meaning and as such is an error.
27    #[cfg(feature = "partial_augmentation")]
28    UserNotRegistered,
29}
30
31impl fmt::Display for Error {
32    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
33        match self {
34            Self::IllegalPointError => write!(f, "illegal point encountered"),
35            Self::PasswordHashing(error) => write!(f, "error while hashing password: {error}"),
36            Self::Rng => write!(f, "random number generator failure"),
37            Self::HashEmpty => write!(f, "password hash empty"),
38            Self::HashSizeInvalid => write!(f, "password hash invalid, should be 32 or 64 bytes"),
39            Self::MutualAuthFail => write!(
40                f,
41                "explicit mutual authentication failed, authenticators didn't match"
42            ),
43            Self::UsernameOrPasswordTooLong => write!(f, "username or password too long"),
44            Self::InsecureSsid => write!(
45                f,
46                "provided SSID is insecure - SSIDs must be at least 16 bytes long"
47            ),
48            #[cfg(feature = "partial_augmentation")]
49            Self::UserNotRegistered => write!(
50                f,
51                "user must be registered before a long-term keypair can be stored"
52            ),
53        }
54    }
55}
56
57/// Result type
58pub type Result<T> = core::result::Result<T, Error>;