33import base64
44import contextlib
55import datetime
6- from typing import Any , Optional , cast
6+ from typing import Any , cast
77
88from cryptography import x509
99from cryptography .hazmat .backends import default_backend
@@ -35,7 +35,7 @@ def __init__(
3535 certificate_authority_configuration : dict [str , Any ],
3636 certificate_authority_type : str ,
3737 revocation_configuration : dict [str , Any ],
38- security_standard : Optional [ str ] ,
38+ security_standard : str | None ,
3939 ):
4040 self .id = mock_random .uuid4 ()
4141 self .arn = f"arn:{ get_partition (region )} :acm-pca:{ region } :{ account_id } :certificate-authority/{ self .id } "
@@ -48,11 +48,11 @@ def __init__(
4848 }
4949 self .set_revocation_configuration (revocation_configuration )
5050 self .created_at = unix_time ()
51- self .updated_at : Optional [ float ] = None
51+ self .updated_at : float | None = None
5252 self .status = "PENDING_CERTIFICATE"
5353 self .usage_mode = "SHORT_LIVED_CERTIFICATE"
5454 self .security_standard = security_standard or "FIPS_140_2_LEVEL_3_OR_HIGHER"
55- self .policy : Optional [ str ] = None
55+ self .policy : str | None = None
5656 self .revoked_certificates : dict [str , dict [str , Any ]] = {}
5757
5858 self .password = str (mock_random .uuid4 ()).encode ("utf-8" )
@@ -65,7 +65,7 @@ def __init__(
6565 )
6666
6767 self .certificate_bytes : bytes = b""
68- self .certificate_chain : Optional [ bytes ] = None
68+ self .certificate_chain : bytes | None = None
6969 self .issued_certificates : dict [str , bytes ] = {}
7070 self .issued_certificates_certificate_chains : dict [str , bytes ] = {}
7171
@@ -103,7 +103,7 @@ def key(self) -> rsa.RSAPrivateKey:
103103 return cast (rsa .RSAPrivateKey , private_key )
104104
105105 @property
106- def certificate (self ) -> Optional [ x509 .Certificate ] :
106+ def certificate (self ) -> x509 .Certificate | None :
107107 if self .certificate_bytes :
108108 return x509 .load_pem_x509_certificate (self .certificate_bytes )
109109 return None
@@ -153,7 +153,7 @@ def csr(self) -> bytes:
153153 )
154154 return csr .public_bytes (serialization .Encoding .PEM )
155155
156- def issue_certificate (self , csr_bytes : bytes , template_arn : Optional [ str ] ) -> str :
156+ def issue_certificate (self , csr_bytes : bytes , template_arn : str | None ) -> str :
157157 csr = x509 .load_pem_x509_csr (base64 .b64decode (csr_bytes ))
158158 extensions = self ._x509_extensions (csr , template_arn )
159159 new_cert = self .generate_cert (
@@ -177,7 +177,7 @@ def issue_certificate(self, csr_bytes: bytes, template_arn: Optional[str]) -> st
177177 return cert_arn
178178
179179 def _x509_extensions (
180- self , csr : x509 .CertificateSigningRequest , template_arn : Optional [ str ]
180+ self , csr : x509 .CertificateSigningRequest , template_arn : str | None
181181 ) -> list [tuple [x509 .ExtensionType , bool ]]:
182182 """
183183 Uses a PCA certificate template ARN to return a list of X.509 extensions.
@@ -283,7 +283,7 @@ def get_certificate(self, certificate_arn: str) -> tuple[bytes, bytes]:
283283 return certificate , certificate_chain
284284
285285 def set_revocation_configuration (
286- self , revocation_configuration : Optional [ dict [str , Any ]]
286+ self , revocation_configuration : dict [str , Any ] | None
287287 ) -> None :
288288 if revocation_configuration is not None :
289289 self .revocation_configuration = revocation_configuration
@@ -300,7 +300,7 @@ def set_revocation_configuration(
300300 raise InvalidS3ObjectAclInCrlConfiguration (acl )
301301
302302 @property
303- def not_valid_after (self ) -> Optional [ float ] :
303+ def not_valid_after (self ) -> float | None :
304304 if self .certificate is None :
305305 return None
306306 try :
@@ -309,7 +309,7 @@ def not_valid_after(self) -> Optional[float]:
309309 return unix_time (self .certificate .not_valid_after )
310310
311311 @property
312- def not_valid_before (self ) -> Optional [ float ] :
312+ def not_valid_before (self ) -> float | None :
313313 if self .certificate is None :
314314 return None
315315 try :
@@ -318,7 +318,7 @@ def not_valid_before(self) -> Optional[float]:
318318 return unix_time (self .certificate .not_valid_before )
319319
320320 def import_certificate_authority_certificate (
321- self , certificate : bytes , certificate_chain : Optional [ bytes ]
321+ self , certificate : bytes , certificate_chain : bytes | None
322322 ) -> None :
323323 try :
324324 x509 .load_pem_x509_certificate (certificate )
@@ -376,7 +376,7 @@ def create_certificate_authority(
376376 certificate_authority_configuration : dict [str , Any ],
377377 revocation_configuration : dict [str , Any ],
378378 certificate_authority_type : str ,
379- security_standard : Optional [ str ] ,
379+ security_standard : str | None ,
380380 tags : list [dict [str , str ]],
381381 ) -> str :
382382 """
@@ -404,7 +404,7 @@ def describe_certificate_authority(
404404
405405 def get_certificate_authority_certificate (
406406 self , certificate_authority_arn : str
407- ) -> tuple [bytes , Optional [ bytes ] ]:
407+ ) -> tuple [bytes , bytes | None ]:
408408 ca = self .describe_certificate_authority (certificate_authority_arn )
409409 if ca .status != "ACTIVE" :
410410 raise InvalidStateException (certificate_authority_arn )
@@ -439,7 +439,7 @@ def delete_certificate_authority(self, certificate_authority_arn: str) -> None:
439439 ca .status = "DELETED"
440440
441441 def issue_certificate (
442- self , certificate_authority_arn : str , csr : bytes , template_arn : Optional [ str ]
442+ self , certificate_authority_arn : str , csr : bytes , template_arn : str | None
443443 ) -> str :
444444 """
445445 The following parameters are not yet implemented: ApiPassthrough, SigningAlgorithm, Validity, ValidityNotBefore, IdempotencyToken
@@ -471,7 +471,7 @@ def import_certificate_authority_certificate(
471471 self ,
472472 certificate_authority_arn : str ,
473473 certificate : bytes ,
474- certificate_chain : Optional [ bytes ] ,
474+ certificate_chain : bytes | None ,
475475 ) -> None :
476476 ca = self .describe_certificate_authority (certificate_authority_arn )
477477 ca .import_certificate_authority_certificate (certificate , certificate_chain )
@@ -532,7 +532,7 @@ def delete_policy(self, resource_arn: str) -> None:
532532 @paginate (pagination_model = PAGINATION_MODEL )
533533 def list_certificate_authorities (
534534 self ,
535- resource_owner : Optional [ str ] = None ,
535+ resource_owner : str | None = None ,
536536 ) -> list [CertificateAuthority ]:
537537 """
538538 Lists the private certificate authorities that you created by using the CreateCertificateAuthority action.
0 commit comments