chore: blacken (#375)
diff --git a/google/auth/crypt/__init__.py b/google/auth/crypt/__init__.py
index 7baa206..bf66e71 100644
--- a/google/auth/crypt/__init__.py
+++ b/google/auth/crypt/__init__.py
@@ -39,12 +39,7 @@
from google.auth.crypt import rsa
-__all__ = [
- 'RSASigner',
- 'RSAVerifier',
- 'Signer',
- 'Verifier',
-]
+__all__ = ["RSASigner", "RSAVerifier", "Signer", "Verifier"]
# Aliases to maintain the v1.0.0 interface, as the crypt module was split
# into submodules.
diff --git a/google/auth/crypt/_cryptography_rsa.py b/google/auth/crypt/_cryptography_rsa.py
index 87076b0..285cf5c 100644
--- a/google/auth/crypt/_cryptography_rsa.py
+++ b/google/auth/crypt/_cryptography_rsa.py
@@ -31,18 +31,18 @@
from google.auth.crypt import base
_IMPORT_ERROR_MSG = (
- 'cryptography>=1.4.0 is required to use cryptography-based RSA '
- 'implementation.')
+ "cryptography>=1.4.0 is required to use cryptography-based RSA " "implementation."
+)
try: # pragma: NO COVER
- release = pkg_resources.get_distribution('cryptography').parsed_version
- if release < pkg_resources.parse_version('1.4.0'):
+ release = pkg_resources.get_distribution("cryptography").parsed_version
+ if release < pkg_resources.parse_version("1.4.0"):
raise ImportError(_IMPORT_ERROR_MSG)
except pkg_resources.DistributionNotFound: # pragma: NO COVER
raise ImportError(_IMPORT_ERROR_MSG)
-_CERTIFICATE_MARKER = b'-----BEGIN CERTIFICATE-----'
+_CERTIFICATE_MARKER = b"-----BEGIN CERTIFICATE-----"
_BACKEND = backends.default_backend()
_PADDING = padding.PKCS1v15()
_SHA256 = hashes.SHA256()
@@ -88,12 +88,12 @@
if _CERTIFICATE_MARKER in public_key_data:
cert = cryptography.x509.load_pem_x509_certificate(
- public_key_data, _BACKEND)
+ public_key_data, _BACKEND
+ )
pubkey = cert.public_key()
else:
- pubkey = serialization.load_pem_public_key(
- public_key_data, _BACKEND)
+ pubkey = serialization.load_pem_public_key(public_key_data, _BACKEND)
return cls(pubkey)
@@ -122,8 +122,7 @@
@_helpers.copy_docstring(base.Signer)
def sign(self, message):
message = _helpers.to_bytes(message)
- return self._key.sign(
- message, _PADDING, _SHA256)
+ return self._key.sign(message, _PADDING, _SHA256)
@classmethod
def from_string(cls, key, key_id=None):
@@ -145,5 +144,6 @@
"""
key = _helpers.to_bytes(key)
private_key = serialization.load_pem_private_key(
- key, password=None, backend=_BACKEND)
+ key, password=None, backend=_BACKEND
+ )
return cls(private_key, key_id=key_id)
diff --git a/google/auth/crypt/_python_rsa.py b/google/auth/crypt/_python_rsa.py
index 44aa791..d53991c 100644
--- a/google/auth/crypt/_python_rsa.py
+++ b/google/auth/crypt/_python_rsa.py
@@ -32,11 +32,9 @@
from google.auth.crypt import base
_POW2 = (128, 64, 32, 16, 8, 4, 2, 1)
-_CERTIFICATE_MARKER = b'-----BEGIN CERTIFICATE-----'
-_PKCS1_MARKER = ('-----BEGIN RSA PRIVATE KEY-----',
- '-----END RSA PRIVATE KEY-----')
-_PKCS8_MARKER = ('-----BEGIN PRIVATE KEY-----',
- '-----END PRIVATE KEY-----')
+_CERTIFICATE_MARKER = b"-----BEGIN CERTIFICATE-----"
+_PKCS1_MARKER = ("-----BEGIN RSA PRIVATE KEY-----", "-----END RSA PRIVATE KEY-----")
+_PKCS8_MARKER = ("-----BEGIN PRIVATE KEY-----", "-----END PRIVATE KEY-----")
_PKCS8_SPEC = PrivateKeyInfo()
@@ -55,9 +53,8 @@
num_bits = len(bit_list)
byte_vals = bytearray()
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 six.moves.zip(_POW2, curr_bits))
+ curr_bits = bit_list[start : start + 8]
+ char_val = sum(val * digit for val, digit in six.moves.zip(_POW2, curr_bits))
byte_vals.append(char_val)
return bytes(byte_vals)
@@ -101,16 +98,16 @@
# If this is a certificate, extract the public key info.
if is_x509_cert:
- der = rsa.pem.load_pem(public_key, 'CERTIFICATE')
+ der = rsa.pem.load_pem(public_key, "CERTIFICATE")
asn1_cert, remaining = decoder.decode(der, asn1Spec=Certificate())
- if remaining != b'':
- raise ValueError('Unused bytes', remaining)
+ if remaining != b"":
+ raise ValueError("Unused bytes", remaining)
- cert_info = asn1_cert['tbsCertificate']['subjectPublicKeyInfo']
- key_bytes = _bit_list_to_bytes(cert_info['subjectPublicKey'])
- pubkey = rsa.PublicKey.load_pkcs1(key_bytes, 'DER')
+ cert_info = asn1_cert["tbsCertificate"]["subjectPublicKeyInfo"]
+ key_bytes = _bit_list_to_bytes(cert_info["subjectPublicKey"])
+ pubkey = rsa.PublicKey.load_pkcs1(key_bytes, "DER")
else:
- pubkey = rsa.PublicKey.load_pkcs1(public_key, 'PEM')
+ pubkey = rsa.PublicKey.load_pkcs1(public_key, "PEM")
return cls(pubkey)
@@ -136,7 +133,7 @@
@_helpers.copy_docstring(base.Signer)
def sign(self, message):
message = _helpers.to_bytes(message)
- return rsa.pkcs1.sign(message, self._key, 'SHA-256')
+ return rsa.pkcs1.sign(message, self._key, "SHA-256")
@classmethod
def from_string(cls, key, key_id=None):
@@ -155,22 +152,22 @@
"""
key = _helpers.from_bytes(key) # PEM expects str in Python 3
marker_id, key_bytes = pem.readPemBlocksFromFile(
- six.StringIO(key), _PKCS1_MARKER, _PKCS8_MARKER)
+ six.StringIO(key), _PKCS1_MARKER, _PKCS8_MARKER
+ )
# Key is in pkcs1 format.
if marker_id == 0:
- private_key = rsa.key.PrivateKey.load_pkcs1(
- key_bytes, format='DER')
+ private_key = rsa.key.PrivateKey.load_pkcs1(key_bytes, format="DER")
# Key is in pkcs8.
elif marker_id == 1:
- key_info, remaining = decoder.decode(
- key_bytes, asn1Spec=_PKCS8_SPEC)
- if remaining != b'':
- raise ValueError('Unused bytes', remaining)
- private_key_info = key_info.getComponentByName('privateKey')
+ key_info, remaining = decoder.decode(key_bytes, asn1Spec=_PKCS8_SPEC)
+ if remaining != b"":
+ raise ValueError("Unused bytes", remaining)
+ private_key_info = key_info.getComponentByName("privateKey")
private_key = rsa.key.PrivateKey.load_pkcs1(
- private_key_info.asOctets(), format='DER')
+ private_key_info.asOctets(), format="DER"
+ )
else:
- raise ValueError('No key could be detected.')
+ raise ValueError("No key could be detected.")
return cls(private_key, key_id=key_id)
diff --git a/google/auth/crypt/base.py b/google/auth/crypt/base.py
index c6c0427..ceb6e9c 100644
--- a/google/auth/crypt/base.py
+++ b/google/auth/crypt/base.py
@@ -21,8 +21,8 @@
import six
-_JSON_FILE_PRIVATE_KEY = 'private_key'
-_JSON_FILE_PRIVATE_KEY_ID = 'private_key_id'
+_JSON_FILE_PRIVATE_KEY = "private_key"
+_JSON_FILE_PRIVATE_KEY_ID = "private_key_id"
@six.add_metaclass(abc.ABCMeta)
@@ -43,7 +43,7 @@
"""
# pylint: disable=missing-raises-doc,redundant-returns-doc
# (pylint doesn't recognize that this is abstract)
- raise NotImplementedError('Verify must be implemented')
+ raise NotImplementedError("Verify must be implemented")
@six.add_metaclass(abc.ABCMeta)
@@ -53,7 +53,7 @@
@abc.abstractproperty
def key_id(self):
"""Optional[str]: The key ID used to identify this private key."""
- raise NotImplementedError('Key id must be implemented')
+ raise NotImplementedError("Key id must be implemented")
@abc.abstractmethod
def sign(self, message):
@@ -67,7 +67,7 @@
"""
# pylint: disable=missing-raises-doc,redundant-returns-doc
# (pylint doesn't recognize that this is abstract)
- raise NotImplementedError('Sign must be implemented')
+ raise NotImplementedError("Sign must be implemented")
@six.add_metaclass(abc.ABCMeta)
@@ -88,7 +88,7 @@
Raises:
ValueError: If the key cannot be parsed.
"""
- raise NotImplementedError('from_string must be implemented')
+ raise NotImplementedError("from_string must be implemented")
@classmethod
def from_service_account_info(cls, info):
@@ -107,12 +107,12 @@
"""
if _JSON_FILE_PRIVATE_KEY not in info:
raise ValueError(
- 'The private_key field was not found in the service account '
- 'info.')
+ "The private_key field was not found in the service account " "info."
+ )
return cls.from_string(
- info[_JSON_FILE_PRIVATE_KEY],
- info.get(_JSON_FILE_PRIVATE_KEY_ID))
+ info[_JSON_FILE_PRIVATE_KEY], info.get(_JSON_FILE_PRIVATE_KEY_ID)
+ )
@classmethod
def from_service_account_file(cls, filename):
@@ -125,7 +125,7 @@
Returns:
google.auth.crypt.Signer: The constructed signer.
"""
- with io.open(filename, 'r', encoding='utf-8') as json_file:
+ with io.open(filename, "r", encoding="utf-8") as json_file:
data = json.load(json_file)
return cls.from_service_account_info(data)