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