about summary refs log tree commit diff
path: root/src/indieauth
diff options
context:
space:
mode:
authorVika <vika@fireburn.ru>2024-08-26 20:25:20 +0300
committerVika <vika@fireburn.ru>2024-08-26 20:25:20 +0300
commit806f5fbfabd914d27ff3fb2e822e1c3869068859 (patch)
treecc805cfb7ef5af3d7e26075106d2663e5ca2dd67 /src/indieauth
parent14e58b4137f8f77af43cad8b712596c2e1ab7e8a (diff)
downloadkittybox-806f5fbfabd914d27ff3fb2e822e1c3869068859.tar.zst
Set MSRV to 1.75, remove #[async_trait] declarations whenever possible
Axum still uses `async_trait`, let them do whatever they want. I will
no longer be subject to the humiliation of trying to dig through
lifetime errors and unreadable declarations. Also I don't fucking care
about MSRV, I'm not a library. If you don't have modern Rust, get one.
Diffstat (limited to 'src/indieauth')
-rw-r--r--src/indieauth/backend.rs50
-rw-r--r--src/indieauth/backend/fs.rs2
2 files changed, 25 insertions, 27 deletions
diff --git a/src/indieauth/backend.rs b/src/indieauth/backend.rs
index 5814dc2..b913256 100644
--- a/src/indieauth/backend.rs
+++ b/src/indieauth/backend.rs
@@ -1,3 +1,4 @@
+use std::future::Future;
 use std::collections::HashMap;
 use kittybox_indieauth::{
     AuthorizationRequest, TokenData
@@ -9,10 +10,9 @@ type Result<T> = std::io::Result<T>;
 pub mod fs;
 pub use fs::FileBackend;
 
-#[async_trait::async_trait]
 pub trait AuthBackend: Clone + Send + Sync + 'static {
     /// Initialize self from URL, possibly performing initialization.
-    async fn new(url: &'_ url::Url) -> Result<Self>;
+    fn new(url: &'_ url::Url) -> impl Future<Output = Result<Self>> + Send;
     // Authorization code management.
     /// Create a one-time OAuth2 authorization code for the passed
     /// authorization request, and save it for later retrieval.
@@ -20,33 +20,33 @@ pub trait AuthBackend: Clone + Send + Sync + 'static {
     /// Note for implementors: the [`AuthorizationRequest::me`] value
     /// is guaranteed to be [`Some(url::Url)`][Option::Some] and can
     /// be trusted to be correct and non-malicious.
-    async fn create_code(&self, data: AuthorizationRequest) -> Result<String>;
+    fn create_code(&self, data: AuthorizationRequest) -> impl Future<Output = Result<String>> + Send;
     /// Retreive an authorization request using the one-time
     /// code. Implementations must sanitize the `code` field to
     /// prevent exploits, and must check if the code should still be
     /// valid at this point in time (validity interval is left up to
     /// the implementation, but is recommended to be no more than 10
     /// minutes).
-    async fn get_code(&self, code: &str) -> Result<Option<AuthorizationRequest>>;
+    fn get_code(&self, code: &str) -> impl Future<Output = Result<Option<AuthorizationRequest>>> + Send;
     // Token management.
-    async fn create_token(&self, data: TokenData) -> Result<String>;
-    async fn get_token(&self, website: &url::Url, token: &str) -> Result<Option<TokenData>>;
-    async fn list_tokens(&self, website: &url::Url) -> Result<HashMap<String, TokenData>>;
-    async fn revoke_token(&self, website: &url::Url, token: &str) -> Result<()>;
+    fn create_token(&self, data: TokenData) -> impl Future<Output = Result<String>> + Send;
+    fn get_token(&self, website: &url::Url, token: &str) -> impl Future<Output = Result<Option<TokenData>>> + Send;
+    fn list_tokens(&self, website: &url::Url) -> impl Future<Output = Result<HashMap<String, TokenData>>> + Send;
+    fn revoke_token(&self, website: &url::Url, token: &str) -> impl Future<Output = Result<()>> + Send;
     // Refresh token management.
-    async fn create_refresh_token(&self, data: TokenData) -> Result<String>;
-    async fn get_refresh_token(&self, website: &url::Url, token: &str) -> Result<Option<TokenData>>;
-    async fn list_refresh_tokens(&self, website: &url::Url) -> Result<HashMap<String, TokenData>>;
-    async fn revoke_refresh_token(&self, website: &url::Url, token: &str) -> Result<()>;
+    fn create_refresh_token(&self, data: TokenData) -> impl Future<Output = Result<String>> + Send;
+    fn get_refresh_token(&self, website: &url::Url, token: &str) -> impl Future<Output = Result<Option<TokenData>>> + Send;
+    fn list_refresh_tokens(&self, website: &url::Url) -> impl Future<Output = Result<HashMap<String, TokenData>>> + Send;
+    fn revoke_refresh_token(&self, website: &url::Url, token: &str) -> impl Future<Output = Result<()>> + Send;
     // Password management.
     /// Verify a password.
     #[must_use]
-    async fn verify_password(&self, website: &url::Url, password: String) -> Result<bool>;
+    fn verify_password(&self, website: &url::Url, password: String) -> impl Future<Output = Result<bool>> + Send;
     /// Enroll a password credential for a user. Only one password
     /// credential must exist for a given user.
-    async fn enroll_password(&self, website: &url::Url, password: String) -> Result<()>;
+    fn enroll_password(&self, website: &url::Url, password: String) -> impl Future<Output = Result<()>> + Send;
     /// List currently enrolled credential types for a given user.
-    async fn list_user_credential_types(&self, website: &url::Url) -> Result<Vec<EnrolledCredential>>;
+    fn list_user_credential_types(&self, website: &url::Url) -> impl Future<Output = Result<Vec<EnrolledCredential>>> + Send;
     // WebAuthn credential management.
     #[cfg(feature = "webauthn")]
     /// Enroll a WebAuthn authenticator public key for this user.
@@ -56,30 +56,30 @@ pub trait AuthBackend: Clone + Send + Sync + 'static {
     /// This function can also be used to overwrite a passkey with an
     /// updated version after using
     /// [webauthn::prelude::Passkey::update_credential()].
-    async fn enroll_webauthn(&self, website: &url::Url, credential: webauthn::prelude::Passkey) -> Result<()>;
+    fn enroll_webauthn(&self, website: &url::Url, credential: webauthn::prelude::Passkey) -> impl Future<Output = Result<()>> + Send;
     #[cfg(feature = "webauthn")]
     /// List currently enrolled WebAuthn authenticators for a given user.
-    async fn list_webauthn_pubkeys(&self, website: &url::Url) -> Result<Vec<webauthn::prelude::Passkey>>;
+    fn list_webauthn_pubkeys(&self, website: &url::Url) -> impl Future<Output = Result<Vec<webauthn::prelude::Passkey>>> + Send;
     #[cfg(feature = "webauthn")]
     /// Persist registration challenge state for a little while so it
     /// can be used later.
     ///
     /// Challenges saved in this manner MUST expire after a little
     /// while. 10 minutes is recommended.
-    async fn persist_registration_challenge(
+    fn persist_registration_challenge(
         &self,
         website: &url::Url,
         state: webauthn::prelude::PasskeyRegistration
-    ) -> Result<String>;
+    ) -> impl Future<Output = Result<String>> + Send;
     #[cfg(feature = "webauthn")]
     /// Retrieve a persisted registration challenge.
     ///
     /// The challenge should be deleted after retrieval.
-    async fn retrieve_registration_challenge(
+    fn retrieve_registration_challenge(
         &self,
         website: &url::Url,
         challenge_id: &str
-    ) -> Result<webauthn::prelude::PasskeyRegistration>;
+    ) -> impl Future<Output = Result<webauthn::prelude::PasskeyRegistration>> + Send;
     #[cfg(feature = "webauthn")]
     /// Persist authentication challenge state for a little while so
     /// it can be used later.
@@ -89,19 +89,19 @@ pub trait AuthBackend: Clone + Send + Sync + 'static {
     ///
     /// To support multiple authentication options, this can return an
     /// opaque token that should be set as a cookie.
-    async fn persist_authentication_challenge(
+    fn persist_authentication_challenge(
         &self,
         website: &url::Url,
         state: webauthn::prelude::PasskeyAuthentication
-    ) -> Result<String>;
+    ) -> impl Future<Output = Result<String>> + Send;
     #[cfg(feature = "webauthn")]
     /// Retrieve a persisted authentication challenge.
     ///
     /// The challenge should be deleted after retrieval.
-    async fn retrieve_authentication_challenge(
+    fn retrieve_authentication_challenge(
         &self,
         website: &url::Url,
         challenge_id: &str
-    ) -> Result<webauthn::prelude::PasskeyAuthentication>;
+    ) -> impl Future<Output = Result<webauthn::prelude::PasskeyAuthentication>> + Send;
 
 }
diff --git a/src/indieauth/backend/fs.rs b/src/indieauth/backend/fs.rs
index ce519da..f74fbbc 100644
--- a/src/indieauth/backend/fs.rs
+++ b/src/indieauth/backend/fs.rs
@@ -1,7 +1,6 @@
 use std::{path::PathBuf, collections::HashMap, borrow::Cow, time::{SystemTime, Duration}};
 
 use super::{AuthBackend, Result, EnrolledCredential};
-use async_trait::async_trait;
 use kittybox_indieauth::{
     AuthorizationRequest, TokenData
 };
@@ -186,7 +185,6 @@ impl FileBackend {
     }
 }
 
-#[async_trait]
 impl AuthBackend for FileBackend {
     async fn new(path: &'_ url::Url) -> Result<Self> {
         let orig_path = path;