202508311827

main
Rebel Zhang 2025-08-31 18:27:37 +08:00
parent c7dd937e3c
commit ff0a4219bc
2 changed files with 23 additions and 0 deletions

View File

@ -0,0 +1,20 @@
#!/usr/bin/python3
import ressenger_cryptography, ressenger_exceptions
import pickle, pathlib
def load_user(password, username='default'):
user_path=pathlib.Path(f'~/.ressenger/{username}').expanduser()
if not user_path.exists():
raise ressenger_exceptions.UserDoesNotExistError(f'File ~/.ressenger/{username} does not exist.')
else:
with open(user_path, 'rb') as file:
bt=file.read()
return pickle.loads(ressenger_cryptography.decrypt_bytes(bt, password))
def dump_user(password, user, username='default'):
user_path=pathlib.Path(f'~/.ressenger/{username}').expanduser()
if not user_path.exists():
raise ressenger_exceptions.UserDoesNotExistError(f'File ~/.ressenger/{username} does not exist.')
else:
with open(user_path, 'wb') as file:
file.write(ressenger_cryptography.encrypt_bytes(pickle.dumps(user, protocol=pickle.HIGHEST_PROTOCOL), password))

View File

@ -2,3 +2,6 @@
class InitialisationError(Exception):
pass
class UserDoesNotExistError(Exception):
pass