Daniel Holth avatar Daniel Holth committed 47ee18a

use ascii instead of latin1 when appropriate

Comments (0)

Files changed (3)


 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(keypair.sk).decode('latin1')
+    vk = binary(urlsafe_b64encode(keypair.vk))
+    sk = binary(urlsafe_b64encode(keypair.sk))
     kr = keyring.get_keyring()
     kr.set_password("wheel", vk, sk)
     sys.stdout.write("Created Ed25519 keypair with vk={0}\n".format(vk))


 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, '/')
+    # 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():
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.