Skip to content

Commit

Permalink
fixup! Add riot-rs-random crate and corresponding initialization
Browse files Browse the repository at this point in the history
This addresses coding convention violations
  • Loading branch information
chrysn committed Apr 11, 2024
1 parent 70dd595 commit a8b8f08
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/riot-rs-random/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@

use rand_core::{RngCore, SeedableRng};

// The Mutex<RefCell> can probably be simplified
static RNG: embassy_sync::blocking_mutex::Mutex<
embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex,
core::cell::RefCell<Option<Rng>>,
> = embassy_sync::blocking_mutex::Mutex::new(core::cell::RefCell::new(None));

// This is one of the points where we can tune easily. If calls to `get_rng()` are rare, it may
// even make sense to move the HWRNG in here to get a global ZST.
// #[cfg(feature = "main-is-csprng")]
Expand Down Expand Up @@ -80,20 +86,14 @@ impl RngCore for Rng {
mod main_is_csprng {
impl rand_core::CryptoRng for super::Rng {}

/// Assert that SelectedRng is CryptoRng, justifying the implementation above.
/// Asserts that SelectedRng is CryptoRng, justifying the implementation above.
fn static_assert_is_cryptorng() -> impl rand_core::CryptoRng {
let result: super::SelectedRng = unreachable!("This function is for type checking only");
result
}
}

// The Mutex<RefCell> can probably be simplified
static RNG: embassy_sync::blocking_mutex::Mutex<
embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex,
core::cell::RefCell<Option<Rng>>,
> = embassy_sync::blocking_mutex::Mutex::new(core::cell::RefCell::new(None));

/// Populate the RNG from a seed value.
/// Populates the RNG from a seed value.
///
/// This is called by RIOT-rs's initialization functions.
pub fn construct_rng(hwrng: impl RngCore) {
Expand All @@ -104,7 +104,7 @@ pub fn construct_rng(hwrng: impl RngCore) {
});
}

/// Obtain a suitably initialized random number generator
/// Obtains a suitably initialized random number generator.
///
/// This may be used by threads or tasks. To avoid synchronizion overhead, in the future,
/// dependency injection for task and thread generation might be provided through the riot-rs
Expand Down

0 comments on commit a8b8f08

Please sign in to comment.