From 55de1402fdd82a9a74c9de19c40575e72fa6f786 Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Sat, 10 Jul 2021 11:50:17 -0600 Subject: [PATCH 1/2] aead: re-export `rand_core` This implements the changes proposed in #681 to simplify access to the `rand_core` traits and `OsRng`. `rand_core` is conditionally re-exported when the eponymous crate feature is enabled. Additionally, the `std` crate feature enables `rand_core/std`, which permits access to `OsRng` as `aead::rand_core::OsRng`. --- Cargo.lock | 20 ++++++++++++++++++++ aead/Cargo.toml | 4 +++- aead/src/lib.rs | 7 ++++++- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8d509c552..624cd8f19 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -304,6 +304,17 @@ dependencies = [ "version_check", ] +[[package]] +name = "getrandom" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "group" version = "0.10.0" @@ -424,6 +435,9 @@ name = "rand_core" version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" +dependencies = [ + "getrandom", +] [[package]] name = "rustc_version" @@ -603,6 +617,12 @@ dependencies = [ "vcell", ] +[[package]] +name = "wasi" +version = "0.10.2+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" + [[package]] name = "wyz" version = "0.4.0" diff --git a/aead/Cargo.toml b/aead/Cargo.toml index a0eda058c..7e69640ed 100644 --- a/aead/Cargo.toml +++ b/aead/Cargo.toml @@ -17,13 +17,15 @@ categories = ["cryptography", "no-std"] [dependencies] generic-array = { version = "0.14", default-features = false } +# optional dependencies blobby = { version = "0.3", optional = true } heapless = { version = "0.7", optional = true, default-features = false } rand_core = { version = "0.6", optional = true } [features] -std = ["alloc"] +default = ["rand_core"] alloc = [] +std = ["alloc", "rand_core/std"] dev = ["blobby"] stream = [] diff --git a/aead/src/lib.rs b/aead/src/lib.rs index 9ddcec352..0ff10d41f 100644 --- a/aead/src/lib.rs +++ b/aead/src/lib.rs @@ -40,10 +40,12 @@ pub mod stream; pub use generic_array::{self, typenum::consts}; #[cfg(feature = "heapless")] +#[cfg_attr(docsrs, doc(cfg(feature = "heapless")))] pub use heapless; #[cfg(feature = "rand_core")] -use rand_core::{CryptoRng, RngCore}; +#[cfg_attr(docsrs, doc(cfg(feature = "rand_core")))] +pub use rand_core; use core::fmt; use generic_array::{typenum::Unsigned, ArrayLength, GenericArray}; @@ -51,6 +53,9 @@ use generic_array::{typenum::Unsigned, ArrayLength, GenericArray}; #[cfg(feature = "alloc")] use alloc::vec::Vec; +#[cfg(feature = "rand_core")] +use rand_core::{CryptoRng, RngCore}; + /// Error type. /// /// This type is deliberately opaque as to avoid potential side-channel From 204631dbec90d92f197c96450e322436f0f08ecd Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Sat, 10 Jul 2021 13:08:39 -0700 Subject: [PATCH 2/2] Cargo.toml: remove default rand_core feature --- aead/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/aead/Cargo.toml b/aead/Cargo.toml index 7e69640ed..5660ff0ee 100644 --- a/aead/Cargo.toml +++ b/aead/Cargo.toml @@ -23,7 +23,6 @@ heapless = { version = "0.7", optional = true, default-features = false } rand_core = { version = "0.6", optional = true } [features] -default = ["rand_core"] alloc = [] std = ["alloc", "rand_core/std"] dev = ["blobby"]