|
|
|
@@ -7,27 +7,24 @@ use anyhow::Result;
|
|
|
|
use nkode_rs::nkode_core::nkode_cipher::NKodeCipher;
|
|
|
|
use nkode_rs::nkode_core::nkode_cipher::NKodeCipher;
|
|
|
|
use nkode_rs::from_bytes::FromBytes;
|
|
|
|
use nkode_rs::from_bytes::FromBytes;
|
|
|
|
use nkode_rs::nkode_core::chacha20prng::Nonce;
|
|
|
|
use nkode_rs::nkode_core::chacha20prng::Nonce;
|
|
|
|
use crate::repository::client_app::repos::ClientRepo;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub struct Login;
|
|
|
|
pub struct Login;
|
|
|
|
pub struct Register;
|
|
|
|
pub struct Register;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub struct ClientAppKey<State, S: ServerAPI, R: ClientRepo> {
|
|
|
|
pub struct ClientAppKey<State, S: ServerAPI> {
|
|
|
|
api: S,
|
|
|
|
api: S,
|
|
|
|
repo: R,
|
|
|
|
|
|
|
|
email: Email,
|
|
|
|
email: Email,
|
|
|
|
user_secret_key: UserSecretKey,
|
|
|
|
user_secret_key: UserSecretKey,
|
|
|
|
_state: PhantomData<State>
|
|
|
|
_state: PhantomData<State>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl <S: ServerAPI, R: ClientRepo> ClientAppKey<Register,S, R> {
|
|
|
|
impl <S: ServerAPI> ClientAppKey<Register,S> {
|
|
|
|
pub async fn register(self) -> Result<ClientAppKey<Login, S, R>, String> {
|
|
|
|
pub async fn register(self) -> Result<ClientAppKey<Login, S>, String> {
|
|
|
|
// self.repo.set_secret_key(&self.email, &self.user_secret_key).await?;
|
|
|
|
// self.repo.set_secret_key(&self.email, &self.user_secret_key).await?;
|
|
|
|
self.api.register_key(&self.email, &self.user_secret_key).await?;
|
|
|
|
self.api.register_key(&self.email, &self.user_secret_key).await?;
|
|
|
|
Ok(ClientAppKey {
|
|
|
|
Ok(ClientAppKey {
|
|
|
|
api: self.api,
|
|
|
|
api: self.api,
|
|
|
|
repo: self.repo,
|
|
|
|
|
|
|
|
email: self.email,
|
|
|
|
email: self.email,
|
|
|
|
user_secret_key: self.user_secret_key,
|
|
|
|
user_secret_key: self.user_secret_key,
|
|
|
|
_state: PhantomData::<Login>,
|
|
|
|
_state: PhantomData::<Login>,
|
|
|
|
@@ -35,11 +32,10 @@ impl <S: ServerAPI, R: ClientRepo> ClientAppKey<Register,S, R> {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl <S: ServerAPI, R: ClientRepo> ClientAppKey<Login,S, R> {
|
|
|
|
impl <S: ServerAPI> ClientAppKey<Login,S> {
|
|
|
|
pub async fn login(self) -> Result<ClientAppKeyLoggedIn<S,R>,String> {
|
|
|
|
pub async fn login(self) -> Result<ClientAppKeyLoggedIn<S>,String> {
|
|
|
|
let key_login = self.api.login_key(&self.email, &self.user_secret_key).await?;
|
|
|
|
let key_login = self.api.login_key(&self.email, &self.user_secret_key).await?;
|
|
|
|
Ok(ClientAppKeyLoggedIn{
|
|
|
|
Ok(ClientAppKeyLoggedIn{
|
|
|
|
repo: self.repo,
|
|
|
|
|
|
|
|
api: self.api,
|
|
|
|
api: self.api,
|
|
|
|
email: self.email,
|
|
|
|
email: self.email,
|
|
|
|
user_secret_key: self.user_secret_key,
|
|
|
|
user_secret_key: self.user_secret_key,
|
|
|
|
@@ -48,15 +44,14 @@ impl <S: ServerAPI, R: ClientRepo> ClientAppKey<Login,S, R> {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub struct ClientAppKeyLoggedIn<S: ServerAPI, R: ClientRepo> {
|
|
|
|
pub struct ClientAppKeyLoggedIn<S: ServerAPI> {
|
|
|
|
repo: R,
|
|
|
|
|
|
|
|
api: S,
|
|
|
|
api: S,
|
|
|
|
email: Email,
|
|
|
|
email: Email,
|
|
|
|
user_secret_key: UserSecretKey,
|
|
|
|
user_secret_key: UserSecretKey,
|
|
|
|
key_login: KeyLoginSession,
|
|
|
|
key_login: KeyLoginSession,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl <S: ServerAPI, R: ClientRepo> ClientAppKeyLoggedIn<S, R> {
|
|
|
|
impl <S: ServerAPI> ClientAppKeyLoggedIn<S> {
|
|
|
|
pub async fn register_code(self) -> Result<ClientAppCodeRegister<S>, String> {
|
|
|
|
pub async fn register_code(self) -> Result<ClientAppCodeRegister<S>, String> {
|
|
|
|
let icon_nonce = Nonce::new();
|
|
|
|
let icon_nonce = Nonce::new();
|
|
|
|
let icons = self.get_icons(&icon_nonce).await?;
|
|
|
|
let icons = self.get_icons(&icon_nonce).await?;
|
|
|
|
|