summaryrefslogtreecommitdiffstats
path: root/Lib/base64.py
diff options
context:
space:
mode:
authorAndrew M. Kuchling <amk@amk.ca>2005-06-08 22:51:38 (GMT)
committerAndrew M. Kuchling <amk@amk.ca>2005-06-08 22:51:38 (GMT)
commit6e57c2a6532d6f1158586232452a3b440e975b98 (patch)
treeae0fffcb88a34fc56dab07dc721e7b9c48b8799e /Lib/base64.py
parent8dbe1a70d788d91dd8851b92557d5e1a011f56f7 (diff)
downloadcpython-6e57c2a6532d6f1158586232452a3b440e975b98.zip
cpython-6e57c2a6532d6f1158586232452a3b440e975b98.tar.gz
cpython-6e57c2a6532d6f1158586232452a3b440e975b98.tar.bz2
[Patch #1171487, bug #1170331] Fix error in base64.b32decode when encoding a single null byte; test a null byte in all encodings to be sure it works
Diffstat (limited to 'Lib/base64.py')
-rwxr-xr-xLib/base64.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/Lib/base64.py b/Lib/base64.py
index f90b91d..8914acc 100755
--- a/Lib/base64.py
+++ b/Lib/base64.py
@@ -221,12 +221,14 @@ def b32decode(s, casefold=False, map01=None):
acc += _b32rev[c] << shift
shift -= 5
if shift < 0:
- parts.append(binascii.unhexlify(hex(acc)[2:-1]))
+ parts.append(binascii.unhexlify('%010x' % acc))
acc = 0
shift = 35
# Process the last, partial quanta
- last = binascii.unhexlify(hex(acc)[2:-1])
- if padchars == 1:
+ last = binascii.unhexlify('%010x' % acc)
+ if padchars == 0:
+ last = '' # No characters
+ elif padchars == 1:
last = last[:-1]
elif padchars == 3:
last = last[:-2]
@@ -234,7 +236,7 @@ def b32decode(s, casefold=False, map01=None):
last = last[:-3]
elif padchars == 6:
last = last[:-4]
- elif padchars <> 0:
+ else:
raise TypeError('Incorrect padding')
parts.append(last)
return EMPTYSTRING.join(parts)