Start working on encryption_modus

This commit is contained in:
jikstra
2022-11-17 22:32:16 +01:00
parent 25be8ccd05
commit cb03e93570
2 changed files with 52 additions and 1 deletions

View File

@@ -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

View File

@@ -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);