diff --git a/crates/precompile/src/interface.rs b/crates/precompile/src/interface.rs index f4651c7a63..f05cd83bf4 100644 --- a/crates/precompile/src/interface.rs +++ b/crates/precompile/src/interface.rs @@ -11,12 +11,7 @@ static CRYPTO: OnceLock> = OnceLock::new(); /// Install a custom crypto provider globally. pub fn install_crypto(crypto: C) -> bool { - if CRYPTO.get().is_some() { - return false; - } - - CRYPTO.get_or_init(|| Box::new(crypto)); - true + CRYPTO.set(Box::new(crypto)).is_ok() } /// Get the installed crypto provider, or the default if none is installed. diff --git a/crates/primitives/src/once_lock.rs b/crates/primitives/src/once_lock.rs index 90d129ea6a..21cb9b9abb 100644 --- a/crates/primitives/src/once_lock.rs +++ b/crates/primitives/src/once_lock.rs @@ -41,6 +41,12 @@ mod no_std_impl { pub fn get(&self) -> Option<&T> { self.inner.get() } + + /// Sets the contents of the OnceLock. + #[inline] + pub fn set(&self, value: T) -> Result<(), T> { + self.inner.set(Box::new(value)).map_err(|e| *e) + } } }