1use core::fmt::{self, Display};
23use crate::{PublicKey, Signature};
45/// Signature error.
6///
7#[derive(Debug)]
8pub enum Error {
9/// This variant is deliberately opaque as to avoid side-channel leakage.
10VerificationFailed,
11/// The key used to verify a signature is not of a type supported by the implementation.
12UnsupportedKeyType,
13/// The encoding of the public key was malformed.
14MalformedPublicKey,
15/// The signature data was malformed.
16MalformedSignature,
17}
1819impl Display for Error {
20fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21match 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}
2930#[cfg(feature = "std")]
31impl std::error::Error for Error {}
3233pub trait Verifier {
34fn verify(pubkey: PublicKey, msg: &[u8], signature: &Signature) -> Result<(), Error>;
35}