implement protocol scaffold

This commit is contained in:
2025-12-14 21:04:02 -06:00
parent 71552911b1
commit 2f3dc5b623
3 changed files with 129 additions and 0 deletions

1
Cargo.lock generated
View File

@@ -412,6 +412,7 @@ dependencies = [
"sha2", "sha2",
"tokio", "tokio",
"uuid", "uuid",
"zeroize",
] ]
[[package]] [[package]]

View File

@@ -11,5 +11,6 @@ async-trait = "0.1.89"
uuid = { version = "1.19.0", features = ["v4"] } uuid = { version = "1.19.0", features = ["v4"] }
tokio = { version = "1.48.0", features = ["macros", "rt-multi-thread", "sync"] } tokio = { version = "1.48.0", features = ["macros", "rt-multi-thread", "sync"] }
nkode-rs = { path = "nkode-rs" } nkode-rs = { path = "nkode-rs" }
zeroize = "1.8.2"

View File

@@ -0,0 +1,127 @@
use uuid::Uuid;
use zeroize::Zeroizing;
struct LoginSession {
identity: Vec<u8>,
session_id: Uuid,
session_key: Zeroizing<Vec<u8>>,
}
struct KeyLoginSession(LoginSession);
struct CodeLoginSession(LoginSession);
struct IconID(u128);
struct Icon {
id: IconID,
data: Vec<u8>,
}
struct CodeLoginData {
mask: Vec<u64>,
icons: Vec<Icon>,
nonce: Vec<u8>,
keypad_indices: Vec<u8>
}
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<KeyLoginSession, String>;
async fn login_code(&self, identity: &[u8], passcode: &[u64]) -> Result<CodeLoginSession, String>;
async fn get_new_icons(&self, key_login_session: &KeyLoginSession) -> Result<Vec<Icon>, 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<CodeLoginData, String>;
async fn is_code_registered(&self, key_login_session: &KeyLoginSession) -> Result<bool, String>;
}
pub struct RegisterKey;
impl RegisterKey {
pub async fn register<S: ServerAPI>(api: S,identity: &[u8], secret_key: &[u8]) -> Result<KeyLogin<S>, String> {
todo!()
}
}
pub struct KeyLogin<S: ServerAPI> {
api: S,
identity: Vec<u8>,
secret_key: Zeroizing<Vec<u8>>
}
impl <S: ServerAPI>KeyLogin<S> {
pub async fn login_register_code(self) -> RegisterCode<S> {
todo!()
}
pub async fn login_with_data(self, data: CodeLoginData) -> CodeLogin<S> {
todo!()
}
pub async fn login_without_data(self) -> CodeLogin<S> {
todo!()
}
}
pub struct RegisterCode<S: ServerAPI> {
api: S,
secret_key: Vec<u8>,
key_login_session: KeyLoginSession,
}
impl <S: ServerAPI>RegisterCode<S> {
pub async fn get_new_icons(&self) -> Result<Vec<Icon>, String> {
todo!()
}
pub async fn register(self, identity: &[u8], passcode: &[u64]) -> Result<CodeLoginData, String> {
todo!()
}
}
pub struct CodeLogin<S: ServerAPI> {
api: S,
}
impl <S: ServerAPI>CodeLogin<S> {
pub async fn login(self, identity: &[u8], passcode: &[u64]) -> Result<CodeLoginSession, String> {
todo!()
}
}
trait ClientRepo {
async fn get_secret_key(&self) -> Result<Vec<u8>, String>;
async fn set_secret_key(&mut self, secret_key: &[u8]) -> Result<(),String>;
async fn get_login_data(&self) -> Result<CodeLoginData, String>;
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<S: ServerAPI, R: ClientRepo> {
repo: R,
api: S
}
impl <S: ServerAPI, R: ClientRepo> ClientApp<S, R> {
pub fn new_secret() -> Vec<u8> {
todo!()
}
pub async fn register_secret(&mut self, identity: &[u8], secret_key: &[u8]) -> Result<(), String> {
todo!()
}
pub async fn get_new_icons(&self) -> Result<Vec<Icon>, String> {
todo!()
}
pub async fn select_icons(&mut self, selected_icons: Vec<IconID>) -> Result<(), String> {
todo!()
}
pub async fn set_secret(&mut self, secret_key: &[u8]) -> Result<(), String> {
todo!()
}
}