@@ -196,9 +196,9 @@ def should_generate_new_rsa_key_pair() -> bool:
196
196
197
197
# If only one file is present: throw exception
198
198
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 } " )
200
200
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 } " )
202
202
203
203
# If neither file is present, generate a new key pair
204
204
return True
@@ -208,7 +208,7 @@ def generate_rsa_key_pair():
208
208
"""Generate a new RSA key pair and save to PEM files."""
209
209
# Safety check: Validate neither file is present
210
210
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" )
212
212
213
213
# This code will generate a new RSA key pair for example use.
214
214
# The public and private key will be written to the files:
@@ -230,7 +230,7 @@ def generate_rsa_key_pair():
230
230
with open (EXAMPLE_RSA_PRIVATE_KEY_FILENAME , "wb" ) as f :
231
231
f .write (private_key_pem )
232
232
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
234
234
235
235
# Write public key PEM file
236
236
public_key = private_key .public_key ()
0 commit comments