Skip to content

Commit

Permalink
Simplify string formatting (#4757)
Browse files Browse the repository at this point in the history
  • Loading branch information
alex authored and reaperhulk committed Feb 20, 2019
1 parent 91e69f3 commit ac1d13f
Show file tree
Hide file tree
Showing 32 changed files with 89 additions and 89 deletions.
2 changes: 1 addition & 1 deletion src/cryptography/__about__.py
Expand Up @@ -20,4 +20,4 @@
__email__ = "cryptography-dev@python.org"

__license__ = "BSD or Apache License, Version 2.0"
__copyright__ = "Copyright 2013-2017 {0}".format(__author__)
__copyright__ = "Copyright 2013-2017 {}".format(__author__)
2 changes: 1 addition & 1 deletion src/cryptography/hazmat/_oid.py
Expand Up @@ -50,7 +50,7 @@ def __ne__(self, other):
return not self == other

def __repr__(self):
return "<ObjectIdentifier(oid={0}, name={1})>".format(
return "<ObjectIdentifier(oid={}, name={})>".format(
self.dotted_string,
self._name
)
Expand Down
4 changes: 2 additions & 2 deletions src/cryptography/hazmat/backends/openssl/aead.py
Expand Up @@ -18,10 +18,10 @@ def _aead_cipher_name(cipher):
if isinstance(cipher, ChaCha20Poly1305):
return b"chacha20-poly1305"
elif isinstance(cipher, AESCCM):
return "aes-{0}-ccm".format(len(cipher._key) * 8).encode("ascii")
return "aes-{}-ccm".format(len(cipher._key) * 8).encode("ascii")
else:
assert isinstance(cipher, AESGCM)
return "aes-{0}-gcm".format(len(cipher._key) * 8).encode("ascii")
return "aes-{}-gcm".format(len(cipher._key) * 8).encode("ascii")


def _aead_setup(backend, cipher_name, key, nonce, tag, tag_len, operation):
Expand Down
14 changes: 7 additions & 7 deletions src/cryptography/hazmat/backends/openssl/backend.py
Expand Up @@ -187,7 +187,7 @@ def create_hmac_ctx(self, key, algorithm):

def _evp_md_from_algorithm(self, algorithm):
if algorithm.name == "blake2b" or algorithm.name == "blake2s":
alg = "{0}{1}".format(
alg = "{}{}".format(
algorithm.name, algorithm.digest_size * 8
).encode("ascii")
else:
Expand Down Expand Up @@ -221,7 +221,7 @@ def cipher_supported(self, cipher, mode):

def register_cipher_adapter(self, cipher_cls, mode_cls, adapter):
if (cipher_cls, mode_cls) in self._cipher_registry:
raise ValueError("Duplicate registration for: {0} {1}.".format(
raise ValueError("Duplicate registration for: {} {}.".format(
cipher_cls, mode_cls)
)
self._cipher_registry[cipher_cls, mode_cls] = adapter
Expand Down Expand Up @@ -980,7 +980,7 @@ def _create_x509_extension(self, handlers, extension):
encode = handlers[extension.oid]
except KeyError:
raise NotImplementedError(
'Extension not supported: {0}'.format(extension.oid)
'Extension not supported: {}'.format(extension.oid)
)

ext_struct = encode(self, extension.value)
Expand Down Expand Up @@ -1244,7 +1244,7 @@ def _load_key(self, openssl_read_func, convert_func, data, password):
else:
assert userdata.error == -2
raise ValueError(
"Passwords longer than {0} bytes are not supported "
"Passwords longer than {} bytes are not supported "
"by this backend.".format(userdata.maxsize - 1)
)
else:
Expand Down Expand Up @@ -1356,7 +1356,7 @@ def generate_elliptic_curve_private_key(self, curve):
return _EllipticCurvePrivateKey(self, ec_cdata, evp_pkey)
else:
raise UnsupportedAlgorithm(
"Backend object does not support {0}.".format(curve.name),
"Backend object does not support {}.".format(curve.name),
_Reasons.UNSUPPORTED_ELLIPTIC_CURVE
)

Expand Down Expand Up @@ -1610,7 +1610,7 @@ def _elliptic_curve_to_nid(self, curve):
curve_nid = self._lib.OBJ_sn2nid(curve_name.encode())
if curve_nid == self._lib.NID_undef:
raise UnsupportedAlgorithm(
"{0} is not a supported elliptic curve".format(curve.name),
"{} is not a supported elliptic curve".format(curve.name),
_Reasons.UNSUPPORTED_ELLIPTIC_CURVE
)
return curve_nid
Expand Down Expand Up @@ -2323,7 +2323,7 @@ def __call__(self, backend, cipher, mode):


def _get_xts_cipher(backend, cipher, mode):
cipher_name = "aes-{0}-xts".format(cipher.key_size // 2)
cipher_name = "aes-{}-xts".format(cipher.key_size // 2)
return backend._lib.EVP_get_cipherbyname(cipher_name.encode("ascii"))


Expand Down
8 changes: 4 additions & 4 deletions src/cryptography/hazmat/backends/openssl/ciphers.py
Expand Up @@ -40,7 +40,7 @@ def __init__(self, backend, cipher, mode, operation):
adapter = registry[type(cipher), type(mode)]
except KeyError:
raise UnsupportedAlgorithm(
"cipher {0} in {1} mode is not supported "
"cipher {} in {} mode is not supported "
"by this backend.".format(
cipher.name, mode.name if mode else mode),
_Reasons.UNSUPPORTED_CIPHER
Expand All @@ -53,7 +53,7 @@ def __init__(self, backend, cipher, mode, operation):
msg += "in {0.name} mode ".format(mode)
msg += (
"is not supported by this backend (Your version of OpenSSL "
"may be too old. Current version: {0}.)"
"may be too old. Current version: {}.)"
).format(self._backend.openssl_version_text())
raise UnsupportedAlgorithm(msg, _Reasons.UNSUPPORTED_CIPHER)

Expand Down Expand Up @@ -127,7 +127,7 @@ def update(self, data):
def update_into(self, data, buf):
if len(buf) < (len(data) + self._block_size_bytes - 1):
raise ValueError(
"buffer must be at least {0} bytes for this "
"buffer must be at least {} bytes for this "
"payload".format(len(data) + self._block_size_bytes - 1)
)

Expand Down Expand Up @@ -207,7 +207,7 @@ def finalize_with_tag(self, tag):
)
if len(tag) < self._mode._min_tag_length:
raise ValueError(
"Authentication tag must be {0} bytes or longer.".format(
"Authentication tag must be {} bytes or longer.".format(
self._mode._min_tag_length)
)
res = self._backend._lib.EVP_CIPHER_CTX_ctrl(
Expand Down
12 changes: 6 additions & 6 deletions src/cryptography/hazmat/backends/openssl/decode_asn1.py
Expand Up @@ -135,7 +135,7 @@ def _decode_general_name(backend, gn):
if "1" in bits[prefix:]:
raise ValueError("Invalid netmask")

ip = ipaddress.ip_network(base.exploded + u"/{0}".format(prefix))
ip = ipaddress.ip_network(base.exploded + u"/{}".format(prefix))
else:
ip = ipaddress.ip_address(data)

Expand All @@ -160,7 +160,7 @@ def _decode_general_name(backend, gn):
else:
# x400Address or ediPartyName
raise x509.UnsupportedGeneralNameType(
"{0} is not a supported type".format(
"{} is not a supported type".format(
x509._GENERAL_NAMES.get(gn.type, gn.type)
),
gn.type
Expand Down Expand Up @@ -202,7 +202,7 @@ def parse(self, backend, x509_obj):
)
if oid in seen_oids:
raise x509.DuplicateExtension(
"Duplicate {0} extension found".format(oid), oid
"Duplicate {} extension found".format(oid), oid
)

# These OIDs are only supported in OpenSSL 1.1.0+ but we want
Expand Down Expand Up @@ -245,7 +245,7 @@ def parse(self, backend, x509_obj):
if ext_data == backend._ffi.NULL:
backend._consume_errors()
raise ValueError(
"The {0} extension is invalid and can't be "
"The {} extension is invalid and can't be "
"parsed".format(oid)
)

Expand Down Expand Up @@ -698,7 +698,7 @@ def _decode_crl_reason(backend, enum):
try:
return x509.CRLReason(_CRL_ENTRY_REASON_CODE_TO_ENUM[code])
except KeyError:
raise ValueError("Unsupported reason code: {0}".format(code))
raise ValueError("Unsupported reason code: {}".format(code))


def _decode_invalidity_date(backend, inv_date):
Expand Down Expand Up @@ -758,7 +758,7 @@ def _asn1_string_to_utf8(backend, asn1_string):
res = backend._lib.ASN1_STRING_to_UTF8(buf, asn1_string)
if res == -1:
raise ValueError(
"Unsupported ASN1 string type. Type: {0}".format(asn1_string.type)
"Unsupported ASN1 string type. Type: {}".format(asn1_string.type)
)

backend.openssl_assert(buf[0] != backend._ffi.NULL)
Expand Down
2 changes: 1 addition & 1 deletion src/cryptography/hazmat/backends/openssl/ec.py
Expand Up @@ -62,7 +62,7 @@ def _sn_to_elliptic_curve(backend, sn):
return ec._CURVE_TYPES[sn]()
except KeyError:
raise UnsupportedAlgorithm(
"{0} is not a supported elliptic curve".format(sn),
"{} is not a supported elliptic curve".format(sn),
_Reasons.UNSUPPORTED_ELLIPTIC_CURVE
)

Expand Down
2 changes: 1 addition & 1 deletion src/cryptography/hazmat/backends/openssl/encode_asn1.py
Expand Up @@ -475,7 +475,7 @@ def _encode_general_name(backend, name):
gn.d.uniformResourceIdentifier = asn1_str
else:
raise ValueError(
"{0} is an unknown GeneralName type".format(name)
"{} is an unknown GeneralName type".format(name)
)

return gn
Expand Down
2 changes: 1 addition & 1 deletion src/cryptography/hazmat/backends/openssl/hashes.py
Expand Up @@ -25,7 +25,7 @@ def __init__(self, backend, algorithm, ctx=None):
evp_md = self._backend._evp_md_from_algorithm(algorithm)
if evp_md == self._backend._ffi.NULL:
raise UnsupportedAlgorithm(
"{0} is not a supported hash on this backend.".format(
"{} is not a supported hash on this backend.".format(
algorithm.name),
_Reasons.UNSUPPORTED_HASH
)
Expand Down
2 changes: 1 addition & 1 deletion src/cryptography/hazmat/backends/openssl/hmac.py
Expand Up @@ -28,7 +28,7 @@ def __init__(self, backend, key, algorithm, ctx=None):
evp_md = self._backend._evp_md_from_algorithm(algorithm)
if evp_md == self._backend._ffi.NULL:
raise UnsupportedAlgorithm(
"{0} is not a supported hash on this backend".format(
"{} is not a supported hash on this backend".format(
algorithm.name),
_Reasons.UNSUPPORTED_HASH
)
Expand Down
4 changes: 2 additions & 2 deletions src/cryptography/hazmat/backends/openssl/ocsp.py
Expand Up @@ -82,7 +82,7 @@ def _hash_algorithm(backend, cert_id):
return _OIDS_TO_HASH[oid]
except KeyError:
raise UnsupportedAlgorithm(
"Signature algorithm OID: {0} not recognized".format(oid)
"Signature algorithm OID: {} not recognized".format(oid)
)


Expand Down Expand Up @@ -134,7 +134,7 @@ def signature_hash_algorithm(self):
return x509._SIG_OIDS_TO_HASH[oid]
except KeyError:
raise UnsupportedAlgorithm(
"Signature algorithm OID:{0} not recognized".format(oid)
"Signature algorithm OID:{} not recognized".format(oid)
)

@property
Expand Down
6 changes: 3 additions & 3 deletions src/cryptography/hazmat/backends/openssl/rsa.py
Expand Up @@ -59,7 +59,7 @@ def _enc_dec_rsa(backend, key, data, padding):

else:
raise UnsupportedAlgorithm(
"{0} is not supported by this backend.".format(
"{} is not supported by this backend.".format(
padding.name
),
_Reasons.UNSUPPORTED_PADDING
Expand Down Expand Up @@ -178,7 +178,7 @@ def _rsa_sig_determine_padding(backend, key, padding, algorithm):
padding_enum = backend._lib.RSA_PKCS1_PSS_PADDING
else:
raise UnsupportedAlgorithm(
"{0} is not supported by this backend.".format(padding.name),
"{} is not supported by this backend.".format(padding.name),
_Reasons.UNSUPPORTED_PADDING
)

Expand All @@ -197,7 +197,7 @@ def _rsa_sig_setup(backend, padding, algorithm, key, data, init_func):
if res == 0:
backend._consume_errors()
raise UnsupportedAlgorithm(
"{0} is not supported by this backend for RSA signing.".format(
"{} is not supported by this backend for RSA signing.".format(
algorithm.name
),
_Reasons.UNSUPPORTED_HASH
Expand Down
10 changes: 5 additions & 5 deletions src/cryptography/hazmat/backends/openssl/x509.py
Expand Up @@ -29,7 +29,7 @@ def __init__(self, backend, x509):
self._x509 = x509

def __repr__(self):
return "<Certificate(subject={0}, ...)>".format(self.subject)
return "<Certificate(subject={}, ...)>".format(self.subject)

def __eq__(self, other):
if not isinstance(other, x509.Certificate):
Expand Down Expand Up @@ -58,7 +58,7 @@ def version(self):
return x509.Version.v3
else:
raise x509.InvalidVersion(
"{0} is not a valid X509 version".format(version), version
"{} is not a valid X509 version".format(version), version
)

@property
Expand Down Expand Up @@ -107,7 +107,7 @@ def signature_hash_algorithm(self):
return x509._SIG_OIDS_TO_HASH[oid]
except KeyError:
raise UnsupportedAlgorithm(
"Signature algorithm OID:{0} not recognized".format(oid)
"Signature algorithm OID:{} not recognized".format(oid)
)

@property
Expand Down Expand Up @@ -261,7 +261,7 @@ def signature_hash_algorithm(self):
return x509._SIG_OIDS_TO_HASH[oid]
except KeyError:
raise UnsupportedAlgorithm(
"Signature algorithm OID:{0} not recognized".format(oid)
"Signature algorithm OID:{} not recognized".format(oid)
)

@property
Expand Down Expand Up @@ -413,7 +413,7 @@ def signature_hash_algorithm(self):
return x509._SIG_OIDS_TO_HASH[oid]
except KeyError:
raise UnsupportedAlgorithm(
"Signature algorithm OID:{0} not recognized".format(oid)
"Signature algorithm OID:{} not recognized".format(oid)
)

@property
Expand Down
2 changes: 1 addition & 1 deletion src/cryptography/hazmat/primitives/ciphers/algorithms.py
Expand Up @@ -17,7 +17,7 @@ def _verify_key_size(algorithm, key):

# Verify that the key size matches the expected key size
if len(key) * 8 not in algorithm.key_sizes:
raise ValueError("Invalid key size ({0}) for {1}.".format(
raise ValueError("Invalid key size ({}) for {}.".format(
len(key) * 8, algorithm.name
))
return key
Expand Down
4 changes: 2 additions & 2 deletions src/cryptography/hazmat/primitives/ciphers/base.py
Expand Up @@ -179,7 +179,7 @@ def _check_limit(self, data_size):
self._bytes_processed += data_size
if self._bytes_processed > self._ctx._mode._MAX_ENCRYPTED_BYTES:
raise ValueError(
"{0} has a maximum encrypted byte limit of {1}".format(
"{} has a maximum encrypted byte limit of {}".format(
self._ctx._mode.name, self._ctx._mode._MAX_ENCRYPTED_BYTES
)
)
Expand Down Expand Up @@ -217,7 +217,7 @@ def authenticate_additional_data(self, data):
self._aad_bytes_processed += len(data)
if self._aad_bytes_processed > self._ctx._mode._MAX_AAD_BYTES:
raise ValueError(
"{0} has a maximum AAD byte limit of {1}".format(
"{} has a maximum AAD byte limit of {}".format(
self._ctx._mode.name, self._ctx._mode._MAX_AAD_BYTES
)
)
Expand Down
6 changes: 3 additions & 3 deletions src/cryptography/hazmat/primitives/ciphers/modes.py
Expand Up @@ -72,7 +72,7 @@ def _check_aes_key_length(self, algorithm):

def _check_iv_length(self, algorithm):
if len(self.initialization_vector) * 8 != algorithm.block_size:
raise ValueError("Invalid IV size ({0}) for {1}.".format(
raise ValueError("Invalid IV size ({}) for {}.".format(
len(self.initialization_vector), self.name
))

Expand Down Expand Up @@ -178,7 +178,7 @@ def __init__(self, nonce):
def validate_for_algorithm(self, algorithm):
_check_aes_key_length(self, algorithm)
if len(self.nonce) * 8 != algorithm.block_size:
raise ValueError("Invalid nonce size ({0}) for {1}.".format(
raise ValueError("Invalid nonce size ({}) for {}.".format(
len(self.nonce), self.name
))

Expand All @@ -205,7 +205,7 @@ def __init__(self, initialization_vector, tag=None, min_tag_length=16):
raise ValueError("min_tag_length must be >= 4")
if len(tag) < min_tag_length:
raise ValueError(
"Authentication tag must be {0} bytes or longer.".format(
"Authentication tag must be {} bytes or longer.".format(
min_tag_length)
)
self._tag = tag
Expand Down
2 changes: 1 addition & 1 deletion src/cryptography/hazmat/primitives/kdf/concatkdf.py
Expand Up @@ -24,7 +24,7 @@ def _common_args_checks(algorithm, length, otherinfo):
max_length = algorithm.digest_size * (2 ** 32 - 1)
if length > max_length:
raise ValueError(
"Can not derive keys larger than {0} bits.".format(
"Can not derive keys larger than {} bits.".format(
max_length
))
if otherinfo is not None:
Expand Down
2 changes: 1 addition & 1 deletion src/cryptography/hazmat/primitives/kdf/hkdf.py
Expand Up @@ -68,7 +68,7 @@ def __init__(self, algorithm, length, info, backend):

if length > max_length:
raise ValueError(
"Can not derive keys larger than {0} octets.".format(
"Can not derive keys larger than {} octets.".format(
max_length
))

Expand Down
2 changes: 1 addition & 1 deletion src/cryptography/hazmat/primitives/kdf/pbkdf2.py
Expand Up @@ -24,7 +24,7 @@ def __init__(self, algorithm, length, salt, iterations, backend):

if not backend.pbkdf2_hmac_supported(algorithm):
raise UnsupportedAlgorithm(
"{0} is not supported for PBKDF2 by this backend.".format(
"{} is not supported for PBKDF2 by this backend.".format(
algorithm.name),
_Reasons.UNSUPPORTED_HASH
)
Expand Down
2 changes: 1 addition & 1 deletion src/cryptography/hazmat/primitives/kdf/x963kdf.py
Expand Up @@ -26,7 +26,7 @@ def __init__(self, algorithm, length, sharedinfo, backend):
max_len = algorithm.digest_size * (2 ** 32 - 1)
if length > max_len:
raise ValueError(
"Can not derive keys larger than {0} bits.".format(max_len))
"Can not derive keys larger than {} bits.".format(max_len))
if sharedinfo is not None:
utils._check_bytes("sharedinfo", sharedinfo)

Expand Down

0 comments on commit ac1d13f

Please sign in to comment.