aboutsummaryrefslogtreecommitdiff
path: root/src/login
diff options
context:
space:
mode:
authorQuentin Dufour <quentin@deuxfleurs.fr>2023-11-01 15:36:06 +0100
committerQuentin Dufour <quentin@deuxfleurs.fr>2023-11-01 15:36:06 +0100
commit3026b217774a51e01cca1ae584fba8c6398754cc (patch)
tree9279ae4eee0fcb13f3f66aadc96ca8e0f2452b2b /src/login
parent92fea414d9d113761b788e409a025ad9cff06071 (diff)
downloadaerogramme-3026b217774a51e01cca1ae584fba8c6398754cc.tar.gz
aerogramme-3026b217774a51e01cca1ae584fba8c6398754cc.zip
integration to login with an enum
Diffstat (limited to 'src/login')
-rw-r--r--src/login/mod.rs23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/login/mod.rs b/src/login/mod.rs
index 3fab90a..f403bcb 100644
--- a/src/login/mod.rs
+++ b/src/login/mod.rs
@@ -15,6 +15,9 @@ use rusoto_credential::{AwsCredentials, StaticProvider};
use rusoto_s3::S3Client;
use crate::cryptoblob::*;
+use crate::storage::*;
+use crate::storage::in_memory::MemTypes;
+use crate::storage::garage::GrgTypes;
/// The trait LoginProvider defines the interface for a login provider that allows
/// to retrieve storage and cryptographic credentials for access to a user account
@@ -23,12 +26,17 @@ use crate::cryptoblob::*;
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<Credentials>;
+ async fn login(&self, username: &str, password: &str) -> Result<AnyCredentials>;
/// 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<PublicCredentials>;
}
+pub enum AnyCredentials {
+ InMemory(Credentials<MemTypes>),
+ Garage(Credentials<GrgTypes>),
+}
+
/// ArcLoginProvider is simply an alias on a structure that is used
/// in many places in the code
pub type ArcLoginProvider = Arc<dyn LoginProvider + Send + Sync>;
@@ -36,9 +44,9 @@ pub type ArcLoginProvider = Arc<dyn LoginProvider + Send + Sync>;
/// 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<T: StorageEngine> {
/// The storage credentials are used to authenticate access to the underlying storage (S3, K2V)
- pub storage: StorageCredentials,
+ pub storage: T::Builder,
/// The cryptographic keys are used to encrypt and decrypt data stored in S3 and K2V
pub keys: CryptoKeys,
}
@@ -106,6 +114,7 @@ impl Region {
// ----
+/*
impl Credentials {
pub fn k2v_client(&self) -> Result<K2vClient> {
self.storage.k2v_client()
@@ -116,6 +125,14 @@ impl Credentials {
pub fn bucket(&self) -> &str {
self.storage.bucket.as_str()
}
+}*/
+impl<T: StorageEngine> From<AnyCredentials> for Credentials<T> {
+ fn from(ac: AnyCredentials) -> Self {
+ match ac {
+ AnyCredentials::InMemory(c) => c,
+ AnyCredentials::Garage(c) => c,
+ }
+ }
}
impl StorageCredentials {