@@ -138,15 +138,15 @@ impl<'s> UncheckedHrpstring<'s> {
138
138
/// checksum if `NoChecksum` is used).
139
139
#[ inline]
140
140
pub fn validate_checksum < Ck : Checksum > ( & self ) -> Result < ( ) , ChecksumError > {
141
- use ChecksumError :: * ;
141
+ use ChecksumError as E ;
142
142
143
143
if Ck :: CHECKSUM_LENGTH == 0 {
144
144
// Called with NoChecksum
145
145
return Ok ( ( ) ) ;
146
146
}
147
147
148
148
if self . data . len ( ) < Ck :: CHECKSUM_LENGTH {
149
- return Err ( InvalidChecksumLength ) ;
149
+ return Err ( E :: InvalidChecksumLength ) ;
150
150
}
151
151
152
152
let mut checksum_eng = checksum:: Engine :: < Ck > :: new ( ) ;
@@ -158,7 +158,7 @@ impl<'s> UncheckedHrpstring<'s> {
158
158
}
159
159
160
160
if checksum_eng. residue ( ) != & Ck :: TARGET_RESIDUE {
161
- return Err ( InvalidChecksum ) ;
161
+ return Err ( E :: InvalidChecksum ) ;
162
162
}
163
163
164
164
Ok ( ( ) )
@@ -405,7 +405,7 @@ impl<'s> SegwitHrpstring<'s> {
405
405
///
406
406
/// The byte-index into the string where the '1' separator occurs, or an error if it does not.
407
407
fn check_characters ( s : & str ) -> Result < usize , CharError > {
408
- use CharError :: * ;
408
+ use CharError as E ;
409
409
410
410
let mut has_upper = false ;
411
411
let mut has_lower = false ;
@@ -417,7 +417,7 @@ fn check_characters(s: &str) -> Result<usize, CharError> {
417
417
sep_pos = Some ( n) ;
418
418
}
419
419
if req_bech32 {
420
- Fe32 :: from_char ( ch) . map_err ( |_| InvalidChar ( ch) ) ?;
420
+ Fe32 :: from_char ( ch) . map_err ( |_| E :: InvalidChar ( ch) ) ?;
421
421
}
422
422
if ch. is_ascii_uppercase ( ) {
423
423
has_upper = true ;
@@ -426,11 +426,11 @@ fn check_characters(s: &str) -> Result<usize, CharError> {
426
426
}
427
427
}
428
428
if has_upper && has_lower {
429
- Err ( MixedCase )
429
+ Err ( E :: MixedCase )
430
430
} else if let Some ( pos) = sep_pos {
431
431
Ok ( pos)
432
432
} else {
433
- Err ( MissingSeparator )
433
+ Err ( E :: MissingSeparator )
434
434
}
435
435
}
436
436
@@ -505,29 +505,25 @@ pub enum SegwitHrpstringError {
505
505
506
506
impl fmt:: Display for SegwitHrpstringError {
507
507
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
508
- use SegwitHrpstringError :: * ;
509
-
510
508
match * self {
511
- Unchecked ( ref e) => write_err ! ( f, "parsing unchecked hrpstring failed" ; e) ,
512
- MissingWitnessVersion => write ! ( f, "the witness version byte is missing" ) ,
513
- InvalidWitnessVersion ( fe) => write ! ( f, "invalid segwit witness version: {}" , fe. to_u8( ) ) ,
514
- Padding ( ref e) => write_err ! ( f, "invalid padding on the witness data" ; e) ,
515
- WitnessLength ( ref e) => write_err ! ( f, "invalid witness length" ; e) ,
516
- Checksum ( ref e) => write_err ! ( f, "invalid checksum" ; e) ,
509
+ Self :: Unchecked ( ref e) => write_err ! ( f, "parsing unchecked hrpstring failed" ; e) ,
510
+ Self :: MissingWitnessVersion => write ! ( f, "the witness version byte is missing" ) ,
511
+ Self :: InvalidWitnessVersion ( fe) => write ! ( f, "invalid segwit witness version: {}" , fe. to_u8( ) ) ,
512
+ Self :: Padding ( ref e) => write_err ! ( f, "invalid padding on the witness data" ; e) ,
513
+ Self :: WitnessLength ( ref e) => write_err ! ( f, "invalid witness length" ; e) ,
514
+ Self :: Checksum ( ref e) => write_err ! ( f, "invalid checksum" ; e) ,
517
515
}
518
516
}
519
517
}
520
518
521
519
impl std:: error:: Error for SegwitHrpstringError {
522
520
fn source ( & self ) -> Option < & ( dyn std:: error:: Error + ' static ) > {
523
- use SegwitHrpstringError :: * ;
524
-
525
521
match * self {
526
- Unchecked ( ref e) => Some ( e) ,
527
- Padding ( ref e) => Some ( e) ,
528
- WitnessLength ( ref e) => Some ( e) ,
529
- Checksum ( ref e) => Some ( e) ,
530
- MissingWitnessVersion | InvalidWitnessVersion ( _) => None ,
522
+ Self :: Unchecked ( ref e) => Some ( e) ,
523
+ Self :: Padding ( ref e) => Some ( e) ,
524
+ Self :: WitnessLength ( ref e) => Some ( e) ,
525
+ Self :: Checksum ( ref e) => Some ( e) ,
526
+ Self :: MissingWitnessVersion | Self :: InvalidWitnessVersion ( _) => None ,
531
527
}
532
528
}
533
529
}
@@ -564,22 +560,18 @@ pub enum CheckedHrpstringError {
564
560
565
561
impl fmt:: Display for CheckedHrpstringError {
566
562
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
567
- use CheckedHrpstringError :: * ;
568
-
569
563
match * self {
570
- Parse ( ref e) => write_err ! ( f, "parse failed" ; e) ,
571
- Checksum ( ref e) => write_err ! ( f, "invalid checksum" ; e) ,
564
+ Self :: Parse ( ref e) => write_err ! ( f, "parse failed" ; e) ,
565
+ Self :: Checksum ( ref e) => write_err ! ( f, "invalid checksum" ; e) ,
572
566
}
573
567
}
574
568
}
575
569
576
570
impl std:: error:: Error for CheckedHrpstringError {
577
571
fn source ( & self ) -> Option < & ( dyn std:: error:: Error + ' static ) > {
578
- use CheckedHrpstringError :: * ;
579
-
580
572
match * self {
581
- Parse ( ref e) => Some ( e) ,
582
- Checksum ( ref e) => Some ( e) ,
573
+ Self :: Parse ( ref e) => Some ( e) ,
574
+ Self :: Checksum ( ref e) => Some ( e) ,
583
575
}
584
576
}
585
577
}
@@ -606,22 +598,18 @@ pub enum UncheckedHrpstringError {
606
598
607
599
impl fmt:: Display for UncheckedHrpstringError {
608
600
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
609
- use UncheckedHrpstringError :: * ;
610
-
611
601
match * self {
612
- Char ( ref e) => write_err ! ( f, "character error" ; e) ,
613
- Hrp ( ref e) => write_err ! ( f, "invalid human-readable part" ; e) ,
602
+ Self :: Char ( ref e) => write_err ! ( f, "character error" ; e) ,
603
+ Self :: Hrp ( ref e) => write_err ! ( f, "invalid human-readable part" ; e) ,
614
604
}
615
605
}
616
606
}
617
607
618
608
impl std:: error:: Error for UncheckedHrpstringError {
619
609
fn source ( & self ) -> Option < & ( dyn std:: error:: Error + ' static ) > {
620
- use UncheckedHrpstringError :: * ;
621
-
622
610
match * self {
623
- Char ( ref e) => Some ( e) ,
624
- Hrp ( ref e) => Some ( e) ,
611
+ Self :: Char ( ref e) => Some ( e) ,
612
+ Self :: Hrp ( ref e) => Some ( e) ,
625
613
}
626
614
}
627
615
}
@@ -656,30 +644,26 @@ pub enum CharError {
656
644
657
645
impl fmt:: Display for CharError {
658
646
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
659
- use CharError :: * ;
660
-
661
647
match * self {
662
- MissingSeparator => write ! ( f, "missing human-readable separator, \" {}\" " , SEP ) ,
663
- NothingAfterSeparator => write ! ( f, "invalid data - no characters after the separator" ) ,
664
- InvalidChecksum => write ! ( f, "invalid checksum" ) ,
665
- InvalidChecksumLength => write ! ( f, "the checksum is not a valid length" ) ,
666
- InvalidChar ( n) => write ! ( f, "invalid character (code={})" , n) ,
667
- MixedCase => write ! ( f, "mixed-case strings not allowed" ) ,
648
+ Self :: MissingSeparator => write ! ( f, "missing human-readable separator, \" {}\" " , SEP ) ,
649
+ Self :: NothingAfterSeparator => write ! ( f, "invalid data - no characters after the separator" ) ,
650
+ Self :: InvalidChecksum => write ! ( f, "invalid checksum" ) ,
651
+ Self :: InvalidChecksumLength => write ! ( f, "the checksum is not a valid length" ) ,
652
+ Self :: InvalidChar ( n) => write ! ( f, "invalid character (code={})" , n) ,
653
+ Self :: MixedCase => write ! ( f, "mixed-case strings not allowed" ) ,
668
654
}
669
655
}
670
656
}
671
657
672
658
impl std:: error:: Error for CharError {
673
659
fn source ( & self ) -> Option < & ( dyn std:: error:: Error + ' static ) > {
674
- use CharError :: * ;
675
-
676
660
match * self {
677
- MissingSeparator
678
- | NothingAfterSeparator
679
- | InvalidChecksum
680
- | InvalidChecksumLength
681
- | InvalidChar ( _)
682
- | MixedCase => None ,
661
+ Self :: MissingSeparator
662
+ | Self :: NothingAfterSeparator
663
+ | Self :: InvalidChecksum
664
+ | Self :: InvalidChecksumLength
665
+ | Self :: InvalidChar ( _)
666
+ | Self :: MixedCase => None ,
683
667
}
684
668
}
685
669
}
@@ -696,21 +680,17 @@ pub enum ChecksumError {
696
680
697
681
impl fmt:: Display for ChecksumError {
698
682
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
699
- use ChecksumError :: * ;
700
-
701
683
match * self {
702
- InvalidChecksum => write ! ( f, "invalid checksum" ) ,
703
- InvalidChecksumLength => write ! ( f, "the checksum is not a valid length" ) ,
684
+ Self :: InvalidChecksum => write ! ( f, "invalid checksum" ) ,
685
+ Self :: InvalidChecksumLength => write ! ( f, "the checksum is not a valid length" ) ,
704
686
}
705
687
}
706
688
}
707
689
708
690
impl std:: error:: Error for ChecksumError {
709
691
fn source ( & self ) -> Option < & ( dyn std:: error:: Error + ' static ) > {
710
- use ChecksumError :: * ;
711
-
712
692
match * self {
713
- InvalidChecksum | InvalidChecksumLength => None ,
693
+ Self :: InvalidChecksum | Self :: InvalidChecksumLength => None ,
714
694
}
715
695
}
716
696
}
@@ -727,21 +707,17 @@ pub enum PaddingError {
727
707
728
708
impl fmt:: Display for PaddingError {
729
709
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
730
- use PaddingError :: * ;
731
-
732
710
match * self {
733
- TooMuch => write ! ( f, "the data payload has too many bits of padding" ) ,
734
- NonZero => write ! ( f, "the data payload is padded with non-zero bits" ) ,
711
+ Self :: TooMuch => write ! ( f, "the data payload has too many bits of padding" ) ,
712
+ Self :: NonZero => write ! ( f, "the data payload is padded with non-zero bits" ) ,
735
713
}
736
714
}
737
715
}
738
716
739
717
impl std:: error:: Error for PaddingError {
740
718
fn source ( & self ) -> Option < & ( dyn std:: error:: Error + ' static ) > {
741
- use PaddingError :: * ;
742
-
743
719
match * self {
744
- TooMuch | NonZero => None ,
720
+ Self :: TooMuch | Self :: NonZero => None ,
745
721
}
746
722
}
747
723
}
@@ -752,32 +728,32 @@ mod tests {
752
728
753
729
#[ test]
754
730
fn bip_173_invalid_parsing_fails ( ) {
755
- use UncheckedHrpstringError :: * ;
731
+ use UncheckedHrpstringError as E ;
756
732
757
733
let invalid: Vec < ( & str , UncheckedHrpstringError ) > = vec ! (
758
734
( "\u{20} 1nwldj5" ,
759
735
// TODO: Rust >= 1.59.0 use Hrp(hrp::Error::InvalidAsciiByte('\u{20}'.try_into().unwrap()))),
760
- Hrp ( hrp:: Error :: InvalidAsciiByte ( 32 ) ) ) ,
736
+ E :: Hrp ( hrp:: Error :: InvalidAsciiByte ( 32 ) ) ) ,
761
737
( "\u{7F} 1axkwrx" ,
762
- Hrp ( hrp:: Error :: InvalidAsciiByte ( 127 ) ) ) ,
738
+ E :: Hrp ( hrp:: Error :: InvalidAsciiByte ( 127 ) ) ) ,
763
739
( "\u{80} 1eym55h" ,
764
- Hrp ( hrp:: Error :: NonAsciiChar ( '\u{80}' ) ) ) ,
740
+ E :: Hrp ( hrp:: Error :: NonAsciiChar ( '\u{80}' ) ) ) ,
765
741
( "an84characterslonghumanreadablepartthatcontainsthetheexcludedcharactersbioandnumber11d6pts4" ,
766
- Hrp ( hrp:: Error :: TooLong ( 84 ) ) ) ,
742
+ E :: Hrp ( hrp:: Error :: TooLong ( 84 ) ) ) ,
767
743
( "pzry9x0s0muk" ,
768
- Char ( CharError :: MissingSeparator ) ) ,
744
+ E :: Char ( CharError :: MissingSeparator ) ) ,
769
745
( "1pzry9x0s0muk" ,
770
- Hrp ( hrp:: Error :: Empty ) ) ,
746
+ E :: Hrp ( hrp:: Error :: Empty ) ) ,
771
747
( "x1b4n0q5v" ,
772
- Char ( CharError :: InvalidChar ( 'b' ) ) ) ,
748
+ E :: Char ( CharError :: InvalidChar ( 'b' ) ) ) ,
773
749
// "li1dgmt3" in separate test because error is a checksum error.
774
750
( "de1lg7wt\u{ff} " ,
775
- Char ( CharError :: InvalidChar ( '\u{ff}' ) ) ) ,
751
+ E :: Char ( CharError :: InvalidChar ( '\u{ff}' ) ) ) ,
776
752
// "A1G7SGD8" in separate test because error is a checksum error.
777
753
( "10a06t8" ,
778
- Hrp ( hrp:: Error :: Empty ) ) ,
754
+ E :: Hrp ( hrp:: Error :: Empty ) ) ,
779
755
( "1qzzfhee" ,
780
- Hrp ( hrp:: Error :: Empty ) ) ,
756
+ E :: Hrp ( hrp:: Error :: Empty ) ) ,
781
757
) ;
782
758
783
759
for ( s, want) in invalid {
@@ -789,54 +765,54 @@ mod tests {
789
765
/*
790
766
#[test]
791
767
fn bip_173_invalid_parsing_fails_invalid_checksum() {
792
- use ChecksumError::* ;
768
+ use ChecksumError as E ;
793
769
794
770
let err = UncheckedHrpstring::new("li1dgmt3")
795
771
.expect("string parses correctly")
796
772
.validate_checksum::<Blech32>()
797
773
.unwrap_err();
798
- assert_eq!(err, InvalidChecksumLength);
774
+ assert_eq!(err, E:: InvalidChecksumLength);
799
775
800
776
let err = UncheckedHrpstring::new("A1G7SGD8")
801
777
.expect("string parses correctly")
802
778
.validate_checksum::<Blech32>()
803
779
.unwrap_err();
804
- assert_eq!(err, InvalidChecksum);
780
+ assert_eq!(err, E:: InvalidChecksum);
805
781
}
806
782
*/
807
783
808
784
#[ test]
809
785
fn bip_350_invalid_parsing_fails ( ) {
810
- use UncheckedHrpstringError :: * ;
786
+ use UncheckedHrpstringError as E ;
811
787
812
788
let invalid: Vec < ( & str , UncheckedHrpstringError ) > = vec ! (
813
789
( "\u{20} 1xj0phk" ,
814
790
// TODO: Rust >= 1.59.0 use Hrp(hrp::Error::InvalidAsciiByte('\u{20}'.try_into().unwrap()))),
815
- Hrp ( hrp:: Error :: InvalidAsciiByte ( 32 ) ) ) ,
791
+ E :: Hrp ( hrp:: Error :: InvalidAsciiByte ( 32 ) ) ) ,
816
792
( "\u{7F} 1g6xzxy" ,
817
- Hrp ( hrp:: Error :: InvalidAsciiByte ( 127 ) ) ) ,
793
+ E :: Hrp ( hrp:: Error :: InvalidAsciiByte ( 127 ) ) ) ,
818
794
( "\u{80} 1g6xzxy" ,
819
- Hrp ( hrp:: Error :: NonAsciiChar ( '\u{80}' ) ) ) ,
795
+ E :: Hrp ( hrp:: Error :: NonAsciiChar ( '\u{80}' ) ) ) ,
820
796
( "an84characterslonghumanreadablepartthatcontainsthenumber1andtheexcludedcharactersbio1569pvx" ,
821
- Hrp ( hrp:: Error :: TooLong ( 84 ) ) ) ,
797
+ E :: Hrp ( hrp:: Error :: TooLong ( 84 ) ) ) ,
822
798
( "qyrz8wqd2c9m" ,
823
- Char ( CharError :: MissingSeparator ) ) ,
799
+ E :: Char ( CharError :: MissingSeparator ) ) ,
824
800
( "1qyrz8wqd2c9m" ,
825
- Hrp ( hrp:: Error :: Empty ) ) ,
801
+ E :: Hrp ( hrp:: Error :: Empty ) ) ,
826
802
( "y1b0jsk6g" ,
827
- Char ( CharError :: InvalidChar ( 'b' ) ) ) ,
803
+ E :: Char ( CharError :: InvalidChar ( 'b' ) ) ) ,
828
804
( "lt1igcx5c0" ,
829
- Char ( CharError :: InvalidChar ( 'i' ) ) ) ,
805
+ E :: Char ( CharError :: InvalidChar ( 'i' ) ) ) ,
830
806
// "in1muywd" in separate test because error is a checksum error.
831
807
( "mm1crxm3i" ,
832
- Char ( CharError :: InvalidChar ( 'i' ) ) ) ,
808
+ E :: Char ( CharError :: InvalidChar ( 'i' ) ) ) ,
833
809
( "au1s5cgom" ,
834
- Char ( CharError :: InvalidChar ( 'o' ) ) ) ,
810
+ E :: Char ( CharError :: InvalidChar ( 'o' ) ) ) ,
835
811
// "M1VUXWEZ" in separate test because error is a checksum error.
836
812
( "16plkw9" ,
837
- Hrp ( hrp:: Error :: Empty ) ) ,
813
+ E :: Hrp ( hrp:: Error :: Empty ) ) ,
838
814
( "1p2gdwpf" ,
839
- Hrp ( hrp:: Error :: Empty ) ) ,
815
+ E :: Hrp ( hrp:: Error :: Empty ) ) ,
840
816
841
817
) ;
842
818
0 commit comments