diff --git a/src/core/dek.rs b/src/core/dek.rs index f8b6028..aca03cd 100644 --- a/src/core/dek.rs +++ b/src/core/dek.rs @@ -81,7 +81,7 @@ impl Dek { .unwrap(); match cursor_dek { - Some(mut data) => return Ok(data.decrypt(&server_kek)), + Some(data) => return Ok(data.decrypt(&server_kek)), None => { return Err(Error::KeyNotFound { message: "DEK not found".to_string(), @@ -103,7 +103,7 @@ impl Dek { .unwrap(); match cursor_dek { - Some(mut data) => return Ok(data.decrypt(&server_kek)), + Some(data) => return Ok(data.decrypt(&server_kek)), None => { return Err(Error::KeyNotFound { message: "DEK not found".to_string(), diff --git a/src/core/session.rs b/src/core/session.rs index e51be34..ef63772 100644 --- a/src/core/session.rs +++ b/src/core/session.rs @@ -31,7 +31,7 @@ impl Session { let db = mongo_client.database("test"); let collection_session: Collection = db.collection("sessions"); - let mut session = self.clone(); + let session = self.clone(); let encrypted_session = session.encrypt(key); match collection_session.insert_one(encrypted_session, None).await { diff --git a/src/core/user.rs b/src/core/user.rs index bc96e75..825dadd 100644 --- a/src/core/user.rs +++ b/src/core/user.rs @@ -98,7 +98,7 @@ impl User { ) .await { - Ok(Some(mut user)) => { + Ok(Some(user)) => { let decrypted_user = user.decrypt(&dek_data.dek); return Ok(decrypted_user); } @@ -132,7 +132,7 @@ impl User { ) .await { - Ok(Some(mut user)) => { + Ok(Some(user)) => { let decrypted_user = user.decrypt(&dek_data.dek); return Ok(decrypted_user); } @@ -150,7 +150,7 @@ impl User { let collection: Collection = db.collection("users"); let collection_dek: Collection = db.collection("deks"); - // let mut cursor = collection.find(None, None).await.unwrap(); + // let cursor = collection.find(None, None).await.unwrap(); let mut cursor_dek = collection_dek.find(None, None).await.unwrap(); let mut users = Vec::new(); @@ -159,7 +159,7 @@ impl User { // iterate over the users and decrypt the data while let Some(dek) = cursor_dek.next().await { let dek_data: Dek = match dek { - Ok(mut data) => data.decrypt(&kek), + Ok(data) => data.decrypt(&kek), Err(_) => { return Err(Error::ServerError { message: "Failed to get DEK".to_string(), @@ -181,7 +181,7 @@ impl User { .unwrap(); match cursor_user { - Some(mut user) => { + Some(user) => { let user_data = user.decrypt(&dek_data.dek); users.push(UserResponse { @@ -317,7 +317,7 @@ impl User { } }; // get user - let mut user = match collection + let user = match collection .find_one( doc! { "email": Encryption::encrypt_data(&email, &dek_data.dek) }, None, diff --git a/src/traits/decryption.rs b/src/traits/decryption.rs index 8525657..a460bba 100644 --- a/src/traits/decryption.rs +++ b/src/traits/decryption.rs @@ -4,14 +4,14 @@ use serde_json::Value; use crate::utils::encryption_utils::Encryption; pub trait Decrypt { - fn decrypt(&mut self, key: &str) -> Self; + fn decrypt(&self, key: &str) -> Self; } impl Decrypt for T where T: Serialize + DeserializeOwned, { - fn decrypt(&mut self, key: &str) -> Self { + fn decrypt(&self, key: &str) -> Self { // Serialize the object to JSON let json_str = serde_json::to_string(self).unwrap(); diff --git a/src/traits/encryption.rs b/src/traits/encryption.rs index f1f921c..1a5abff 100644 --- a/src/traits/encryption.rs +++ b/src/traits/encryption.rs @@ -4,14 +4,14 @@ use serde_json::Value; use crate::utils::encryption_utils::Encryption; pub trait Encrypt { - fn encrypt(&mut self, key: &str) -> Self; + fn encrypt(&self, key: &str) -> Self; } impl Encrypt for T where T: Serialize + DeserializeOwned, { - fn encrypt(&mut self, key: &str) -> Self { + fn encrypt(&self, key: &str) -> Self { // Serialize the object to JSON let json_str = serde_json::to_string(self).unwrap();