Skip to content
This repository was archived by the owner on Jan 6, 2026. It is now read-only.

Commit 3645df3

Browse files
committed
encrypt emd and add url dependency
1 parent c5e55b3 commit 3645df3

3 files changed

Lines changed: 29 additions & 9 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ tracing = "0.1.41"
1616
tracing-appender = "0.2.3"
1717
tracing-subscriber = {version = "0.3.20", features = ["env-filter"] }
1818
turso_core = { version = "0.3.2" }
19+
url = "2.5.7"

rs_src/lib.rs

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use std::{
99
extern crate turso_core;
1010
use tracing_subscriber::{EnvFilter, layer::SubscriberExt, util::SubscriberInitExt};
1111
use turso_core::{Connection, LimboError};
12+
use url::Url;
1213

1314
use crate::types::ResultCode;
1415

@@ -24,29 +25,46 @@ pub unsafe extern "C" fn db_open(path: *const c_char) -> *mut c_void {
2425
println!("Path is null");
2526
return std::ptr::null_mut();
2627
}
27-
let path = unsafe { std::ffi::CStr::from_ptr(path) };
28-
let path = path.to_str().unwrap();
28+
29+
let path_str = unsafe { std::ffi::CStr::from_ptr(path) }
30+
.to_str()
31+
.unwrap_or_else(|_| {
32+
eprintln!("Failed to convert path to string");
33+
""
34+
});
35+
2936
let _ = init_tracing();
37+
3038
let indexes = true;
3139
let mvcc = false;
32-
let encryption = false;
40+
let mut encryption = false;
3341
let views = false;
3442
let strict = false;
3543
let custom_modules = false;
3644
let autovacuum = false;
37-
let Ok((io, conn)) = Connection::from_uri(
38-
path,
45+
46+
if let Ok(parsed_url) = Url::parse(path_str) {
47+
if parsed_url.query_pairs().any(|(key, _)| key == "hexkey") {
48+
encryption = true;
49+
}
50+
}
51+
52+
match Connection::from_uri(
53+
path_str,
3954
indexes,
4055
mvcc,
4156
views,
4257
strict,
4358
encryption,
4459
custom_modules,
4560
autovacuum,
46-
) else {
47-
panic!("Failed to open connection with path: {path}");
48-
};
49-
TursoConn::new(conn, io).to_ptr()
61+
) {
62+
Ok((io, conn)) => TursoConn::new(conn, io).to_ptr(),
63+
Err(e) => {
64+
eprintln!("Connection::from_uri failed: {:?}", e);
65+
std::ptr::null_mut()
66+
}
67+
}
5068
}
5169

5270
/// # Safety

0 commit comments

Comments
 (0)