From 24729dbd610d4a7a15855c4934c627e4ead97b59 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Mon, 3 Aug 2020 11:06:46 -0400 Subject: [PATCH] Port to Python 3. --- src/allmydata/crypto/__init__.py | 11 +++++++++++ src/allmydata/crypto/aes.py | 10 ++++++++++ src/allmydata/crypto/ed25519.py | 11 +++++++++++ src/allmydata/crypto/error.py | 10 ++++++++++ src/allmydata/crypto/rsa.py | 11 ++++++++++- src/allmydata/crypto/util.py | 10 ++++++++++ src/allmydata/util/_python3.py | 6 ++++++ 7 files changed, 68 insertions(+), 1 deletion(-) diff --git a/src/allmydata/crypto/__init__.py b/src/allmydata/crypto/__init__.py index ee92f223a..4eb753b57 100644 --- a/src/allmydata/crypto/__init__.py +++ b/src/allmydata/crypto/__init__.py @@ -5,4 +5,15 @@ For the most part, these functions use and return objects that are documented in the `cryptography` library -- however, code inside Tahoe should only use these functions and not rely on features of any objects that `cryptography` documents. + +Ported to Python 3. """ + +from __future__ import unicode_literals +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +from future.utils import PY2 +if PY2: + from builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, int, list, object, range, str, max, min # noqa: F401 diff --git a/src/allmydata/crypto/aes.py b/src/allmydata/crypto/aes.py index 4194c63df..196d751bd 100644 --- a/src/allmydata/crypto/aes.py +++ b/src/allmydata/crypto/aes.py @@ -6,7 +6,17 @@ These functions use and return objects that are documented in the `cryptography` library -- however, code inside Tahoe should only use functions from allmydata.crypto.aes and not rely on features of any objects that `cryptography` documents. + +Ported to Python 3. """ +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function +from __future__ import unicode_literals + +from future.utils import PY2 +if PY2: + from builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, int, list, object, range, str, max, min # noqa: F401 import six diff --git a/src/allmydata/crypto/ed25519.py b/src/allmydata/crypto/ed25519.py index 37e305d19..424dc23fa 100644 --- a/src/allmydata/crypto/ed25519.py +++ b/src/allmydata/crypto/ed25519.py @@ -13,7 +13,18 @@ cut-and-pasteability. The base62 encoding is shorter than the base32 form, but the minor usability improvement is not worth the documentation and specification confusion of using a non-standard encoding. So we stick with base32. + +Ported to Python 3. ''' +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function +from __future__ import unicode_literals + + +from future.utils import PY2 +if PY2: + from builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, int, list, object, range, str, max, min # noqa: F401 import six diff --git a/src/allmydata/crypto/error.py b/src/allmydata/crypto/error.py index 62c0b3e5b..b105805a5 100644 --- a/src/allmydata/crypto/error.py +++ b/src/allmydata/crypto/error.py @@ -1,6 +1,16 @@ """ Exceptions raise by allmydata.crypto.* modules + +Ported to Python 3. """ +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function +from __future__ import unicode_literals + +from future.utils import PY2 +if PY2: + from builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, int, list, object, range, str, max, min # noqa: F401 class BadSignature(Exception): diff --git a/src/allmydata/crypto/rsa.py b/src/allmydata/crypto/rsa.py index e82bf12d1..95c39bcc6 100644 --- a/src/allmydata/crypto/rsa.py +++ b/src/allmydata/crypto/rsa.py @@ -9,8 +9,17 @@ features of any objects that `cryptography` documents. That is, the public and private keys are opaque objects; DO NOT depend on any of their methods. -""" +Ported to Python 3. +""" +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function +from __future__ import unicode_literals + +from future.utils import PY2 +if PY2: + from builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, int, list, object, range, str, max, min # noqa: F401 from cryptography.exceptions import InvalidSignature from cryptography.hazmat.backends import default_backend diff --git a/src/allmydata/crypto/util.py b/src/allmydata/crypto/util.py index 6aa1f0973..6c6ed1059 100644 --- a/src/allmydata/crypto/util.py +++ b/src/allmydata/crypto/util.py @@ -1,6 +1,16 @@ """ Utilities used by allmydata.crypto modules + +Ported to Python 3. """ +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function +from __future__ import unicode_literals + +from future.utils import PY2 +if PY2: + from builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, int, list, object, range, str, max, min # noqa: F401 from allmydata.crypto.error import BadPrefixError diff --git a/src/allmydata/util/_python3.py b/src/allmydata/util/_python3.py index f96a6f1e4..c29184b6c 100644 --- a/src/allmydata/util/_python3.py +++ b/src/allmydata/util/_python3.py @@ -15,6 +15,12 @@ if PY2: # Keep these sorted alphabetically, to reduce merge conflicts: PORTED_MODULES = [ + "allmydata.crypto", + "allmydata.crypto.aes", + "allmydata.crypto.ed25519", + "allmydata.crypto.error", + "allmydata.crypto.rsa", + "allmydata.crypto.util", "allmydata.hashtree", "allmydata.util.abbreviate", "allmydata.util.assertutil",