File tree Expand file tree Collapse file tree 2 files changed +39
-2
lines changed
Expand file tree Collapse file tree 2 files changed +39
-2
lines changed Original file line number Diff line number Diff line change 11use super :: * ;
22
3- #[ derive( Clone , Copy , Debug ) ]
3+ #[ derive( Clone , Copy , Debug , PartialEq ) ]
44pub enum Bech32mType {
55 Fingerprint ,
66 PrivateKey ,
Original file line number Diff line number Diff line change @@ -60,7 +60,10 @@ impl FromStr for Signature {
6060
6161#[ cfg( test) ]
6262mod tests {
63- use super :: * ;
63+ use {
64+ super :: * ,
65+ bech32:: primitives:: decode:: { ChecksumError , CodeLengthError } ,
66+ } ;
6467
6568 #[ test]
6669 fn error_display ( ) {
@@ -99,6 +102,40 @@ mod tests {
99102 ) ;
100103 }
101104
105+ #[ test]
106+ fn overlong_pgp_suffix ( ) {
107+ let bech32m = [ Fe32 :: P , Fe32 :: _4, Fe32 :: P ]
108+ . into_iter ( )
109+ . chain ( [ 0u8 ; 64 ] . into_iter ( ) . chain ( vec ! [ 0u8 ; 65536 ] ) . bytes_to_fes ( ) )
110+ . with_checksum :: < bech32:: Bech32m > ( Signature :: TYPE . hrp ( ) )
111+ . with_witness_version ( Fe32 :: A )
112+ . chars ( )
113+ . collect :: < String > ( ) ;
114+
115+ let SignatureError :: Bech32m { source } = bech32m. parse :: < Signature > ( ) . unwrap_err ( ) else {
116+ panic ! ( "expected bech32m error" ) ;
117+ } ;
118+
119+ let Bech32mError :: Decode { ty, source } = source else {
120+ panic ! ( "expected decode error" ) ;
121+ } ;
122+
123+ assert_eq ! ( ty, Bech32mType :: Signature ) ;
124+
125+ let CheckedHrpstringError :: Checksum ( err) = source else {
126+ panic ! ( "expected checksum error" ) ;
127+ } ;
128+
129+ assert_matches ! (
130+ err,
131+ ChecksumError :: CodeLength ( CodeLengthError {
132+ encoded_length: 104_980 ,
133+ code_length: 1023 ,
134+ ..
135+ } )
136+ ) ;
137+ }
138+
102139 #[ test]
103140 fn parse ( ) {
104141 let message = Message {
You can’t perform that action at this time.
0 commit comments