1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(
feature = "serde-types-minimal",
derive(serde::Serialize, serde::Deserialize)
)]
pub enum Error {
InvalidSecretKey,
InvalidPublicKey,
InvalidMessage,
InvalidSignature,
NotEnoughMemory,
}
#[cfg(feature = "std")]
mod use_std {
use super::*;
use secp256k1::Error as Secp256k1Error;
use std::{error, fmt, io};
impl From<Secp256k1Error> for Error {
fn from(secp: Secp256k1Error) -> Self {
match secp {
Secp256k1Error::IncorrectSignature
| Secp256k1Error::InvalidSignature
| Secp256k1Error::InvalidTweak
| Secp256k1Error::TweakCheckFailed
| Secp256k1Error::InvalidRecoveryId => Self::InvalidSignature,
Secp256k1Error::InvalidMessage => Self::InvalidMessage,
Secp256k1Error::InvalidPublicKey => Self::InvalidPublicKey,
Secp256k1Error::InvalidSecretKey => Self::InvalidSecretKey,
Secp256k1Error::NotEnoughMemory => Self::NotEnoughMemory,
}
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", self)
}
}
impl error::Error for Error {
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
None
}
}
impl From<Error> for io::Error {
fn from(e: Error) -> io::Error {
io::Error::new(io::ErrorKind::Other, e)
}
}
}