mirror of
https://github.com/chatmail/core.git
synced 2026-04-27 02:16:29 +03:00
cargo fmt
This commit is contained in:
24
src/chat.rs
24
src/chat.rs
@@ -923,7 +923,11 @@ impl ChatId {
|
||||
|
||||
/// 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)
|
||||
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
|
||||
.sql
|
||||
.execute(
|
||||
@@ -946,12 +950,9 @@ impl ChatId {
|
||||
)
|
||||
.await?;
|
||||
|
||||
|
||||
|
||||
Ok(encryption_modus)
|
||||
}
|
||||
|
||||
|
||||
/// Bad evil escape hatch.
|
||||
///
|
||||
/// Avoid using this, eventually types should be cleaned up enough
|
||||
@@ -5712,18 +5713,25 @@ mod tests {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn test_encryption_modus() -> Result<()> {
|
||||
let t = TestContext::new_alice().await;
|
||||
let contact_fiona = Contact::create(&t, "", "fiona@example.net").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(())
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ use deltachat_derive::{FromSql, ToSql};
|
||||
use rusqlite::types::ValueRef;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::chat::EncryptionModus;
|
||||
use crate::chat::{self, Chat, ChatId};
|
||||
use crate::config::Config;
|
||||
use crate::constants::{
|
||||
@@ -31,7 +32,6 @@ use crate::tools::{
|
||||
create_smeared_timestamp, get_filebytes, get_filemeta, gm2local_offset, read_file, time,
|
||||
timestamp_to_str, truncate,
|
||||
};
|
||||
use crate::chat::EncryptionModus;
|
||||
|
||||
/// Message ID, including reserved IDs.
|
||||
///
|
||||
@@ -356,7 +356,7 @@ impl Message {
|
||||
location_id: row.get("location")?,
|
||||
chat_blocked: row
|
||||
.get::<_, Option<Blocked>>("blocked")?
|
||||
.unwrap_or_default()
|
||||
.unwrap_or_default(),
|
||||
};
|
||||
Ok(msg)
|
||||
},
|
||||
@@ -855,7 +855,11 @@ impl Message {
|
||||
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
|
||||
.sql
|
||||
.execute(
|
||||
@@ -867,7 +871,7 @@ impl Message {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn get_encryption_modus(&self, context: &Context) -> Result<Option<EncryptionModus>> {
|
||||
pub async fn get_encryption_modus(&self, context: &Context) -> Result<Option<EncryptionModus>> {
|
||||
let encryption_modus: Option<EncryptionModus> = context
|
||||
.sql
|
||||
.query_get_value(
|
||||
|
||||
@@ -9,6 +9,7 @@ use tokio::fs;
|
||||
|
||||
use crate::blob::BlobObject;
|
||||
use crate::chat::Chat;
|
||||
use crate::chat::EncryptionModus;
|
||||
use crate::config::Config;
|
||||
use crate::constants::{Chattype, DC_FROM_HANDSHAKE};
|
||||
use crate::contact::Contact;
|
||||
@@ -29,7 +30,6 @@ use crate::tools::{
|
||||
create_outgoing_rfc724_mid, create_smeared_timestamp, get_filebytes, remove_subject_prefix,
|
||||
time,
|
||||
};
|
||||
use crate::chat::EncryptionModus;
|
||||
|
||||
// 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).
|
||||
@@ -607,7 +607,7 @@ impl<'a> MimeFactory<'a> {
|
||||
let grpimage = self.grpimage();
|
||||
let encryption_modus = match self.msg.get_encryption_modus(context).await? {
|
||||
Some(encryption_modus) => encryption_modus,
|
||||
None => EncryptionModus::Opportunistic
|
||||
None => EncryptionModus::Opportunistic,
|
||||
};
|
||||
let force_plaintext = self.should_force_plaintext(&encryption_modus);
|
||||
let skip_autocrypt = self.should_skip_autocrypt();
|
||||
@@ -651,23 +651,31 @@ impl<'a> MimeFactory<'a> {
|
||||
encrypt_helper.should_encrypt(context, e2ee_guaranteed, &peerstates)?;
|
||||
let is_encrypted = should_encrypt && !force_plaintext;
|
||||
|
||||
|
||||
// Ensure we fulfill encryption_modus
|
||||
match encryption_modus {
|
||||
EncryptionModus::Opportunistic => {},
|
||||
EncryptionModus::Opportunistic => {}
|
||||
EncryptionModus::ForcePlaintext => {
|
||||
ensure!(!is_encrypted, "EncryptionModus is ForcePlaintext but message is encrypted");
|
||||
},
|
||||
ensure!(
|
||||
!is_encrypted,
|
||||
"EncryptionModus is ForcePlaintext but message is encrypted"
|
||||
);
|
||||
}
|
||||
EncryptionModus::ForceEncrypted => {
|
||||
ensure!(is_encrypted, "EncryptionModus is ForceEncrypted but message is unencrypted");
|
||||
},
|
||||
ensure!(
|
||||
is_encrypted,
|
||||
"EncryptionModus is ForceEncrypted but message is unencrypted"
|
||||
);
|
||||
}
|
||||
EncryptionModus::ForceVerified => {
|
||||
let chat_is_protected = if let Loaded::Message { chat } = &self.loaded {
|
||||
chat.is_protected()
|
||||
} else {
|
||||
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"
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user