@@ -174,7 +174,7 @@ impl<'s> UncheckedHrpstring<'s> {
174
174
}
175
175
176
176
if self . data . len ( ) < Ck :: CHECKSUM_LENGTH {
177
- return Err ( InvalidChecksumLength ) ;
177
+ return Err ( InvalidLength ) ;
178
178
}
179
179
180
180
let mut checksum_eng = checksum:: Engine :: < Ck > :: new ( ) ;
@@ -186,7 +186,7 @@ impl<'s> UncheckedHrpstring<'s> {
186
186
}
187
187
188
188
if checksum_eng. residue ( ) != & Ck :: TARGET_RESIDUE {
189
- return Err ( InvalidChecksum ) ;
189
+ return Err ( InvalidResidue ) ;
190
190
}
191
191
192
192
Ok ( ( ) )
@@ -705,10 +705,6 @@ pub enum CharError {
705
705
MissingSeparator ,
706
706
/// No characters after the separator.
707
707
NothingAfterSeparator ,
708
- /// The checksum does not match the rest of the data.
709
- InvalidChecksum ,
710
- /// The checksum is not a valid length.
711
- InvalidChecksumLength ,
712
708
/// Some part of the string contains an invalid character.
713
709
InvalidChar ( char ) ,
714
710
/// The whole string must be of one case.
@@ -722,8 +718,6 @@ impl fmt::Display for CharError {
722
718
match * self {
723
719
MissingSeparator => write ! ( f, "missing human-readable separator, \" {}\" " , SEP ) ,
724
720
NothingAfterSeparator => write ! ( f, "invalid data - no characters after the separator" ) ,
725
- InvalidChecksum => write ! ( f, "invalid checksum" ) ,
726
- InvalidChecksumLength => write ! ( f, "the checksum is not a valid length" ) ,
727
721
InvalidChar ( n) => write ! ( f, "invalid character (code={})" , n) ,
728
722
MixedCase => write ! ( f, "mixed-case strings not allowed" ) ,
729
723
}
@@ -736,12 +730,7 @@ impl std::error::Error for CharError {
736
730
use CharError :: * ;
737
731
738
732
match * self {
739
- MissingSeparator
740
- | NothingAfterSeparator
741
- | InvalidChecksum
742
- | InvalidChecksumLength
743
- | InvalidChar ( _)
744
- | MixedCase => None ,
733
+ MissingSeparator | NothingAfterSeparator | InvalidChar ( _) | MixedCase => None ,
745
734
}
746
735
}
747
736
}
@@ -750,19 +739,19 @@ impl std::error::Error for CharError {
750
739
#[ derive( Debug , Clone , PartialEq , Eq ) ]
751
740
#[ non_exhaustive]
752
741
pub enum ChecksumError {
753
- /// The checksum does not match the rest of the data.
754
- InvalidChecksum ,
742
+ /// The checksum residue is not valid for the data.
743
+ InvalidResidue ,
755
744
/// The checksum is not a valid length.
756
- InvalidChecksumLength ,
745
+ InvalidLength ,
757
746
}
758
747
759
748
impl fmt:: Display for ChecksumError {
760
749
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
761
750
use ChecksumError :: * ;
762
751
763
752
match * self {
764
- InvalidChecksum => write ! ( f, "invalid checksum" ) ,
765
- InvalidChecksumLength => write ! ( f, "the checksum is not a valid length" ) ,
753
+ InvalidResidue => write ! ( f, "the checksum residue is not valid for the data " ) ,
754
+ InvalidLength => write ! ( f, "the checksum is not a valid length" ) ,
766
755
}
767
756
}
768
757
}
@@ -773,7 +762,7 @@ impl std::error::Error for ChecksumError {
773
762
use ChecksumError :: * ;
774
763
775
764
match * self {
776
- InvalidChecksum | InvalidChecksumLength => None ,
765
+ InvalidResidue | InvalidLength => None ,
777
766
}
778
767
}
779
768
}
@@ -858,13 +847,13 @@ mod tests {
858
847
. expect ( "string parses correctly" )
859
848
. validate_checksum :: < Bech32 > ( )
860
849
. unwrap_err ( ) ;
861
- assert_eq ! ( err, InvalidChecksumLength ) ;
850
+ assert_eq ! ( err, InvalidLength ) ;
862
851
863
852
let err = UncheckedHrpstring :: new ( "A1G7SGD8" )
864
853
. expect ( "string parses correctly" )
865
854
. validate_checksum :: < Bech32 > ( )
866
855
. unwrap_err ( ) ;
867
- assert_eq ! ( err, InvalidChecksum ) ;
856
+ assert_eq ! ( err, InvalidResidue ) ;
868
857
}
869
858
870
859
#[ test]
@@ -918,14 +907,14 @@ mod tests {
918
907
for s in invalid {
919
908
let err =
920
909
UncheckedHrpstring :: new ( s) . unwrap ( ) . validate_checksum :: < Bech32m > ( ) . unwrap_err ( ) ;
921
- assert_eq ! ( err, InvalidChecksumLength ) ;
910
+ assert_eq ! ( err, InvalidLength ) ;
922
911
}
923
912
924
913
let err = UncheckedHrpstring :: new ( "M1VUXWEZ" )
925
914
. unwrap ( )
926
915
. validate_checksum :: < Bech32m > ( )
927
916
. unwrap_err ( ) ;
928
- assert_eq ! ( err, InvalidChecksum ) ;
917
+ assert_eq ! ( err, InvalidResidue ) ;
929
918
}
930
919
931
920
#[ test]
0 commit comments