fix bugs
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
from dataclasses import dataclass
|
||||
from uuid import UUID
|
||||
import numpy as np
|
||||
from uuid import UUID, uuid4
|
||||
from src.customer_cipher import CustomerCipher
|
||||
from src.models import NKodePolicy
|
||||
from src.user import User
|
||||
@@ -12,7 +11,18 @@ class Customer:
|
||||
cipher: CustomerCipher
|
||||
users: dict[str, User]
|
||||
|
||||
# TODO: validate policy and keypad_list size don't conflict
|
||||
@classmethod
|
||||
def create(cls, nkode_policy: NKodePolicy, cipher: CustomerCipher) -> 'Customer':
|
||||
if nkode_policy.distinct_sets > cipher.keypad_size.numb_of_keys:
|
||||
raise ValueError("Distinct sets cannot be greater than the number of keys")
|
||||
if nkode_policy.distinct_properties > cipher.keypad_size.total_props:
|
||||
raise ValueError("Distinct properties cannot be greater than the total number of properties")
|
||||
return Customer(
|
||||
customer_id=uuid4(),
|
||||
nkode_policy=nkode_policy,
|
||||
cipher=cipher,
|
||||
users={}
|
||||
)
|
||||
|
||||
def add_new_user(self, user: User):
|
||||
if user.username in self.users:
|
||||
@@ -30,17 +40,13 @@ class Customer:
|
||||
passcode_set_vals = user.cipher.decipher_mask(
|
||||
user.enciphered_passcode.mask, self.cipher.set_key, passcode_len)
|
||||
set_vals_idx = [self.cipher.get_set_index(set_val) for set_val in passcode_set_vals]
|
||||
presumed_property_idxs = []
|
||||
for idx in range(passcode_len):
|
||||
key_numb = selected_keys[idx]
|
||||
set_idx = set_vals_idx[idx]
|
||||
selected_prop_idx = user.user_keypad.get_prop_idx_by_keynumb_setidx(key_numb, set_idx)
|
||||
presumed_property_idxs.append(selected_prop_idx)
|
||||
presumed_property_idxs = user.user_keypad.get_prop_idxs_by_keynumb_setidx(selected_keys, set_vals_idx)
|
||||
if not user.cipher.compare_nkode(presumed_property_idxs, self.cipher,user.enciphered_passcode.code):
|
||||
return False
|
||||
if user.renew:
|
||||
user.refresh_passcode(presumed_property_idxs, self.cipher)
|
||||
user.user_keypad.split_shuffle()
|
||||
#self.users[username] = user
|
||||
return True
|
||||
|
||||
def renew_keys(self) -> bool:
|
||||
|
||||
Reference in New Issue
Block a user