@@ -15,9 +15,7 @@ pub use self::serialized_signature::SerializedSignature;
1515use crate :: ffi:: CPtr ;
1616#[ cfg( feature = "global-context" ) ]
1717use 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 } ;
2119
2220/// An ECDSA signature
2321#[ derive( Copy , Clone , PartialOrd , Ord , PartialEq , Eq , Hash ) ]
@@ -36,22 +34,22 @@ impl fmt::Display for Signature {
3634}
3735
3836impl str:: FromStr for Signature {
39- type Err = Error ;
37+ type Err = SignatureError ;
4038 fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
4139 let mut res = [ 0u8 ; 72 ] ;
4240 match from_hex ( s, & mut res) {
4341 Ok ( x) => Signature :: from_der ( & res[ 0 ..x] ) ,
44- _ => Err ( Error :: InvalidSignature ) ,
42+ _ => Err ( SignatureError ) ,
4543 }
4644 }
4745}
4846
4947impl Signature {
5048 #[ inline]
5149 /// 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 > {
5351 if data. is_empty ( ) {
54- return Err ( Error :: InvalidSignature ) ;
52+ return Err ( SignatureError ) ;
5553 }
5654
5755 unsafe {
@@ -65,15 +63,15 @@ impl Signature {
6563 {
6664 Ok ( Signature ( ret) )
6765 } else {
68- Err ( Error :: InvalidSignature )
66+ Err ( SignatureError )
6967 }
7068 }
7169 }
7270
7371 /// 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 > {
7573 if data. len ( ) != 64 {
76- return Err ( Error :: InvalidSignature ) ;
74+ return Err ( SignatureError ) ;
7775 }
7876
7977 unsafe {
@@ -86,7 +84,7 @@ impl Signature {
8684 {
8785 Ok ( Signature ( ret) )
8886 } else {
89- Err ( Error :: InvalidSignature )
87+ Err ( SignatureError )
9088 }
9189 }
9290 }
@@ -95,9 +93,9 @@ impl Signature {
9593 /// only useful for validating signatures in the Bitcoin blockchain from before
9694 /// 2016. It should never be used in new applications. This library does not
9795 /// 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 > {
9997 if data. is_empty ( ) {
100- return Err ( Error :: InvalidSignature ) ;
98+ return Err ( SignatureError ) ;
10199 }
102100
103101 unsafe {
@@ -111,7 +109,7 @@ impl Signature {
111109 {
112110 Ok ( Signature ( ret) )
113111 } else {
114- Err ( Error :: InvalidSignature )
112+ Err ( SignatureError )
115113 }
116114 }
117115 }
@@ -194,7 +192,7 @@ impl Signature {
194192 /// The signature must be normalized or verification will fail (see [`Signature::normalize_s`]).
195193 #[ inline]
196194 #[ 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 > {
198196 SECP256K1 . verify_ecdsa ( msg, self , pk)
199197 }
200198}
@@ -366,7 +364,7 @@ impl<C: Verification> Secp256k1<C> {
366364 ///
367365 /// ```rust
368366 /// # #[cfg(feature = "rand-std")] {
369- /// # use secp256k1::{rand, Secp256k1, Message, Error };
367+ /// # use secp256k1::{ecdsa, rand, Secp256k1, Message};
370368 /// #
371369 /// # let secp = Secp256k1::new();
372370 /// # let (secret_key, public_key) = secp.generate_keypair(&mut rand::thread_rng());
@@ -376,7 +374,7 @@ impl<C: Verification> Secp256k1<C> {
376374 /// assert_eq!(secp.verify_ecdsa(&message, &sig, &public_key), Ok(()));
377375 ///
378376 /// 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 ));
380378 /// # }
381379 /// ```
382380 #[ inline]
@@ -385,7 +383,7 @@ impl<C: Verification> Secp256k1<C> {
385383 msg : & Message ,
386384 sig : & Signature ,
387385 pk : & PublicKey ,
388- ) -> Result < ( ) , Error > {
386+ ) -> Result < ( ) , SignatureError > {
389387 unsafe {
390388 if ffi:: secp256k1_ecdsa_verify (
391389 self . ctx . as_ptr ( ) ,
@@ -394,7 +392,7 @@ impl<C: Verification> Secp256k1<C> {
394392 pk. as_c_ptr ( ) ,
395393 ) == 0
396394 {
397- Err ( Error :: IncorrectSignature )
395+ Err ( SignatureError )
398396 } else {
399397 Ok ( ( ) )
400398 }
@@ -429,3 +427,15 @@ pub(crate) fn der_length_check(sig: &ffi::Signature, max_len: usize) -> bool {
429427 }
430428 len <= max_len
431429}
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