Skip to content

Commit

Permalink
fixup some sqlcipher issues
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed May 12, 2024
1 parent 46039cb commit 312f3d1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,9 @@ chrono = { version = "0.4.38", default-features=false, features = ["alloc", "clo
[features]
default = ["vendored", "sqlcipher"]
internals = []
sqlcipher = ["rusqlite/sqlcipher"]
sqlcipher = ["rusqlite/bundled-sqlcipher-vendored-openssl"]
vendored = [
"async-native-tls/vendored",
"rusqlite/bundled-sqlcipher-vendored-openssl",
"reqwest/native-tls-vendored"
]

Expand Down
7 changes: 5 additions & 2 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1410,10 +1410,13 @@ mod tests {
let tmp = tempfile::tempdir()?;
let dbfile = tmp.path().join("db.sqlite");
tokio::fs::write(&dbfile, b"123").await?;
let res = Context::new(&dbfile, 1, Events::new(), StockStrings::new()).await?;
let res = Context::new(&dbfile, 1, Events::new(), StockStrings::new()).await;

// Broken database is indistinguishable from encrypted one.
assert_eq!(res.is_open().await, false);
#[cfg(feature = "sqlcipher")]
assert_eq!(res?.is_open().await, false);
#[cfg(not(feature = "sqlcipher"))]
assert!(res.is_err());
Ok(())
}

Expand Down
3 changes: 3 additions & 0 deletions src/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,16 @@ impl Sql {
.context("failed to vacuum the database")?;
conn.set_db_config(DbConfig::SQLITE_DBCONFIG_RESET_DATABASE, false)
.context("failed to unset SQLITE_DBCONFIG_RESET_DATABASE")?;

#[cfg(feature = "sqlcipher")]
let res = conn
.query_row("SELECT sqlcipher_export('main', 'backup')", [], |_row| {
Ok(())
})
.context("failed to import from attached backup database");
conn.execute("DETACH DATABASE backup", [])
.context("failed to detach backup database")?;
#[cfg(feature = "sqlcipher")]
res?;
Ok(())
})
Expand Down

0 comments on commit 312f3d1

Please sign in to comment.