hyperlane-plugin-auth 23.3.0

A zero-external-crypto-dependency authentication and RBAC plugin for the Hyperlane framework providing pure-Rust HS256 JWT with kid rotation, API key and HTTP Basic authenticators, extensible async Authenticator traits, and constant-time verification.
Documentation
use super::*;

/// Pluggable asynchronous authenticator resolving a Hyperlane [`Context`] into an [`AuthPrincipal`].
pub trait Authenticator: Send + Sync + 'static {
    /// Authenticates the incoming request represented by `ctx`.
    ///
    /// # Arguments
    ///
    /// - `&'a self` - Shared reference to self.
    /// - `&'a Context` - Incoming request context.
    ///
    /// # Returns
    ///
    /// - `AuthFuture<'a>` - Future resolving to the verified [`AuthPrincipal`] or [`AuthError`].
    fn authenticate<'a>(&'a self, ctx: &'a Context) -> AuthFuture<'a>;

    /// Optional zero-allocation synchronous fast path for non-blocking authenticators.
    ///
    /// Returning `Some(result)` bypasses `Box::pin` future allocation on the hot request path.
    /// Returning `None` falls back to [`Authenticator::authenticate`].
    ///
    /// # Arguments
    ///
    /// - `&Self` - Shared reference to self.
    /// - `&Context` - Incoming request context.
    ///
    /// # Returns
    ///
    /// - `Option<Result<AuthPrincipal, AuthError>>` - Synchronous authentication result when available.
    #[inline(always)]
    fn authenticate_sync(&self, _ctx: &Context) -> Option<Result<AuthPrincipal, AuthError>> {
        None
    }
}