Better error message.
GitOrigin-RevId: 2779dcf8fa07fbc2e191141774b34fb9c2282b64
This commit is contained in:
parent
e60cf58d68
commit
38b3c1b52c
@ -150,23 +150,21 @@ Status SqliteDb::commit_transaction() {
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
bool SqliteDb::is_encrypted() {
|
||||
return exec("SELECT count(*) FROM sqlite_master").is_error();
|
||||
Status SqliteDb::check_encryption() {
|
||||
return exec("SELECT count(*) FROM sqlite_master");
|
||||
}
|
||||
|
||||
Result<SqliteDb> SqliteDb::open_with_key(CSlice path, const DbKey &db_key) {
|
||||
SqliteDb db;
|
||||
TRY_STATUS(db.init(path));
|
||||
if (!db_key.is_empty()) {
|
||||
if (!db.is_encrypted()) {
|
||||
if (db.check_encryption().is_ok()) {
|
||||
return Status::Error("No key is needed");
|
||||
}
|
||||
auto key = db_key_to_sqlcipher_key(db_key);
|
||||
TRY_STATUS(db.exec(PSLICE() << "PRAGMA key = " << key));
|
||||
}
|
||||
if (db.is_encrypted()) {
|
||||
return Status::Error("Wrong key or database is corrupted");
|
||||
}
|
||||
TRY_STATUS_PREFIX(db.check_encryption(), "Can't open database: ");
|
||||
return std::move(db);
|
||||
}
|
||||
|
||||
|
@ -81,7 +81,7 @@ class SqliteDb {
|
||||
}
|
||||
std::shared_ptr<detail::RawSqliteDb> raw_;
|
||||
|
||||
bool is_encrypted();
|
||||
Status check_encryption();
|
||||
};
|
||||
|
||||
} // namespace td
|
||||
|
Reference in New Issue
Block a user