@@ -196,9 +196,9 @@ def should_generate_new_rsa_key_pair() -> bool:
196196
197197 # If only one file is present: throw exception
198198 if private_key_file and not public_key_file :
199- raise RuntimeError (f"Missing public key file at { EXAMPLE_RSA_PUBLIC_KEY_FILENAME } " )
199+ raise ValueError (f"Missing public key file at { EXAMPLE_RSA_PUBLIC_KEY_FILENAME } " )
200200 if not private_key_file and public_key_file :
201- raise RuntimeError (f"Missing private key file at { EXAMPLE_RSA_PRIVATE_KEY_FILENAME } " )
201+ raise ValueError (f"Missing private key file at { EXAMPLE_RSA_PRIVATE_KEY_FILENAME } " )
202202
203203 # If neither file is present, generate a new key pair
204204 return True
@@ -208,7 +208,7 @@ def generate_rsa_key_pair():
208208 """Generate a new RSA key pair and save to PEM files."""
209209 # Safety check: Validate neither file is present
210210 if os .path .exists (EXAMPLE_RSA_PRIVATE_KEY_FILENAME ) or os .path .exists (EXAMPLE_RSA_PUBLIC_KEY_FILENAME ):
211- raise RuntimeError ("generateRsaKeyPair will not overwrite existing PEM files" )
211+ raise FileExistsError ("generateRsaKeyPair will not overwrite existing PEM files" )
212212
213213 # This code will generate a new RSA key pair for example use.
214214 # The public and private key will be written to the files:
@@ -230,7 +230,7 @@ def generate_rsa_key_pair():
230230 with open (EXAMPLE_RSA_PRIVATE_KEY_FILENAME , "wb" ) as f :
231231 f .write (private_key_pem )
232232 except IOError as e :
233- raise RuntimeError ("IOError while writing private key PEM" ) from e
233+ raise OSError ("IOError while writing private key PEM" ) from e
234234
235235 # Write public key PEM file
236236 public_key = private_key .public_key ()
0 commit comments