32 lines
1.0 KiB
Python
32 lines
1.0 KiB
Python
from dataclasses import dataclass, field
|
|
|
|
import numpy as np
|
|
|
|
from src.models import EncipheredNKode
|
|
from src.customer_cipher import CustomerCipher
|
|
from src.user_cipher import UserCipher
|
|
from src.user_keypad import UserKeypad
|
|
|
|
|
|
@dataclass
|
|
class User:
|
|
username: str
|
|
enciphered_passcode: EncipheredNKode
|
|
cipher: UserCipher
|
|
user_keypad: UserKeypad
|
|
renew: bool = field(default=False)
|
|
|
|
def renew_keys(self, set_xor: np.ndarray, prop_xor: np.ndarray):
|
|
self.renew = True
|
|
self.cipher.combined_set_key = self.cipher.combined_set_key ^ set_xor
|
|
self.cipher.prop_key = self.cipher.prop_key ^ prop_xor
|
|
|
|
def refresh_passcode(self, passcode_prop_idxs: list[int], customer_cipher: CustomerCipher):
|
|
self.cipher = UserCipher.create(
|
|
customer_cipher.keypad_size,
|
|
customer_cipher.position_key,
|
|
self.cipher.max_nkode_len
|
|
)
|
|
self.enciphered_passcode = self.cipher.encipher_nkode(passcode_prop_idxs, customer_cipher)
|
|
self.renew = False
|