-
Notifications
You must be signed in to change notification settings - Fork 77
Adapted for latest rand
APIs
#474
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
bt-hci = { version = "0.6" } | ||
embassy-futures = "0.1.1" | ||
embassy-sync = { version = "0.7" } | ||
embassy-sync = { version = "0.7" } # host-macros |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
marked the reason of existence for certain dependencies (here and static_cell
, heapless
, below).
pub mod ble_advertise; | ||
pub mod ble_advertise_multiple; | ||
pub mod ble_bas_central; | ||
#[cfg(feature = "security")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*_sec
were treated as feature-flagged, except here.
panic-probe = { version = "1.0", features = ["print-defmt"] } | ||
|
||
cortex-m = { version = "0.7.6" } | ||
chacha20 = { version = "0.10.0-rc.2", default-features = false, features = ["rng"], optional = true } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rand
0.10 changelog:
The dependency on
rand_chacha
has been replaced with a dependency onchacha20
.
Moved it upwards, to have the list in roughly alphabetical order (imho, a good idea). Do you agree with this, or should it be in-place of the earlier rand_core
?
chacha20 = { version = "0.10.0-rc.2", default-features = false, features = ["rng"], optional = true } | ||
cortex-m-rt = "0.7.0" | ||
rand = { version = "0.8.5", default-features = false } | ||
rand_core = { version = "0.9.3", default-features = false, optional = true } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rand_core
is interesting. crates.io for 0.9.3 states:
This crate is mainly of interest to crates publishing implementations of RngCore. Other users are encouraged to use the rand crate instead which re-exports the main traits and error types.
But the current README says it differently:
The main rand crate re-exports most items defined in this crate, along with tools [...] Most users should prefer to use the main rand crate.
I feel there's a justification for keeping rand_core
, if the code only needs the interface of the RNG's, and doesn't actually create random numbers. What do you think?
That's the approach I took here - nrf-sdc
- but in host
I've opted for rand
and use the interfaces as rand::rand_core::...
.
rand_core = "0.6" | ||
rand_chacha = { version = "0.3", default-features = false, optional = true } | ||
rand = { version="0.8", default-features = false, optional = true} | ||
p256 = { version = "0.14.0-pre.11", default-features = false, features = ["ecdh","arithmetic"], optional = true } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 0.14.0-pre.3
seems to be the release that has the rand
0.6 -> 0.9 upgrade.
This actually is the BIG THING about the PR. Whether we want to jump onto -pre
or wait until p256
0.14.0 proper has been released.
use heapless::Vec; | ||
use rand_core::{CryptoRng, RngCore}; | ||
#[cfg(feature = "security")] | ||
use rand::rand_core::{CryptoRng, RngCore}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: here, we could go on with the earlier lines, if rand_core
is added (alongside rand
), as a dependency to trouble-host
. It's a compromise between either:
- shorter code; two dependencies
- slightly longer code; just
rand
dep
The upstream seems to recomment going rand
only, but it's really our choice. Which way is better?
- please inform of the choice.
/// | ||
/// Only relevant if the feature `security` is enabled. | ||
pub fn set_io_capabilities(self, io_capabilities: IoCapabilities) -> Self { | ||
#[cfg(feature = "security")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved the conditional above the method name. This was made possible by making the security
feature handling more consistent, elsewhere.
Should be beneficial: one only needs to see such method signatures in IDE if the security
feature is enabled.
pairing_data.local_secret_ra = | ||
rng.sample(rand::distributions::Uniform::new_inclusive(0, 999999)); | ||
rng.sample(rand::distr::Uniform::new_inclusive(0, 999999).unwrap()); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, I chose to leave the original code (after API catch-up), but the rand
authors recommend:
Constructors may do extra work up front to allow faster sampling of multiple values. Where only a single sample is required it is suggested to use
Rng::random_range [...]"
.
Should we?
This comment was marked as outdated.
This comment was marked as outdated.
A bit about the status:
|
Issues unrelated to random/crypto are now in #476 . If we merge that in, I can remove them from this PR. |
/test |
8d76b38
to
9655720
Compare
/test |
…cludes changes to 'security' feature flags, making its use more consistent.
9655720
to
86e2aae
Compare
The version of
rand
used in the project has fallen behind, mainly due top256
still relying on the earlier version.I wanted to give it a try, and attached is a PR that:
rand
to0.10.0-rc.0
(currently latest)rand
(security
feature)The changes to 0.9.x were extensive, covering not only the API but the whole
rand
ecosystem, as well.I chose to push past the 0.9, since we already can see what the 0.10 API would look like. Happy to keep maintaining this, as a PR, until the 0.10 proper is released.
Some questions to authors in the comments below. I need guidance.
Discussed previously: #423