From e949b2e15c65262a38b3e3d410c469bf1e4e6c0e Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Wed, 12 Jul 2023 22:40:26 -0400 Subject: [PATCH] Prepare for new ruff release (#9227) --- .../development/custom-vectors/arc4/generate_arc4.py | 4 +--- .../custom-vectors/cast5/generate_cast5.py | 4 +--- src/cryptography/hazmat/backends/openssl/backend.py | 4 +--- src/cryptography/hazmat/backends/openssl/rsa.py | 4 +--- src/cryptography/x509/extensions.py | 12 +++--------- src/cryptography/x509/general_name.py | 4 +--- tests/hazmat/primitives/test_ec.py | 8 ++------ tests/hazmat/primitives/test_pkcs12.py | 4 +--- tests/hazmat/primitives/test_x963_vectors.py | 4 +--- 9 files changed, 12 insertions(+), 36 deletions(-) diff --git a/docs/development/custom-vectors/arc4/generate_arc4.py b/docs/development/custom-vectors/arc4/generate_arc4.py index 2ca919b40858..208d18585ac6 100644 --- a/docs/development/custom-vectors/arc4/generate_arc4.py +++ b/docs/development/custom-vectors/arc4/generate_arc4.py @@ -69,9 +69,7 @@ def _build_vectors(): for offset in _RFC6229_OFFSETS: if offset % 16 != 0: raise ValueError( - "Offset {} is not evenly divisible by 16".format( - offset - ) + f"Offset {offset} is not evenly divisible by 16" ) while current_offset < offset: encryptor.update(plaintext) diff --git a/docs/development/custom-vectors/cast5/generate_cast5.py b/docs/development/custom-vectors/cast5/generate_cast5.py index 27fb4634e295..38d68c0b6df7 100644 --- a/docs/development/custom-vectors/cast5/generate_cast5.py +++ b/docs/development/custom-vectors/cast5/generate_cast5.py @@ -31,9 +31,7 @@ def build_vectors(mode, filename): if line.startswith("KEY"): if count != 0: output.append( - "CIPHERTEXT = {}".format( - encrypt(mode, key, iv, plaintext) - ) + f"CIPHERTEXT = {encrypt(mode, key, iv, plaintext)}" ) output.append(f"\nCOUNT = {count}") count += 1 diff --git a/src/cryptography/hazmat/backends/openssl/backend.py b/src/cryptography/hazmat/backends/openssl/backend.py index b4294224035a..3319e8f3a18f 100644 --- a/src/cryptography/hazmat/backends/openssl/backend.py +++ b/src/cryptography/hazmat/backends/openssl/backend.py @@ -242,9 +242,7 @@ def cipher_supported(self, cipher: CipherAlgorithm, mode: Mode) -> bool: def register_cipher_adapter(self, cipher_cls, mode_cls, adapter) -> None: if (cipher_cls, mode_cls) in self._cipher_registry: raise ValueError( - "Duplicate registration for: {} {}.".format( - cipher_cls, mode_cls - ) + f"Duplicate registration for: {cipher_cls} {mode_cls}." ) self._cipher_registry[cipher_cls, mode_cls] = adapter diff --git a/src/cryptography/hazmat/backends/openssl/rsa.py b/src/cryptography/hazmat/backends/openssl/rsa.py index b9c96a78faa1..3a99fbfa80cf 100644 --- a/src/cryptography/hazmat/backends/openssl/rsa.py +++ b/src/cryptography/hazmat/backends/openssl/rsa.py @@ -242,9 +242,7 @@ def _rsa_sig_setup( if res <= 0: backend._consume_errors() raise UnsupportedAlgorithm( - "{} is not supported for the RSA signature operation.".format( - padding.name - ), + f"{padding.name} is not supported for the RSA signature operation", _Reasons.UNSUPPORTED_PADDING, ) if isinstance(padding, PSS): diff --git a/src/cryptography/x509/extensions.py b/src/cryptography/x509/extensions.py index ac99592f55a7..f3cd53059849 100644 --- a/src/cryptography/x509/extensions.py +++ b/src/cryptography/x509/extensions.py @@ -104,9 +104,7 @@ def public_bytes(self) -> bytes: Serializes the extension type to DER. """ raise NotImplementedError( - "public_bytes is not implemented for extension type {!r}".format( - self - ) + f"public_bytes is not implemented for extension type {self!r}" ) @@ -1795,9 +1793,7 @@ def __init__(self, invalidity_date: datetime.datetime) -> None: self._invalidity_date = invalidity_date def __repr__(self) -> str: - return "".format( - self._invalidity_date - ) + return f"" def __eq__(self, other: object) -> bool: if not isinstance(other, InvalidityDate): @@ -1841,9 +1837,7 @@ def __init__( ) def __repr__(self) -> str: - return "".format( - list(self) - ) + return f"" def __hash__(self) -> int: return hash(tuple(self._signed_certificate_timestamps)) diff --git a/src/cryptography/x509/general_name.py b/src/cryptography/x509/general_name.py index 79271afbf91e..672f28759cb0 100644 --- a/src/cryptography/x509/general_name.py +++ b/src/cryptography/x509/general_name.py @@ -269,9 +269,7 @@ def value(self) -> bytes: return self._value def __repr__(self) -> str: - return "".format( - self.type_id, self.value - ) + return f"" def __eq__(self, other: object) -> bool: if not isinstance(other, OtherName): diff --git a/tests/hazmat/primitives/test_ec.py b/tests/hazmat/primitives/test_ec.py index beb5739b22c0..1da36b86abf8 100644 --- a/tests/hazmat/primitives/test_ec.py +++ b/tests/hazmat/primitives/test_ec.py @@ -55,9 +55,7 @@ def _skip_ecdsa_vector(backend, curve_type, hash_type): def _skip_curve_unsupported(backend, curve): if not backend.elliptic_curve_supported(curve): pytest.skip( - "Curve {} is not supported by this backend {}".format( - curve.name, backend - ) + f"Curve {curve.name} is not supported by this backend {backend}" ) @@ -66,9 +64,7 @@ def _skip_exchange_algorithm_unsupported(backend, algorithm, curve): algorithm, curve ): pytest.skip( - "Exchange with {} curve is not supported by {}".format( - curve.name, backend - ) + f"Exchange with {curve.name} curve is not supported by {backend}" ) diff --git a/tests/hazmat/primitives/test_pkcs12.py b/tests/hazmat/primitives/test_pkcs12.py index 79f54e495241..0cd3111bc2b7 100644 --- a/tests/hazmat/primitives/test_pkcs12.py +++ b/tests/hazmat/primitives/test_pkcs12.py @@ -40,9 +40,7 @@ def _skip_curve_unsupported(backend, curve): if not backend.elliptic_curve_supported(curve): pytest.skip( - "Curve {} is not supported by this backend {}".format( - curve.name, backend - ) + f"Curve {curve.name} is not supported by this backend {backend}" ) diff --git a/tests/hazmat/primitives/test_x963_vectors.py b/tests/hazmat/primitives/test_x963_vectors.py index 7614c373c9ea..fcb3d8b02b56 100644 --- a/tests/hazmat/primitives/test_x963_vectors.py +++ b/tests/hazmat/primitives/test_x963_vectors.py @@ -19,9 +19,7 @@ def _skip_hashfn_unsupported(backend, hashfn): if not backend.hash_supported(hashfn): pytest.skip( - "Hash {} is not supported by this backend {}".format( - hashfn.name, backend - ) + f"Hash {hashfn.name} is not supported by this backend {backend}" )