In many places we document how to import and pass OsRng, often providing a getrandom feature that re-exports rand_core.
Instead of that, we can add #[cfg(feature = "getrandom")]-gated functions which pass OsRng for you.
For example:
#[cfg(feature = "getrandom")]
use rand_core::OsRng;
impl PrivateKey {
pub fn generate(rng: &mut impl CryptoRngCore) -> Self { ... }
#[cfg(feature = "getrandom")]
pub fn generate_from_os_rng() -> Self {
Self::generate(&mut OsRng)
}
}
If we go this route, some questions:
- What should the convention for the
CryptoRng(Core)-parameterized methods be? We use both generate and random.
- What should the convention be for the
getrandom-gated wrapper which passes OsRng for you? Should we make that shorter to be more convenient?
- Should we enable
getrandom by default for even more convenience?