mirror of
https://github.com/LemmyNet/activitypub-federation-rust.git
synced 2025-03-13 10:42:40 +00:00
remove once_cell
This commit is contained in:
parent
1ef34749a7
commit
eff97d87ca
4 changed files with 16 additions and 17 deletions
|
@ -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"
|
||||
|
|
|
@ -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<T>) -> Result<&
|
|||
where
|
||||
T: Clone,
|
||||
{
|
||||
static WEBFINGER_REGEX: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new(r"^acct:([\p{L}0-9_\.\-]+)@(.*)$").expect("compile regex"));
|
||||
static WEBFINGER_REGEX: LazyLock<Regex> =
|
||||
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
|
||||
|
|
|
@ -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<Request, Error> {
|
||||
static CONFIG: Lazy<Config<DefaultSpawner>> =
|
||||
Lazy::new(|| Config::new().set_expiration(EXPIRES_AFTER));
|
||||
static CONFIG_COMPAT: Lazy<Config> = Lazy::new(|| {
|
||||
static CONFIG: LazyLock<Config<DefaultSpawner>> =
|
||||
LazyLock::new(|| Config::new().set_expiration(EXPIRES_AFTER));
|
||||
static CONFIG_COMPAT: LazyLock<Config> = 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<http_signature_normalization::Config> = Lazy::new(|| {
|
||||
static CONFIG: LazyLock<http_signature_normalization::Config> = 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<Url> = Lazy::new(|| Url::parse("https://example.com/u/alice").unwrap());
|
||||
static INBOX_URL: Lazy<Url> =
|
||||
Lazy::new(|| Url::parse("https://example.com/u/alice/inbox").unwrap());
|
||||
static ACTOR_ID: LazyLock<Url> =
|
||||
LazyLock::new(|| Url::parse("https://example.com/u/alice").unwrap());
|
||||
static INBOX_URL: LazyLock<Url> =
|
||||
LazyLock::new(|| Url::parse("https://example.com/u/alice/inbox").unwrap());
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_sign() {
|
||||
|
|
|
@ -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<Keypair> = Lazy::new(|| generate_actor_keypair().unwrap());
|
||||
pub static DB_USER_KEYPAIR: LazyLock<Keypair> =
|
||||
LazyLock::new(|| generate_actor_keypair().unwrap());
|
||||
|
||||
pub static DB_USER: Lazy<DbUser> = Lazy::new(|| DbUser {
|
||||
pub static DB_USER: LazyLock<DbUser> = LazyLock::new(|| DbUser {
|
||||
name: String::new(),
|
||||
federation_id: "https://localhost/123".parse().unwrap(),
|
||||
inbox: "https://localhost/123/inbox".parse().unwrap(),
|
||||
|
|
Loading…
Reference in a new issue