Skip to content

Commit

Permalink
Change std::rand to just rand::, though there is still a 'unimplement…
Browse files Browse the repository at this point in the history
…ed trait' error :/
  • Loading branch information
apoelstra committed Mar 25, 2015
1 parent d2fcbbe commit 7bd2461
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use std::intrinsics::copy_nonoverlapping;
use std::cmp;
use std::fmt;
use std::rand::Rng;
use rand::Rng;
use serialize::{Decoder, Decodable, Encoder, Encodable};

use crypto::digest::Digest;
Expand Down
26 changes: 14 additions & 12 deletions src/secp256k1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@
extern crate crypto;

extern crate libc;
extern crate rand;
extern crate serialize;
extern crate test;

use std::intrinsics::copy_nonoverlapping;
use std::io;
use std::rand::{OsRng, Rng, SeedableRng};
use std::rand::OsRng;
use std::sync::{Once, ONCE_INIT};
use libc::c_int;
use rand::{Rng, SeedableRng};

use crypto::fortuna::Fortuna;

Expand Down Expand Up @@ -272,8 +274,8 @@ impl Secp256k1 {
#[cfg(test)]
mod tests {
use std::iter::repeat;
use std::rand;
use std::rand::Rng;
use std::rand::thread_rng;
use rand::Rng;

use test::{Bencher, black_box};

Expand All @@ -287,7 +289,7 @@ mod tests {
let sig = Signature::from_slice(&[0; 72]).unwrap();
let pk = PublicKey::new(true);

rand::thread_rng().fill_bytes(msg.as_mut_slice());
thread_rng().fill_bytes(msg.as_mut_slice());

assert_eq!(Secp256k1::verify(msg.as_mut_slice(), &sig, &pk), Err(InvalidPublicKey));
}
Expand All @@ -301,7 +303,7 @@ mod tests {
let mut msg: Vec<u8> = repeat(0).take(32).collect();
let sig = Signature::from_slice(&[0; 72]).unwrap();

rand::thread_rng().fill_bytes(msg.as_mut_slice());
thread_rng().fill_bytes(msg.as_mut_slice());

assert_eq!(Secp256k1::verify(msg.as_mut_slice(), &sig, &pk), Err(InvalidSignature));
}
Expand All @@ -314,7 +316,7 @@ mod tests {
let mut msg: Vec<u8> = repeat(0).take(32).collect();
let sig = Signature::from_slice(&[0; 72]).unwrap();

rand::thread_rng().fill_bytes(msg.as_mut_slice());
thread_rng().fill_bytes(msg.as_mut_slice());

assert_eq!(Secp256k1::verify(msg.as_mut_slice(), &sig, &pk), Err(InvalidSignature));
}
Expand All @@ -324,7 +326,7 @@ mod tests {
let mut s = Secp256k1::new().unwrap();

let mut msg = [0u8; 32];
rand::thread_rng().fill_bytes(&mut msg);
thread_rng().fill_bytes(&mut msg);

let (sk, _) = s.generate_keypair(false);
let nonce = s.generate_nonce();
Expand All @@ -337,7 +339,7 @@ mod tests {
let mut s = Secp256k1::new().unwrap();

let mut msg: Vec<u8> = repeat(0).take(32).collect();
rand::thread_rng().fill_bytes(msg.as_mut_slice());
thread_rng().fill_bytes(msg.as_mut_slice());

let (sk, pk) = s.generate_keypair(false);
let nonce = s.generate_nonce();
Expand All @@ -352,14 +354,14 @@ mod tests {
let mut s = Secp256k1::new().unwrap();

let mut msg: Vec<u8> = repeat(0).take(32).collect();
rand::thread_rng().fill_bytes(msg.as_mut_slice());
thread_rng().fill_bytes(msg.as_mut_slice());

let (sk, pk) = s.generate_keypair(false);
let nonce = s.generate_nonce();

let sig = s.sign(msg.as_slice(), &sk, &nonce).unwrap();

rand::thread_rng().fill_bytes(msg.as_mut_slice());
thread_rng().fill_bytes(msg.as_mut_slice());
assert_eq!(Secp256k1::verify(msg.as_slice(), &sig, &pk), Err(IncorrectSignature));
}

Expand All @@ -368,7 +370,7 @@ mod tests {
let mut s = Secp256k1::new().unwrap();

let mut msg = [0u8; 32];
rand::thread_rng().fill_bytes(msg.as_mut_slice());
thread_rng().fill_bytes(msg.as_mut_slice());

let (sk, pk) = s.generate_keypair(false);
let nonce = s.generate_nonce();
Expand All @@ -381,7 +383,7 @@ mod tests {
#[test]
fn deterministic_sign() {
let mut msg = [0u8; 32];
rand::thread_rng().fill_bytes(msg.as_mut_slice());
thread_rng().fill_bytes(msg.as_mut_slice());

let mut s = Secp256k1::new().unwrap();
let (sk, pk) = s.generate_keypair(true);
Expand Down

0 comments on commit 7bd2461

Please sign in to comment.