From aa3213a5ad436a3aa9b02e72376731c0b33e83ed Mon Sep 17 00:00:00 2001
From: librelois <elois@ifee.fr>
Date: Fri, 21 Feb 2020 22:03:52 +0100
Subject: [PATCH] [ref] rand: make the rand module an optional feature

---
 Cargo.toml          | 3 ++-
 src/hashs/mod.rs    | 3 +++
 src/keys/ed25519.rs | 2 ++
 src/lib.rs          | 1 +
 src/seeds.rs        | 4 ++++
 5 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/Cargo.toml b/Cargo.toml
index b0ac1af..93abfbc 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -29,8 +29,9 @@ zeroize = { version = "1.1.0", features = ["zeroize_derive"] }
 bincode = "1.2.0"
 
 [features]
-default = ["dewif", "ser"]
+default = ["dewif", "rand", "ser"]
 
 aes256 = ["aes"]
 dewif = ["aes256", "arrayvec"]
+rand = []
 ser = ["serde"]
diff --git a/src/hashs/mod.rs b/src/hashs/mod.rs
index 8268083..a89af43 100644
--- a/src/hashs/mod.rs
+++ b/src/hashs/mod.rs
@@ -16,6 +16,7 @@
 //! Provide wrappers for cryptographic hashs
 
 use crate::bases::*;
+#[cfg(feature = "rand")]
 use crate::rand::UnspecifiedRandError;
 use ring::digest;
 #[cfg(feature = "ser")]
@@ -57,6 +58,7 @@ impl Hash {
     /// Hash size (in bytes).
     pub const SIZE_IN_BYTES: usize = 32;
 
+    #[cfg(feature = "rand")]
     /// Generate a random Hash
     #[inline]
     pub fn random() -> Result<Self, UnspecifiedRandError> {
@@ -102,6 +104,7 @@ mod tests {
 
     use super::*;
 
+    #[cfg(feature = "rand")]
     #[test]
     fn test_hash_random() {
         let hash1 = Hash::random();
diff --git a/src/keys/ed25519.rs b/src/keys/ed25519.rs
index c269748..e6690a0 100644
--- a/src/keys/ed25519.rs
+++ b/src/keys/ed25519.rs
@@ -23,6 +23,7 @@ use super::PublicKey as PublicKeyMethods;
 use super::{PubkeyFromBytesError, SigError};
 use crate::bases::b58::{bytes_to_str_base58, ToBase58};
 use crate::bases::*;
+#[cfg(feature = "rand")]
 use crate::rand::UnspecifiedRandError;
 use crate::seeds::Seed32;
 use base64;
@@ -278,6 +279,7 @@ pub struct Ed25519KeyPair {
 }
 
 impl Ed25519KeyPair {
+    #[cfg(feature = "rand")]
     /// Generate random keypair
     pub fn generate_random() -> Result<Self, UnspecifiedRandError> {
         Ok(KeyPairFromSeed32Generator::generate(Seed32::random()?))
diff --git a/src/lib.rs b/src/lib.rs
index 7793628..0eeb19e 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -38,5 +38,6 @@ pub mod bases;
 pub mod dewif;
 pub mod hashs;
 pub mod keys;
+#[cfg(feature = "rand")]
 pub mod rand;
 pub mod seeds;
diff --git a/src/seeds.rs b/src/seeds.rs
index 089c26c..c94b9ca 100644
--- a/src/seeds.rs
+++ b/src/seeds.rs
@@ -17,6 +17,7 @@
 
 use crate::bases::b58::{bytes_to_str_base58, ToBase58};
 use crate::bases::*;
+#[cfg(feature = "rand")]
 use crate::rand::UnspecifiedRandError;
 #[cfg(feature = "ser")]
 use serde::{Deserialize, Serialize};
@@ -64,6 +65,7 @@ impl Seed32 {
     pub fn from_base58(base58_str: &str) -> Result<Self, BaseConvertionError> {
         Ok(Seed32::new(b58::str_base58_to_32bytes(base58_str)?.0))
     }
+    #[cfg(feature = "rand")]
     #[inline]
     /// Generate random seed
     pub fn random() -> Result<Seed32, UnspecifiedRandError> {
@@ -75,8 +77,10 @@ impl Seed32 {
 #[cfg(test)]
 mod tests {
 
+    #[cfg(feature = "rand")]
     use super::*;
 
+    #[cfg(feature = "rand")]
     #[test]
     fn test_gen_random_seed() {
         assert_ne!(Seed32::random(), Seed32::random());
-- 
GitLab