2020from os import environ , getenv , path
2121import re
2222import subprocess
23- from typing import Generator , Optional , Tuple , Union
23+ from typing import cast , Generator , Optional , Tuple , Union
2424
2525from google .auth import _agent_identity_utils
2626from google .auth import environment_vars
@@ -118,7 +118,9 @@ def secure_cert_key_paths(
118118 if (cert_path is None or os .path .exists (cert_path )) and (
119119 key_path is None or os .path .exists (key_path )
120120 ):
121- yield cert_path or cert , key_path or key , passphrase
121+ yield cast (str , cert_path or cert ), cast (
122+ str , key_path or key
123+ ), passphrase
122124 return
123125 finally :
124126 import sys
@@ -137,7 +139,7 @@ def secure_cert_key_paths(
137139 key_path ,
138140 new_passphrase ,
139141 ):
140- yield cert_path or cert , key_path or key , new_passphrase
142+ yield cast ( str , cert_path or cert ), cast ( str , key_path or key ) , new_passphrase
141143
142144
143145def _encrypt_key_if_plaintext (
@@ -199,7 +201,9 @@ def _secure_wipe_and_remove(file_path: str):
199201
200202
201203@contextlib .contextmanager
202- def _memfd_cert_key_paths (cert_bytes : Optional [bytes ], key_bytes : Optional [bytes ]):
204+ def _memfd_cert_key_paths (
205+ cert_bytes : Optional [bytes ], key_bytes : Optional [bytes ]
206+ ) -> Generator [Tuple [Optional [str ], Optional [str ]], None , None ]:
203207 """Creates secure, in-memory virtual files on Linux using memfd_create.
204208
205209 Yields:
@@ -237,8 +241,10 @@ def _memfd_cert_key_paths(cert_bytes: Optional[bytes], key_bytes: Optional[bytes
237241
238242@contextlib .contextmanager
239243def _tempfile_cert_key_paths (
240- cert_bytes : Optional [bytes ], key_bytes : Optional [bytes ], passphrase : Optional [bytes ]
241- ):
244+ cert_bytes : Optional [bytes ],
245+ key_bytes : Optional [bytes ],
246+ passphrase : Optional [bytes ],
247+ ) -> Generator [Tuple [Optional [str ], Optional [str ], Optional [bytes ]], None , None ]:
242248 """Creates secure temporary file paths on disk, encrypting private keys.
243249
244250 Yields:
0 commit comments