Daniel Holth  committed 47ee18a

use ascii instead of latin1 when appropriate

  • Participants
  • Parent commits 01bab4d

Comments (0)

Files changed (3)

File wheel/

 import wheel.install
 import wheel.signatures
 import json
-from .util import urlsafe_b64decode, urlsafe_b64encode, native
+from .util import urlsafe_b64decode, urlsafe_b64encode, native, binary
 wb = baker.Baker()
     """Generate a public/private key pair."""
     import keyring
     keypair = ed25519ll.crypto_sign_keypair()
-    vk = urlsafe_b64encode(keypair.vk).decode('latin1')
-    sk = urlsafe_b64encode('latin1')
+    vk = binary(urlsafe_b64encode(keypair.vk))
+    sk = binary(urlsafe_b64encode(
     kr = keyring.get_keyring()
     kr.set_password("wheel", vk, sk)
     sys.stdout.write("Created Ed25519 keypair with vk={0}\n".format(vk))

File wheel/

 from distutils import log as logger
 import shutil
-from .util import get_abbr_impl, get_impl_ver
+from .util import get_abbr_impl, get_impl_ver, native
 from .archive import archive_wheelfile
 from .pkginfo import read_pkg_info, write_pkg_info
                 data = open(path, 'rb').read()
                 digest = hashlib.sha256(data).digest()
-                hash = 'sha256=%s' % urlsafe_b64encode(digest).decode('latin1')
+                hash = 'sha256='+native(urlsafe_b64encode(digest))
                 size = len(data)
             record_path = os.path.relpath(
                 path, bdist_dir).replace(os.path.sep, '/')

File wheel/

+    # For encoding ascii back and forth between bytestrings, as is repeatedly
+    # necessary in JSON-based crypto under Python 3
     def native(s):
         return s
     def binary(s):
         if isinstance(s, unicode):
-            return s.encode('latin1')
+            return s.encode('ascii')
         return s
 except NameError:
     def native(s):
         if isinstance(s, bytes):
-            return s.decode('latin1')
+            return s.decode('ascii')
         return s
     def binary(s):
         if isinstance(s, str):
-            return s.encode('latin1')
+            return s.encode('ascii')
 def get_abbr_impl():