#!/usr/bin/python3 import ressenger_cryptography, ressenger_exceptions import pickle, pathlib class Contact(): def __init__(self, nickname, b32address, pub_enc, pub_sig): 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))