New submission from Kent Watsen <kent+pyth...@watsen.net>:

[Tested on 3.8.2 and 3.9.0, bug may manifest in other versions too]

The IETF sometimes uses the dummy base64 value "base64encodedvalue==" in 
specifications in lieu of a block of otherwise meaningless b64.  

Even though it is a dummy value, the value should be convertible to binary and 
back again.  This works using the built-in command `base64` as well as OpenSSL 
command line, but binascii is unable to do it.  See below:

$ echo "base64encodedvalue==" | base64 | base64 -d
base64encodedvalue==

$ echo "base64encodedvalue==" | openssl enc -base64 -A | openssl enc -d base64 
-A
base64encodedvalue==                                                            
                                             

$ printf "import 
binascii\nprint(binascii.b2a_base64(binascii.a2b_base64('base64encodedvalue=='),
 newline=False).decode('ascii'))" |  python -
base64encodedvaluQ==

After some investigation, it appears that almost any valid base64 matching the 
pattern "??==" fails.  For instance:

$ printf "import 
binascii\nprint(binascii.b2a_base64(binascii.a2b_base64('ue=='), 
newline=False).decode('ascii'))" |  python -                                    
                       
uQ==

$ printf "import 
binascii\nprint(binascii.b2a_base64(binascii.a2b_base64('aa=='), 
newline=False).decode('ascii'))" |  python -                                    
                       
aQ==

$ printf "import 
binascii\nprint(binascii.b2a_base64(binascii.a2b_base64('a0=='), 
newline=False).decode('ascii'))" |  python -                                    
                       
aw==


Is this a bug?

----------
messages: 382922
nosy: kwatsen2
priority: normal
severity: normal
status: open
title: binascii doesn't work on some base64
type: behavior
versions: Python 3.8, Python 3.9

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue42628>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to