Merge pull request #64 from michalkucharczyk/mku-use-reexports-fix
Use rand crate re-exports when available
This commit is contained in:
commit
a4c57cb84c
11
src/lib.rs
11
src/lib.rs
|
@ -48,6 +48,13 @@ pub extern crate serde;
|
||||||
use alloc::{borrow::Cow, string::ToString, vec::Vec};
|
use alloc::{borrow::Cow, string::ToString, vec::Vec};
|
||||||
use core::{fmt, str};
|
use core::{fmt, str};
|
||||||
|
|
||||||
|
/// We support a wide range of dependency versions for `rand` and `rand_core` and not
|
||||||
|
/// all versions play nicely together. These re-exports fix that.
|
||||||
|
#[cfg(all(feature = "rand", feature = "rand_core"))]
|
||||||
|
use rand::{CryptoRng, RngCore};
|
||||||
|
#[cfg(all(not(feature = "rand"), feature = "rand_core"))]
|
||||||
|
use rand_core::{CryptoRng, RngCore};
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
use std::error;
|
use std::error;
|
||||||
|
|
||||||
|
@ -263,7 +270,7 @@ impl Mnemonic {
|
||||||
word_count: usize,
|
word_count: usize,
|
||||||
) -> Result<Mnemonic, Error>
|
) -> Result<Mnemonic, Error>
|
||||||
where
|
where
|
||||||
R: rand_core::RngCore + rand_core::CryptoRng,
|
R: RngCore + CryptoRng,
|
||||||
{
|
{
|
||||||
if is_invalid_word_count(word_count) {
|
if is_invalid_word_count(word_count) {
|
||||||
return Err(Error::BadWordCount(word_count));
|
return Err(Error::BadWordCount(word_count));
|
||||||
|
@ -271,7 +278,7 @@ impl Mnemonic {
|
||||||
|
|
||||||
let entropy_bytes = (word_count / 3) * 4;
|
let entropy_bytes = (word_count / 3) * 4;
|
||||||
let mut entropy = [0u8; (MAX_NB_WORDS / 3) * 4];
|
let mut entropy = [0u8; (MAX_NB_WORDS / 3) * 4];
|
||||||
rand_core::RngCore::fill_bytes(rng, &mut entropy[0..entropy_bytes]);
|
RngCore::fill_bytes(rng, &mut entropy[0..entropy_bytes]);
|
||||||
Mnemonic::from_entropy_in(language, &entropy[0..entropy_bytes])
|
Mnemonic::from_entropy_in(language, &entropy[0..entropy_bytes])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue