hyperlane_plugin_auth/trait.rs
1use super::*;
2
3/// Pluggable asynchronous authenticator resolving a Hyperlane [`Context`] into an [`AuthPrincipal`].
4pub trait Authenticator: Send + Sync + 'static {
5 /// Authenticates the incoming request represented by `ctx`.
6 ///
7 /// # Arguments
8 ///
9 /// - `&'a self` - Shared reference to self.
10 /// - `&'a Context` - Incoming request context.
11 ///
12 /// # Returns
13 ///
14 /// - `AuthFuture<'a>` - Future resolving to the verified [`AuthPrincipal`] or [`AuthError`].
15 fn authenticate<'a>(&'a self, ctx: &'a Context) -> AuthFuture<'a>;
16
17 /// Optional zero-allocation synchronous fast path for non-blocking authenticators.
18 ///
19 /// Returning `Some(result)` bypasses `Box::pin` future allocation on the hot request path.
20 /// Returning `None` falls back to [`Authenticator::authenticate`].
21 ///
22 /// # Arguments
23 ///
24 /// - `&Self` - Shared reference to self.
25 /// - `&Context` - Incoming request context.
26 ///
27 /// # Returns
28 ///
29 /// - `Option<Result<AuthPrincipal, AuthError>>` - Synchronous authentication result when available.
30 #[inline(always)]
31 fn authenticate_sync(&self, _ctx: &Context) -> Option<Result<AuthPrincipal, AuthError>> {
32 None
33 }
34}