-
Notifications
You must be signed in to change notification settings - Fork 166
Expand file tree
/
Copy pathsqlcipher.cc
More file actions
56 lines (47 loc) · 1.34 KB
/
sqlcipher.cc
File metadata and controls
56 lines (47 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <catch.hpp>
#include <sqlite_modern_cpp/sqlcipher.h>
using namespace sqlite;
using namespace std;
struct TmpFile
{
string fname;
TmpFile(): fname("./sqlcipher.db") { }
~TmpFile() { remove(fname.c_str()); }
};
TEST_CASE("sqlcipher works", "[sqlcipher]") {
TmpFile file;
sqlcipher_config config;
{
config.key = "DebugKey";
sqlcipher_database db(file.fname, config);
db << "CREATE TABLE foo (a integer, b string);";
db << "INSERT INTO foo VALUES (?, ?)" << 1 << "hello";
db << "INSERT INTO foo VALUES (?, ?)" << 2 << "world";
string str;
db << "SELECT b from FOO where a=?;" << 2 >> str;
REQUIRE(str == "world");
}
bool failed = false;
try {
config.key = "DebugKey2";
sqlcipher_database db(file.fname, config);
db << "INSERT INTO foo VALUES (?, ?)" << 3 << "fail";
} catch(const errors::notadb&) {
failed = true;
// Expected, wrong key
}
REQUIRE(failed == true);
{
config.key = "DebugKey";
sqlcipher_database db(file.fname, config);
db.rekey("DebugKey2");
}
{
config.key = "DebugKey2";
sqlcipher_database db(file.fname, config);
db << "INSERT INTO foo VALUES (?, ?)" << 3 << "fail";
}
}