Skip to content

Commit f56ae24

Browse files
authored
Allows empty encryption keys (#350)
* Fixes invalidated module not resolving promises * Allow empty encryption key * Fix encryption key * Fix Cpp
1 parent 7ad55ad commit f56ae24

4 files changed

Lines changed: 24 additions & 41 deletions

File tree

cpp/DBHostObject.cpp

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -142,24 +142,21 @@ void DBHostObject::auto_register_update_hook() {
142142
#ifdef OP_SQLITE_USE_LIBSQL
143143
// Remote connection constructor
144144
DBHostObject::DBHostObject(jsi::Runtime &rt, std::string &url,
145-
std::string &auth_token,
146-
std::shared_ptr<react::CallInvoker> invoker)
147-
: db_name(url), invoker(std::move(invoker)), rt(rt) {
145+
std::string &auth_token)
146+
: db_name(url), rt(rt) {
148147
_thread_pool = std::make_shared<ThreadPool>();
149148
db = opsqlite_libsql_open_remote(url, auth_token);
150149

151150
create_jsi_functions();
152151
}
153152

154153
// Sync connection constructor
155-
DBHostObject::DBHostObject(jsi::Runtime &rt,
156-
std::shared_ptr<react::CallInvoker> invoker,
157-
std::string &db_name, std::string &path,
158-
std::string &url, std::string &auth_token,
159-
int sync_interval, bool offline,
160-
std::string &encryption_key,
154+
DBHostObject::DBHostObject(jsi::Runtime &rt, std::string &db_name,
155+
std::string &path, std::string &url,
156+
std::string &auth_token, int sync_interval,
157+
bool offline, std::string &encryption_key,
161158
std::string &remote_encryption_key)
162-
: db_name(db_name), invoker(std::move(invoker)), rt(rt) {
159+
: db_name(db_name), rt(rt) {
163160

164161
_thread_pool = std::make_shared<ThreadPool>();
165162

@@ -173,13 +170,11 @@ DBHostObject::DBHostObject(jsi::Runtime &rt,
173170
#endif
174171

175172
DBHostObject::DBHostObject(jsi::Runtime &rt, std::string &base_path,
176-
std::shared_ptr<react::CallInvoker> invoker,
177173
std::string &db_name, std::string &path,
178174
std::string &crsqlite_path,
179175
std::string &sqlite_vec_path,
180176
std::string &encryption_key)
181-
: base_path(base_path), invoker(std::move(invoker)), db_name(db_name),
182-
rt(rt) {
177+
: base_path(base_path), db_name(db_name), rt(rt) {
183178
_thread_pool = std::make_shared<ThreadPool>();
184179

185180
#ifdef OP_SQLITE_USE_SQLCIPHER
@@ -617,13 +612,12 @@ void DBHostObject::create_jsi_functions() {
617612
return jsi::String::createFromUtf8(rt, result);
618613
});
619614

620-
function_map["flushPendingReactiveQueries"] =
621-
HOSTFN("flushPendingReactiveQueries") {
615+
function_map["flushPendingReactiveQueries"] = HFN(this) {
622616
auto promiseCtr = rt.global().getPropertyAsFunction(rt, "Promise");
623-
auto promise = promiseCtr.callAsConstructor(rt, HOSTFN("executor") {
617+
auto promise = promiseCtr.callAsConstructor(rt, HFN(this) {
624618
auto resolve = std::make_shared<jsi::Value>(rt, args[0]);
625619

626-
auto task = [&rt, this, resolve]() {
620+
auto task = [this, resolve]() {
627621
flush_pending_reactive_queries(resolve);
628622
};
629623

cpp/DBHostObject.h

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,19 @@ struct ReactiveQuery {
4444
class JSI_EXPORT DBHostObject : public jsi::HostObject {
4545
public:
4646
// Normal constructor shared between all backends
47-
DBHostObject(jsi::Runtime &rt, std::string &base_path,
48-
std::shared_ptr<react::CallInvoker> invoker,
49-
std::string &db_name, std::string &path,
50-
std::string &crsqlite_path, std::string &sqlite_vec_path,
51-
std::string &encryption_key);
47+
DBHostObject(jsi::Runtime &rt, std::string &base_path, std::string &db_name,
48+
std::string &path, std::string &crsqlite_path,
49+
std::string &sqlite_vec_path, std::string &encryption_key);
5250

5351
#ifdef OP_SQLITE_USE_LIBSQL
5452
// Constructor for remoteOpen, purely for remote databases
55-
DBHostObject(jsi::Runtime &rt, std::string &url, std::string &auth_token,
56-
std::shared_ptr<react::CallInvoker> invoker);
53+
DBHostObject(jsi::Runtime &rt, std::string &url, std::string &auth_token);
5754

5855
// Constructor for a local database with remote sync
59-
DBHostObject(jsi::Runtime &rt, std::shared_ptr<react::CallInvoker> invoker,
60-
std::string &db_name, std::string &path, std::string &url,
61-
std::string &auth_token, int sync_interval, bool offline,
62-
std::string &encryption_key, std::string &remote_encryption_key);
56+
DBHostObject(jsi::Runtime &rt, std::string &db_name, std::string &path,
57+
std::string &url, std::string &auth_token, int sync_interval,
58+
bool offline, std::string &encryption_key,
59+
std::string &remote_encryption_key);
6360
#endif
6461

6562
std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime &rt) override;
@@ -82,7 +79,6 @@ class JSI_EXPORT DBHostObject : public jsi::HostObject {
8279

8380
std::unordered_map<std::string, jsi::Value> function_map;
8481
std::string base_path;
85-
std::shared_ptr<react::CallInvoker> invoker;
8682
std::shared_ptr<ThreadPool> _thread_pool;
8783
std::string db_name;
8884
std::shared_ptr<jsi::Value> update_hook_callback;

cpp/OPSqlite.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,6 @@ void install(jsi::Runtime &rt,
6969
options.getProperty(rt, "encryptionKey").asString(rt).utf8(rt);
7070
}
7171

72-
#ifdef OP_SQLITE_USE_SQLCIPHER
73-
if (encryption_key.empty()) {
74-
log_to_console(rt, "Encryption key is missing for SQLCipher");
75-
}
76-
#endif
77-
7872
if (!location.empty()) {
7973
if (location == ":memory:") {
8074
path = ":memory:";
@@ -86,8 +80,7 @@ void install(jsi::Runtime &rt,
8680
}
8781

8882
std::shared_ptr<DBHostObject> db = std::make_shared<DBHostObject>(
89-
rt, path, opsqlite::invoker, name, path, _crsqlite_path,
90-
_sqlite_vec_path, encryption_key);
83+
rt, path, name, path, _crsqlite_path, _sqlite_vec_path, encryption_key);
9184
dbs.emplace_back(db);
9285
return jsi::Object::createFromHostObject(rt, db);
9386
});
@@ -126,7 +119,7 @@ void install(jsi::Runtime &rt,
126119
options.getProperty(rt, "authToken").asString(rt).utf8(rt);
127120

128121
std::shared_ptr<DBHostObject> db =
129-
std::make_shared<DBHostObject>(rt, url, auth_token, invoker);
122+
std::make_shared<DBHostObject>(rt, url, auth_token);
130123

131124
return jsi::Object::createFromHostObject(rt, db);
132125
});
@@ -177,8 +170,8 @@ void install(jsi::Runtime &rt,
177170
}
178171

179172
std::shared_ptr<DBHostObject> db = std::make_shared<DBHostObject>(
180-
rt, invoker, name, path, url, auth_token, sync_interval, offline,
181-
encryption_key, remote_encryption_key);
173+
rt, name, path, url, auth_token, sync_interval, offline, encryption_key,
174+
remote_encryption_key);
182175
return jsi::Object::createFromHostObject(rt, db);
183176
});
184177
#endif

example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
},
4747
"op-sqlite": {
4848
"libsql": false,
49-
"sqlcipher": false,
49+
"sqlcipher": true,
5050
"iosSqlite": false,
5151
"fts5": true,
5252
"rtree": true,

0 commit comments

Comments
 (0)