From 24d693667a481894dc6695651cba57634702b2d2 Mon Sep 17 00:00:00 2001 From: Mikko Ylinen Date: Thu, 2 Jan 2025 16:03:43 +0200 Subject: [PATCH] confidential-data-hub: use LazyLock from std library LazyLock has been part of the standard library since 1.80.x and is already used by other dependencies in this repository. Replace lazy_static macro with LazyLock. Signed-off-by: Mikko Ylinen --- Cargo.lock | 1 - confidential-data-hub/hub/Cargo.toml | 1 - confidential-data-hub/hub/src/kms/plugins/kbs/mod.rs | 8 +++----- .../hub/src/kms/plugins/kbs/sev/client.rs | 6 ++---- 4 files changed, 5 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c7acc1f2e..242823279 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1130,7 +1130,6 @@ dependencies = [ "hex", "image-rs", "kbs_protocol", - "lazy_static", "log", "nix 0.29.0", "p12", diff --git a/confidential-data-hub/hub/Cargo.toml b/confidential-data-hub/hub/Cargo.toml index 89edc7f62..817b5876f 100644 --- a/confidential-data-hub/hub/Cargo.toml +++ b/confidential-data-hub/hub/Cargo.toml @@ -48,7 +48,6 @@ env_logger = { workspace = true, optional = true } hex = { workspace = true, optional = true } image-rs = { path = "../../image-rs", default-features = false, features = ["kata-cc-rustls-tls"] } kbs_protocol = { path = "../../attestation-agent/kbs_protocol", default-features = false, features = ["passport", "aa_token", "openssl"], optional = true } -lazy_static.workspace = true log.workspace = true p12 = { version = "0.6.3", optional = true } prost = { workspace = true, optional = true } diff --git a/confidential-data-hub/hub/src/kms/plugins/kbs/mod.rs b/confidential-data-hub/hub/src/kms/plugins/kbs/mod.rs index f3c816350..91c593d41 100644 --- a/confidential-data-hub/hub/src/kms/plugins/kbs/mod.rs +++ b/confidential-data-hub/hub/src/kms/plugins/kbs/mod.rs @@ -13,11 +13,10 @@ mod sev; mod offline_fs; -use std::{env, sync::Arc}; +use std::{env, sync::Arc, sync::LazyLock}; use async_trait::async_trait; use attestation_agent::config::aa_kbc_params::AaKbcParams; -use lazy_static::lazy_static; pub use resource_uri::ResourceUri; use tokio::sync::Mutex; @@ -50,9 +49,8 @@ impl RealClient { } } -lazy_static! { - static ref KBS_CLIENT: Arc>> = Arc::new(Mutex::new(None)); -} +static KBS_CLIENT: LazyLock>>> = + LazyLock::new(|| Arc::new(Mutex::new(None))); #[async_trait] pub trait Kbc: Send + Sync { diff --git a/confidential-data-hub/hub/src/kms/plugins/kbs/sev/client.rs b/confidential-data-hub/hub/src/kms/plugins/kbs/sev/client.rs index 920a44153..5b4e6fb8d 100644 --- a/confidential-data-hub/hub/src/kms/plugins/kbs/sev/client.rs +++ b/confidential-data-hub/hub/src/kms/plugins/kbs/sev/client.rs @@ -5,11 +5,11 @@ // use std::collections::HashMap; +use std::sync::LazyLock; use async_trait::async_trait; use base64::{engine::general_purpose::STANDARD, Engine}; use crypto::WrapType; -use lazy_static::lazy_static; use resource_uri::ResourceUri; use serde::Deserialize; use tokio::{fs, sync::RwLock}; @@ -25,9 +25,7 @@ use super::keybroker::{ const KEYS_PATH: &str = "/sys/kernel/security/secrets/coco/1ee27366-0c87-43a6-af48-28543eaf7cb0"; -lazy_static! { - static ref ONLINE_SEV_KBC: RwLock> = RwLock::new(None); -} +static ONLINE_SEV_KBC: LazyLock>> = LazyLock::new(|| RwLock::new(None)); #[derive(Deserialize, Clone)] struct Connection {