Skip to content

Commit 7e9c537

Browse files
committed
chore: remove once_cell dependency
Now that MSRV is 1.65, we can replace the once_cell dependency by using a standard mutex.
1 parent 7fe8b76 commit 7e9c537

File tree

4 files changed

+17
-26
lines changed

4 files changed

+17
-26
lines changed

Cargo.lock

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

boreal/Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,5 @@ glob = "0.3.1"
7474
tempfile = "3.8"
7575
yara = { version = "0.21", features = ["vendored"] }
7676

77-
# Only needed in tests because Mutex::new is not const
78-
# in 1.62 MSRV. Can be removed once MSRV is bumped above it.
79-
once_cell = "1.18"
80-
8177
[package.metadata.docs.rs]
8278
features = ["authenticode", "memmap"]

boreal/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ use base64 as _;
7979
#[cfg(test)]
8080
use glob as _;
8181
#[cfg(test)]
82-
use once_cell as _;
83-
#[cfg(test)]
8482
use tempfile as _;
8583
#[cfg(test)]
8684
use yara as _;

boreal/tests/it/utils.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -185,21 +185,25 @@ impl Compiler {
185185
#[cfg(all(feature = "object", feature = "authenticode"))]
186186
fn build_compiler() -> boreal::Compiler {
187187
use boreal::module::Pe;
188-
use once_cell::sync::Lazy;
189-
190-
// Can be replaced with a std Mutex once MSRV is bumped to 1.63.
191-
static PE_MODULE: Lazy<Pe> = Lazy::new(|| {
192-
// Safety:
193-
// - This is in a critical section that ensures a single thread can call this function
194-
// - The only openssl code in this codebase is in the authenticode parsing, called when
195-
// scanning. Since to scan rules must first be compiled, and this is called on the very
196-
// first build of a compiler, there can be no other threads calling into OpenSSL while
197-
// this is called.
198-
unsafe { Pe::new_with_signatures() }
199-
});
188+
use std::sync::Mutex;
189+
190+
static PE_MODULE: Mutex<Option<Pe>> = Mutex::new(None);
200191

201192
let mut compiler = boreal::Compiler::new_without_pe_module();
202-
compiler.add_module(*PE_MODULE);
193+
{
194+
let mut mutex = PE_MODULE.lock().unwrap();
195+
let pe_module = mutex.get_or_insert_with(|| {
196+
// Safety:
197+
// - This is in a critical section that ensures a single thread can call this function
198+
// - The only openssl code in this codebase is in the authenticode parsing, called when
199+
// scanning. Since to scan rules must first be compiled, and this is called on the very
200+
// first build of a compiler, there can be no other threads calling into OpenSSL while
201+
// this is called.
202+
unsafe { Pe::new_with_signatures() }
203+
});
204+
compiler.add_module(*pe_module);
205+
}
206+
203207
compiler
204208
}
205209

0 commit comments

Comments
 (0)