1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-07-29 22:01:14 +03:00

handlers: box the rng and clock, and extract it from the state

This commit is contained in:
Quentin Gliech
2023-01-18 17:32:54 +01:00
parent 8c585b20f0
commit 9005931e2a
52 changed files with 291 additions and 193 deletions

View File

@ -28,6 +28,12 @@ pub trait Clock: Sync {
fn now(&self) -> DateTime<Utc>;
}
impl<C: Clock + ?Sized> Clock for Box<C> {
fn now(&self) -> DateTime<Utc> {
(**self).now()
}
}
/// A clock which uses the system time
#[derive(Clone, Default)]
pub struct SystemClock {

View File

@ -15,7 +15,7 @@
use async_trait::async_trait;
use chrono::Duration;
use mas_data_model::{CompatAccessToken, CompatSession};
use rand::RngCore;
use rand_core::RngCore;
use ulid::Ulid;
use crate::Clock;

View File

@ -14,7 +14,7 @@
use async_trait::async_trait;
use mas_data_model::{CompatAccessToken, CompatRefreshToken, CompatSession};
use rand::RngCore;
use rand_core::RngCore;
use ulid::Ulid;
use crate::Clock;

View File

@ -14,7 +14,7 @@
use async_trait::async_trait;
use mas_data_model::{CompatSession, Device, User};
use rand::RngCore;
use rand_core::RngCore;
use ulid::Ulid;
use crate::Clock;

View File

@ -14,7 +14,7 @@
use async_trait::async_trait;
use mas_data_model::{CompatSession, CompatSsoLogin, User};
use rand::RngCore;
use rand_core::RngCore;
use ulid::Ulid;
use url::Url;

View File

@ -37,8 +37,13 @@ pub(crate) mod repository;
pub mod upstream_oauth2;
pub mod user;
use rand_core::CryptoRngCore;
pub use self::{
clock::{Clock, SystemClock},
pagination::{Page, Pagination},
repository::Repository,
};
pub type BoxClock = Box<dyn Clock + Send>;
pub type BoxRng = Box<dyn CryptoRngCore + Send>;

View File

@ -15,7 +15,7 @@
use async_trait::async_trait;
use chrono::Duration;
use mas_data_model::{AccessToken, Session};
use rand::RngCore;
use rand_core::RngCore;
use ulid::Ulid;
use crate::Clock;

View File

@ -17,7 +17,7 @@ use std::num::NonZeroU32;
use async_trait::async_trait;
use mas_data_model::{AuthorizationCode, AuthorizationGrant, Client, Session};
use oauth2_types::{requests::ResponseMode, scope::Scope};
use rand::RngCore;
use rand_core::RngCore;
use ulid::Ulid;
use url::Url;

View File

@ -19,7 +19,7 @@ use mas_data_model::{Client, User};
use mas_iana::{jose::JsonWebSignatureAlg, oauth::OAuthClientAuthenticationMethod};
use mas_jose::jwk::PublicJsonWebKeySet;
use oauth2_types::{requests::GrantType, scope::Scope};
use rand::{Rng, RngCore};
use rand_core::RngCore;
use ulid::Ulid;
use url::Url;
@ -67,7 +67,7 @@ pub trait OAuth2ClientRepository: Send + Sync {
#[allow(clippy::too_many_arguments)]
async fn add_from_config(
&mut self,
mut rng: impl Rng + Send,
rng: &mut (dyn RngCore + Send),
clock: &dyn Clock,
client_id: Ulid,
client_auth_method: OAuthClientAuthenticationMethod,

View File

@ -14,7 +14,7 @@
use async_trait::async_trait;
use mas_data_model::{AccessToken, RefreshToken, Session};
use rand::RngCore;
use rand_core::RngCore;
use ulid::Ulid;
use crate::Clock;

View File

@ -14,7 +14,7 @@
use async_trait::async_trait;
use mas_data_model::{AuthorizationGrant, BrowserSession, Session, User};
use rand::RngCore;
use rand_core::RngCore;
use ulid::Ulid;
use crate::{pagination::Page, Clock, Pagination};

View File

@ -14,7 +14,7 @@
use async_trait::async_trait;
use mas_data_model::{UpstreamOAuthLink, UpstreamOAuthProvider, User};
use rand::RngCore;
use rand_core::RngCore;
use ulid::Ulid;
use crate::{pagination::Page, Clock, Pagination};

View File

@ -16,7 +16,7 @@ use async_trait::async_trait;
use mas_data_model::UpstreamOAuthProvider;
use mas_iana::{jose::JsonWebSignatureAlg, oauth::OAuthClientAuthenticationMethod};
use oauth2_types::scope::Scope;
use rand::RngCore;
use rand_core::RngCore;
use ulid::Ulid;
use crate::{pagination::Page, Clock, Pagination};

View File

@ -14,7 +14,7 @@
use async_trait::async_trait;
use mas_data_model::{UpstreamOAuthAuthorizationSession, UpstreamOAuthLink, UpstreamOAuthProvider};
use rand::RngCore;
use rand_core::RngCore;
use ulid::Ulid;
use crate::Clock;

View File

@ -14,7 +14,7 @@
use async_trait::async_trait;
use mas_data_model::{User, UserEmail, UserEmailVerification};
use rand::RngCore;
use rand_core::RngCore;
use ulid::Ulid;
use crate::{pagination::Page, Clock, Pagination};

View File

@ -14,7 +14,7 @@
use async_trait::async_trait;
use mas_data_model::User;
use rand::RngCore;
use rand_core::RngCore;
use ulid::Ulid;
use crate::Clock;

View File

@ -14,7 +14,7 @@
use async_trait::async_trait;
use mas_data_model::{Password, User};
use rand::RngCore;
use rand_core::RngCore;
use crate::Clock;

View File

@ -14,7 +14,7 @@
use async_trait::async_trait;
use mas_data_model::{BrowserSession, Password, UpstreamOAuthLink, User};
use rand::RngCore;
use rand_core::RngCore;
use ulid::Ulid;
use crate::{pagination::Page, Clock, Pagination};