test in memory client app

This commit is contained in:
2025-12-20 09:55:47 -06:00
parent e1acc2eab1
commit 43932c9148
4 changed files with 9 additions and 14 deletions

View File

@@ -53,7 +53,6 @@ where
}
async fn register_code(&self, email: &Email, passcode: &[u64], key_login_session: &KeyLoggedInSession, register_code_data: RegisterCodeData) -> Result<(), String> {
println!("register passcode: {:?}", passcode.to_vec());
let auth_data = OpaqueAuthData::from_code(email.as_str(), passcode);
self.opaque_code_register.register(&auth_data).await.map_err(|e| format!("error: {}", e))?;
let signed_session = SignedSessionData::new(
@@ -71,7 +70,6 @@ where
}
async fn login_code(&self, email: &Email, passcode: &[u64], key_login_session: &KeyLoggedInSession, keypad: Keypad) -> Result<CodeLoggedInSession, String> {
println!("login passcode: {:?}", passcode.to_vec());
let auth_data = OpaqueAuthData::from_code(email.as_str(), passcode);
let signed_session = SignedSessionData::new(
key_login_session.0.session_id,

View File

@@ -82,7 +82,7 @@ impl UserStateKeyLoggedIn {
let icons = self.get_icons(api, &login_data.icon_nonce).await?;
let policy = api.get_policy().await?;
let nkode_secret_key = self.user_secret_key.chacha20_secret_key();
let cipher = NKodeCipher::from_nonce(policy, &nkode_secret_key, &login_data.icon_nonce)?;
let cipher = NKodeCipher::from_nonce(policy, &nkode_secret_key, &login_data.cipher_nonce)?;
Ok(
UserStateCodeLogin {
email: self.email,
@@ -154,12 +154,12 @@ pub struct UserStateCodeLogin {
mask: Vec<u64>,
icons: Vec<Icon>,
keypad: Keypad,
cipher: NKodeCipher,
pub cipher: NKodeCipher,
key_login: KeyLoggedInSession,
}
impl UserStateCodeLogin {
pub fn sort_icons(&self) -> Vec<Icon> {
fn sort_icons(&self) -> Vec<Icon> {
nkode_rs::tensor::reorder(
&self.icons,
self.keypad.indices()
@@ -169,8 +169,7 @@ impl UserStateCodeLogin {
pub async fn login(&mut self, api: &dyn AuthAPI, selected_keys: &Vec<usize>) -> Result<CodeLoggedInSession, String> {
let passcode = self.cipher.decipher(selected_keys, self.keypad.indices(), &self.mask).map_err(|e| format!("invalid keys: {e}"))?;
self.keypad.login_shuffle();
api.login_code(&self.email, &passcode,&self.key_login ,self.keypad.clone()).await?;
todo!()
api.login_code(&self.email, &passcode,&self.key_login ,self.keypad.clone()).await
}
pub fn get_keypad(&self) -> DisplayKeypad {

View File

@@ -51,13 +51,11 @@ async fn in_memory_client_app() {
let user_secret_key = UserSecretKey::new();
let register_code = new_user.new_user(user_email, user_secret_key).await.unwrap();
let icons: Vec<Icon> = register_code.get_new_user_icons().await.unwrap();
let passcode_idx = ..4;
let icon_ids:Vec<IconID> = icons.iter().map(|el| el.id.clone()).collect();
let selected_icons = icon_ids[0..4].to_vec();
let code_login = register_code.new_user_register_code(selected_icons.clone()).await.unwrap();
let selected_icon_ids = icon_ids[passcode_idx].to_vec();
let code_login = register_code.new_user_register_code(selected_icon_ids.clone()).await.unwrap();
let display_keypad = code_login.get_keypad().unwrap();
let icon_idxs: Vec<usize> = selected_icons.iter().map(|x| {
display_keypad.sorted_icons.iter().position(|x1| {x1.id == *x}).unwrap()
}).collect();
let selected_keys = display_keypad.keypad.select_keys(&icon_idxs).unwrap();
let selected_keys = display_keypad.keypad.select_keys(&(0..passcode_idx.end).collect()).unwrap();
code_login.login(&selected_keys).await.unwrap();
}