Trait rocket::tls::Resolver

source ·
pub trait Resolver:
    Send
    + Sync
    + 'static {
    // Required method
    fn resolve<'life0, 'life1, 'async_trait>(
        &'life0 self,
        hello: ClientHello<'life1>,
    ) -> Pin<Box<dyn Future<Output = Option<Arc<ServerConfig>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;

    // Provided methods
    fn init<'life0, 'async_trait>(
        rocket: &'life0 Rocket<Build>,
    ) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>
       where Self: Sized + 'async_trait,
             'life0: 'async_trait { ... }
    fn fairing() -> Fairing<Self>
       where Self: Sized { ... }
}
Available on crate feature tls only.
Expand description

A dynamic TLS configuration resolver.

§Example

This is an async trait. Implement it as follows:

use std::sync::Arc;
use rocket::tls::{self, Resolver, TlsConfig, ClientHello, ServerConfig};
use rocket::{Rocket, Build};

struct MyResolver(Arc<ServerConfig>);

#[rocket::async_trait]
impl Resolver for MyResolver {
    async fn init(rocket: &Rocket<Build>) -> tls::Result<Self> {
        // This is equivalent to what the default resolver would do.
        let config: TlsConfig = rocket.figment().extract_inner("tls")?;
        let server_config = config.server_config().await?;
        Ok(MyResolver(Arc::new(server_config)))
    }

    async fn resolve(&self, hello: ClientHello<'_>) -> Option<Arc<ServerConfig>> {
        // return a `ServerConfig` based on `hello`; here we ignore it
        Some(self.0.clone())
    }
}

#[launch]
fn rocket() -> _ {
    rocket::build().attach(MyResolver::fairing())
}

Required Methods§

source

fn resolve<'life0, 'life1, 'async_trait>( &'life0 self, hello: ClientHello<'life1>, ) -> Pin<Box<dyn Future<Output = Option<Arc<ServerConfig>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Provided Methods§

source

fn init<'life0, 'async_trait>( rocket: &'life0 Rocket<Build>, ) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>
where Self: Sized + 'async_trait, 'life0: 'async_trait,

source

fn fairing() -> Fairing<Self>
where Self: Sized,

Implementors§