catacomb/pwsafe.py: Use `binascii' for Base64 conversion.
authorMark Wooding <mdw@distorted.org.uk>
Mon, 21 Oct 2019 17:26:39 +0000 (18:26 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sat, 11 Apr 2020 11:44:21 +0000 (12:44 +0100)
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.

catacomb/pwsafe.py

index d453c8e..8fa5ee6 100644 (file)
@@ -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."""