@@ -382,10 +382,7 @@ impl From<(libsecp256k1::Signature, libsecp256k1::RecoveryId)> for Signature {
382
382
impl < ' a > TryFrom < & ' a Signature > for ( libsecp256k1:: Signature , libsecp256k1:: RecoveryId ) {
383
383
type Error = ( ) ;
384
384
fn try_from ( x : & ' a Signature ) -> Result < ( libsecp256k1:: Signature , libsecp256k1:: RecoveryId ) , Self :: Error > {
385
- Ok ( (
386
- libsecp256k1:: Signature :: parse_overflowing_slice ( & x. 0 [ 0 ..64 ] ) . expect ( "hardcoded to 64 bytes; qed" ) ,
387
- libsecp256k1:: RecoveryId :: parse ( x. 0 [ 64 ] ) . map_err ( |_| ( ) ) ?,
388
- ) )
385
+ parse_signature ( & x. 0 ) . map_err ( |_| ( ) )
389
386
}
390
387
}
391
388
@@ -511,8 +508,10 @@ impl TraitPair for Pair {
511
508
fn verify_weak < P : AsRef < [ u8 ] > , M : AsRef < [ u8 ] > > ( sig : & [ u8 ] , message : M , pubkey : P ) -> bool {
512
509
let message = libsecp256k1:: Message :: parse ( & blake2_256 ( message. as_ref ( ) ) ) ;
513
510
if sig. len ( ) != 65 { return false }
514
- let ri = match libsecp256k1:: RecoveryId :: parse ( sig[ 64 ] ) { Ok ( x) => x, _ => return false } ;
515
- let sig = match libsecp256k1:: Signature :: parse_overflowing_slice ( & sig[ 0 ..64 ] ) { Ok ( x) => x, _ => return false } ;
511
+ let ( sig, ri) = match parse_signature ( & sig) {
512
+ Ok ( sigri) => sigri,
513
+ _ => return false ,
514
+ } ;
516
515
match libsecp256k1:: recover ( & message, & sig, & ri) {
517
516
Ok ( actual) => pubkey. as_ref ( ) == & actual. serialize ( ) [ 1 ..] ,
518
517
_ => false ,
@@ -565,6 +564,36 @@ impl Pair {
565
564
_ => false ,
566
565
}
567
566
}
567
+
568
+ /// Verify a signature on a message. Returns true if the signature is good.
569
+ /// Parses Signature using parse_overflowing_slice
570
+ pub fn verify_deprecated < M : AsRef < [ u8 ] > > ( sig : & Signature , message : M , pubkey : & Public ) -> bool {
571
+ let message = libsecp256k1:: Message :: parse ( & blake2_256 ( message. as_ref ( ) ) ) ;
572
+ let ( sig, ri) = match parse_signature_deprecated ( & sig. 0 ) {
573
+ Ok ( sigri) => sigri,
574
+ _ => return false
575
+ } ;
576
+ match libsecp256k1:: recover ( & message, & sig, & ri) {
577
+ Ok ( actual) => pubkey. 0 [ ..] == actual. serialize_compressed ( ) [ ..] ,
578
+ _ => false ,
579
+ }
580
+ }
581
+ }
582
+
583
+ fn parse_signature (
584
+ x : & [ u8 ] ,
585
+ ) -> Result < ( libsecp256k1:: Signature , libsecp256k1:: RecoveryId ) , libsecp256k1:: Error > {
586
+ let sig = libsecp256k1:: Signature :: parse_standard_slice ( & x[ 0 ..64 ] ) ?;
587
+ let ri = libsecp256k1:: RecoveryId :: parse ( x[ 64 ] ) ?;
588
+ Ok ( ( sig, ri) )
589
+ }
590
+
591
+ fn parse_signature_deprecated (
592
+ x : & [ u8 ] ,
593
+ ) -> Result < ( libsecp256k1:: Signature , libsecp256k1:: RecoveryId ) , libsecp256k1:: Error > {
594
+ let sig = libsecp256k1:: Signature :: parse_overflowing_slice ( & x[ 0 ..64 ] ) ?;
595
+ let ri = libsecp256k1:: RecoveryId :: parse ( x[ 64 ] ) ?;
596
+ Ok ( ( sig, ri) )
568
597
}
569
598
570
599
impl CryptoType for Public {
0 commit comments