refactor files
This commit is contained in:
68
src/shared/models/app.rs
Normal file
68
src/shared/models/app.rs
Normal file
@@ -0,0 +1,68 @@
|
||||
use async_trait::async_trait;
|
||||
use nkode_rs::nkode_core::chacha20prng::Nonce; use nkode_rs::nkode_core::keypad::Keypad;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use getset::Getters;
|
||||
use nkode_rs::from_bytes::FromBytes;
|
||||
use nkode_rs::nkode_core::policy::NKodePolicy;
|
||||
use crate::shared::models::email::Email;
|
||||
use crate::shared::models::opaque::{OpaqueSessionKey, UserSecretKey};
|
||||
pub struct LoginSession {
|
||||
pub(crate) email: Email,
|
||||
pub(crate) session_key: OpaqueSessionKey,
|
||||
}
|
||||
|
||||
pub struct KeyLoginSession(pub(crate) LoginSession);
|
||||
pub struct CodeLoginSession(pub(crate) LoginSession);
|
||||
|
||||
pub const ICON_ID_SIZE: usize = 32;
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct IconID([u8; 32]);
|
||||
|
||||
impl FromBytes<ICON_ID_SIZE> for IconID {
|
||||
fn from_array(arr: [u8; ICON_ID_SIZE]) -> Self {
|
||||
Self(arr)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Getters)]
|
||||
pub struct Icon {
|
||||
#[get = "pub"]
|
||||
id: IconID,
|
||||
#[get = "pub"]
|
||||
data: Vec<u8>,
|
||||
}
|
||||
|
||||
impl Icon {
|
||||
pub fn update_id(&mut self, new_id: IconID) {
|
||||
self.id = new_id
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Getters, Serialize, Deserialize)]
|
||||
pub struct CodeLoginData {
|
||||
#[get = "pub"]
|
||||
pub(crate) mask: Vec<u64>,
|
||||
#[get = "pub"]
|
||||
pub(crate) cipher_nonce: Nonce,
|
||||
#[get = "pub"]
|
||||
pub(crate) icon_nonce: Nonce,
|
||||
#[get = "pub"]
|
||||
pub(crate) keypad: Keypad,
|
||||
}
|
||||
|
||||
#[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_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_policy(&self) -> Result<NKodePolicy, String>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user