diff --git a/CHANGELOG.md b/CHANGELOG.md index f71f3f010..3f937129f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ - sql: enable `auto_vacuum=INCREMENTAL` #2931 - Synchronize Seen status across devices #2942 - Add API to set the database password #2956 +- Add information about whether the database is encrypted or not to `dc_get_info()` #3000 - Add Webxdc #2826 #2971 #2975 #2977 #2979 #2993 #2998 ### Changed diff --git a/src/context.rs b/src/context.rs index 7d12f681a..3ed0278fd 100644 --- a/src/context.rs +++ b/src/context.rs @@ -383,6 +383,13 @@ impl Context { res.insert("number_of_contacts", contacts.to_string()); res.insert("database_dir", self.get_dbfile().display().to_string()); res.insert("database_version", dbversion.to_string()); + res.insert( + "database_encrypted", + self.sql + .is_encrypted() + .await + .map_or_else(|| "closed".to_string(), |b| b.to_string()), + ); res.insert("journal_mode", journal_mode); res.insert("blobdir", self.get_blobdir().display().to_string()); res.insert("display_name", displayname.unwrap_or_else(|| unset.into())); diff --git a/src/sql.rs b/src/sql.rs index 895bfb29d..d3d796387 100644 --- a/src/sql.rs +++ b/src/sql.rs @@ -43,6 +43,10 @@ pub struct Sql { pub(crate) dbfile: PathBuf, pool: RwLock>>, + + /// None if the database is not open, true if it is open with passphrase and false if it is + /// open without a passphrase. + is_encrypted: RwLock>, } impl Sql { @@ -50,6 +54,7 @@ impl Sql { Self { dbfile, pool: Default::default(), + is_encrypted: Default::default(), } } @@ -85,6 +90,13 @@ impl Sql { self.pool.read().await.is_some() } + /// Returns true if the database is encrypted. + /// + /// If database is not open, returns `None`. + pub(crate) async fn is_encrypted(&self) -> Option { + *self.is_encrypted.read().await + } + /// Closes all underlying Sqlite connections. async fn close(&self) { let _ = self.pool.write().await.take(); @@ -286,11 +298,13 @@ impl Sql { bail!("SQL database is already opened."); } + let passphrase_nonempty = !passphrase.is_empty(); if let Err(err) = self.try_open(context, &self.dbfile, passphrase).await { self.close().await; Err(err) } else { info!(context, "Opened database {:?}.", self.dbfile); + *self.is_encrypted.write().await = Some(passphrase_nonempty); Ok(()) } }