-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsafebox.py
More file actions
54 lines (43 loc) · 1.69 KB
/
safebox.py
File metadata and controls
54 lines (43 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import argparse
import sys
from core.safebox_handler import SafeBox
class SafeBoxCLI:
def __init__(self):
self.safebox = SafeBox()
self.args = self.parse_arguments()
def parse_arguments(self):
parser = argparse.ArgumentParser("SafeBox CLI")
parser.add_argument("-e", "--encrypt", action="store_true", help="Encrypt a File")
parser.add_argument("-d", "--decrypt", action="store_true", help="Decrypt a File")
parser.add_argument("-f", "--file", help="Path to the File", required=True)
parser.add_argument("-p", "--password", help="The Password", required=True)
parser.add_argument("-o", "--out", help="Path to the output File, including the File name (Optional)")
return parser.parse_args()
def validate(self):
if not self.args.encrypt and not self.args.decrypt:
sys.exit("Select either '-e' or '-d'")
if self.args.encrypt and self.args.decrypt:
sys.exit("Select one mode only ('-e' or '-d')")
if not self.args.file or not self.args.password:
sys.exit("both, 'file' and 'password' are required")
def run(self):
self.validate()
if self.args.encrypt:
print(
self.safebox.encrypt_file(
self.args.file,
self.args.password,
self.args.out
)
)
elif self.args.decrypt:
print(
self.safebox.decrypt_file(
self.args.file,
self.args.password,
self.args.out
)
)
if __name__ == "__main__":
cli = SafeBoxCLI()
cli.run()