tendermint/crypto/
signature.rs

1use core::fmt::{self, Display};
2
3use crate::{PublicKey, Signature};
4
5/// Signature error.
6///
7#[derive(Debug)]
8pub enum Error {
9    /// This variant is deliberately opaque as to avoid side-channel leakage.
10    VerificationFailed,
11    /// The key used to verify a signature is not of a type supported by the implementation.
12    UnsupportedKeyType,
13    /// The encoding of the public key was malformed.
14    MalformedPublicKey,
15    /// The signature data was malformed.
16    MalformedSignature,
17}
18
19impl Display for Error {
20    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21        match self {
22            Error::VerificationFailed => f.write_str("invalid signature"),
23            Error::UnsupportedKeyType => f.write_str("key type not supported"),
24            Error::MalformedPublicKey => f.write_str("malformed public key encoding"),
25            Error::MalformedSignature => f.write_str("malformed signature"),
26        }
27    }
28}
29
30#[cfg(feature = "std")]
31impl std::error::Error for Error {}
32
33pub trait Verifier {
34    fn verify(pubkey: PublicKey, msg: &[u8], signature: &Signature) -> Result<(), Error>;
35}