Rustfmt updates + refactor Travis configuration (#60)

* Update rustfmt compliance

Looks like rustfmt has made some improvements recently, so wanted to bring the
code up to date.

* Add rustfmt to nightly item in Travis matrix

* Use Travis Cargo cache

* Allow fast_finish in Travis

Items that match the `allow_failures` predicate (right now, just Rust nightly),
will still finish, but Travis won't wait for them to report a result if the
other builds have already finished.

* Run kcov in a separate matrix build in Travis

* Rework allowed_failures logic

We don't want rustfmt to match `allow_failures` just because it needs to use
nightly, while we do want nightly to match `allow_failures`. Env vars provide a
solution.

* Add --all switch to rustfmt Travis

* Test building docs in Travis

* Use exact Ubuntu dependencies listed for kcov

Some of the dependencies we were installing were not listed on
https://github.com/SimonKagstrom/kcov/blob/master/INSTALL.md, and we were
missing one dependency that was listed there. When `sudo: true` Travis uses
Ubuntu Trusty.

* No need to build before running kcov

kcov builds its own test executables.

* Generate `Cargo.lock` w/ `cargo update` before running kcov

As noted in aeb3906cce8e3e26c7bc80d6aec417b365f3d2f1 it is not necessary to
build the project before running kcov, but kcov does require a `Cargo.lock`
file, which can be generated with `cargo update`.
This commit is contained in:
Noah Vesely
2018-04-02 15:02:10 -05:00
committed by Romain Ruetschi
parent d6407c0e8a
commit c25f661645
24 changed files with 115 additions and 90 deletions

View File

@ -1,38 +1,50 @@
sudo: required
language: rust
cache: cargo # https://docs.travis-ci.com/user/caching/#Rust-Cargo-cache
rust:
- stable
- beta
- nightly
matrix:
# Since this item is allowed to fail, don't wait for it's result to mark the
# build complete.
fast_finish: true
allow_failures:
- rust: nightly
- env: NAME='nightly'
- env: NAME='kcov'
include:
- env: NAME='nightly'
rust: nightly
- env: NAME='rustfmt'
rust: nightly
before_script:
- rustup component add rustfmt-preview
script:
- cargo fmt --all -- --write-mode=diff
- env: NAME='kcov'
sudo: required # travis-ci/travis-ci#9061
before_script:
- cargo install cargo-update || echo "cargo-update already installed"
- cargo install cargo-kcov || echo "cargo-kcov already installed"
- cargo install-update -a
script:
- cargo kcov --print-install-kcov-sh | sh
- cargo update # Creates `Cargo.lock` needed by next command
- cargo kcov --verbose --features dss --coveralls -- --verify --exclude-pattern=/.cargo,/usr/lib,src/proto
addons:
apt:
packages:
- libcurl4-openssl-dev
- libdw-dev
- binutils-dev
- libiberty-dev
- zlib1g-dev
env:
global:
- RUSTFLAGS="-C link-dead-code"
addons:
apt:
packages:
- libcurl4-openssl-dev
- libdw-dev
- cmake
- g++
- pkg-config
- binutils-dev
- libiberty-dev
script:
- cargo build --verbose --all-features
- cargo test --verbose --all-features
after_success:
- cargo install cargo-kcov
- cargo kcov --print-install-kcov-sh | sh
- cargo kcov --verbose --features dss --coveralls -- --verify --exclude-pattern=/.cargo,/usr/lib,src/proto
- cargo doc --verbose --all-features

View File

@ -10,29 +10,37 @@ mod shared;
mod ss1 {
use rusty_secrets::dss::ss1;
use test::{black_box, Bencher};
use shared;
use test::{black_box, Bencher};
macro_rules! bench_generate {
($name:ident, $k:expr, $n:expr, $secret:ident) => (
($name:ident, $k:expr, $n:expr, $secret:ident) => {
#[bench]
fn $name(b: &mut Bencher) {
let secret = shared::$secret();
b.iter(move || {
let shares = ss1::split_secret($k, $n, &secret, ss1::Reproducibility::reproducible(), &None).unwrap();
let shares = ss1::split_secret(
$k,
$n,
&secret,
ss1::Reproducibility::reproducible(),
&None,
).unwrap();
black_box(shares);
});
}
)
};
}
macro_rules! bench_recover {
($name:ident, $k:expr, $n:expr, $secret:ident) => (
($name:ident, $k:expr, $n:expr, $secret:ident) => {
#[bench]
fn $name(b: &mut Bencher) {
let secret = shared::$secret();
let all_shares = ss1::split_secret($k, $n, &secret, ss1::Reproducibility::reproducible(), &None).unwrap();
let all_shares =
ss1::split_secret($k, $n, &secret, ss1::Reproducibility::reproducible(), &None)
.unwrap();
let shares = &all_shares.into_iter().take($k).collect::<Vec<_>>().clone();
b.iter(|| {
@ -40,7 +48,7 @@ mod ss1 {
black_box(result);
});
}
)
};
}
bench_generate!(generate_1kb_3_5, 3, 5, secret_1kb);

View File

@ -8,12 +8,12 @@ mod shared;
mod sss {
use test::{black_box, Bencher};
use rusty_secrets::sss;
use shared;
use test::{black_box, Bencher};
macro_rules! bench_generate {
($name:ident, $k:expr, $n:expr, $secret:ident, $signed:expr) => (
($name:ident, $k:expr, $n:expr, $secret:ident, $signed:expr) => {
#[bench]
fn $name(b: &mut Bencher) {
let secret = shared::$secret();
@ -23,11 +23,11 @@ mod sss {
black_box(shares);
});
}
)
};
}
macro_rules! bench_recover {
($name:ident, $k:expr, $n:expr, $secret:ident, $signed:expr) => (
($name:ident, $k:expr, $n:expr, $secret:ident, $signed:expr) => {
#[bench]
fn $name(b: &mut Bencher) {
let secret = shared::$secret();
@ -39,7 +39,7 @@ mod sss {
black_box(result);
});
}
)
};
}
bench_generate!(generate_1kb_3_5, 3, 5, secret_1kb, false);

View File

@ -10,11 +10,11 @@ mod shared;
mod thss {
use rusty_secrets::dss::thss;
use test::{black_box, Bencher};
use shared;
use test::{black_box, Bencher};
macro_rules! bench_generate {
($name:ident, $k:expr, $n:expr, $secret:ident) => (
($name:ident, $k:expr, $n:expr, $secret:ident) => {
#[bench]
fn $name(b: &mut Bencher) {
let secret = shared::$secret();
@ -24,11 +24,11 @@ mod thss {
black_box(shares);
});
}
)
};
}
macro_rules! bench_recover {
($name:ident, $k:expr, $n:expr, $secret:ident) => (
($name:ident, $k:expr, $n:expr, $secret:ident) => {
#[bench]
fn $name(b: &mut Bencher) {
let secret = shared::$secret();
@ -40,7 +40,7 @@ mod thss {
black_box(result);
});
}
)
};
}
bench_generate!(generate_1kb_3_5, 3, 5, secret_1kb);

View File

@ -8,30 +8,32 @@ mod shared;
mod wrapped_secrets {
use test::{black_box, Bencher};
use rusty_secrets::wrapped_secrets;
use shared;
use test::{black_box, Bencher};
macro_rules! bench_generate {
($name:ident, $k:expr, $n:expr, $secret:ident, $signed:expr) => (
($name:ident, $k:expr, $n:expr, $secret:ident, $signed:expr) => {
#[bench]
fn $name(b: &mut Bencher) {
let secret = shared::$secret();
b.iter(move || {
let shares = wrapped_secrets::split_secret($k, $n, secret, None, $signed).unwrap();
let shares =
wrapped_secrets::split_secret($k, $n, secret, None, $signed).unwrap();
black_box(shares);
});
}
)
};
}
macro_rules! bench_recover {
($name:ident, $k:expr, $n:expr, $secret:ident, $signed:expr) => (
($name:ident, $k:expr, $n:expr, $secret:ident, $signed:expr) => {
#[bench]
fn $name(b: &mut Bencher) {
let secret = shared::$secret();
let all_shares = wrapped_secrets::split_secret($k, $n, &secret, None, $signed).unwrap();
let all_shares =
wrapped_secrets::split_secret($k, $n, &secret, None, $signed).unwrap();
let shares = all_shares.into_iter().take($k).collect::<Vec<_>>();
b.iter(|| {
@ -39,7 +41,7 @@ mod wrapped_secrets {
black_box(result);
});
}
)
};
}
bench_generate!(generate_1kb_3_5, 3, 5, secret_1kb, false);

View File

@ -1,9 +1,9 @@
use std::env;
use std::fmt;
use std::fs::File;
use std::io::Write;
use std::path::Path;
use std::fmt;
use std::num::Wrapping;
use std::path::Path;
const POLY: u8 = 0x1D;

View File

@ -1,7 +1,7 @@
use std::error::Error;
use protobuf::{self, Message};
use base64;
use protobuf::{self, Message};
use errors::*;
use proto::dss::ShareProto;

View File

@ -1,5 +1,5 @@
use std::collections::BTreeMap;
use ring::digest;
use std::collections::BTreeMap;
/// A share's public metadata.
#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Default)]

View File

@ -27,8 +27,8 @@
//! **ErrDet** | An inauthentic set of shares produced by an adversary will be flagged as such when fed to the recovery algorithm.
//! **Repro** | Share reproducible: The scheme can produce shares in a deterministic way.
pub mod thss;
pub mod ss1;
pub mod thss;
mod metadata;

View File

@ -29,8 +29,8 @@ mod share;
pub use self::share::*;
mod scheme;
use self::scheme::SS1;
pub use self::scheme::Reproducibility;
use self::scheme::SS1;
use dss::AccessStructure;

View File

@ -1,17 +1,17 @@
use std::collections::HashSet;
use ring::{hkdf, hmac};
use ring::rand::{SecureRandom, SystemRandom};
use ring::digest::{Context, SHA256};
use rand::{ChaChaRng, Rng, SeedableRng};
use ring::digest::{Context, SHA256};
use ring::rand::{SecureRandom, SystemRandom};
use ring::{hkdf, hmac};
use errors::*;
use dss::{thss, AccessStructure};
use dss::thss::{MetaData, ThSS};
use dss::random::{random_bytes_count, FixedRandom, MAX_MESSAGE_SIZE};
use share::validation::{validate_share_count, validate_shares};
use super::share::*;
use dss::random::{random_bytes_count, FixedRandom, MAX_MESSAGE_SIZE};
use dss::thss::{MetaData, ThSS};
use dss::utils;
use dss::{thss, AccessStructure};
use errors::*;
use share::validation::{validate_share_count, validate_shares};
use vol_hash::VOLHash;
/// We bound the message size at about 16MB to avoid overflow in `random_bytes_count`.

View File

@ -1,8 +1,8 @@
use errors::*;
use super::{MetaData, Share};
use dss::format::{format_share_protobuf, parse_share_protobuf};
use proto::dss::{MetaDataProto, ShareProto};
use dss::utils::{btreemap_to_hashmap, hashmap_to_btreemap};
use errors::*;
use proto::dss::{MetaDataProto, ShareProto};
pub(crate) fn share_to_string(share: Share) -> String {
let proto = share_to_protobuf(share);

View File

@ -1,6 +1,6 @@
use super::serialize::{share_from_string, share_to_string};
use errors::*;
use share::IsShare;
use super::serialize::{share_from_string, share_to_string};
pub use dss::metadata::MetaData;

View File

@ -4,15 +4,15 @@ use std::fmt;
use ring::rand::{SecureRandom, SystemRandom};
use dss::random::{random_bytes, random_bytes_count, MAX_MESSAGE_SIZE};
use errors::*;
use gf256::Gf256;
use dss::random::{random_bytes, random_bytes_count, MAX_MESSAGE_SIZE};
use share::validation::{validate_share_count, validate_shares};
use lagrange;
use share::validation::{validate_share_count, validate_shares};
use super::AccessStructure;
use super::share::*;
use super::encode::encode_secret;
use super::share::*;
/// We bound the message size at about 16MB to avoid overflow in `random_bytes_count`.
/// Moreover, given the current performances, it is almost unpractical to run

View File

@ -1,8 +1,8 @@
use errors::*;
use super::{MetaData, Share};
use dss::format::{format_share_protobuf, parse_share_protobuf};
use proto::dss::{MetaDataProto, ShareProto};
use dss::utils::{btreemap_to_hashmap, hashmap_to_btreemap};
use errors::*;
use proto::dss::{MetaDataProto, ShareProto};
pub(crate) fn share_to_string(share: Share) -> String {
let proto = share_to_protobuf(share);

View File

@ -1,6 +1,6 @@
use super::serialize::{share_from_string, share_to_string};
use errors::*;
use share::IsShare;
use super::serialize::{share_from_string, share_to_string};
pub use dss::metadata::MetaData;

View File

@ -1,7 +1,7 @@
use std;
use std::hash::Hash;
use std::collections::{BTreeMap, HashMap};
use std::hash::Hash;
/// Transmutes a `&[u8]` into a `&[u32]`.
/// Despite `std::mem::transmute` being very unsafe in

View File

@ -143,7 +143,9 @@ impl Neg for Gf256 {
#[macro_export]
#[doc(hidden)]
macro_rules! gf256 {
($e:expr) => (Gf256::from_byte($e))
($e:expr) => {
Gf256::from_byte($e)
};
}
#[macro_export]
@ -178,10 +180,10 @@ mod tests {
mod vectors {
use super::*;
use flate2::read::GzDecoder;
use itertools::Itertools;
use std::fs::File;
use std::io::{BufRead, BufReader};
use itertools::Itertools;
use flate2::read::GzDecoder;
macro_rules! mk_test {
($id:ident, $op:expr, $val:expr) => {
@ -196,7 +198,8 @@ mod tests {
});
let ref_path = format!("tests/fixtures/gf256/gf256_{}.txt.gz", stringify!($id));
let reference = BufReader::new(GzDecoder::new(File::open(ref_path).unwrap()).unwrap());
let reference =
BufReader::new(GzDecoder::new(File::open(ref_path).unwrap()).unwrap());
for ((i, j, k), line) in results.zip(reference.lines()) {
let left = format!("{} {} {} = {}", i, $op, j, k);
@ -204,7 +207,7 @@ mod tests {
assert_eq!(left, right);
}
}
}
};
}
mk_test!(add, "+", |i: Gf256, j: Gf256| i + j);

View File

@ -86,10 +86,10 @@ pub(crate) fn interpolate(points: &[(Gf256, Gf256)]) -> Poly {
#[allow(trivial_casts)]
mod tests {
use std;
use super::*;
use gf256::*;
use quickcheck::*;
use std;
quickcheck! {

View File

@ -18,15 +18,15 @@ extern crate ring;
#[macro_use]
mod gf256;
mod share;
mod poly;
mod lagrange;
mod poly;
mod share;
mod vol_hash;
pub mod errors;
pub mod proto;
pub mod sss;
pub mod wrapped_secrets;
pub mod proto;
#[cfg(feature = "dss")]
pub mod dss;

View File

@ -1,9 +1,9 @@
use base64;
use errors::*;
use merkle_sigs::{MerklePublicKey, Proof, PublicKey};
use protobuf::{self, Message, RepeatedField};
use base64;
use sss::{Share, HASH_ALGO};
use proto::wrapped::ShareProto;
use protobuf::{self, Message, RepeatedField};
use sss::{Share, HASH_ALGO};
use std::error::Error;
const BASE64_CONFIG: base64::Config = base64::STANDARD_NO_PAD;

View File

@ -1,13 +1,13 @@
//! SSS provides Shamir's secret sharing with raw data.
use rand::{OsRng, Rng};
use merkle_sigs::sign_data_vec;
use rand::{OsRng, Rng};
use errors::*;
use sss::{Share, HASH_ALGO};
use sss::format::format_share_for_signing;
use share::validation::{validate_share_count, validate_signed_shares};
use lagrange::interpolate_at;
use share::validation::{validate_share_count, validate_signed_shares};
use sss::format::format_share_for_signing;
use sss::{Share, HASH_ALGO};
use super::encode::encode_secret_byte;

View File

@ -1,8 +1,8 @@
use std::error::Error;
use std::collections::{HashMap, HashSet};
use std::error::Error;
use merkle_sigs::{MerklePublicKey, Proof};
use merkle_sigs::verify_data_vec_signature;
use merkle_sigs::{MerklePublicKey, Proof};
use errors::*;
use share::{IsShare, IsSignedShare};

View File

@ -1,8 +1,8 @@
use errors::*;
use proto::VersionProto;
use proto::wrapped::SecretProto;
use protobuf;
use protobuf::Message;
use proto::wrapped::SecretProto;
use proto::VersionProto;
use sss::SSS;
pub(crate) use sss::Share;