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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
mod sign_error {
/// Errors when performing ECDSA [`sign`](fn.sign) operations.
#[derive(Debug)]
pub enum SignError {
/// The message hash is not in the range of `[0, 2^251)`.
InvalidMessageHash,
/// The random `k` value results in an invalid signature. A different `k` value should be
/// used instead, typically by using a new seed per RFC-6979.
InvalidK,
}
#[cfg(feature = "std")]
impl std::error::Error for SignError {}
impl core::fmt::Display for SignError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::InvalidMessageHash => write!(f, "Invalid message hash"),
Self::InvalidK => write!(f, "Invalid k"),
}
}
}
}
pub use sign_error::SignError;
mod verify_error {
/// Errors when performing ECDSA [`verify`](fn.verify) operations.
#[derive(Debug)]
pub enum VerifyError {
/// The public key is not a valid point on the STARK curve.
InvalidPublicKey,
/// The message hash is not in the range of `[0, 2^251)`.
InvalidMessageHash,
/// The `r` value is not in the range of `[0, 2^251)`.
InvalidR,
/// The `s` value is not in the range of `[0, 2^251)`.
InvalidS,
}
#[cfg(feature = "std")]
impl std::error::Error for VerifyError {}
impl core::fmt::Display for VerifyError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::InvalidMessageHash => write!(f, "Invalid message hash"),
Self::InvalidPublicKey => write!(f, "Invalid public key"),
Self::InvalidR => write!(f, "Invalid r"),
Self::InvalidS => write!(f, "Invalid s"),
}
}
}
}
pub use verify_error::VerifyError;
mod recover_error {
/// Errors when performing ECDSA [`recover`](fn.recover) operations.
#[derive(Debug)]
pub enum RecoverError {
/// The message hash is not in the range of `[0, 2^251)`.
InvalidMessageHash,
/// The `r` value is not in the range of `[0, 2^251)`.
InvalidR,
/// The `s` value is not in the range of `[0,
/// 0x0800000000000010ffffffffffffffffb781126dcae7b2321e66a241adc64d2f)`.
InvalidS,
/// The `v` value is neither `0` nor `1`.
InvalidV,
}
#[cfg(feature = "std")]
impl std::error::Error for RecoverError {}
impl core::fmt::Display for RecoverError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::InvalidMessageHash => write!(f, "Invalid message hash"),
Self::InvalidR => write!(f, "Invalid r"),
Self::InvalidS => write!(f, "Invalid s"),
Self::InvalidV => write!(f, "Invalid v"),
}
}
}
}
pub use recover_error::RecoverError;