Exposed encrypt() function to be used by extensions

This commit is contained in:
2022-07-20 16:23:43 -04:00
parent 5aeaee4c8f
commit 033bbd59de
+7 -6
View File
@@ -136,9 +136,10 @@ def pass_gen(): # generates and returns a random password based on user-specifi
return _gen
def encrypt(_shm_folder, _shm_entry, _location): # encrypts an entry and cleans up the temporary files
system(f"{gpg} -qr {str(gpg_id)} -e '{tmp_dir}{_shm_folder}/{_shm_entry}'")
move(f"{tmp_dir}{_shm_folder}/{_shm_entry}.gpg", f"{directory}{_location}.gpg")
def encrypt(_entry_dir, _shm_folder, _shm_entry, _gpg_command, _tmp_dir=path.expanduser('~/.config/sshyp/tmp/')):
# encrypts an entry and cleans up the temporary files
system(f"{_gpg_command} -qr {str(gpg_id)} -e '{tmp_dir}{_shm_folder}/{_shm_entry}'")
move(f"{tmp_dir}{_shm_folder}/{_shm_entry}.gpg", f"{_entry_dir}.gpg")
rmtree(f"{tmp_dir}{_shm_folder}")
@@ -491,7 +492,7 @@ def add_entry(): # adds a new entry
.writelines(optimized_edit([_password, _username, _url, _notes], None, -1))
print('\n\u001b[1mentry preview:\u001b[0m')
entry_reader(f"{tmp_dir}{_shm_folder}/{_shm_entry}")
encrypt(_shm_folder, _shm_entry, _entry_name)
encrypt(directory + _entry_name, _shm_folder, _shm_entry, 'gpg --pinentry-mode loopback')
def add_folder(): # creates a new folder
@@ -554,7 +555,7 @@ def edit(): # edits the contents of an entry
remove(f"{directory}{_entry_name}.gpg")
print('\n\u001b[1mentry preview:\u001b[0m')
entry_reader(f"{tmp_dir}{_shm_folder}/{_shm_entry}")
encrypt(_shm_folder, _shm_entry, _entry_name)
encrypt(directory + _entry_name, _shm_folder, _shm_entry, 'gpg --pinentry-mode loopback')
def gen(): # generates a password for a new or an existing entry
@@ -592,7 +593,7 @@ def gen(): # generates a password for a new or an existing entry
remove(f"{directory}{_entry_name}.gpg")
print('\n\u001b[1mentry preview:\u001b[0m')
entry_reader(f"{tmp_dir}{_shm_folder}/{_shm_entry}")
encrypt(_shm_folder, _shm_entry, _entry_name)
encrypt(directory + _entry_name, _shm_folder, _shm_entry, 'gpg --pinentry-mode loopback')
def copy_data(): # copies a specified field of an entry to the clipboard