@@ -15,9 +15,7 @@ pub use self::serialized_signature::SerializedSignature;
15
15
use crate :: ffi:: CPtr ;
16
16
#[ cfg( feature = "global-context" ) ]
17
17
use crate :: SECP256K1 ;
18
- use crate :: {
19
- ffi, from_hex, Error , Message , PublicKey , Secp256k1 , SecretKey , Signing , Verification ,
20
- } ;
18
+ use crate :: { ffi, from_hex, Message , PublicKey , Secp256k1 , SecretKey , Signing , Verification } ;
21
19
22
20
/// An ECDSA signature
23
21
#[ derive( Copy , Clone , PartialOrd , Ord , PartialEq , Eq , Hash ) ]
@@ -36,22 +34,22 @@ impl fmt::Display for Signature {
36
34
}
37
35
38
36
impl str:: FromStr for Signature {
39
- type Err = Error ;
37
+ type Err = SignatureError ;
40
38
fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
41
39
let mut res = [ 0u8 ; 72 ] ;
42
40
match from_hex ( s, & mut res) {
43
41
Ok ( x) => Signature :: from_der ( & res[ 0 ..x] ) ,
44
- _ => Err ( Error :: InvalidSignature ) ,
42
+ _ => Err ( SignatureError ) ,
45
43
}
46
44
}
47
45
}
48
46
49
47
impl Signature {
50
48
#[ inline]
51
49
/// Converts a DER-encoded byte slice to a signature
52
- pub fn from_der ( data : & [ u8 ] ) -> Result < Signature , Error > {
50
+ pub fn from_der ( data : & [ u8 ] ) -> Result < Signature , SignatureError > {
53
51
if data. is_empty ( ) {
54
- return Err ( Error :: InvalidSignature ) ;
52
+ return Err ( SignatureError ) ;
55
53
}
56
54
57
55
unsafe {
@@ -65,15 +63,15 @@ impl Signature {
65
63
{
66
64
Ok ( Signature ( ret) )
67
65
} else {
68
- Err ( Error :: InvalidSignature )
66
+ Err ( SignatureError )
69
67
}
70
68
}
71
69
}
72
70
73
71
/// Converts a 64-byte compact-encoded byte slice to a signature
74
- pub fn from_compact ( data : & [ u8 ] ) -> Result < Signature , Error > {
72
+ pub fn from_compact ( data : & [ u8 ] ) -> Result < Signature , SignatureError > {
75
73
if data. len ( ) != 64 {
76
- return Err ( Error :: InvalidSignature ) ;
74
+ return Err ( SignatureError ) ;
77
75
}
78
76
79
77
unsafe {
@@ -86,7 +84,7 @@ impl Signature {
86
84
{
87
85
Ok ( Signature ( ret) )
88
86
} else {
89
- Err ( Error :: InvalidSignature )
87
+ Err ( SignatureError )
90
88
}
91
89
}
92
90
}
@@ -95,9 +93,9 @@ impl Signature {
95
93
/// only useful for validating signatures in the Bitcoin blockchain from before
96
94
/// 2016. It should never be used in new applications. This library does not
97
95
/// support serializing to this "format"
98
- pub fn from_der_lax ( data : & [ u8 ] ) -> Result < Signature , Error > {
96
+ pub fn from_der_lax ( data : & [ u8 ] ) -> Result < Signature , SignatureError > {
99
97
if data. is_empty ( ) {
100
- return Err ( Error :: InvalidSignature ) ;
98
+ return Err ( SignatureError ) ;
101
99
}
102
100
103
101
unsafe {
@@ -111,7 +109,7 @@ impl Signature {
111
109
{
112
110
Ok ( Signature ( ret) )
113
111
} else {
114
- Err ( Error :: InvalidSignature )
112
+ Err ( SignatureError )
115
113
}
116
114
}
117
115
}
@@ -194,7 +192,7 @@ impl Signature {
194
192
/// The signature must be normalized or verification will fail (see [`Signature::normalize_s`]).
195
193
#[ inline]
196
194
#[ cfg( feature = "global-context" ) ]
197
- pub fn verify ( & self , msg : & Message , pk : & PublicKey ) -> Result < ( ) , Error > {
195
+ pub fn verify ( & self , msg : & Message , pk : & PublicKey ) -> Result < ( ) , SignatureError > {
198
196
SECP256K1 . verify_ecdsa ( msg, self , pk)
199
197
}
200
198
}
@@ -366,7 +364,7 @@ impl<C: Verification> Secp256k1<C> {
366
364
///
367
365
/// ```rust
368
366
/// # #[cfg(feature = "rand-std")] {
369
- /// # use secp256k1::{rand, Secp256k1, Message, Error };
367
+ /// # use secp256k1::{ecdsa, rand, Secp256k1, Message};
370
368
/// #
371
369
/// # let secp = Secp256k1::new();
372
370
/// # let (secret_key, public_key) = secp.generate_keypair(&mut rand::thread_rng());
@@ -376,7 +374,7 @@ impl<C: Verification> Secp256k1<C> {
376
374
/// assert_eq!(secp.verify_ecdsa(&message, &sig, &public_key), Ok(()));
377
375
///
378
376
/// let message = Message::from_slice(&[0xcd; 32]).expect("32 bytes");
379
- /// assert_eq!(secp.verify_ecdsa(&message, &sig, &public_key), Err(Error::IncorrectSignature ));
377
+ /// assert_eq!(secp.verify_ecdsa(&message, &sig, &public_key), Err(ecdsa::SignatureError ));
380
378
/// # }
381
379
/// ```
382
380
#[ inline]
@@ -385,7 +383,7 @@ impl<C: Verification> Secp256k1<C> {
385
383
msg : & Message ,
386
384
sig : & Signature ,
387
385
pk : & PublicKey ,
388
- ) -> Result < ( ) , Error > {
386
+ ) -> Result < ( ) , SignatureError > {
389
387
unsafe {
390
388
if ffi:: secp256k1_ecdsa_verify (
391
389
self . ctx . as_ptr ( ) ,
@@ -394,7 +392,7 @@ impl<C: Verification> Secp256k1<C> {
394
392
pk. as_c_ptr ( ) ,
395
393
) == 0
396
394
{
397
- Err ( Error :: IncorrectSignature )
395
+ Err ( SignatureError )
398
396
} else {
399
397
Ok ( ( ) )
400
398
}
@@ -429,3 +427,15 @@ pub(crate) fn der_length_check(sig: &ffi::Signature, max_len: usize) -> bool {
429
427
}
430
428
len <= max_len
431
429
}
430
+
431
+ /// Signature is invalid.
432
+ #[ derive( Clone , Copy , Debug , PartialEq , Eq ) ]
433
+ pub struct SignatureError ;
434
+
435
+ crate :: error:: impl_simple_struct_error!( SignatureError , "signature is invalid" ) ;
436
+
437
+ /// Recovery ID is invalid.
438
+ #[ derive( Clone , Copy , Debug , PartialEq , Eq ) ]
439
+ pub struct RecoveryIdError ;
440
+
441
+ crate :: error:: impl_simple_struct_error!( RecoveryIdError , "recover ID is invalid" ) ;
0 commit comments