Poll-based encrypt/decrypt/sign API support in asynchronous and synchronous call
Author: taikulawoCreated May 31, 2024Updated Jul 21, 2026
Checklist
- I've searched the issue tracker for similar requests https://github.com/rustls/rustls/issues/850#issuecomment-1544457213 https://github.com/rustls/rustls/issues/341 https://github.com/rustls/rustls/pull/1648 https://github.com/rustls/rustls/issues/1808 Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
Describe the solution you'd like https://docs.rs/rustls/latest/rustls/crypto/cipher/trait.MessageDecrypter.html
convert crypto api to poll based
from
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
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
Source: rustls/rustls