30 lines
1.1 KiB
Python
30 lines
1.1 KiB
Python
from pydantic import BaseModel
|
|
|
|
from src.models import EncipheredNKode
|
|
from src.customer_interface import CustomerInterface
|
|
from src.user_cipher_keys import UserCipherKeys
|
|
from src.user_interface import UserInterface
|
|
from src.utils import xor_lists
|
|
|
|
|
|
class User(BaseModel):
|
|
username: str
|
|
enciphered_passcode: EncipheredNKode
|
|
user_keys: UserCipherKeys
|
|
user_interface: UserInterface
|
|
renew: bool = False
|
|
|
|
def renew_keys(self, sets_xor: list[int], attrs_xor: list[int]):
|
|
self.renew = True
|
|
self.user_keys.set_key = xor_lists(self.user_keys.set_key, sets_xor)
|
|
self.user_keys.alpha_key = xor_lists(self.user_keys.alpha_key, attrs_xor)
|
|
|
|
def refresh_passcode(self, passcode_attr_idx: list[int], customer_interface: CustomerInterface):
|
|
self.user_keys = UserCipherKeys.new(
|
|
customer_interface.keypad_size,
|
|
customer_interface.set_vals,
|
|
self.user_keys.max_nkode_len
|
|
)
|
|
self.enciphered_passcode = self.user_keys.encipher_nkode(passcode_attr_idx, customer_interface)
|
|
self.renew = False
|