Skip to content

Commit 8c455f5

Browse files
authored
Make rand_core optional (#262)
* Make rand_core optional * Bench requires features rand_core
1 parent b5dc40b commit 8c455f5

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

.github/workflows/rust.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ jobs:
3030
- run: cargo test --target ${{ matrix.target }} --no-default-features --features alloc --lib
3131
- run: cargo test --target ${{ matrix.target }}
3232
- run: cargo test --target ${{ matrix.target }} --features batch
33+
- run: cargo test --target ${{ matrix.target }} --features rand_core
3334
- run: cargo test --target ${{ matrix.target }} --features serde
3435
- run: cargo test --target ${{ matrix.target }} --features pem
3536

Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ sha2 = { version = "0.10", default-features = false }
3434
zeroize = { version = "1.5", default-features = false, optional = true }
3535

3636
[dev-dependencies]
37+
curve25519-dalek = { version = "=4.0.0-pre.5", default-features = false, features = ["digest", "rand_core"] }
3738
hex = "0.4"
3839
bincode = "1.0"
3940
serde_json = "1.0"
@@ -43,14 +44,14 @@ rand = "0.8"
4344
rand_core = { version = "0.6.4", default-features = false }
4445
serde = { version = "1.0", features = ["derive"] }
4546
toml = { version = "0.5" }
46-
curve25519-dalek = { version = "=4.0.0-pre.5", default-features = false, features = ["digest", "rand_core"] }
4747

4848
[[bench]]
4949
name = "ed25519_benchmarks"
5050
harness = false
51+
required-features = ["rand_core"]
5152

5253
[features]
53-
default = ["std", "rand_core", "zeroize"]
54+
default = ["std", "zeroize"]
5455
alloc = ["curve25519-dalek/alloc", "ed25519/alloc", "serde?/alloc", "zeroize/alloc"]
5556
std = ["alloc", "ed25519/std", "serde?/std", "sha2/std"]
5657

@@ -60,6 +61,7 @@ batch = ["alloc", "merlin", "rand_core"]
6061
legacy_compatibility = []
6162
pkcs8 = ["ed25519/pkcs8"]
6263
pem = ["alloc", "ed25519/pem", "pkcs8"]
64+
rand_core = ["dep:rand_core"]
6365
serde = ["dep:serde", "serde_bytes", "ed25519/serde"]
6466
zeroize = ["dep:zeroize", "curve25519-dalek/zeroize"]
6567

src/signing.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#[cfg(feature = "pkcs8")]
1313
use ed25519::pkcs8::{self, DecodePrivateKey};
1414

15-
#[cfg(feature = "rand_core")]
15+
#[cfg(any(test, feature = "rand_core"))]
1616
use rand_core::CryptoRngCore;
1717

1818
#[cfg(feature = "serde")]
@@ -183,7 +183,7 @@ impl SigningKey {
183183
/// The standard hash function used for most ed25519 libraries is SHA-512,
184184
/// which is available with `use sha2::Sha512` as in the example above.
185185
/// Other suitable hash functions include Keccak-512 and Blake2b-512.
186-
#[cfg(feature = "rand_core")]
186+
#[cfg(any(test, feature = "rand_core"))]
187187
pub fn generate<R: CryptoRngCore + ?Sized>(csprng: &mut R) -> SigningKey {
188188
let mut secret = SecretKey::default();
189189
csprng.fill_bytes(&mut secret);
@@ -208,7 +208,8 @@ impl SigningKey {
208208
///
209209
/// # Examples
210210
///
211-
/// ```
211+
#[cfg_attr(feature = "rand_core", doc = "```")]
212+
#[cfg_attr(not(feature = "rand_core"), doc = "```ignore")]
212213
/// use ed25519_dalek::Digest;
213214
/// use ed25519_dalek::SigningKey;
214215
/// use ed25519_dalek::Sha512;

tests/ed25519.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ use ed25519_dalek::*;
1616
use hex::FromHex;
1717
use hex_literal::hex;
1818

19-
#[cfg(feature = "rand_core")]
20-
use sha2::Sha512;
21-
2219
#[cfg(test)]
2320
mod vectors {
2421
use super::*;
@@ -285,6 +282,7 @@ mod vectors {
285282
mod integrations {
286283
use super::*;
287284
use rand::rngs::OsRng;
285+
use sha2::Sha512;
288286

289287
#[test]
290288
fn sign_verify() {

0 commit comments

Comments
 (0)