Replace `Error::*Error(String)` with non-heap-allocating localizable enum variants

Open
#889 2 comments 2 reactions 1 assignee View on GitHub

Maintainers usually reply within 1 day

@ctz is already working on this.

Since Jan 17, 2023.

Assessment

This issue has not been assessed yet.

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.

Dominant language
Rust
Stars
7.7k
Forks
947
Avg merge
3d 11h
Merged PRs (30d)
46

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from rustls/rustls

All issues in rustls/rustls

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.