Skip to content

Commit 2aa6461

Browse files
committed
Conditionally use getrandom().
1 parent 24ff5b9 commit 2aa6461

File tree

5 files changed

+36
-2
lines changed

5 files changed

+36
-2
lines changed

Cargo.lock

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

crates/core/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,7 @@ features = []
3333
loadable_extension = ["sqlite_nostd/loadable_extension"]
3434
static = ["sqlite_nostd/static"]
3535
omit_load_extension = ["sqlite_nostd/omit_load_extension"]
36+
# Enable to use the getrandom crate instead of sqlite3_randomness
37+
# Enable for Windows builds; do not enable for WASM
38+
getrandom = ["uuid/v4"]
3639

crates/core/src/util.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,18 @@ pub fn deserialize_optional_string_to_i64<'de, D>(deserializer: D) -> Result<Opt
8585
}
8686
}
8787

88+
// Use getrandom crate to generate UUID
89+
#[cfg(feature = "getrandom")]
90+
pub fn gen_uuid() -> Uuid {
91+
let id = Uuid::new_v4();
92+
id
93+
}
94+
95+
// Default - use sqlite3_randomness to generate UUID
96+
// This uses ChaCha20 PRNG, with /dev/urandom as a seed on unix.
97+
// On Windows, it uses custom logic for the seed, which may not be secure.
98+
// Rather avoid this version for Windows builds.
99+
#[cfg(not(feature = "getrandom"))]
88100
pub fn gen_uuid() -> Uuid {
89101
let mut random_bytes: [u8; 16] = [0; 16];
90102
sqlite::randomness(&mut random_bytes);

crates/shell/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ powersync_core = { path="../core" }
1313
sqlite_nostd = { workspace=true }
1414

1515
[features]
16-
default = ["powersync_core/static", "powersync_core/omit_load_extension", "sqlite_nostd/static", "sqlite_nostd/omit_load_extension"]
16+
default = ["powersync_core/static", "powersync_core/omit_load_extension", "powersync_core/getrandom", "sqlite_nostd/static", "sqlite_nostd/omit_load_extension"]
1717

1818
[build-dependencies]
1919
cc = "1.0.46"

crates/shell/build.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,4 @@ fn main() {
2525
cfg.compile("sqlite-ps");
2626

2727
println!("cargo:rustc-link-lib=readline");
28-
println!("cargo:rustc-link-lib=c");
2928
}

0 commit comments

Comments
 (0)