ckb_crypto/secp/
error.rs

1use secp256k1::Error as SecpError;
2use thiserror::Error;
3
4/// The error type wrap SecpError
5#[derive(Error, Debug, PartialEq, Eq)]
6pub enum Error {
7    /// Invalid privkey
8    #[error("Invalid privkey")]
9    InvalidPrivKey,
10    /// Invalid pubkey
11    #[error("Invalid pubkey")]
12    InvalidPubKey,
13    /// Invalid signature
14    #[error("Invalid signature")]
15    InvalidSignature,
16    /// Invalid message
17    #[error("Invalid message")]
18    InvalidMessage,
19    /// Invalid recovery_id
20    #[error("Invalid recovery_id")]
21    InvalidRecoveryId,
22    /// Any error not part of this list.
23    #[error("{0}")]
24    Other(String),
25}
26
27impl From<SecpError> for Error {
28    fn from(e: SecpError) -> Self {
29        match e {
30            SecpError::InvalidPublicKey => Error::InvalidPubKey,
31            SecpError::InvalidSecretKey => Error::InvalidPrivKey,
32            SecpError::InvalidMessage => Error::InvalidMessage,
33            SecpError::InvalidRecoveryId => Error::InvalidRecoveryId,
34            _ => Error::InvalidSignature,
35        }
36    }
37}