Replace `Error::*Error(String)` with non-heap-allocating localizable enum variants
@ctz is already working on this.
Since Jan 17, 2023.
- Dominant language
- Rust
- Stars
- 7.6k
- Forks
- 896
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 39
Description
There are many places where we do things like this:
return Err(Error::General("No end-entity certificate in certificate chain".to_string()));
and
return Err(Error::PeerMisbehavedError("client sent wrong binder".to_string()));
Each of these does a heap allocation. There are many reasons why we want to reduce heap allocations in Rustls.
The most straightforward way of eliminating these allocations would be to use &'static str; this would also eliminate any possibility of (secret) application data getting into the strings. If that weren't practical, Cow<'static, str> would be another alternative.
However, in both of those cases, we're stuck with English strings in the error messages. We might as well replace the strings with an enum like this:
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum PeerMisbehavedError {
NoEndEntityCertificateInCertificateChain,
...
}
In the case of General, instead of creating a new enum, we might just add the enum variants to Error itself.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.