summaryrefslogtreecommitdiff
path: root/foreign/client_handling/encrypt.py
blob: 13deb969301264ba8a23e224ff7c6f20c99d46ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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'}