cargo fmt

This commit is contained in:
jikstra
2022-11-18 02:44:19 +01:00
parent d8844a0524
commit bc4eea0c28
3 changed files with 41 additions and 21 deletions

View File

@@ -923,7 +923,11 @@ impl ChatId {
/// This sets a protection modus for the chat and enforces that messages are only send if they /// This sets a protection modus for the chat and enforces that messages are only send if they
/// meet the encryption modus (ForcePlaintext, Opportunistic, ForceEncrypted, ForceVerified) /// meet the encryption modus (ForcePlaintext, Opportunistic, ForceEncrypted, ForceVerified)
pub async fn set_encryption_modus(self, context: &Context, modus: &EncryptionModus) -> Result<()> { pub async fn set_encryption_modus(
self,
context: &Context,
modus: &EncryptionModus,
) -> Result<()> {
context context
.sql .sql
.execute( .execute(
@@ -946,12 +950,9 @@ impl ChatId {
) )
.await?; .await?;
Ok(encryption_modus) Ok(encryption_modus)
} }
/// Bad evil escape hatch. /// Bad evil escape hatch.
/// ///
/// Avoid using this, eventually types should be cleaned up enough /// Avoid using this, eventually types should be cleaned up enough
@@ -5712,18 +5713,25 @@ mod tests {
Ok(()) Ok(())
} }
#[tokio::test(flavor = "multi_thread", worker_threads = 2)] #[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_encryption_modus() -> Result<()> { async fn test_encryption_modus() -> Result<()> {
let t = TestContext::new_alice().await; let t = TestContext::new_alice().await;
let contact_fiona = Contact::create(&t, "", "fiona@example.net").await?; let contact_fiona = Contact::create(&t, "", "fiona@example.net").await?;
let chat_id = create_group_chat(&t, ProtectionStatus::Unprotected, "Group").await?; let chat_id = create_group_chat(&t, ProtectionStatus::Unprotected, "Group").await?;
assert_eq!(chat_id.get_encryption_modus(&t).await?, Some(EncryptionModus::Opportunistic)); assert_eq!(
chat_id.get_encryption_modus(&t).await?,
Some(EncryptionModus::Opportunistic)
);
chat_id.set_encryption_modus(&t, &EncryptionModus::ForceEncrypted).await?; chat_id
.set_encryption_modus(&t, &EncryptionModus::ForceEncrypted)
.await?;
assert_eq!(chat_id.get_encryption_modus(&t).await?, Some(EncryptionModus::ForceEncrypted)); assert_eq!(
chat_id.get_encryption_modus(&t).await?,
Some(EncryptionModus::ForceEncrypted)
);
Ok(()) Ok(())
} }

View File

@@ -8,6 +8,7 @@ use deltachat_derive::{FromSql, ToSql};
use rusqlite::types::ValueRef; use rusqlite::types::ValueRef;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::chat::EncryptionModus;
use crate::chat::{self, Chat, ChatId}; use crate::chat::{self, Chat, ChatId};
use crate::config::Config; use crate::config::Config;
use crate::constants::{ use crate::constants::{
@@ -31,7 +32,6 @@ use crate::tools::{
create_smeared_timestamp, get_filebytes, get_filemeta, gm2local_offset, read_file, time, create_smeared_timestamp, get_filebytes, get_filemeta, gm2local_offset, read_file, time,
timestamp_to_str, truncate, timestamp_to_str, truncate,
}; };
use crate::chat::EncryptionModus;
/// Message ID, including reserved IDs. /// Message ID, including reserved IDs.
/// ///
@@ -356,7 +356,7 @@ impl Message {
location_id: row.get("location")?, location_id: row.get("location")?,
chat_blocked: row chat_blocked: row
.get::<_, Option<Blocked>>("blocked")? .get::<_, Option<Blocked>>("blocked")?
.unwrap_or_default() .unwrap_or_default(),
}; };
Ok(msg) Ok(msg)
}, },
@@ -855,7 +855,11 @@ impl Message {
self.param.set_int(Param::ForcePlaintext, 1); self.param.set_int(Param::ForcePlaintext, 1);
} }
async fn set_encryption_modus(&mut self, context: &Context, encryption_modus: &EncryptionModus) -> Result<()> { async fn set_encryption_modus(
&mut self,
context: &Context,
encryption_modus: &EncryptionModus,
) -> Result<()> {
context context
.sql .sql
.execute( .execute(

View File

@@ -9,6 +9,7 @@ use tokio::fs;
use crate::blob::BlobObject; use crate::blob::BlobObject;
use crate::chat::Chat; use crate::chat::Chat;
use crate::chat::EncryptionModus;
use crate::config::Config; use crate::config::Config;
use crate::constants::{Chattype, DC_FROM_HANDSHAKE}; use crate::constants::{Chattype, DC_FROM_HANDSHAKE};
use crate::contact::Contact; use crate::contact::Contact;
@@ -29,7 +30,6 @@ use crate::tools::{
create_outgoing_rfc724_mid, create_smeared_timestamp, get_filebytes, remove_subject_prefix, create_outgoing_rfc724_mid, create_smeared_timestamp, get_filebytes, remove_subject_prefix,
time, time,
}; };
use crate::chat::EncryptionModus;
// attachments of 25 mb brutto should work on the majority of providers // attachments of 25 mb brutto should work on the majority of providers
// (brutto examples: web.de=50, 1&1=40, t-online.de=32, gmail=25, posteo=50, yahoo=25, all-inkl=100). // (brutto examples: web.de=50, 1&1=40, t-online.de=32, gmail=25, posteo=50, yahoo=25, all-inkl=100).
@@ -607,7 +607,7 @@ impl<'a> MimeFactory<'a> {
let grpimage = self.grpimage(); let grpimage = self.grpimage();
let encryption_modus = match self.msg.get_encryption_modus(context).await? { let encryption_modus = match self.msg.get_encryption_modus(context).await? {
Some(encryption_modus) => encryption_modus, Some(encryption_modus) => encryption_modus,
None => EncryptionModus::Opportunistic None => EncryptionModus::Opportunistic,
}; };
let force_plaintext = self.should_force_plaintext(&encryption_modus); let force_plaintext = self.should_force_plaintext(&encryption_modus);
let skip_autocrypt = self.should_skip_autocrypt(); let skip_autocrypt = self.should_skip_autocrypt();
@@ -651,23 +651,31 @@ impl<'a> MimeFactory<'a> {
encrypt_helper.should_encrypt(context, e2ee_guaranteed, &peerstates)?; encrypt_helper.should_encrypt(context, e2ee_guaranteed, &peerstates)?;
let is_encrypted = should_encrypt && !force_plaintext; let is_encrypted = should_encrypt && !force_plaintext;
// Ensure we fulfill encryption_modus // Ensure we fulfill encryption_modus
match encryption_modus { match encryption_modus {
EncryptionModus::Opportunistic => {}, EncryptionModus::Opportunistic => {}
EncryptionModus::ForcePlaintext => { EncryptionModus::ForcePlaintext => {
ensure!(!is_encrypted, "EncryptionModus is ForcePlaintext but message is encrypted"); ensure!(
}, !is_encrypted,
"EncryptionModus is ForcePlaintext but message is encrypted"
);
}
EncryptionModus::ForceEncrypted => { EncryptionModus::ForceEncrypted => {
ensure!(is_encrypted, "EncryptionModus is ForceEncrypted but message is unencrypted"); ensure!(
}, is_encrypted,
"EncryptionModus is ForceEncrypted but message is unencrypted"
);
}
EncryptionModus::ForceVerified => { EncryptionModus::ForceVerified => {
let chat_is_protected = if let Loaded::Message { chat } = &self.loaded { let chat_is_protected = if let Loaded::Message { chat } = &self.loaded {
chat.is_protected() chat.is_protected()
} else { } else {
false false
}; };
ensure!(is_encrypted && chat_is_protected, "EncryptionModus is ForceVerified but chat is not protected"); ensure!(
is_encrypted && chat_is_protected,
"EncryptionModus is ForceVerified but chat is not protected"
);
} }
}; };