Use current dependency versions.

Small tweaks to be compatible with updated rand api.
This commit is contained in:
Marshall Pierce 2018-10-02 21:14:30 -06:00
parent 61bb3b6f04
commit 1f0b90d113
9 changed files with 50 additions and 49 deletions

View File

@ -11,11 +11,11 @@ categories = ["encoding"]
license = "MIT/Apache-2.0"
[dependencies]
byteorder = "1.1.0"
byteorder = "1.2.6"
safemem = "0.3"
[dev-dependencies]
rand = "0.4"
rand = "0.5.5"
[profile.bench]
# Useful for better disassembly when using `perf record` and `perf annotate`

View File

@ -8,7 +8,7 @@ use base64::display;
use base64::{decode, decode_config_buf, decode_config_slice, encode, encode_config_buf,
encode_config_slice, Config, MIME, STANDARD};
use rand::Rng;
use rand::{Rng, FromEntropy};
use test::Bencher;
#[bench]
@ -338,7 +338,7 @@ fn do_encode_bench_slice(b: &mut Bencher, size: usize, config: Config) {
fn fill(v: &mut Vec<u8>) {
let cap = v.capacity();
// weak randomness is plenty; we just want to not be completely friendly to the branch predictor
let mut r = rand::weak_rng();
let mut r = rand::rngs::SmallRng::from_entropy();
while v.len() < cap {
v.push(r.gen::<u8>());
}

View File

@ -4,7 +4,7 @@ extern crate ring;
use self::base64::*;
use self::rand::{Rng, SeedableRng, XorShiftRng};
use self::rand::distributions::{IndependentSample, Range};
use self::rand::distributions::{Distribution, Range};
use self::ring::digest;
pub fn random_config(data: &[u8]) -> Config {
@ -26,7 +26,7 @@ pub fn random_config(data: &[u8]) -> Config {
let (line_wrap, strip_whitespace) = if rng.gen() {
(LineWrap::NoWrap, rng.gen())
} else {
let line_len = line_len_range.ind_sample(&mut rng);
let line_len = line_len_range.sample(&mut rng);
let line_ending = if rng.gen() {
LineEnding::LF

View File

@ -173,8 +173,8 @@ pub mod tests {
use std::str;
use self::rand::distributions::{IndependentSample, Range};
use self::rand::Rng;
use self::rand::distributions::{Distribution, Range};
use self::rand::{Rng, FromEntropy};
#[test]
fn chunked_encode_empty() {
@ -398,7 +398,7 @@ pub mod tests {
pub fn chunked_encode_matches_normal_encode_random<S: SinkTestHelper>(sink_test_helper: &S) {
let mut input_buf: Vec<u8> = Vec::new();
let mut output_buf = String::new();
let mut rng = rand::weak_rng();
let mut rng = rand::rngs::SmallRng::from_entropy();
let line_len_range = Range::new(1, 1020);
let input_len_range = Range::new(1, 10_000);
@ -406,7 +406,7 @@ pub mod tests {
input_buf.clear();
output_buf.clear();
let buf_len = input_len_range.ind_sample(&mut rng);
let buf_len = input_len_range.sample(&mut rng);
for _ in 0..buf_len {
input_buf.push(rng.gen());
}

View File

@ -538,8 +538,9 @@ mod tests {
use encode::encode_config_buf;
use tests::{assert_encode_sanity, random_config};
use self::rand::distributions::{IndependentSample, Range};
use self::rand::Rng;
use self::rand::distributions::{Distribution, Range};
use self::rand::{Rng, FromEntropy};
#[test]
fn decode_chunk_precise_writes_only_6_bytes() {
@ -569,7 +570,7 @@ mod tests {
let input_len_range = Range::new(0, 1000);
let line_len_range = Range::new(1, 1000);
let mut rng = rand::weak_rng();
let mut rng = rand::rngs::SmallRng::from_entropy();
for _ in 0..10_000 {
orig_data.clear();
@ -578,7 +579,7 @@ mod tests {
decoded_without_prefix.clear();
prefix.clear();
let input_len = input_len_range.ind_sample(&mut rng);
let input_len = input_len_range.sample(&mut rng);
for _ in 0..input_len {
orig_data.push(rng.gen());
@ -588,7 +589,7 @@ mod tests {
encode_config_buf(&orig_data, config, &mut encoded_data);
assert_encode_sanity(&encoded_data, &config, input_len);
let prefix_len = prefix_len_range.ind_sample(&mut rng);
let prefix_len = prefix_len_range.sample(&mut rng);
// fill the buf with a prefix
for _ in 0..prefix_len {
@ -626,7 +627,7 @@ mod tests {
let input_len_range = Range::new(0, 1000);
let line_len_range = Range::new(1, 1000);
let mut rng = rand::weak_rng();
let mut rng = rand::rngs::SmallRng::from_entropy();
for _ in 0..10_000 {
orig_data.clear();
@ -634,7 +635,7 @@ mod tests {
decode_buf.clear();
decode_buf_copy.clear();
let input_len = input_len_range.ind_sample(&mut rng);
let input_len = input_len_range.sample(&mut rng);
for _ in 0..input_len {
orig_data.push(rng.gen());
@ -680,14 +681,14 @@ mod tests {
let input_len_range = Range::new(0, 1000);
let line_len_range = Range::new(1, 1000);
let mut rng = rand::weak_rng();
let mut rng = rand::rngs::SmallRng::from_entropy();
for _ in 0..10_000 {
orig_data.clear();
encoded_data.clear();
decode_buf.clear();
let input_len = input_len_range.ind_sample(&mut rng);
let input_len = input_len_range.sample(&mut rng);
for _ in 0..input_len {
orig_data.push(rng.gen());

View File

@ -351,8 +351,8 @@ mod tests {
use tests::{assert_encode_sanity, random_config};
use {CharacterSet, Config, LineEnding, LineWrap, MIME, STANDARD, URL_SAFE_NO_PAD};
use self::rand::distributions::{IndependentSample, Range};
use self::rand::Rng;
use self::rand::distributions::{Distribution, Range};
use self::rand::{Rng, FromEntropy};
use std;
use std::str;
@ -485,7 +485,7 @@ mod tests {
let input_len_range = Range::new(0, 1000);
let line_len_range = Range::new(1, 1000);
let mut rng = rand::weak_rng();
let mut rng = rand::rngs::SmallRng::from_entropy();
for _ in 0..10_000 {
orig_data.clear();
@ -494,13 +494,13 @@ mod tests {
encoded_data_with_prefix.clear();
decoded.clear();
let input_len = input_len_range.ind_sample(&mut rng);
let input_len = input_len_range.sample(&mut rng);
for _ in 0..input_len {
orig_data.push(rng.gen());
}
let prefix_len = prefix_len_range.ind_sample(&mut rng);
let prefix_len = prefix_len_range.sample(&mut rng);
for _ in 0..prefix_len {
// getting convenient random single-byte printable chars that aren't base64 is
// annoying
@ -539,7 +539,7 @@ mod tests {
let input_len_range = Range::new(0, 1000);
let line_len_range = Range::new(1, 1000);
let mut rng = rand::weak_rng();
let mut rng = rand::rngs::SmallRng::from_entropy();
for _ in 0..10_000 {
orig_data.clear();
@ -547,7 +547,7 @@ mod tests {
encoded_data_original_state.clear();
decoded.clear();
let input_len = input_len_range.ind_sample(&mut rng);
let input_len = input_len_range.sample(&mut rng);
for _ in 0..input_len {
orig_data.push(rng.gen());
@ -594,14 +594,14 @@ mod tests {
let input_len_range = Range::new(0, 1000);
let line_len_range = Range::new(1, 1000);
let mut rng = rand::weak_rng();
let mut rng = rand::rngs::SmallRng::from_entropy();
for _ in 0..10_000 {
orig_data.clear();
encoded_data.clear();
decoded.clear();
let input_len = input_len_range.ind_sample(&mut rng);
let input_len = input_len_range.sample(&mut rng);
for _ in 0..input_len {
orig_data.push(rng.gen());
@ -637,13 +637,13 @@ mod tests {
let input_len_range = Range::new(0, 1000);
let line_len_range = Range::new(1, 1000);
let mut rng = rand::weak_rng();
let mut rng = rand::rngs::SmallRng::from_entropy();
for _ in 0..10_000 {
input.clear();
output.clear();
let input_len = input_len_range.ind_sample(&mut rng);
let input_len = input_len_range.sample(&mut rng);
for _ in 0..input_len {
input.push(rng.gen());
@ -678,13 +678,13 @@ mod tests {
let input_len_range = Range::new(0, 1000);
let line_len_range = Range::new(1, 1000);
let mut rng = rand::weak_rng();
let mut rng = rand::rngs::SmallRng::from_entropy();
for _ in 0..10_000 {
input.clear();
output.clear();
let input_len = input_len_range.ind_sample(&mut rng);
let input_len = input_len_range.sample(&mut rng);
for _ in 0..input_len {
input.push(rng.gen());
@ -719,7 +719,7 @@ mod tests {
fn add_padding_random_valid_utf8() {
let mut output = Vec::new();
let mut rng = rand::weak_rng();
let mut rng = rand::rngs::SmallRng::from_entropy();
// cover our bases for length % 3
for input_len in 0..10 {
@ -746,7 +746,7 @@ mod tests {
assert_eq!(encoded_len, encoded_size(input_len, &config).unwrap());
let mut bytes: Vec<u8> = Vec::new();
let mut rng = rand::weak_rng();
let mut rng = rand::rngs::SmallRng::from_entropy();
for _ in 0..input_len {
bytes.push(rng.gen());

View File

@ -163,8 +163,8 @@ mod tests {
use super::*;
use self::rand::distributions::{IndependentSample, Range};
use self::rand::Rng;
use self::rand::distributions::{Distribution, Range};
use self::rand::{Rng, FromEntropy};
#[test]
fn line_params_perfect_multiple_of_line_length_lf() {
@ -305,13 +305,13 @@ mod tests {
let mut buf: Vec<u8> = Vec::new();
let buf_range = Range::new(10, 1000);
let line_range = Range::new(10, 100);
let mut rng = rand::weak_rng();
let mut rng = rand::rngs::SmallRng::from_entropy();
for _ in 0..10_000 {
buf.clear();
let buf_len = buf_range.ind_sample(&mut rng);
let line_len = line_range.ind_sample(&mut rng);
let buf_len = buf_range.sample(&mut rng);
let line_len = line_range.sample(&mut rng);
let line_ending = if rng.gen() {
LineEnding::LF
} else {
@ -343,7 +343,7 @@ mod tests {
}
fn do_line_wrap(buf: &mut Vec<u8>, line_len: usize, line_ending: LineEnding) -> usize {
let mut rng = rand::weak_rng();
let mut rng = rand::rngs::SmallRng::from_entropy();
let orig_len = buf.len();

View File

@ -6,8 +6,8 @@ use *;
use std::str;
use self::rand::distributions::{IndependentSample, Range};
use self::rand::Rng;
use self::rand::distributions::{Distribution, Range};
use self::rand::{Rng, FromEntropy};
#[test]
fn roundtrip_random_config_short() {
@ -61,13 +61,13 @@ fn roundtrip_random_config(
) {
let mut input_buf: Vec<u8> = Vec::new();
let mut encoded_buf = String::new();
let mut rng = rand::weak_rng();
let mut rng = rand::rngs::SmallRng::from_entropy();
for _ in 0..iterations {
input_buf.clear();
encoded_buf.clear();
let input_len = input_len_range.ind_sample(&mut rng);
let input_len = input_len_range.sample(&mut rng);
let config = random_config(&mut rng, &line_len_range);
@ -87,7 +87,7 @@ pub fn random_config<R: Rng>(rng: &mut R, line_len_range: &Range<usize>) -> Conf
let line_wrap = if rng.gen() {
LineWrap::NoWrap
} else {
let line_len = line_len_range.ind_sample(rng);
let line_len = line_len_range.sample(rng);
let line_ending = if rng.gen() {
LineEnding::LF

View File

@ -1,7 +1,7 @@
extern crate base64;
extern crate rand;
use rand::Rng;
use rand::{Rng, FromEntropy};
use base64::*;
@ -19,7 +19,7 @@ fn roundtrip_random(
) {
// let the short ones be short but don't let it get too crazy large
let num_rounds = calculate_number_of_rounds(byte_len, approx_values_per_byte, max_rounds);
let mut r = rand::weak_rng();
let mut r = rand::rngs::SmallRng::from_entropy();
let mut decode_buf = Vec::new();
for _ in 0..num_rounds {
@ -158,7 +158,7 @@ fn encode_config_slice_can_use_inline_buffer() {
let mut larger_buf: [u8; 24] = [0; 24];
let mut input: [u8; 16] = [0; 16];
let mut rng = rand::weak_rng();
let mut rng = rand::rngs::SmallRng::from_entropy();
for elt in &mut input {
*elt = rng.gen();
}
@ -182,7 +182,7 @@ fn encode_config_slice_panics_when_buffer_too_small() {
let mut buf: [u8; 22] = [0; 22];
let mut input: [u8; 16] = [0; 16];
let mut rng = rand::weak_rng();
let mut rng = rand::rngs::SmallRng::from_entropy();
for elt in &mut input {
*elt = rng.gen();
}