Skip to content

Commit

Permalink
typing and fallbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
jvanasco committed Jan 10, 2025
1 parent 98e4e26 commit 4c384c8
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/josepy/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def __init__(
else:
# this is a x509 AND we have pyOpenSSL installed
# as an interim bridge, create a legacy version
_wrapped_legacy: Union[crypto.X509, crypto.X509Req]
_wrapped_legacy: Union["OpenSSL.crypto.X509", "OpenSSL.crypto.X509Req"]
if isinstance(wrapped, x509.Certificate):
_wrapped_legacy = crypto.load_certificate(
crypto.FILETYPE_ASN1, wrapped.public_bytes(Encoding.DER)
Expand Down Expand Up @@ -155,11 +155,15 @@ def wrapped_legacy(self) -> Union["OpenSSL.crypto.X509", "OpenSSL.crypto.X509Req
)
else:
raise ValueError("no compatible legacy object")
if TYPE_CHECKING:
assert isinstance(self._wrapped_legacy, (crypto.X509, crypto.X509Req))
return self._wrapped_legacy

def __getattr__(self, name: str) -> Any:
if self._wrapped_legacy:
try:
return getattr(self._wrapped_legacy, name)
except Exception:
pass
# fallback to compat and _wrapped_new
if name == "has_expired":
# a unittest addresses this attribute
# x509.CertificateSigningRequest does not have this attribute
Expand Down

0 comments on commit 4c384c8

Please sign in to comment.