diff --git a/src/login/mod.rs b/src/login/mod.rs index 5bd976e..e87a17d 100644 --- a/src/login/mod.rs +++ b/src/login/mod.rs @@ -24,7 +24,7 @@ use crate::storage::*; pub trait LoginProvider { /// The login method takes an account's password as an input to decypher /// decryption keys and obtain full access to the user's account. - async fn login(&self, username: &str, password: &str) -> Result; + async fn login(&self, username: &str, password: &str) -> Result; /// The public_login method takes an account's email address and returns /// public credentials for adding mails to the user's inbox. async fn public_login(&self, email: &str) -> Result; @@ -34,26 +34,12 @@ pub trait LoginProvider { /// in many places in the code pub type ArcLoginProvider = Arc; -pub enum AnyCredentials { - InMemory(Credentials), - Garage(Credentials), -} -impl AnyCredentials where X: Sto -{ - fn to_gen(&self) -> Credentials { - match self { - Self::InMemory(u) => u, - Self::Garage(u) => u, - } - } -} - /// The struct Credentials represent all of the necessary information to interact /// with a user account's data after they are logged in. #[derive(Clone, Debug)] -pub struct Credentials { +pub struct Credentials { /// The storage credentials are used to authenticate access to the underlying storage (S3, K2V) - pub storage: T::Builder, + pub storage: AnyEngine, /// The cryptographic keys are used to encrypt and decrypt data stored in S3 and K2V pub keys: CryptoKeys, } diff --git a/src/mail/user.rs b/src/mail/user.rs index 9d94563..360786d 100644 --- a/src/mail/user.rs +++ b/src/mail/user.rs @@ -32,9 +32,9 @@ const MAILBOX_LIST_SK: &str = "list"; use crate::storage::*; -pub struct User { +pub struct User { pub username: String, - pub creds: Credentials, + pub creds: Credentials, pub k2v: K2vClient, pub mailboxes: std::sync::Mutex>>, diff --git a/src/storage/mod.rs b/src/storage/mod.rs index 2e4f757..c0835e6 100644 --- a/src/storage/mod.rs +++ b/src/storage/mod.rs @@ -29,12 +29,30 @@ pub enum Error { } pub trait Sto: Sized { - type Builder: RowStore; + type Builder: RowBuilder; type Store: RowStore; type Ref: RowRef; type Value: RowValue; } +pub struct Engine { + bucket: String, + row: T::Builder, +} + +pub enum AnyEngine { + InMemory(Engine), + Garage(Engine), +} +impl AnyEngine { + fn engine(&self) -> &Engine { + match self { + Self::InMemory(x) => x, + Self::Garage(x) => x, + } + } +} + // ------ Row Builder pub trait RowBuilder {