@@ -441,30 +441,54 @@ def begin_work(config_loader):
441
441
post_sync_manager .run (rule_processor .post_sync_data )
442
442
443
443
444
- @main .command (short_help = "Encrypt an existing RSA private key" )
444
+ @main .command (short_help = "Encrypt RSA private key" )
445
445
@click .help_option ('-h' , '--help' )
446
446
@click .argument ('key-path' , default = 'private.key' , type = click .Path (exists = True ))
447
+ @click .option ('-o' , '--output-file' , help = "Path of encrypted file [default: key specified by KEY_PATH will be overwritten]" ,
448
+ default = None )
447
449
@click .option ('--password' , '-p' , prompt = 'Create password' , hide_input = True , confirmation_prompt = True )
448
- def encrypt (password , key_path ):
449
- """Encrypt an existing RSA private key file with a passphrase"""
450
+ def encrypt (output_file , password , key_path ):
451
+ """Encrypt RSA private key specified by KEY_PATH.
452
+
453
+ KEY_PATH default: private.key
454
+
455
+ A passphrase is required to encrypt the file"""
456
+ if output_file is None :
457
+ output_file = key_path
458
+ if output_file != key_path and Path (output_file ).exists () \
459
+ and not click .confirm ('\n Warning - file already exists: \n {}\n Overwrite?' .format (output_file )):
460
+ return
450
461
try :
451
462
data = user_sync .encryption .encrypt_file (password , key_path )
452
- user_sync .encryption .write_key (data , key_path )
453
- click .echo ('Encryption was successful.\n {0}' .format (os .path .abspath (key_path )))
463
+ user_sync .encryption .write_key (data , output_file )
464
+ click .echo ('Encryption was successful.' )
465
+ click .echo ('Wrote file: {}' .format (os .path .abspath (output_file )))
454
466
except AssertionException as e :
455
467
click .echo (str (e ))
456
468
457
469
458
- @main .command ()
470
+ @main .command (short_help = "Decrypt RSA private key" )
459
471
@click .help_option ('-h' , '--help' )
460
472
@click .argument ('key-path' , default = 'private.key' , type = click .Path (exists = True ))
473
+ @click .option ('-o' , '--output-file' , help = "Path of decrypted file [default: key specified by KEY_PATH will be overwritten]" ,
474
+ default = None )
461
475
@click .option ('--password' , '-p' , prompt = 'Enter password' , hide_input = True )
462
- def decrypt (password , key_path ):
463
- """Decrypt an RSA private key file with a passphrase"""
476
+ def decrypt (output_file , password , key_path ):
477
+ """Decrypt RSA private key specified by KEY_PATH.
478
+
479
+ KEY_PATH default: private.key
480
+
481
+ A passphrase is required to decrypt the file"""
482
+ if output_file is None :
483
+ output_file = key_path
484
+ if output_file != key_path and Path (output_file ).exists () \
485
+ and not click .confirm ('\n Warning - file already exists: \n {}\n Overwrite?' .format (output_file )):
486
+ return
464
487
try :
465
488
data = user_sync .encryption .decrypt_file (password , key_path )
466
- user_sync .encryption .write_key (data , key_path )
467
- click .echo ('Decryption was successful.\n {0}' .format (os .path .abspath (key_path )))
489
+ user_sync .encryption .write_key (data , output_file )
490
+ click .echo ('Decryption was successful.' )
491
+ click .echo ('Wrote file: {}' .format (os .path .abspath (output_file )))
468
492
except AssertionException as e :
469
493
click .echo (str (e ))
470
494
0 commit comments