Skip to content

Commit

Permalink
Fix type checker errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sffjunkie committed Mar 13, 2024
1 parent c95b31d commit 473eb52
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 32 deletions.
5 changes: 2 additions & 3 deletions src/pkiviewer/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,9 @@ def load_binary(
return [load_crl_der(data)]
elif ext == ".p12":
if password is not None:
passwd = password.encode("ascii")
return [load_pkcs12(data, password.encode("ascii"))]
else:
passwd = password
return [load_pkcs12(data, passwd)]
return [load_pkcs12(data, None)]
else:
return []

Expand Down
10 changes: 6 additions & 4 deletions src/pkiviewer/model/crl.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ class CertificateRevocationListInfo(X509Info):
next_update: datetime.datetime | None
fingerprint: bytes | None
extensions: dict[Oid, X509ExtensionInfo]
revoked_certificates: list[RevocationInfo]
fingerprint: bytes | None
revoked_certificates: list[RevocationInfo] | None


def revocation_date_parse(x509_dt: X509RevocationDate) -> datetime.datetime:
Expand Down Expand Up @@ -70,8 +69,11 @@ def certiticate_revocation_list_parse(crl: CertificateRevocationList, filename:
warnings: list[Warning] = []

rl = decode_tbs_certlist.decode_crl(crl.tbs_certlist_bytes)
revoked_certificates = rl["revokedCertificates"]
revoked_certificates = revocation_info_parse(revoked_certificates)
if rl is not None:
revoked_certificates = rl["revokedCertificates"]
revoked_certificates = revocation_info_parse(revoked_certificates)
else:
revoked_certificates = None

if crl.signature_hash_algorithm:
fingerprint = crl.fingerprint(crl.signature_hash_algorithm)
Expand Down
14 changes: 7 additions & 7 deletions src/pkiviewer/model/extension/issuer_alternative_name.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import cast

from cryptography.x509 import general_name
from cryptography import x509
from cryptography.x509.extensions import ExtensionType, IssuerAlternativeName

from pkiviewer.types import X509ExtensionTypeInfo
Expand All @@ -16,16 +16,16 @@ def issuer_alternative_name_parse(
) -> IssuerAlternativeNameInfo:
extension = cast(IssuerAlternativeName, extension)
names = {
general_name.DNSName: "DNS",
general_name.RFC822Name: "email",
general_name.UniformResourceIdentifier: "URI",
general_name.IPAddress: "IP Address",
general_name.RegisteredID: "Registered ID",
x509.DNSName: "DNS",
x509.RFC822Name: "email",
x509.UniformResourceIdentifier: "URI",
x509.IPAddress: "IP Address",
x509.RegisteredID: "Registered ID",
}
ians: dict[str, list[str]] = {}
for key, value in names.items():
ian_list: list[str] = []
for address in extension.get_values_for_type(type(key)):
for address in extension.get_values_for_type(key): # type: ignore
ian_list.append(str(address))
if ian_list:
ians[value] = ian_list
Expand Down
19 changes: 9 additions & 10 deletions src/pkiviewer/model/extension/not_implemented_by_cryptography.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,21 @@


# RFC5280 4.2.1.8
class SubjectDirectoryAttributesInfo(X509ExtensionTypeInfo):
...
class SubjectDirectoryAttributesInfo(X509ExtensionTypeInfo): ...


def subject_directory_attributes_parse(
extension: UnrecognizedExtension,
) -> SubjectDirectoryAttributesInfo:
...
) -> SubjectDirectoryAttributesInfo | None: ...


# RFC5280 4.2.1.11
class PolicyConstraintsInfo(X509ExtensionTypeInfo):
...
class PolicyConstraintsInfo(X509ExtensionTypeInfo): ...


def policy_constraints_parse(extension: UnrecognizedExtension) -> PolicyConstraintsInfo:
...
def policy_constraints_parse(
extension: UnrecognizedExtension,
) -> PolicyConstraintsInfo | None: ...


# RFC5280 4.2.1.5
Expand All @@ -40,5 +38,6 @@ class PolicyMappingsInfo(X509ExtensionTypeInfo):
policies: list[PolicyMapping]


def policy_mappings_parse(extension: UnrecognizedExtension) -> PolicyMappingsInfo:
...
def policy_mappings_parse(
extension: UnrecognizedExtension,
) -> PolicyMappingsInfo | None: ...
4 changes: 3 additions & 1 deletion src/pkiviewer/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ def maybe(
else:
data = data[elem]
except IndexError:
return None
pass

return None
2 changes: 1 addition & 1 deletion src/pkiviewer/view/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pkiviewer.context import _config, _console, _err_console, _theme # type: ignore


def rich_init(**kwargs: object):
def rich_init(**kwargs):
config = _config.get()

theme = rich.theme.Theme(config["theme"])
Expand Down
13 changes: 7 additions & 6 deletions src/pkiviewer/view/display/crl.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pkiviewer.context import _console # type: ignore; type: ignore
from pkiviewer.context import _console # type: ignore
from pkiviewer.model.crl import CertificateRevocationListInfo
from pkiviewer.oid.names import OidNames
from pkiviewer.view.console import (
Expand Down Expand Up @@ -121,11 +121,12 @@ def signature_display(crl_info: CertificateRevocationListInfo, indent: int = 0)

def crl_display(crl_info: CertificateRevocationListInfo, indent: int = 0) -> None:
print_key_oneline("Revocation List:", indent=indent)
for revocation in crl_info["revoked_certificates"]:
key = revocation["certificate_id"]
print_key_value_oneline("Certificate ID:", key, indent=indent + 1)
value = format_date_time(revocation["revocation_date"])
print_key_value_oneline("Revocation Date:", value, indent=indent + 1)
if (revoked_certs := crl_info["revoked_certificates"]) is not None:
for revocation in revoked_certs:
key = revocation["certificate_id"]
print_key_value_oneline("Certificate ID:", key, indent=indent + 1)
value = format_date_time(revocation["revocation_date"])
print_key_value_oneline("Revocation Date:", value, indent=indent + 1)


def certificate_revocation_list_display(
Expand Down

0 comments on commit 473eb52

Please sign in to comment.