@@ -242,6 +242,21 @@ def test_ascii85_valid(self):
242242 res += b
243243 self .assertEqual (res , rawdata )
244244
245+ # Test decoding inputs with length 1 mod 5
246+ params = [
247+ (b"a" , False , False , b"" , b"" ),
248+ (b"xbw" , False , False , b"wx" , b"" ),
249+ (b"<~c~>" , False , True , b"" , b"" ),
250+ (b"{d ~>" , False , True , b" {" , b"" ),
251+ (b"ye" , True , False , b"" , b" " ),
252+ (b"z\x01 y\x00 f" , True , False , b"\x00 \x01 " , b"\x00 \x00 \x00 \x00 " ),
253+ (b"<~FCfN8yg~>" , True , True , b"" , b"test " ),
254+ (b"FE;\x03 #8zFCf\x02 N8yh~>" , True , True , b"\x02 \x03 " , b"tset\x00 \x00 \x00 \x00 test " ),
255+ ]
256+ for a , fold_spaces , wrap , ignore , b in params :
257+ kwargs = {"fold_spaces" : fold_spaces , "wrap" : wrap , "ignore" : ignore }
258+ self .assertEqual (binascii .a2b_ascii85 (self .type2test (a ), ** kwargs ), b )
259+
245260 def test_ascii85_invalid (self ):
246261 # Test Ascii85 with invalid characters interleaved
247262 lines , i = [], 0
@@ -284,19 +299,16 @@ def _assertRegexTemplate(assert_regex, data, **kwargs):
284299 binascii .a2b_ascii85 (self .type2test (data ), ** kwargs )
285300
286301 def assertMissingDelimiter (data ):
287- _assertRegexTemplate (r"(?i)end with '~>'" , data , wrap = True )
302+ _assertRegexTemplate (r"(?i)end with b '~>'" , data , wrap = True )
288303
289304 def assertOverflow (data ):
290- _assertRegexTemplate (r"(?i)85 overflow" , data )
305+ _assertRegexTemplate (r"(?i)Ascii85 overflow" , data )
291306
292307 def assertInvalidSpecial (data ):
293308 _assertRegexTemplate (r"(?i)'[yz]'.+5-tuple" , data , fold_spaces = True )
294309
295310 def assertInvalidChar (data , ** kwargs ):
296- _assertRegexTemplate (r"(?i)invalid in Ascii85" , data , ** kwargs )
297-
298- def assertInvalidLength (data ):
299- _assertRegexTemplate (r"(?i)invalid length" , data )
311+ _assertRegexTemplate (r"(?i)Non-Ascii85 digit" , data , ** kwargs )
300312
301313 # Test Ascii85 with missing delimiters
302314 assertMissingDelimiter (b"" )
@@ -331,15 +343,6 @@ def assertInvalidLength(data):
331343 assertInvalidChar (b"\t FCb" , ignore = b"\n " )
332344 assertInvalidChar (b"xxxB\n P\t hU'D v/F+" , ignore = b" \n \t v" )
333345
334- # Test Ascii85 with invalid length of final group (1 mod 5)
335- assertInvalidLength (b"a" )
336- assertInvalidLength (b"b" )
337- assertInvalidLength (b"zc" )
338- assertInvalidLength (b"zza" )
339- assertInvalidLength (b"!!!!!a" )
340- assertInvalidLength (b"+<VdL+<VdLZ" )
341- assertInvalidLength (b"Z" * (5 * 43 + 21 ))
342-
343346 def test_ascii85_width (self ):
344347 # Test Ascii85 splitting lines by width
345348 def assertEncode (a_expected , data , n , wrap = False ):
@@ -411,7 +414,7 @@ def test_ascii85_ignore(self):
411414 def assertIgnore (data , expected , ignore = b"" , ** kwargs ):
412415 data = self .type2test (data )
413416 ignore = self .type2test (ignore )
414- with self .assertRaisesRegex (binascii .Error , r"(?i)invalid in Ascii85" ):
417+ with self .assertRaisesRegex (binascii .Error , r"(?i)Non- Ascii85 digit " ):
415418 binascii .a2b_ascii85 (data , ** kwargs )
416419 res = binascii .a2b_ascii85 (data , ignore = ignore , ** kwargs )
417420 self .assertEqual (res , expected )
@@ -441,6 +444,11 @@ def test_base85_valid(self):
441444 res += b
442445 self .assertEqual (res , self .rawdata )
443446
447+ # Test decoding inputs with length 1 mod 5
448+ self .assertEqual (binascii .a2b_base85 (self .type2test (b"a" )), b"" )
449+ self .assertEqual (binascii .a2b_base85 (self .type2test (b" b " )), b"" )
450+ self .assertEqual (binascii .a2b_base85 (self .type2test (b"b/Y\" *,j'Nc" )), b"test" )
451+
444452 def test_base85_invalid (self ):
445453 # Test base85 with invalid characters interleaved
446454 lines , i = [], 0
@@ -480,9 +488,6 @@ def _assertRegexTemplate(assert_regex, data, **kwargs):
480488 def assertOverflow (data ):
481489 _assertRegexTemplate (r"(?i)base85 overflow" , data )
482490
483- def assertInvalidLength (data ):
484- _assertRegexTemplate (r"(?i)invalid length" , data )
485-
486491 # Test base85 with out-of-range encoded value
487492 assertOverflow (b"}" )
488493 assertOverflow (b"|O" )
@@ -492,13 +497,6 @@ def assertInvalidLength(data):
492497 assertOverflow (b"|NsC0~" )
493498 assertOverflow (b"|NsC0|NsC0|NsD0" )
494499
495- # Test base85 with invalid length of final group (1 mod 5)
496- assertInvalidLength (b"0" )
497- assertInvalidLength (b"1" )
498- assertInvalidLength (b"^^^^^^" )
499- assertInvalidLength (b"|NsC0|NsC0a" )
500- assertInvalidLength (b"_" * (5 * 43 + 21 ))
501-
502500 def test_base85_pad (self ):
503501 # Test base85 with encode padding
504502 rawdata = b"n1n3Tee\n ch@rAc\t e\r $"
@@ -514,7 +512,7 @@ def test_base85_strict_mode(self):
514512 # Test base85 with strict mode on
515513 def assertNonBase85Data (data , expected ):
516514 data = self .type2test (data )
517- with self .assertRaisesRegex (binascii .Error , r"(?i)invalid in base85" ):
515+ with self .assertRaisesRegex (binascii .Error , r"(?i)bad base85 character " ):
518516 binascii .a2b_base85 (data , strict_mode = True )
519517 default_res = binascii .a2b_base85 (data )
520518 non_strict_res = binascii .a2b_base85 (data , strict_mode = False )
0 commit comments