decaf377_rdsa/
error.rs

1use core::fmt;
2
3/// An error related to `decaf377-rdsa` signatures.
4#[derive(Debug, Copy, Clone, Eq, PartialEq)]
5pub enum Error {
6    /// The encoding of a signing key was malformed.
7    MalformedSigningKey,
8    /// The encoding of a verification key was malformed.
9    MalformedVerificationKey,
10    /// Signature verification failed.
11    InvalidSignature,
12    /// Occurs when reading from a slice of the wrong length.
13    WrongSliceLength { expected: usize, found: usize },
14}
15
16impl fmt::Display for Error {
17    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
18        match self {
19            Self::MalformedSigningKey => f.write_str("Malformed signing key encoding."),
20            Self::MalformedVerificationKey => f.write_str("Malformed verification key encoding."),
21            Self::InvalidSignature => f.write_str("Invalid signature."),
22            Self::WrongSliceLength { expected, found } => {
23                f.write_str("Wrong slice length, expected ")?;
24                expected.fmt(f)?;
25                f.write_str(", found ")?;
26                found.fmt(f)
27            }
28        }
29    }
30}
31
32#[cfg(feature = "std")]
33impl std::error::Error for Error {}