fix: add back python 2.7 for gcloud usage only (#892)
* fix: add back python 2.7 for gcloud
* fix: fix setup and tests
* fix: add enum34 for python 2.7
* fix: add app engine app and fix noxfile
* fix: move test_app_engine.py
* fix: fix downscoped
* fix: fix downscoped
* fix: remove py2 from classifiers
diff --git a/google/auth/crypt/__init__.py b/google/auth/crypt/__init__.py
index 97e9d81..15ac950 100644
--- a/google/auth/crypt/__init__.py
+++ b/google/auth/crypt/__init__.py
@@ -37,6 +37,8 @@
version is at least 1.4.0.
"""
+import six
+
from google.auth.crypt import base
from google.auth.crypt import rsa
@@ -88,7 +90,7 @@
Returns:
bool: True if the signature is valid, otherwise False.
"""
- if isinstance(certs, (str, bytes)):
+ if isinstance(certs, (six.text_type, six.binary_type)):
certs = [certs]
for cert in certs:
diff --git a/google/auth/crypt/_python_rsa.py b/google/auth/crypt/_python_rsa.py
index 1c4a9da..ec30dd0 100644
--- a/google/auth/crypt/_python_rsa.py
+++ b/google/auth/crypt/_python_rsa.py
@@ -21,13 +21,12 @@
from __future__ import absolute_import
-import io
-
from pyasn1.codec.der import decoder
from pyasn1_modules import pem
from pyasn1_modules.rfc2459 import Certificate
from pyasn1_modules.rfc5208 import PrivateKeyInfo
import rsa
+import six
from google.auth import _helpers
from google.auth.crypt import base
@@ -53,9 +52,9 @@
"""
num_bits = len(bit_list)
byte_vals = bytearray()
- for start in range(0, num_bits, 8):
+ for start in six.moves.xrange(0, num_bits, 8):
curr_bits = bit_list[start : start + 8]
- char_val = sum(val * digit for val, digit in zip(_POW2, curr_bits))
+ char_val = sum(val * digit for val, digit in six.moves.zip(_POW2, curr_bits))
byte_vals.append(char_val)
return bytes(byte_vals)
@@ -153,7 +152,7 @@
"""
key = _helpers.from_bytes(key) # PEM expects str in Python 3
marker_id, key_bytes = pem.readPemBlocksFromFile(
- io.StringIO(key), _PKCS1_MARKER, _PKCS8_MARKER
+ six.StringIO(key), _PKCS1_MARKER, _PKCS8_MARKER
)
# Key is in pkcs1 format.
diff --git a/google/auth/crypt/base.py b/google/auth/crypt/base.py
index 0bda9c3..c98d5bf 100644
--- a/google/auth/crypt/base.py
+++ b/google/auth/crypt/base.py
@@ -18,12 +18,15 @@
import io
import json
+import six
+
_JSON_FILE_PRIVATE_KEY = "private_key"
_JSON_FILE_PRIVATE_KEY_ID = "private_key_id"
-class Verifier(object, metaclass=abc.ABCMeta):
+@six.add_metaclass(abc.ABCMeta)
+class Verifier(object):
"""Abstract base class for crytographic signature verifiers."""
@abc.abstractmethod
@@ -43,7 +46,8 @@
raise NotImplementedError("Verify must be implemented")
-class Signer(object, metaclass=abc.ABCMeta):
+@six.add_metaclass(abc.ABCMeta)
+class Signer(object):
"""Abstract base class for cryptographic signers."""
@abc.abstractproperty
@@ -66,7 +70,8 @@
raise NotImplementedError("Sign must be implemented")
-class FromServiceAccountMixin(object, metaclass=abc.ABCMeta):
+@six.add_metaclass(abc.ABCMeta)
+class FromServiceAccountMixin(object):
"""Mix-in to enable factory constructors for a Signer."""
@abc.abstractmethod
diff --git a/google/auth/crypt/es256.py b/google/auth/crypt/es256.py
index 71dcbfc..c6d6176 100644
--- a/google/auth/crypt/es256.py
+++ b/google/auth/crypt/es256.py
@@ -15,6 +15,7 @@
"""ECDSA (ES256) verifier and signer that use the ``cryptography`` library.
"""
+from cryptography import utils
import cryptography.exceptions
from cryptography.hazmat import backends
from cryptography.hazmat.primitives import hashes
@@ -52,8 +53,8 @@
sig_bytes = _helpers.to_bytes(signature)
if len(sig_bytes) != 64:
return False
- r = int.from_bytes(sig_bytes[:32], byteorder="big")
- s = int.from_bytes(sig_bytes[32:], byteorder="big")
+ r = utils.int_from_bytes(sig_bytes[:32], byteorder="big")
+ s = utils.int_from_bytes(sig_bytes[32:], byteorder="big")
asn1_sig = encode_dss_signature(r, s)
message = _helpers.to_bytes(message)
@@ -120,7 +121,7 @@
# Convert ASN1 encoded signature to (r||s) raw signature.
(r, s) = decode_dss_signature(asn1_signature)
- return r.to_bytes(32, byteorder="big") + s.to_bytes(32, byteorder="big")
+ return utils.int_to_bytes(r, 32) + utils.int_to_bytes(s, 32)
@classmethod
def from_string(cls, key, key_id=None):