From 2f3dc5b62329d35e356e9cb5b055b28f145259b9 Mon Sep 17 00:00:00 2001 From: Donovan Date: Sun, 14 Dec 2025 21:04:02 -0600 Subject: [PATCH] implement protocol scaffold --- Cargo.lock | 1 + Cargo.toml | 1 + src/app/client.rs | 127 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 129 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 18c253a..abc2ba3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -412,6 +412,7 @@ dependencies = [ "sha2", "tokio", "uuid", + "zeroize", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 7c59ecb..cb8c222 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,5 +11,6 @@ async-trait = "0.1.89" uuid = { version = "1.19.0", features = ["v4"] } tokio = { version = "1.48.0", features = ["macros", "rt-multi-thread", "sync"] } nkode-rs = { path = "nkode-rs" } +zeroize = "1.8.2" diff --git a/src/app/client.rs b/src/app/client.rs index e69de29..b53dd6f 100644 --- a/src/app/client.rs +++ b/src/app/client.rs @@ -0,0 +1,127 @@ +use uuid::Uuid; +use zeroize::Zeroizing; + + +struct LoginSession { + identity: Vec, + session_id: Uuid, + session_key: Zeroizing>, +} + +struct KeyLoginSession(LoginSession); +struct CodeLoginSession(LoginSession); + +struct IconID(u128); + +struct Icon { + id: IconID, + data: Vec, +} + +struct CodeLoginData { + mask: Vec, + icons: Vec, + nonce: Vec, + keypad_indices: Vec +} + +trait ServerAPI { + async fn register_key(&self, identity: &[u8], secret_key: &[u8]) -> Result<(), String>; + async fn register_code(&self, identity: &[u8], passcode: &[u64]) -> Result<(), String>; + async fn login_key(&self, identity: &[u8], secret_key: &[u8]) -> Result; + async fn login_code(&self, identity: &[u8], passcode: &[u64]) -> Result; + async fn get_new_icons(&self, key_login_session: &KeyLoginSession) -> Result, String>; + async fn set_login_data(&self, key_login_session: &KeyLoginSession, data: &CodeLoginData) -> Result<(), String>; + async fn get_login_data(&self, key_login_session: &KeyLoginSession) -> Result; + async fn is_code_registered(&self, key_login_session: &KeyLoginSession) -> Result; +} + +pub struct RegisterKey; + +impl RegisterKey { + pub async fn register(api: S,identity: &[u8], secret_key: &[u8]) -> Result, String> { + todo!() + } +} + +pub struct KeyLogin { + api: S, + identity: Vec, + secret_key: Zeroizing> +} + +impl KeyLogin { + pub async fn login_register_code(self) -> RegisterCode { + todo!() + } + + pub async fn login_with_data(self, data: CodeLoginData) -> CodeLogin { + todo!() + } + + pub async fn login_without_data(self) -> CodeLogin { + todo!() + } +} + +pub struct RegisterCode { + api: S, + secret_key: Vec, + key_login_session: KeyLoginSession, +} + +impl RegisterCode { + pub async fn get_new_icons(&self) -> Result, String> { + todo!() + } + + pub async fn register(self, identity: &[u8], passcode: &[u64]) -> Result { + todo!() + } +} + +pub struct CodeLogin { + api: S, +} + +impl CodeLogin { + pub async fn login(self, identity: &[u8], passcode: &[u64]) -> Result { + todo!() + } +} + +trait ClientRepo { + async fn get_secret_key(&self) -> Result, String>; + async fn set_secret_key(&mut self, secret_key: &[u8]) -> Result<(),String>; + async fn get_login_data(&self) -> Result; + async fn set_login_data(&mut self, data: CodeLoginData) -> Result<(), String>; + async fn set_identity(&mut self, identity: &[u8]) -> Result<(), String>; + async fn get_identity(&self) -> Result<&[u8], String>; +} + +pub struct ClientApp { + repo: R, + api: S +} + +impl ClientApp { + pub fn new_secret() -> Vec { + todo!() + } + + pub async fn register_secret(&mut self, identity: &[u8], secret_key: &[u8]) -> Result<(), String> { + todo!() + } + + pub async fn get_new_icons(&self) -> Result, String> { + todo!() + } + + pub async fn select_icons(&mut self, selected_icons: Vec) -> Result<(), String> { + todo!() + } + + pub async fn set_secret(&mut self, secret_key: &[u8]) -> Result<(), String> { + todo!() + } +}