Skip to content

Commit

Permalink
Apply a couple refurb suggestions (#9944)
Browse files Browse the repository at this point in the history
* Apply refurb suggestion

[FURB138]: Consider using list comprehension

* Apply refurb suggestion

[FURB108]: Replace `x == y or x == z` with `x in (y, z)`
  • Loading branch information
DimitriPapadopoulos authored Nov 30, 2023
1 parent d146423 commit 3fa1405
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
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

0 comments on commit 3fa1405

Please sign in to comment.