202508311827
parent
c7dd937e3c
commit
ff0a4219bc
|
@ -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))
|
|
@ -2,3 +2,6 @@
|
||||||
|
|
||||||
class InitialisationError(Exception):
|
class InitialisationError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
class UserDoesNotExistError(Exception):
|
||||||
|
pass
|
||||||
|
|
Loading…
Reference in New Issue