@@ -174,7 +174,7 @@ impl<'s> UncheckedHrpstring<'s> {
174174 }
175175
176176 if self . data . len ( ) < Ck :: CHECKSUM_LENGTH {
177- return Err ( InvalidChecksumLength ) ;
177+ return Err ( InvalidLength ) ;
178178 }
179179
180180 let mut checksum_eng = checksum:: Engine :: < Ck > :: new ( ) ;
@@ -186,7 +186,7 @@ impl<'s> UncheckedHrpstring<'s> {
186186 }
187187
188188 if checksum_eng. residue ( ) != & Ck :: TARGET_RESIDUE {
189- return Err ( InvalidChecksum ) ;
189+ return Err ( InvalidResidue ) ;
190190 }
191191
192192 Ok ( ( ) )
@@ -705,10 +705,6 @@ pub enum CharError {
705705 MissingSeparator ,
706706 /// No characters after the separator.
707707 NothingAfterSeparator ,
708- /// The checksum does not match the rest of the data.
709- InvalidChecksum ,
710- /// The checksum is not a valid length.
711- InvalidChecksumLength ,
712708 /// Some part of the string contains an invalid character.
713709 InvalidChar ( char ) ,
714710 /// The whole string must be of one case.
@@ -722,8 +718,6 @@ impl fmt::Display for CharError {
722718 match * self {
723719 MissingSeparator => write ! ( f, "missing human-readable separator, \" {}\" " , SEP ) ,
724720 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" ) ,
727721 InvalidChar ( n) => write ! ( f, "invalid character (code={})" , n) ,
728722 MixedCase => write ! ( f, "mixed-case strings not allowed" ) ,
729723 }
@@ -736,12 +730,7 @@ impl std::error::Error for CharError {
736730 use CharError :: * ;
737731
738732 match * self {
739- MissingSeparator
740- | NothingAfterSeparator
741- | InvalidChecksum
742- | InvalidChecksumLength
743- | InvalidChar ( _)
744- | MixedCase => None ,
733+ MissingSeparator | NothingAfterSeparator | InvalidChar ( _) | MixedCase => None ,
745734 }
746735 }
747736}
@@ -750,19 +739,19 @@ impl std::error::Error for CharError {
750739#[ derive( Debug , Clone , PartialEq , Eq ) ]
751740#[ non_exhaustive]
752741pub 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 ,
755744 /// The checksum is not a valid length.
756- InvalidChecksumLength ,
745+ InvalidLength ,
757746}
758747
759748impl fmt:: Display for ChecksumError {
760749 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
761750 use ChecksumError :: * ;
762751
763752 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" ) ,
766755 }
767756 }
768757}
@@ -773,7 +762,7 @@ impl std::error::Error for ChecksumError {
773762 use ChecksumError :: * ;
774763
775764 match * self {
776- InvalidChecksum | InvalidChecksumLength => None ,
765+ InvalidResidue | InvalidLength => None ,
777766 }
778767 }
779768}
@@ -858,13 +847,13 @@ mod tests {
858847 . expect ( "string parses correctly" )
859848 . validate_checksum :: < Bech32 > ( )
860849 . unwrap_err ( ) ;
861- assert_eq ! ( err, InvalidChecksumLength ) ;
850+ assert_eq ! ( err, InvalidLength ) ;
862851
863852 let err = UncheckedHrpstring :: new ( "A1G7SGD8" )
864853 . expect ( "string parses correctly" )
865854 . validate_checksum :: < Bech32 > ( )
866855 . unwrap_err ( ) ;
867- assert_eq ! ( err, InvalidChecksum ) ;
856+ assert_eq ! ( err, InvalidResidue ) ;
868857 }
869858
870859 #[ test]
@@ -918,14 +907,14 @@ mod tests {
918907 for s in invalid {
919908 let err =
920909 UncheckedHrpstring :: new ( s) . unwrap ( ) . validate_checksum :: < Bech32m > ( ) . unwrap_err ( ) ;
921- assert_eq ! ( err, InvalidChecksumLength ) ;
910+ assert_eq ! ( err, InvalidLength ) ;
922911 }
923912
924913 let err = UncheckedHrpstring :: new ( "M1VUXWEZ" )
925914 . unwrap ( )
926915 . validate_checksum :: < Bech32m > ( )
927916 . unwrap_err ( ) ;
928- assert_eq ! ( err, InvalidChecksum ) ;
917+ assert_eq ! ( err, InvalidResidue ) ;
929918 }
930919
931920 #[ test]
0 commit comments