diff --git a/Cargo.toml b/Cargo.toml index 9a21e7a..c5e957b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,7 +47,6 @@ tracing = "0.1.41" base64 = "0.22.1" rand = "0.8.5" rsa = "0.9.7" -once_cell = "1.20.2" http = "1.2.0" sha2 = { version = "0.10.8", features = ["oid"] } thiserror = "2.0.9" diff --git a/src/fetch/webfinger.rs b/src/fetch/webfinger.rs index 8d53078..b73e28c 100644 --- a/src/fetch/webfinger.rs +++ b/src/fetch/webfinger.rs @@ -7,10 +7,9 @@ use crate::{ }; use http::HeaderValue; use itertools::Itertools; -use once_cell::sync::Lazy; use regex::Regex; use serde::{Deserialize, Serialize}; -use std::{collections::HashMap, fmt::Display}; +use std::{collections::HashMap, fmt::Display, sync::LazyLock}; use tracing::debug; use url::Url; @@ -130,8 +129,8 @@ pub fn extract_webfinger_name<'i, T>(query: &'i str, data: &Data) -> Result<& where T: Clone, { - static WEBFINGER_REGEX: Lazy = - Lazy::new(|| Regex::new(r"^acct:([\p{L}0-9_\.\-]+)@(.*)$").expect("compile regex")); + static WEBFINGER_REGEX: LazyLock = + LazyLock::new(|| Regex::new(r"^acct:([\p{L}0-9_\.\-]+)@(.*)$").expect("compile regex")); // Regex to extract usernames from webfinger query. Supports different alphabets using `\p{L}`. // TODO: This should use a URL parser let captures = WEBFINGER_REGEX diff --git a/src/http_signatures.rs b/src/http_signatures.rs index f30e75c..95d0a12 100644 --- a/src/http_signatures.rs +++ b/src/http_signatures.rs @@ -19,7 +19,6 @@ use http_signature_normalization_reqwest::{ prelude::{Config, SignExt}, DefaultSpawner, }; -use once_cell::sync::Lazy; use reqwest::Request; use reqwest_middleware::RequestBuilder; use rsa::{ @@ -30,7 +29,7 @@ use rsa::{ }; use serde::Deserialize; use sha2::{Digest, Sha256}; -use std::{collections::BTreeMap, fmt::Debug, time::Duration}; +use std::{collections::BTreeMap, fmt::Debug, sync::LazyLock, time::Duration}; use tracing::debug; use url::Url; @@ -82,9 +81,9 @@ pub(crate) async fn sign_request( private_key: RsaPrivateKey, http_signature_compat: bool, ) -> Result { - static CONFIG: Lazy> = - Lazy::new(|| Config::new().set_expiration(EXPIRES_AFTER)); - static CONFIG_COMPAT: Lazy = Lazy::new(|| { + static CONFIG: LazyLock> = + LazyLock::new(|| Config::new().set_expiration(EXPIRES_AFTER)); + static CONFIG_COMPAT: LazyLock = LazyLock::new(|| { Config::new() .mastodon_compat() .set_expiration(EXPIRES_AFTER) @@ -185,7 +184,7 @@ fn verify_signature_inner( uri: &Uri, public_key: &str, ) -> Result<(), Error> { - static CONFIG: Lazy = Lazy::new(|| { + static CONFIG: LazyLock = LazyLock::new(|| { http_signature_normalization::Config::new() .set_expiration(EXPIRES_AFTER) .require_digest() @@ -288,9 +287,10 @@ pub mod test { use rsa::{pkcs1::DecodeRsaPrivateKey, pkcs8::DecodePrivateKey}; use std::str::FromStr; - static ACTOR_ID: Lazy = Lazy::new(|| Url::parse("https://example.com/u/alice").unwrap()); - static INBOX_URL: Lazy = - Lazy::new(|| Url::parse("https://example.com/u/alice/inbox").unwrap()); + static ACTOR_ID: LazyLock = + LazyLock::new(|| Url::parse("https://example.com/u/alice").unwrap()); + static INBOX_URL: LazyLock = + LazyLock::new(|| Url::parse("https://example.com/u/alice/inbox").unwrap()); #[tokio::test] async fn test_sign() { diff --git a/src/traits.rs b/src/traits.rs index 9976bda..7ca20d5 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -346,8 +346,8 @@ pub mod tests { protocol::verification::verify_domains_match, }; use activitystreams_kinds::{activity::FollowType, actor::PersonType}; - use once_cell::sync::Lazy; use serde::{Deserialize, Serialize}; + use std::sync::LazyLock; #[derive(Clone)] pub struct DbConnection; @@ -389,9 +389,10 @@ pub mod tests { pub local: bool, } - pub static DB_USER_KEYPAIR: Lazy = Lazy::new(|| generate_actor_keypair().unwrap()); + pub static DB_USER_KEYPAIR: LazyLock = + LazyLock::new(|| generate_actor_keypair().unwrap()); - pub static DB_USER: Lazy = Lazy::new(|| DbUser { + pub static DB_USER: LazyLock = LazyLock::new(|| DbUser { name: String::new(), federation_id: "https://localhost/123".parse().unwrap(), inbox: "https://localhost/123/inbox".parse().unwrap(),