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

Apply a couple refurb suggestions #9944

Merged
merged 2 commits into from
Nov 30, 2023
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
2 changes: 1 addition & 1 deletion src/cryptography/hazmat/backends/openssl/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def openssl_version_number(self) -> int:
return self._lib.OpenSSL_version_num()

def _evp_md_from_algorithm(self, algorithm: hashes.HashAlgorithm):
if algorithm.name == "blake2b" or algorithm.name == "blake2s":
if algorithm.name in ("blake2b", "blake2s"):
alg = f"{algorithm.name}{algorithm.digest_size * 8}".encode(
"ascii"
)
Expand Down
5 changes: 1 addition & 4 deletions src/cryptography/x509/name.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,7 @@ def __init__(
if not isinstance(value, str):
raise TypeError("value argument must be a str")

if (
oid == NameOID.COUNTRY_NAME
or oid == NameOID.JURISDICTION_COUNTRY_NAME
):
if oid in (NameOID.COUNTRY_NAME, NameOID.JURISDICTION_COUNTRY_NAME):
assert isinstance(value, str)
c_len = len(value.encode("utf8"))
if c_len != 2 and _validate is True:
Expand Down
18 changes: 10 additions & 8 deletions tests/hazmat/primitives/test_aead.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,10 +732,11 @@ def test_vectors(self, backend, subtests):
aad1 = vector.get("aad", None)
aad2 = vector.get("aad2", None)
aad3 = vector.get("aad3", None)
aad = []
for a in [aad1, aad2, aad3]:
if a is not None:
aad.append(binascii.unhexlify(a))
aad = [
binascii.unhexlify(a)
for a in (aad1, aad2, aad3)
if a is not None
]
ct = binascii.unhexlify(vector["ciphertext"])
tag = binascii.unhexlify(vector["tag"])
pt = binascii.unhexlify(vector.get("plaintext", b""))
Expand All @@ -757,10 +758,11 @@ def test_vectors_invalid(self, backend, subtests):
aad1 = vector.get("aad", None)
aad2 = vector.get("aad2", None)
aad3 = vector.get("aad3", None)
aad = []
for a in [aad1, aad2, aad3]:
if a is not None:
aad.append(binascii.unhexlify(a))
aad = [
binascii.unhexlify(a)
for a in (aad1, aad2, aad3)
if a is not None
]

ct = binascii.unhexlify(vector["ciphertext"])
aessiv = AESSIV(key)
Expand Down
Loading