changeset 8025:82b1eaec25f5

py3: replace base64 encoding with base64 module
author Mads Kiilerich <mads@kiilerich.com>
date Mon, 16 Dec 2019 00:53:11 +0100
parents ae12fabba699
children d4ea298c3ec4
files kallithea/lib/base.py kallithea/lib/ssh.py kallithea/model/db.py
diffstat 3 files changed, 7 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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 <http://www.gnu.org/licenses/>.
 
-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'):
--- 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()