mirror of
https://github.com/chatmail/core.git
synced 2026-04-17 21:46:35 +03:00
Start working on encryption_modus
This commit is contained in:
50
src/chat.rs
50
src/chat.rs
@@ -75,6 +75,29 @@ pub enum ProtectionStatus {
|
||||
Protected = 1,
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Debug,
|
||||
Display,
|
||||
Clone,
|
||||
Copy,
|
||||
PartialEq,
|
||||
Eq,
|
||||
FromPrimitive,
|
||||
ToPrimitive,
|
||||
FromSql,
|
||||
ToSql,
|
||||
IntoStaticStr,
|
||||
Serialize,
|
||||
Deserialize,
|
||||
)]
|
||||
#[repr(u32)]
|
||||
pub enum EncryptionModus {
|
||||
Opportunistic = 0,
|
||||
ForcePlaintext = 1,
|
||||
ForceEncrypted = 2,
|
||||
ForceVerified = 3,
|
||||
}
|
||||
|
||||
impl Default for ProtectionStatus {
|
||||
fn default() -> Self {
|
||||
ProtectionStatus::Unprotected
|
||||
@@ -898,6 +921,33 @@ impl ChatId {
|
||||
Ok(ret.trim().to_string())
|
||||
}
|
||||
|
||||
/// 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<()> {
|
||||
let encryption_modus: u32 = context
|
||||
.sql
|
||||
.query_get_value(
|
||||
"SELECT encryption_modus FROM chats WHERE id=?;",
|
||||
paramsv![self],
|
||||
)
|
||||
.await??;
|
||||
Ok(encryption_modus.unwrap_or_default())
|
||||
}
|
||||
|
||||
/// 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 get_encryption_modus(self, context: &Context) -> Result<EncryptionModus> {
|
||||
let encryption_modus: u32 = context
|
||||
.sql
|
||||
.query_get_value(
|
||||
"SELECT encryption_modus FROM chats WHERE id=?;",
|
||||
paramsv![self],
|
||||
)
|
||||
.await??;
|
||||
Ok(encryption_modus.into())
|
||||
}
|
||||
|
||||
|
||||
/// Bad evil escape hatch.
|
||||
///
|
||||
/// Avoid using this, eventually types should be cleaned up enough
|
||||
|
||||
@@ -38,7 +38,8 @@ CREATE TABLE chats (
|
||||
locations_last_sent INTEGER DEFAULT 0,
|
||||
created_timestamp INTEGER DEFAULT 0,
|
||||
muted_until INTEGER DEFAULT 0,
|
||||
ephemeral_timer INTEGER
|
||||
ephemeral_timer INTEGER,
|
||||
encryption_modus INTEGER DEFAULT 0
|
||||
);
|
||||
CREATE INDEX chats_index1 ON chats (grpid);
|
||||
CREATE INDEX chats_index2 ON chats (archived);
|
||||
|
||||
Reference in New Issue
Block a user