Skip to content

Commit af9df37

Browse files
ghedokornelski
authored andcommitted
replace once_cell with LazyLock
We can drop the once_cell dependency since the same functionality is implemented in std now. Requires bumping MSRV to 1.80.
1 parent 6ca27a7 commit af9df37

File tree

8 files changed

+28
-30
lines changed

8 files changed

+28
-30
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ hyper1 = { package = "hyper", version = "1" }
4444
hyper-util = "0.1.6"
4545
hyper0 = { package = "hyper", version = "0.14", default-features = false }
4646
linked_hash_set = "0.1"
47-
once_cell = "1.0"
4847
openssl-macros = "0.1.1"
4948
tower = { version = "0.4", default-features = false, features = ["util"] }
5049
tower-layer = "0.3"

boring/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ readme = "README.md"
1010
keywords = ["crypto", "tls", "ssl", "dtls"]
1111
categories = ["cryptography", "api-bindings"]
1212
edition = { workspace = true }
13-
rust-version = "1.70"
13+
rust-version = "1.80"
1414

1515
[package.metadata.docs.rs]
1616
features = ["rpk", "pq-experimental", "underscore-wildcards"]
@@ -74,7 +74,6 @@ kx-client-nist-required = ["kx-safe-default"]
7474
[dependencies]
7575
bitflags = { workspace = true }
7676
foreign-types = { workspace = true }
77-
once_cell = { workspace = true }
7877
openssl-macros = { workspace = true }
7978
libc = { workspace = true }
8079
boring-sys = { workspace = true }

boring/src/ssl/async_callbacks.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ use super::{
55
SslVerifyMode,
66
};
77
use crate::ex_data::Index;
8-
use once_cell::sync::Lazy;
98
use std::convert::identity;
109
use std::future::Future;
1110
use std::pin::Pin;
11+
use std::sync::LazyLock;
1212
use std::task::{ready, Context, Poll, Waker};
1313

1414
/// The type of futures to pass to [`SslContextBuilderExt::set_async_select_certificate_callback`].
@@ -42,19 +42,20 @@ pub type BoxCustomVerifyFinish = Box<dyn FnOnce(&mut SslRef) -> Result<(), SslAl
4242
/// Public for documentation purposes.
4343
pub type ExDataFuture<T> = Pin<Box<dyn Future<Output = T> + Send>>;
4444

45-
pub(crate) static TASK_WAKER_INDEX: Lazy<Index<Ssl, Option<Waker>>> =
46-
Lazy::new(|| Ssl::new_ex_index().unwrap());
47-
pub(crate) static SELECT_CERT_FUTURE_INDEX: Lazy<Index<Ssl, MutOnly<Option<BoxSelectCertFuture>>>> =
48-
Lazy::new(|| Ssl::new_ex_index().unwrap());
49-
pub(crate) static SELECT_PRIVATE_KEY_METHOD_FUTURE_INDEX: Lazy<
45+
pub(crate) static TASK_WAKER_INDEX: LazyLock<Index<Ssl, Option<Waker>>> =
46+
LazyLock::new(|| Ssl::new_ex_index().unwrap());
47+
pub(crate) static SELECT_CERT_FUTURE_INDEX: LazyLock<
48+
Index<Ssl, MutOnly<Option<BoxSelectCertFuture>>>,
49+
> = LazyLock::new(|| Ssl::new_ex_index().unwrap());
50+
pub(crate) static SELECT_PRIVATE_KEY_METHOD_FUTURE_INDEX: LazyLock<
5051
Index<Ssl, MutOnly<Option<BoxPrivateKeyMethodFuture>>>,
51-
> = Lazy::new(|| Ssl::new_ex_index().unwrap());
52-
pub(crate) static SELECT_GET_SESSION_FUTURE_INDEX: Lazy<
52+
> = LazyLock::new(|| Ssl::new_ex_index().unwrap());
53+
pub(crate) static SELECT_GET_SESSION_FUTURE_INDEX: LazyLock<
5354
Index<Ssl, MutOnly<Option<BoxGetSessionFuture>>>,
54-
> = Lazy::new(|| Ssl::new_ex_index().unwrap());
55-
pub(crate) static SELECT_CUSTOM_VERIFY_FUTURE_INDEX: Lazy<
55+
> = LazyLock::new(|| Ssl::new_ex_index().unwrap());
56+
pub(crate) static SELECT_CUSTOM_VERIFY_FUTURE_INDEX: LazyLock<
5657
Index<Ssl, MutOnly<Option<BoxCustomVerifyFuture>>>,
57-
> = Lazy::new(|| Ssl::new_ex_index().unwrap());
58+
> = LazyLock::new(|| Ssl::new_ex_index().unwrap());
5859

5960
impl SslContextBuilder {
6061
/// Sets a callback that is called before most [`ClientHello`] processing

boring/src/ssl/mod.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
//! ```
6060
use foreign_types::{ForeignType, ForeignTypeRef, Opaque};
6161
use libc::{c_char, c_int, c_long, c_uchar, c_uint, c_void};
62-
use once_cell::sync::Lazy;
6362
use openssl_macros::corresponds;
6463
use std::any::TypeId;
6564
use std::collections::HashMap;
@@ -76,7 +75,7 @@ use std::path::Path;
7675
use std::ptr::{self, NonNull};
7776
use std::slice;
7877
use std::str;
79-
use std::sync::{Arc, Mutex};
78+
use std::sync::{Arc, LazyLock, Mutex};
8079

8180
use crate::dh::DhRef;
8281
use crate::ec::EcKeyRef;
@@ -426,12 +425,15 @@ impl NameType {
426425
}
427426
}
428427

429-
static INDEXES: Lazy<Mutex<HashMap<TypeId, c_int>>> = Lazy::new(|| Mutex::new(HashMap::new()));
430-
static SSL_INDEXES: Lazy<Mutex<HashMap<TypeId, c_int>>> = Lazy::new(|| Mutex::new(HashMap::new()));
431-
static SESSION_CTX_INDEX: Lazy<Index<Ssl, SslContext>> = Lazy::new(|| Ssl::new_ex_index().unwrap());
428+
static INDEXES: LazyLock<Mutex<HashMap<TypeId, c_int>>> =
429+
LazyLock::new(|| Mutex::new(HashMap::new()));
430+
static SSL_INDEXES: LazyLock<Mutex<HashMap<TypeId, c_int>>> =
431+
LazyLock::new(|| Mutex::new(HashMap::new()));
432+
static SESSION_CTX_INDEX: LazyLock<Index<Ssl, SslContext>> =
433+
LazyLock::new(|| Ssl::new_ex_index().unwrap());
432434
#[cfg(feature = "rpk")]
433-
static RPK_FLAG_INDEX: Lazy<Index<SslContext, bool>> =
434-
Lazy::new(|| SslContext::new_ex_index().unwrap());
435+
static RPK_FLAG_INDEX: LazyLock<Index<SslContext, bool>> =
436+
LazyLock::new(|| SslContext::new_ex_index().unwrap());
435437

436438
unsafe extern "C" fn free_data_box<T>(
437439
_parent: *mut c_void,

boring/src/ssl/test/private_key_method.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use once_cell::sync::OnceCell;
2-
31
use super::server::{Builder, Server};
42
use super::KEY;
53
use crate::hash::MessageDigest;
@@ -12,7 +10,7 @@ use crate::ssl::{
1210
};
1311
use std::io::Write;
1412
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
15-
use std::sync::Arc;
13+
use std::sync::{Arc, OnceLock};
1614

1715
#[allow(clippy::type_complexity)]
1816
pub(super) struct Method {
@@ -233,7 +231,7 @@ fn test_sign_ok() {
233231

234232
#[test]
235233
fn test_sign_retry_complete_ok() {
236-
let input_cell = Arc::new(OnceCell::new());
234+
let input_cell = Arc::new(OnceLock::new());
237235
let input_cell_clone = input_cell.clone();
238236

239237
let mut builder = builder_with_private_key_method(

hyper-boring/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ repository = { workspace = true }
99
documentation = "https://docs.rs/hyper-boring"
1010
readme = "README.md"
1111
exclude = ["test/*"]
12+
rust-version = "1.80"
1213

1314
[package.metadata.docs.rs]
1415
features = ["pq-experimental"]
@@ -45,7 +46,6 @@ hyper1 = { workspace = true, optional = true }
4546
hyper-util = { workspace = true, optional = true, features = ["client", "client-legacy"] }
4647
hyper0 = { workspace = true, optional = true, features = ["client"] }
4748
linked_hash_set = { workspace = true }
48-
once_cell = { workspace = true }
4949
boring = { workspace = true }
5050
tokio = { workspace = true }
5151
tokio-boring = { workspace = true }

hyper-boring/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use crate::cache::SessionKey;
66
use boring::error::ErrorStack;
77
use boring::ex_data::Index;
88
use boring::ssl::Ssl;
9-
use once_cell::sync::OnceCell;
109
use std::fmt;
10+
use std::sync::LazyLock;
1111
use tokio_boring::SslStream;
1212

1313
mod cache;
@@ -21,8 +21,8 @@ mod v1;
2121
pub use self::v1::*;
2222

2323
fn key_index() -> Result<Index<Ssl, SessionKey>, ErrorStack> {
24-
static IDX: OnceCell<Index<Ssl, SessionKey>> = OnceCell::new();
25-
IDX.get_or_try_init(Ssl::new_ex_index).copied()
24+
static IDX: LazyLock<Index<Ssl, SessionKey>> = LazyLock::new(|| Ssl::new_ex_index().unwrap());
25+
Ok(*IDX)
2626
}
2727

2828
/// Settings for [`HttpsLayer`]

tokio-boring/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ rpk = ["boring/rpk"]
3131
[dependencies]
3232
boring = { workspace = true }
3333
boring-sys = { workspace = true }
34-
once_cell = { workspace = true }
3534
tokio = { workspace = true }
3635

3736
[dev-dependencies]

0 commit comments

Comments
 (0)