From: Mark Wooding Date: Mon, 21 Oct 2019 17:26:39 +0000 (+0100) Subject: catacomb/pwsafe.py: Use `binascii' for Base64 conversion. X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb-python/commitdiff_plain/a3869542180f9bff989afc5b5f56e0930bc41991 catacomb/pwsafe.py: Use `binascii' for Base64 conversion. The `.encode()' and `.decode()' string methods were apparently too convenient, so Python 3 doesn't do Base64 conversion like this. Instead, we have to use the steam-powered `binascii'. And, to make things even better, encoding produces `bytes' rather than `str' because, err, it's not really text or something? No idea. Stoats. --- diff --git a/catacomb/pwsafe.py b/catacomb/pwsafe.py index 5e296e3..97ad354 100644 --- a/catacomb/pwsafe.py +++ b/catacomb/pwsafe.py @@ -28,6 +28,7 @@ from __future__ import with_statement +import binascii as _B import errno as _E import os as _OS from cStringIO import StringIO as _StringIO @@ -103,10 +104,10 @@ def _dec_metaname(name): def _b64(s): """Encode S as base64, without newlines, and trimming `=' padding.""" - return s.encode('base64').replace('\n', '').rstrip('=') + return _text(_B.b2a_base64(s)).replace('\n', '').rstrip('=') def _unb64(s): """Decode S as base64 with trimmed `=' padding.""" - return (s + '='*((4 - len(s))%4)).decode('base64') + return _B.a2b_base64(s + '='*((4 - len(s))%4)) def _enc_metaval(val): """Encode VAL as a metadata item value, returning the result."""