Skip to content

Commit 24ff5b9

Browse files
committed
Use "sqlite::randomness" to generate uuids.
1 parent 308ca1d commit 24ff5b9

File tree

6 files changed

+13
-27
lines changed

6 files changed

+13
-27
lines changed

Cargo.lock

Lines changed: 0 additions & 20 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: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ serde = { version = "1.0", default-features = false, features = ["alloc", "deriv
2323
[dependencies.uuid]
2424
version = "1.4.1"
2525
default-features = false
26-
features = [
27-
"v4"
28-
]
26+
features = []
2927

3028

3129
[dev-dependencies]

crates/core/src/operations.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use serde_json as json;
66

77
use sqlite_nostd as sqlite;
88
use sqlite_nostd::{Connection, ResultCode};
9-
use uuid::Uuid;
109
use crate::error::{SQLiteError, PSResult};
1110

1211
use crate::ext::SafeManagedStmt;
@@ -263,7 +262,7 @@ pub fn delete_pending_buckets(
263262
pub fn delete_bucket(
264263
db: *mut sqlite::sqlite3, name: &str) -> Result<(), SQLiteError> {
265264

266-
let id = Uuid::new_v4();
265+
let id = gen_uuid();
267266
let new_name = format!("$delete_{}_{}", name, id.hyphenated().to_string());
268267

269268
// language=SQLite

crates/core/src/util.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use serde_json as json;
88

99
use sqlite::{Connection, ResultCode};
1010
use sqlite_nostd as sqlite;
11+
use uuid::{Builder,Uuid};
1112
use sqlite_nostd::ManagedStmt;
1213

1314
use crate::error::SQLiteError;
@@ -84,6 +85,12 @@ pub fn deserialize_optional_string_to_i64<'de, D>(deserializer: D) -> Result<Opt
8485
}
8586
}
8687

88+
pub fn gen_uuid() -> Uuid {
89+
let mut random_bytes: [u8; 16] = [0; 16];
90+
sqlite::randomness(&mut random_bytes);
91+
let id = Builder::from_random_bytes(random_bytes).into_uuid();
92+
id
93+
}
8794

8895
pub const MAX_OP_ID: &str = "9223372036854775807";
8996

crates/core/src/uuid.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,17 @@ use core::slice;
99
use sqlite::ResultCode;
1010
use sqlite_nostd as sqlite;
1111
use sqlite_nostd::{Connection, Context};
12-
use uuid::Uuid;
1312

1413
use crate::create_sqlite_text_fn;
1514
use crate::error::SQLiteError;
15+
use crate::util::*;
16+
1617

1718
fn uuid_v4_impl(
1819
_ctx: *mut sqlite::context,
1920
_args: &[*mut sqlite::value],
2021
) -> Result<String, ResultCode> {
21-
let id = Uuid::new_v4();
22+
let id = gen_uuid();
2223
Ok(id.hyphenated().to_string())
2324
}
2425

crates/shell/build.rs

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

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

0 commit comments

Comments
 (0)