Skip to content

Commit 9f5ac9c

Browse files
authored
Merge pull request #3 from auax/master
Master
2 parents 4190fab + 2115120 commit 9f5ac9c

File tree

4 files changed

+68
-33
lines changed

4 files changed

+68
-33
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ eggs
99
parts
1010
src/*.egg-info
1111
lib
12-
lib64
12+
lib64
13+
.idea

resources/main.ui

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,9 +430,11 @@ p, li { white-space: pre-wrap; }
430430
</property>
431431
<widget class="QMenu" name="menu_github">
432432
<property name="title">
433-
<string>GitHub</string>
433+
<string>Options</string>
434434
</property>
435435
<addaction name="open_github"/>
436+
<addaction name="report_issue"/>
437+
<addaction name="donate"/>
436438
</widget>
437439
<addaction name="menu_github"/>
438440
</widget>
@@ -447,6 +449,16 @@ p, li { white-space: pre-wrap; }
447449
<string>Report a bug</string>
448450
</property>
449451
</action>
452+
<action name="report_issue">
453+
<property name="text">
454+
<string>Report Issue</string>
455+
</property>
456+
</action>
457+
<action name="donate">
458+
<property name="text">
459+
<string>Donate</string>
460+
</property>
461+
</action>
450462
</widget>
451463
<resources/>
452464
<connections/>

secauax.py

Lines changed: 51 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@
77

88

99
class Secauax:
10+
"""
11+
Secauax encryption class
12+
"""
13+
1014
def __init__(self):
15+
"""
16+
Init method
17+
"""
1118
self.key_ = Fernet.generate_key()
1219

1320
def __str__(self):
@@ -23,7 +30,7 @@ def key(self):
2330
@staticmethod
2431
def load_key(path: Union[Path, str]) -> bytes:
2532
"""
26-
Return a key from a ".key" file.
33+
Return a key from a file. This key must be valid, otherwise, an error will be thrown.
2734
:param path: path to key
2835
:return: bytes
2936
"""
@@ -35,39 +42,42 @@ def load_key(path: Union[Path, str]) -> bytes:
3542

3643
def load_key_into_class(self, path: Union[Path, str]):
3744
"""
38-
Replace the key class variable with loaded key.
39-
File extension is ".key"
45+
Replace the key class variable with the loaded key and return it.
4046
:param path: path to key
4147
:return: bytes
4248
"""
4349
self.key_ = Secauax.load_key(path)
4450
return self.key
4551

46-
def save_key(self, filename: Union[Path, str]) -> None:
52+
def save_key(self, filename: Union[Path, str]) -> bool:
4753
"""
48-
Save generated key to a file.
49-
File extension is ".key"
54+
Save set key to a file. You can choose the file extension, although the ".key" extension is recommended.
55+
This method returns a true boolean if the file is saved successfully. An OSError will result in a false boolean.
5056
:param filename: path to save the key
51-
:return: None
57+
:return: bool
5258
"""
53-
with open(filename, 'wb') as filekey:
54-
filekey.write(self.key)
55-
filekey.close()
59+
try:
60+
with open(filename, 'wb') as filekey:
61+
filekey.write(self.key)
62+
filekey.close()
63+
except OSError:
64+
return False
65+
return True
5666

5767
def encrypt_file(self, path: Union[Path, str], filename: Union[Path, str] = None) -> bytes:
5868
"""
59-
Encrypt a file with a generated key.
60-
DISCLAIMER: if no "filename" parameter is specified, the file will be overwritten.
61-
Returns the encrypted file data in bytes.
62-
:param path: path to original file
69+
Encrypt a file with the set key.
70+
Attention: If the filename parameter is not specified, the new file will overwrite the original.
71+
It returns the encrypted file data in bytes.
72+
:param path: path to the original file
6373
:param filename: path to save the encrypted file
6474
:return: bytes
6575
"""
6676
fernet = Fernet(self.key)
6777

6878
# Open original file
6979
with open(path, "rb") as file:
70-
original_file = file.read()
80+
original_file = file.read() # Read data in bytes
7181
file.close()
7282

7383
# Encrypt the file
@@ -83,27 +93,32 @@ def encrypt_file(self, path: Union[Path, str], filename: Union[Path, str] = None
8393
def bulk_encrypt(self,
8494
pathname: Union[Path, str],
8595
output_directory: Union[Path, str] = None,
86-
file_extension: str = "*") -> None:
96+
file_extension: str = "*") -> bool:
8797
"""
88-
Encrypt all files inside a directory and save them into another directory.
89-
If the "output_directory" is the same as the "pathname", the files will be overwritten.
98+
Encrypt all the files inside a directory and save them into another directory.
99+
Attention: If the output_directory parameter is not specified, the new file(s) will overwrite the original(s).
100+
This method returns a true boolean if the files are saved successfully. Any error will result in a false boolean.
90101
:param pathname: path to the decrypted folder
91102
:param output_directory: path to save the encrypted files
92-
:param file_extension: select which files will be encrypted. Format: ".png" or, for all type of files: "*"
93-
:return: None
103+
:param file_extension: filter files by extension: ".png" / ".txt" / ...
104+
:return: bool
94105
"""
95106

96107
assert os.path.isdir(pathname), "pathname path doesn't exist"
97108
assert os.path.isdir(output_directory), "output_directory path doesn't exist"
98109

99-
for file in glob.glob(os.path.join(pathname, file_extension)):
100-
self.encrypt_file(file, os.path.join(output_directory, os.path.basename(file)))
110+
try:
111+
for file in glob.glob(os.path.join(pathname, file_extension)):
112+
self.encrypt_file(file, os.path.join(output_directory, os.path.basename(file)))
113+
except:
114+
return False
115+
return True
101116

102117
def decrypt_file(self, path: Union[Path, str], filename: Union[Path, str] = None) -> bytes:
103118
"""
104-
Decrypt a file with a generated key.
105-
DISCLAIMER: if no "filename" parameter is specified, the file will be overwritten.
106-
Returns the decrypted file data in bytes.
119+
Decrypt a file with the set key.
120+
Attention: If the filename parameter is not specified, the new file will overwrite the original.
121+
It returns the decrypted file data in bytes.
107122
:param path: path to the encrypted file
108123
:param filename: path to save the decrypted file
109124
:return: bytes
@@ -126,18 +141,23 @@ def decrypt_file(self, path: Union[Path, str], filename: Union[Path, str] = None
126141
def bulk_decrypt(self,
127142
pathname: Union[Path, str],
128143
output_directory: Union[Path, str] = None,
129-
file_extension: str = "*") -> None:
144+
file_extension: str = "*") -> bool:
130145
"""
131-
Decrypt all files inside a directory and save them into another directory.
132-
If the "output_directory" is the same as the "pathname", the files will be overwritten.
146+
Decrypt all the files inside a directory and save them into another directory.
147+
Attention: If the output_directory parameter is not specified, the new file(s) will overwrite the original(s).
148+
This method returns a true boolean if the files are saved successfully. Any error will result in a false boolean.
133149
:param pathname: path to encrypted folder
134150
:param output_directory: path to save the decrypted files
135151
:param file_extension: select which files will be decrypted. Format: ".png" or, for all type of files: "*"
136-
:return: None
152+
:return: bool
137153
"""
138154

139155
assert os.path.isdir(pathname), "pathname path doesn't exist"
140156
assert os.path.isdir(output_directory), "output_directory path doesn't exist"
141157

142-
for file in glob.glob(os.path.join(pathname, file_extension)):
143-
self.decrypt_file(file, os.path.join(output_directory, os.path.basename(file)))
158+
try:
159+
for file in glob.glob(os.path.join(pathname, file_extension)):
160+
self.decrypt_file(file, os.path.join(output_directory, os.path.basename(file)))
161+
except:
162+
return False
163+
return True

window.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ def __init__(self):
3636

3737
# Connect Menu
3838
self.open_github.triggered.connect(lambda: webbrowser.open("https://github.com/auax"))
39+
self.report_issue.triggered.connect(lambda: webbrowser.open("https://github.com/auax/secauax/issues/new"))
40+
self.donate.triggered.connect(lambda: webbrowser.open("https://paypal.me/zellius"))
3941

4042
# Connect First Section (input path)
4143
self.browse_file_inp_btn.clicked.connect(lambda: self.browse_file(self.input_path))

0 commit comments

Comments
 (0)