make `rand` crate optional
This commit is contained in:
parent
dba0d67912
commit
298929600b
|
@ -26,10 +26,14 @@ default = []
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
|
rand = "0.3"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rand = "0.3"
|
|
||||||
libc = "0.2"
|
libc = "0.2"
|
||||||
rustc-serialize = "0.3"
|
rustc-serialize = "0.3"
|
||||||
serde = "1.0"
|
serde = "1.0"
|
||||||
|
|
||||||
|
[dependencies.rand]
|
||||||
|
version = "0.3"
|
||||||
|
optional = true
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
//! # Public and secret keys
|
//! # Public and secret keys
|
||||||
|
|
||||||
use std::marker;
|
use std::marker;
|
||||||
use rand::Rng;
|
#[cfg(any(test, feature = "rand"))] use rand::Rng;
|
||||||
use serialize::{Decoder, Decodable, Encoder, Encodable};
|
use serialize::{Decoder, Decodable, Encoder, Encodable};
|
||||||
use serde::{Serialize, Deserialize, Serializer, Deserializer};
|
use serde::{Serialize, Deserialize, Serializer, Deserializer};
|
||||||
|
|
||||||
|
@ -54,6 +54,7 @@ pub const ONE_KEY: SecretKey = SecretKey([0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
pub struct PublicKey(ffi::PublicKey);
|
pub struct PublicKey(ffi::PublicKey);
|
||||||
|
|
||||||
|
|
||||||
|
#[cfg(any(test, feature = "rand"))]
|
||||||
fn random_32_bytes<R: Rng>(rng: &mut R) -> [u8; 32] {
|
fn random_32_bytes<R: Rng>(rng: &mut R) -> [u8; 32] {
|
||||||
let mut ret = [0u8; 32];
|
let mut ret = [0u8; 32];
|
||||||
rng.fill_bytes(&mut ret);
|
rng.fill_bytes(&mut ret);
|
||||||
|
@ -63,6 +64,7 @@ fn random_32_bytes<R: Rng>(rng: &mut R) -> [u8; 32] {
|
||||||
impl SecretKey {
|
impl SecretKey {
|
||||||
/// Creates a new random secret key
|
/// Creates a new random secret key
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[cfg(any(test, feature = "rand"))]
|
||||||
pub fn new<R: Rng>(secp: &Secp256k1, rng: &mut R) -> SecretKey {
|
pub fn new<R: Rng>(secp: &Secp256k1, rng: &mut R) -> SecretKey {
|
||||||
let mut data = random_32_bytes(rng);
|
let mut data = random_32_bytes(rng);
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
|
@ -39,16 +39,16 @@
|
||||||
#![cfg_attr(all(test, feature = "unstable"), feature(test))]
|
#![cfg_attr(all(test, feature = "unstable"), feature(test))]
|
||||||
#[cfg(all(test, feature = "unstable"))] extern crate test;
|
#[cfg(all(test, feature = "unstable"))] extern crate test;
|
||||||
#[cfg(test)] extern crate serde_json as json;
|
#[cfg(test)] extern crate serde_json as json;
|
||||||
|
#[cfg(any(test, feature = "rand"))] extern crate rand;
|
||||||
|
|
||||||
extern crate rustc_serialize as serialize;
|
extern crate rustc_serialize as serialize;
|
||||||
extern crate serde;
|
extern crate serde;
|
||||||
|
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
extern crate rand;
|
|
||||||
|
|
||||||
use libc::size_t;
|
use libc::size_t;
|
||||||
use std::{error, fmt, ops, ptr};
|
use std::{error, fmt, ops, ptr};
|
||||||
use rand::Rng;
|
#[cfg(any(test, feature = "rand"))] use rand::Rng;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod macros;
|
mod macros;
|
||||||
|
@ -519,6 +519,7 @@ impl Secp256k1 {
|
||||||
|
|
||||||
/// (Re)randomizes the Secp256k1 context for cheap sidechannel resistence;
|
/// (Re)randomizes the Secp256k1 context for cheap sidechannel resistence;
|
||||||
/// see comment in libsecp256k1 commit d2275795f by Gregory Maxwell
|
/// see comment in libsecp256k1 commit d2275795f by Gregory Maxwell
|
||||||
|
#[cfg(any(test, feature = "rand"))]
|
||||||
pub fn randomize<R: Rng>(&mut self, rng: &mut R) {
|
pub fn randomize<R: Rng>(&mut self, rng: &mut R) {
|
||||||
let mut seed = [0; 32];
|
let mut seed = [0; 32];
|
||||||
rng.fill_bytes(&mut seed);
|
rng.fill_bytes(&mut seed);
|
||||||
|
@ -540,6 +541,7 @@ impl Secp256k1 {
|
||||||
/// and `key::PublicKey::from_secret_key`; call those functions directly for
|
/// and `key::PublicKey::from_secret_key`; call those functions directly for
|
||||||
/// batch key generation. Requires a signing-capable context.
|
/// batch key generation. Requires a signing-capable context.
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[cfg(any(test, feature = "rand"))]
|
||||||
pub fn generate_keypair<R: Rng>(&self, rng: &mut R)
|
pub fn generate_keypair<R: Rng>(&self, rng: &mut R)
|
||||||
-> Result<(key::SecretKey, key::PublicKey), Error> {
|
-> Result<(key::SecretKey, key::PublicKey), Error> {
|
||||||
let sk = key::SecretKey::new(self, rng);
|
let sk = key::SecretKey::new(self, rng);
|
||||||
|
|
Loading…
Reference in New Issue