#1976·rustls

Poll-based encrypt/decrypt/sign API support in asynchronous and synchronous call

Author: taikulawoCreated May 31, 2024Updated Jul 21, 2026

Checklist

Describe the solution you'd like https://docs.rs/rustls/latest/rustls/crypto/cipher/trait.MessageDecrypter.html

convert crypto api to poll based

from

rust
pub trait MessageDecrypter: Send + Sync {
    /// Decrypt the given TLS message `msg`, using the sequence number
    /// `seq` which can be used to derive a unique [`Nonce`].
    fn decrypt<'a>(
        &mut self,
        msg: InboundOpaqueMessage<'a>,
        seq: u64,
    ) -> Result<InboundPlainMessage<'a>, Error>;
}

to

rust
pub trait MessageDecrypter: Send + Sync {
    /// Decrypt the given TLS message `msg`, using the sequence number
    /// `seq` which can be used to derive a unique [`Nonce`].
    fn decrypt<'a>(
        &mut self,
        cx: &mut Context<'a>,
        msg: InboundOpaqueMessage<'a>,
        seq: u64,
    ) -> Result<InboundPlainMessage<'a>, Error>;
}

so that we can call tokio#poll_read to make encrypt/decrypt async

every encrypt/decrypt should call through trait, so we can hack it

Additional context rustls only support poll method. user decide whether sync or async. If sync, just do and return Poll::Ready