Skip to content

Commit 0411cd9

Browse files
committed
removed double if loops
1 parent 34a3f49 commit 0411cd9

File tree

1 file changed

+18
-16
lines changed
  • src/cryptography/hazmat/primitives/serialization

1 file changed

+18
-16
lines changed

src/cryptography/hazmat/primitives/serialization/pkcs7.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
)
2323
from cryptography.utils import _check_byteslike
2424
from cryptography.x509 import Certificate
25+
from cryptography.x509.oid import ExtendedKeyUsageOID
2526
from cryptography.x509.verification import (
2627
Criticality,
2728
ExtensionPolicy,
@@ -83,14 +84,14 @@ def _validate_basic_constraints(
8384
def _validate_key_usage(
8485
policy: Policy, cert: Certificate, ku: x509.KeyUsage | None
8586
) -> None:
86-
if ku is not None:
87-
# Content commitment used to be named non repudiation
88-
if not (ku.digital_signature or ku.content_commitment):
89-
raise ValueError(
90-
"Key Usage, if specified, must have at least one of the "
91-
"digital signature or content commitment (formerly non "
92-
"repudiation) bits set."
93-
)
87+
if ku is not None and not (
88+
ku.digital_signature or ku.content_commitment
89+
):
90+
raise ValueError(
91+
"Key Usage, if specified, must have at least one of the "
92+
"digital signature or content commitment (formerly non "
93+
"repudiation) bits set."
94+
)
9495

9596
def _validate_subject_alternative_name(
9697
policy: Policy,
@@ -125,14 +126,15 @@ def _validate_subject_alternative_name(
125126
def _validate_extended_key_usage(
126127
policy: Policy, cert: Certificate, eku: x509.ExtendedKeyUsage | None
127128
) -> None:
128-
if eku is not None:
129-
ep = x509.ExtendedKeyUsageOID.EMAIL_PROTECTION in eku # type: ignore[attr-defined]
130-
aeku = x509.ExtendedKeyUsageOID.ANY_EXTENDED_KEY_USAGE in eku # type: ignore[attr-defined]
131-
if not (ep or aeku):
132-
raise ValueError(
133-
"Extended Key Usage, if specified, must include "
134-
"emailProtection or anyExtendedKeyUsage."
135-
)
129+
if (
130+
eku is not None
131+
and ExtendedKeyUsageOID.EMAIL_PROTECTION not in eku
132+
and ExtendedKeyUsageOID.ANY_EXTENDED_KEY_USAGE not in eku
133+
):
134+
raise ValueError(
135+
"Extended Key Usage, if specified, must include "
136+
"emailProtection or anyExtendedKeyUsage."
137+
)
136138

137139
ee_policy = (
138140
ExtensionPolicy.webpki_defaults_ee()

0 commit comments

Comments
 (0)