# HG changeset patch # User Mads Kiilerich # Date 1576453991 -3600 # Node ID 82b1eaec25f552d33b02ebf2b31a7d2c3b7b094b # Parent ae12fabba699dd7deb8f5b4062068d390d6cac23 py3: replace base64 encoding with base64 module diff -r ae12fabba699 -r 82b1eaec25f5 kallithea/lib/base.py --- a/kallithea/lib/base.py Tue Dec 10 02:56:48 2019 +0100 +++ b/kallithea/lib/base.py Mon Dec 16 00:53:11 2019 +0100 @@ -28,6 +28,7 @@ :license: GPLv3, see LICENSE.md for more details. """ +import base64 import datetime import logging import traceback @@ -171,7 +172,7 @@ (authmeth, auth) = authorization.split(' ', 1) if 'basic' != authmeth.lower(): return self.build_authentication(environ) - auth = auth.strip().decode('base64') + auth = base64.b64decode(auth.strip()) _parts = auth.split(':', 1) if len(_parts) == 2: username, password = _parts diff -r ae12fabba699 -r 82b1eaec25f5 kallithea/lib/ssh.py --- a/kallithea/lib/ssh.py Tue Dec 10 02:56:48 2019 +0100 +++ b/kallithea/lib/ssh.py Mon Dec 16 00:53:11 2019 +0100 @@ -21,7 +21,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -import binascii +import base64 import logging import re @@ -84,8 +84,8 @@ raise SshKeyParseError(_("Incorrect SSH key - unexpected characters in base64 part %r") % keyvalue) try: - decoded = keyvalue.decode('base64') - except binascii.Error: + decoded = base64.b64decode(keyvalue) + except TypeError: raise SshKeyParseError(_("Incorrect SSH key - failed to decode base64 part %r") % keyvalue) if not decoded.startswith('\x00\x00\x00' + chr(len(keytype)) + str(keytype) + '\x00'): diff -r ae12fabba699 -r 82b1eaec25f5 kallithea/model/db.py --- a/kallithea/model/db.py Tue Dec 10 02:56:48 2019 +0100 +++ b/kallithea/model/db.py Mon Dec 16 00:53:11 2019 +0100 @@ -25,6 +25,7 @@ :license: GPLv3, see LICENSE.md for more details. """ +import base64 import collections import datetime import functools @@ -2544,4 +2545,4 @@ # use fingerprints similar to 'ssh-keygen -E sha256 -lf ~/.ssh/id_rsa.pub' self._public_key = full_key enc_key = full_key.split(" ")[1] - self.fingerprint = hashlib.sha256(enc_key.decode('base64')).digest().encode('base64').replace('\n', '').rstrip('=') + self.fingerprint = base64.b64encode(hashlib.sha256(base64.b64decode(enc_key)).digest()).replace(b'\n', b'').rstrip(b'=').decode()