//! Errors for `plexus-crypto`.

use core::fmt;

/// Cryptographic operation errors.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum Error {
    /// HMAC verification failed. (Compared in constant time; see §9.2.)
    MacMismatch,
    /// An input or output buffer had an invalid length.
    InvalidLength,
    /// Malformed or wrong-sized key material.
    InvalidKey,
}

impl fmt::Display for Error {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let msg = match self {
            Self::MacMismatch => "MAC verification failed",
            Self::InvalidLength => "invalid buffer length",
            Self::InvalidKey => "invalid key material",
        };
        f.write_str(msg)
    }
}
