Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement fixes to ruff check --preview #12230

Merged
merged 1 commit into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/cryptography/fernet.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import os
import time
import typing
from collections.abc import Iterable

from cryptography import utils
from cryptography.exceptions import InvalidSignature
Expand Down Expand Up @@ -168,7 +169,7 @@ def _decrypt_data(


class MultiFernet:
def __init__(self, fernets: typing.Iterable[Fernet]):
def __init__(self, fernets: Iterable[Fernet]):
fernets = list(fernets)
if not fernets:
raise ValueError(
Expand Down
4 changes: 2 additions & 2 deletions src/cryptography/hazmat/bindings/_rust/ocsp.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# for complete details.

import datetime
import typing
from collections.abc import Iterator

from cryptography import x509
from cryptography.hazmat.primitives import hashes, serialization
Expand All @@ -25,7 +25,7 @@ class OCSPRequest:

class OCSPResponse:
@property
def responses(self) -> typing.Iterator[OCSPSingleResponse]: ...
def responses(self) -> Iterator[OCSPSingleResponse]: ...
@property
def response_status(self) -> ocsp.OCSPResponseStatus: ...
@property
Expand Down
3 changes: 2 additions & 1 deletion src/cryptography/hazmat/bindings/_rust/pkcs12.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# for complete details.

import typing
from collections.abc import Iterable

from cryptography import x509
from cryptography.hazmat.primitives.asymmetric.types import PrivateKeyTypes
Expand Down Expand Up @@ -41,6 +42,6 @@ def serialize_key_and_certificates(
name: bytes | None,
key: PKCS12PrivateKeyTypes | None,
cert: x509.Certificate | None,
cas: typing.Iterable[x509.Certificate | PKCS12Certificate] | None,
cas: Iterable[x509.Certificate | PKCS12Certificate] | None,
encryption_algorithm: KeySerializationEncryption,
) -> bytes: ...
12 changes: 6 additions & 6 deletions src/cryptography/hazmat/bindings/_rust/pkcs7.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# 2.0, and the BSD License. See the LICENSE file in the root of this repository
# for complete details.

import typing
from collections.abc import Iterable

from cryptography import x509
from cryptography.hazmat.primitives import serialization
Expand All @@ -17,30 +17,30 @@ def encrypt_and_serialize(
builder: pkcs7.PKCS7EnvelopeBuilder,
content_encryption_algorithm: pkcs7.ContentEncryptionAlgorithm,
encoding: serialization.Encoding,
options: typing.Iterable[pkcs7.PKCS7Options],
options: Iterable[pkcs7.PKCS7Options],
) -> bytes: ...
def sign_and_serialize(
builder: pkcs7.PKCS7SignatureBuilder,
encoding: serialization.Encoding,
options: typing.Iterable[pkcs7.PKCS7Options],
options: Iterable[pkcs7.PKCS7Options],
) -> bytes: ...
def decrypt_der(
data: bytes,
certificate: x509.Certificate,
private_key: rsa.RSAPrivateKey,
options: typing.Iterable[pkcs7.PKCS7Options],
options: Iterable[pkcs7.PKCS7Options],
) -> bytes: ...
def decrypt_pem(
data: bytes,
certificate: x509.Certificate,
private_key: rsa.RSAPrivateKey,
options: typing.Iterable[pkcs7.PKCS7Options],
options: Iterable[pkcs7.PKCS7Options],
) -> bytes: ...
def decrypt_smime(
data: bytes,
certificate: x509.Certificate,
private_key: rsa.RSAPrivateKey,
options: typing.Iterable[pkcs7.PKCS7Options],
options: Iterable[pkcs7.PKCS7Options],
) -> bytes: ...
def load_pem_pkcs7_certificates(
data: bytes,
Expand Down
9 changes: 5 additions & 4 deletions src/cryptography/hazmat/bindings/_rust/x509.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import datetime
import typing
from collections.abc import Iterator

from cryptography import x509
from cryptography.hazmat.primitives import hashes, serialization
Expand Down Expand Up @@ -108,7 +109,7 @@ class Certificate:
@property
def signature_algorithm_parameters(
self,
) -> None | PSS | PKCS1v15 | ECDSA: ...
) -> PSS | PKCS1v15 | ECDSA | None: ...
@property
def extensions(self) -> x509.Extensions: ...
@property
Expand Down Expand Up @@ -139,7 +140,7 @@ class CertificateRevocationList:
@property
def signature_algorithm_parameters(
self,
) -> None | PSS | PKCS1v15 | ECDSA: ...
) -> PSS | PKCS1v15 | ECDSA | None: ...
@property
def issuer(self) -> x509.Name: ...
@property
Expand All @@ -162,7 +163,7 @@ class CertificateRevocationList:
def __getitem__(self, idx: int) -> x509.RevokedCertificate: ...
@typing.overload
def __getitem__(self, idx: slice) -> list[x509.RevokedCertificate]: ...
def __iter__(self) -> typing.Iterator[x509.RevokedCertificate]: ...
def __iter__(self) -> Iterator[x509.RevokedCertificate]: ...
def is_signature_valid(
self, public_key: CertificateIssuerPublicKeyTypes
) -> bool: ...
Expand All @@ -182,7 +183,7 @@ class CertificateSigningRequest:
@property
def signature_algorithm_parameters(
self,
) -> None | PSS | PKCS1v15 | ECDSA: ...
) -> PSS | PKCS1v15 | ECDSA | None: ...
@property
def extensions(self) -> x509.Extensions: ...
@property
Expand Down
3 changes: 2 additions & 1 deletion src/cryptography/hazmat/bindings/openssl/binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import types
import typing
import warnings
from collections.abc import Callable

import cryptography
from cryptography.exceptions import InternalError
Expand All @@ -35,7 +36,7 @@ def _openssl_assert(ok: bool) -> None:

def build_conditional_library(
lib: typing.Any,
conditional_names: dict[str, typing.Callable[[], list[str]]],
conditional_names: dict[str, Callable[[], list[str]]],
) -> typing.Any:
conditional_lib = types.ModuleType("lib")
conditional_lib._original_lib = lib # type: ignore[attr-defined]
Expand Down
2 changes: 1 addition & 1 deletion src/cryptography/hazmat/primitives/ciphers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ def decryptor(self):
typing.Union[
modes.ModeWithNonce,
modes.ModeWithTweak,
None,
modes.ECB,
modes.ModeWithInitializationVector,
None,
]
]

Expand Down
3 changes: 2 additions & 1 deletion src/cryptography/hazmat/primitives/kdf/concatkdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from __future__ import annotations

import typing
from collections.abc import Callable

from cryptography import utils
from cryptography.exceptions import AlreadyFinalized, InvalidKey
Expand All @@ -31,7 +32,7 @@ def _common_args_checks(
def _concatkdf_derive(
key_material: bytes,
length: int,
auxfn: typing.Callable[[], hashes.HashContext],
auxfn: Callable[[], hashes.HashContext],
otherinfo: bytes,
) -> bytes:
utils._check_byteslike("key_material", key_material)
Expand Down
3 changes: 2 additions & 1 deletion src/cryptography/hazmat/primitives/kdf/kbkdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from __future__ import annotations

import typing
from collections.abc import Callable

from cryptography import utils
from cryptography.exceptions import (
Expand Down Expand Up @@ -36,7 +37,7 @@ class CounterLocation(utils.Enum):
class _KBKDFDeriver:
def __init__(
self,
prf: typing.Callable,
prf: Callable,
mode: Mode,
length: int,
rlen: int,
Expand Down
6 changes: 3 additions & 3 deletions src/cryptography/hazmat/primitives/padding.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from __future__ import annotations

import abc
import typing
from collections.abc import Callable

from cryptography import utils
from cryptography.exceptions import AlreadyFinalized
Expand Down Expand Up @@ -59,7 +59,7 @@ def _byte_padding_update(
def _byte_padding_pad(
buffer_: bytes | None,
block_size: int,
paddingfn: typing.Callable[[int], bytes],
paddingfn: Callable[[int], bytes],
) -> bytes:
if buffer_ is None:
raise AlreadyFinalized("Context was already finalized.")
Expand Down Expand Up @@ -89,7 +89,7 @@ def _byte_unpadding_update(
def _byte_unpadding_check(
buffer_: bytes | None,
block_size: int,
checkfn: typing.Callable[[bytes], int],
checkfn: Callable[[bytes], int],
) -> bytes:
if buffer_ is None:
raise AlreadyFinalized("Context was already finalized.")
Expand Down
3 changes: 2 additions & 1 deletion src/cryptography/hazmat/primitives/serialization/pkcs12.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from __future__ import annotations

import typing
from collections.abc import Iterable

from cryptography import x509
from cryptography.hazmat.bindings._rust import pkcs12 as rust_pkcs12
Expand Down Expand Up @@ -122,7 +123,7 @@ def serialize_key_and_certificates(
name: bytes | None,
key: PKCS12PrivateKeyTypes | None,
cert: x509.Certificate | None,
cas: typing.Iterable[_PKCS12CATypes] | None,
cas: Iterable[_PKCS12CATypes] | None,
encryption_algorithm: serialization.KeySerializationEncryption,
) -> bytes:
if key is not None and not isinstance(
Expand Down
5 changes: 3 additions & 2 deletions src/cryptography/hazmat/primitives/serialization/pkcs7.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import email.policy
import io
import typing
from collections.abc import Iterable

from cryptography import utils, x509
from cryptography.exceptions import UnsupportedAlgorithm, _Reasons
Expand Down Expand Up @@ -133,7 +134,7 @@ def add_certificate(
def sign(
self,
encoding: serialization.Encoding,
options: typing.Iterable[PKCS7Options],
options: Iterable[PKCS7Options],
backend: typing.Any = None,
) -> bytes:
if len(self._signers) == 0:
Expand Down Expand Up @@ -258,7 +259,7 @@ def set_content_encryption_algorithm(
def encrypt(
self,
encoding: serialization.Encoding,
options: typing.Iterable[PKCS7Options],
options: Iterable[PKCS7Options],
) -> bytes:
if len(self._recipients) == 0:
raise ValueError("Must have at least one recipient")
Expand Down
6 changes: 3 additions & 3 deletions src/cryptography/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import enum
import sys
import types
import typing
import warnings
from collections.abc import Callable, Sequence


# We use a UserWarning subclass, instead of DeprecationWarning, because CPython
Expand Down Expand Up @@ -81,7 +81,7 @@ def __delattr__(self, attr: str) -> None:

delattr(self._module, attr)

def __dir__(self) -> typing.Sequence[str]:
def __dir__(self) -> Sequence[str]:
return ["_module", *dir(self._module)]


Expand All @@ -102,7 +102,7 @@ def deprecated(
return dv


def cached_property(func: typing.Callable) -> property:
def cached_property(func: Callable) -> property:
cached_name = f"_cached_{func}"
sentinel = object()

Expand Down
3 changes: 2 additions & 1 deletion src/cryptography/x509/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import os
import typing
import warnings
from collections.abc import Iterable

from cryptography import utils
from cryptography.hazmat.bindings._rust import x509 as rust_x509
Expand Down Expand Up @@ -131,7 +132,7 @@ def __hash__(self) -> int:
class Attributes:
def __init__(
self,
attributes: typing.Iterable[Attribute],
attributes: Iterable[Attribute],
) -> None:
self._attributes = list(attributes)

Expand Down
Loading
Loading