@@ -392,8 +392,10 @@ impl From<(libsecp256k1::Signature, libsecp256k1::RecoveryId)> for Signature {
392
392
#[ cfg( feature = "full_crypto" ) ]
393
393
impl < ' a > TryFrom < & ' a Signature > for ( libsecp256k1:: Signature , libsecp256k1:: RecoveryId ) {
394
394
type Error = ( ) ;
395
- fn try_from ( x : & ' a Signature ) -> Result < ( libsecp256k1:: Signature , libsecp256k1:: RecoveryId ) , Self :: Error > {
396
- parse_signature ( & x. 0 ) . map_err ( |_| ( ) )
395
+ fn try_from (
396
+ x : & ' a Signature ,
397
+ ) -> Result < ( libsecp256k1:: Signature , libsecp256k1:: RecoveryId ) , Self :: Error > {
398
+ parse_signature_standard ( & x. 0 ) . map_err ( |_| ( ) )
397
399
}
398
400
}
399
401
@@ -507,7 +509,10 @@ impl TraitPair for Pair {
507
509
/// Verify a signature on a message. Returns true if the signature is good.
508
510
fn verify < M : AsRef < [ u8 ] > > ( sig : & Self :: Signature , message : M , pubkey : & Self :: Public ) -> bool {
509
511
let message = libsecp256k1:: Message :: parse ( & blake2_256 ( message. as_ref ( ) ) ) ;
510
- let sig: ( _ , _ ) = match sig. try_into ( ) { Ok ( x) => x, _ => return false } ;
512
+ let sig: ( _ , _ ) = match sig. try_into ( ) {
513
+ Ok ( x) => x,
514
+ _ => return false ,
515
+ } ;
511
516
match libsecp256k1:: recover ( & message, & sig. 0 , & sig. 1 ) {
512
517
Ok ( actual) => pubkey. 0 [ ..] == actual. serialize_compressed ( ) [ ..] ,
513
518
_ => false ,
@@ -520,8 +525,10 @@ impl TraitPair for Pair {
520
525
/// size. Use it only if you're coming from byte buffers and need the speed.
521
526
fn verify_weak < P : AsRef < [ u8 ] > , M : AsRef < [ u8 ] > > ( sig : & [ u8 ] , message : M , pubkey : P ) -> bool {
522
527
let message = libsecp256k1:: Message :: parse ( & blake2_256 ( message. as_ref ( ) ) ) ;
523
- if sig. len ( ) != 65 { return false }
524
- let ( sig, ri) = match parse_signature ( & sig) {
528
+ if sig. len ( ) != 65 {
529
+ return false
530
+ }
531
+ let ( sig, ri) = match parse_signature_standard ( & sig) {
525
532
Ok ( sigri) => sigri,
526
533
_ => return false ,
527
534
} ;
@@ -582,9 +589,9 @@ impl Pair {
582
589
/// Parses Signature using parse_overflowing_slice
583
590
pub fn verify_deprecated < M : AsRef < [ u8 ] > > ( sig : & Signature , message : M , pubkey : & Public ) -> bool {
584
591
let message = libsecp256k1:: Message :: parse ( & blake2_256 ( message. as_ref ( ) ) ) ;
585
- let ( sig, ri) = match parse_signature_deprecated ( & sig. 0 ) {
592
+ let ( sig, ri) = match parse_signature_overflowing ( & sig. 0 ) {
586
593
Ok ( sigri) => sigri,
587
- _ => return false
594
+ _ => return false ,
588
595
} ;
589
596
match libsecp256k1:: recover ( & message, & sig, & ri) {
590
597
Ok ( actual) => pubkey. 0 [ ..] == actual. serialize_compressed ( ) [ ..] ,
@@ -594,21 +601,21 @@ impl Pair {
594
601
}
595
602
596
603
#[ cfg( feature = "full_crypto" ) ]
597
- fn parse_signature (
598
- x : & [ u8 ] ,
604
+ fn parse_signature_standard (
605
+ x : & [ u8 ] ,
599
606
) -> Result < ( libsecp256k1:: Signature , libsecp256k1:: RecoveryId ) , libsecp256k1:: Error > {
600
- let sig = libsecp256k1:: Signature :: parse_standard_slice ( & x[ 0 ..64 ] ) ?;
601
- let ri = libsecp256k1:: RecoveryId :: parse ( x[ 64 ] ) ?;
602
- Ok ( ( sig, ri) )
607
+ let sig = libsecp256k1:: Signature :: parse_standard_slice ( & x[ 0 ..64 ] ) ?;
608
+ let ri = libsecp256k1:: RecoveryId :: parse ( x[ 64 ] ) ?;
609
+ Ok ( ( sig, ri) )
603
610
}
604
611
605
612
#[ cfg( feature = "full_crypto" ) ]
606
- fn parse_signature_deprecated (
607
- x : & [ u8 ] ,
613
+ fn parse_signature_overflowing (
614
+ x : & [ u8 ] ,
608
615
) -> Result < ( libsecp256k1:: Signature , libsecp256k1:: RecoveryId ) , libsecp256k1:: Error > {
609
- let sig = libsecp256k1:: Signature :: parse_overflowing_slice ( & x[ 0 ..64 ] ) ?;
610
- let ri = libsecp256k1:: RecoveryId :: parse ( x[ 64 ] ) ?;
611
- Ok ( ( sig, ri) )
616
+ let sig = libsecp256k1:: Signature :: parse_overflowing_slice ( & x[ 0 ..64 ] ) ?;
617
+ let ri = libsecp256k1:: RecoveryId :: parse ( x[ 64 ] ) ?;
618
+ Ok ( ( sig, ri) )
612
619
}
613
620
614
621
impl CryptoType for Public {
@@ -852,7 +859,8 @@ mod test {
852
859
// `msg` shouldn't be mangled
853
860
let msg = [ 0u8 ; 32 ] ;
854
861
let sig1 = pair. sign_prehashed ( & msg) ;
855
- let sig2: Signature = libsecp256k1:: sign ( & libsecp256k1:: Message :: parse ( & msg) , & pair. secret ) . into ( ) ;
862
+ let sig2: Signature =
863
+ libsecp256k1:: sign ( & libsecp256k1:: Message :: parse ( & msg) , & pair. secret ) . into ( ) ;
856
864
857
865
assert_eq ! ( sig1, sig2) ;
858
866
@@ -864,7 +872,8 @@ mod test {
864
872
// using pre-hashed `msg` works
865
873
let msg = keccak_256 ( b"this should be hashed" ) ;
866
874
let sig1 = pair. sign_prehashed ( & msg) ;
867
- let sig2: Signature = libsecp256k1:: sign ( & libsecp256k1:: Message :: parse ( & msg) , & pair. secret ) . into ( ) ;
875
+ let sig2: Signature =
876
+ libsecp256k1:: sign ( & libsecp256k1:: Message :: parse ( & msg) , & pair. secret ) . into ( ) ;
868
877
869
878
assert_eq ! ( sig1, sig2) ;
870
879
}
0 commit comments