default crypto provider improvements#2089
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2089 +/- ##
=======================================
Coverage 94.63% 94.63%
=======================================
Files 102 102
Lines 23400 23408 +8
=======================================
+ Hits 22145 22153 +8
Misses 1255 1255 ☔ View full report in Codecov by Sentry. |
Benchmark resultsInstruction countsSignificant differencesThere are no significant instruction count differences Other differencesClick to expand
Wall-timeSignificant differencesThere are no significant wall-time differences Other differencesClick to expand
Additional informationCheckout details:
|
|
Having not reviewed #2088 yet I think I'd appreciate some elaboration in the accompanying text to help this change set stand alone. At the moment the commit message only says "default crypto provider improvements" and doesn't get into any motivation or enumerate any improvements. Similarly the PR description says it makes it easier to configure the provider in 2088, but doesn't expand on how. The actual mechanics of the diff seem reasonable (once djc's feedback is addressed). |
|
With the one clarification that I requested. all suggestions sounds good. I will try to get this proposal fixed within the next 1-2 days. Thanks! |
62bc348 to
45ebcf1
Compare
|
I have now updated the description, rebased, and included some more info in the commit message to include the details of the what & why (with |
c34c7cd to
36e39ef
Compare
96eaf28 to
fb1e514
Compare
be9bd9f to
ffe5ba4
Compare
|
@djc thanks for taking the time to review this! I may need a few days to go through your comments.... I would like to quote myself from what I wrote in both the updated PR description & in the updated commit message in terms of general motivation - please let me know if my motivation or any part of my motivation does not sound clear enough:
|
@brodycj Checking in on this PR: will you have time to address Djc's feedback? |
3302836 to
a8f18e3
Compare
|
I have now addressed @djc most recent comments & rebased into a clean commit, with an updated commit message that contains the updated justification. Heads up that I will likely unplug for the rest of this week due to a religious holiday. Thanks! |
| #[cfg(not(feature = "std"))] | ||
| pub(crate) fn install_default( | ||
| default_provider: CryptoProvider, | ||
| ) -> Result<(), Arc<CryptoProvider>> { |
There was a problem hiding this comment.
Is changing this return type from Result<(), Box<Arc<Self>>> a breaking change for no-std users? It feels like yes.
There was a problem hiding this comment.
I think so, but it fixes the feature-controlled breaking change which I would argue is kind of worse.
There was a problem hiding this comment.
True, and I think the no-std userbase is very small at this point.
- add & use inline module to manage default crypto provider within `rustls/src/crypto/mod.rs` - fix `rustls::crypto::CryptoProvider::install_default` fn to return consistent result type with both `std` & `no-std` build config --- WHY This refactoring & cleanup would help make it easier to update & maintain the code that manages the default crypto provider. The code needed to store the default crypto provider already depends on the build environment, requiring `#[cfg(...)` statements sprinkled through some of the existing import statements, `rustls::crypto::CryptoProvider` API functions, and configuration-specific static variables in `rustls/src/crypto/mod.rs`. This issue with the various bits of conditional code is expected to compound as more build options are added over time, for example: - replace `alloc::arc::Arc` with `alloc::rc::Rc`, with help from some type aliasing, to help support targets with non-atomic pointers - option to use `once_cell` with `portable-atomic` & `critical-section` crate options, as may be needed to support non-atomic pointers - and it should be possible to turn this option off in case there may be a more performant solution for certain build targets Moving the default crypto provider functionality into an internal module would simplify the ability to keep or remove this functionality depending on the build target. This refactoring should offer some further benefits, regardless of these anticipated updated: - improve readability of the default crypto provider code in general - improve `rustls::crypto::CryptoProvider::install_default` API consistency for `std` vs `non-std` build config in general
81c25bc to
f3c7813
Compare
|
rebased again with a few more updates & fixes:
|
|
Thanks! |
WHAT (updated)
rustls/src/crypto/mod.rsrustls::crypto::CryptoProvider::install_default()to return consistent result type with bothstd&no-stdbuild configuseOption:: unwrap_or_else()to shorten an internal functionrename some default crypto provider test functions (I would like to pull these out of PR ALT DRAFT RFC: add option to use alloc::rc::Rc for no-std targets w/o built-in atomic ops - INITIAL HACK #2088)WHY - UPDATED:
SEE PR: #2088 & ISSUE #2068
This refactoring & cleanup would help make it easier to update & maintain the code that manages the default crypto provider.
The code needed to store the default crypto provider already depends on the build environment, requiring
#[cfgstatements sprinkled through some of the existing import statements,rustls::crypto::CryptoProviderAPI functions, and configuration-specific static variables inrustls/src/crypto/mod.rs.This issue with the various bits of conditional code is expected to compound as more build options are added over time, for example:
alloc::arc::Arcwithalloc::rc::Rc, with help from some type aliasing, to help support targets with non-atomic pointersonce_cellwithportable-atomic&critical-sectioncrate options, as needed to support non-atomic pointers - and it should be possible to turn this option off in case there may be a more performant solution for certain build targetsIn case of an embedded target with no atomic pointers or references, it would not be possible to build any part of this library usingalloc::arc::Arc, and another solution such as usingalloc::rc::Rcwould be needed instead. For example, a type alias could be used to usealloc::rc::Rcin place ofArc(alloc::arc::Arc).In this case, it would not be possible to support the existing default crypto provider API as it is depending on theSend & Syncsupport. Assuming that the existing default crypto provider API will be preserved, we would need to use acfgdirective to disable this default crypto provider functionality in this case. This would involve integratingcfgdirective updates with some previously existingcfgdirectives in multiple places, becoming harder & harder to read, understand, and maintain.Moving the default crypto provider functionality into an internal module would simplify the ability to keep or remove this functionality depending on the build target.
I think this refactoring should offer some further benefits, regardless of these anticipated updated:
rustls::crypto::CryptoProvider::install_defaultAPI consistency forstdvsnon-stdbuild config in general