diff options
author | AL-LCL <alvin@alvinhavel.com> | 2023-05-19 11:01:49 +0200 |
---|---|---|
committer | AL-LCL <alvin@alvinhavel.com> | 2023-05-19 11:01:49 +0200 |
commit | 20dbeb2f38684c65ff0a4b99012c161295708e88 (patch) | |
tree | a5b8445f55da2fbbb92443b68e9d7354a290c598 /foreign/client_handling/encrypt.py |
Diffstat (limited to 'foreign/client_handling/encrypt.py')
-rw-r--r-- | foreign/client_handling/encrypt.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/foreign/client_handling/encrypt.py b/foreign/client_handling/encrypt.py new file mode 100644 index 0000000..13deb96 --- /dev/null +++ b/foreign/client_handling/encrypt.py @@ -0,0 +1,20 @@ +from foreign.global_state import state + + +def encrypt(filename, decrypt): + if decrypt: + with open(filename, 'rb') as rf: + filedata = state['settings']['encryption'].do_decrypt(rf.read()) + + with open(filename, 'wb') as wf: + wf.write(filedata) + + return {'message': f'{filename} successfully decrypted', 'text_mode': 'success'} + else: + with open(filename, 'rb') as rf: + filedata = state['settings']['encryption'].do_encrypt(rf.read()) + + with open(filename, 'wb') as wf: + wf.write(filedata) + + return {'message': f'{filename} successfully encrypted', 'text_mode': 'success'}
\ No newline at end of file |