refactor auth_repo to server_app

This commit is contained in:
2025-12-17 12:29:17 -06:00
parent 467f4feadd
commit 3029a41386
20 changed files with 450 additions and 375 deletions

View File

@@ -4,15 +4,23 @@ use serde::{Deserialize, Serialize};
use getset::Getters;
use nkode_rs::from_bytes::FromBytes;
use nkode_rs::nkode_core::policy::NKodePolicy;
use uuid::Uuid;
use crate::shared::models::email::Email;
use crate::shared::models::opaque::{OpaqueSessionKey, UserSecretKey};
pub struct LoginSession {
#[derive(Debug, Clone)]
pub struct LoggedInSession {
pub(crate) session_id: Uuid,
pub(crate) email: Email,
pub(crate) session_key: OpaqueSessionKey,
}
pub struct KeyLoginSession(pub(crate) LoginSession);
pub struct CodeLoginSession(pub(crate) LoginSession);
#[derive(Debug, Clone)]
pub struct KeyLoggedInSession(pub(crate) LoggedInSession);
#[derive(Debug, Clone)]
pub struct CodeLoggedInSession(pub(crate) LoggedInSession);
pub const ICON_ID_SIZE: usize = 32;
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
@@ -53,16 +61,16 @@ pub struct CodeLoginData {
#[async_trait]
pub trait OpaqueAPI {
async fn register_key(&self, email: &Email, secret_key: &UserSecretKey) -> Result<(), String>;
async fn register_code(&self, email: &Email, passcode: &[u64], key_login_session: &KeyLoginSession, data: &CodeLoginData) -> Result<(), String>;
async fn login_key(&self, email: &Email, secret_key: &UserSecretKey) -> Result<KeyLoginSession, String>;
async fn login_code(&self, email: &Email, passcode: &[u64]) -> Result<CodeLoginSession, String>;
async fn register_code(&self, email: &Email, passcode: &[u64], key_login_session: &KeyLoggedInSession, data: &CodeLoginData) -> Result<(), String>;
async fn login_key(&self, email: &Email, secret_key: &UserSecretKey) -> Result<KeyLoggedInSession, String>;
async fn login_code(&self, email: &Email, passcode: &[u64]) -> Result<CodeLoggedInSession, String>;
}
#[async_trait]
pub trait AuthAPI {
async fn get_new_icons(&self, key_login_session: &KeyLoginSession) -> Result<Vec<Icon>, 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>;
async fn get_new_icons(&self, key_login_session: &KeyLoggedInSession) -> Result<Vec<Icon>, String>;
async fn get_login_data(&self, key_login_session: &KeyLoggedInSession) -> Result<CodeLoginData, String>;
async fn is_code_registered(&self, key_login_session: &KeyLoggedInSession) -> Result<bool, String>;
async fn get_policy(&self) -> Result<NKodePolicy, String>;
}