Skip to content

Commit

Permalink
Rustfmt updates + refactor Travis configuration (#60)
Browse files Browse the repository at this point in the history
* 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 aeb3906 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`.
  • Loading branch information
psivesely authored and romac committed Apr 2, 2018
1 parent a6ff8a7 commit 12cefb1
Show file tree
Hide file tree
Showing 24 changed files with 114 additions and 89 deletions.
56 changes: 34 additions & 22 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
22 changes: 15 additions & 7 deletions benches/ss1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,45 @@ 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(|| {
let result = ss1::recover_secret(&shares.to_vec()).unwrap();
black_box(result);
});
}
)
};
}

bench_generate!(generate_1kb_3_5, 3, 5, secret_1kb);
Expand Down
10 changes: 5 additions & 5 deletions benches/sss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -39,7 +39,7 @@ mod sss {
black_box(result);
});
}
)
};
}

bench_generate!(generate_1kb_3_5, 3, 5, secret_1kb, false);
Expand Down
10 changes: 5 additions & 5 deletions benches/thss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -40,7 +40,7 @@ mod thss {
black_box(result);
});
}
)
};
}

bench_generate!(generate_1kb_3_5, 3, 5, secret_1kb);
Expand Down
16 changes: 9 additions & 7 deletions benches/wrapped_secrets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,40 @@ 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(|| {
let result = wrapped_secrets::recover_secret(&shares, $signed).unwrap();
black_box(result);
});
}
)
};
}

bench_generate!(generate_1kb_3_5, 3, 5, secret_1kb, false);
Expand Down
4 changes: 2 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/dss/format.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::error::Error;

use protobuf::{self, Message};
use base64;
use protobuf::{self, Message};

use errors::*;
use proto::dss::ShareProto;
Expand Down
2 changes: 1 addition & 1 deletion src/dss/metadata.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion src/dss/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/dss/ss1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
16 changes: 8 additions & 8 deletions src/dss/ss1/scheme.rs
Original file line number Diff line number Diff line change
@@ -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`.
Expand Down
4 changes: 2 additions & 2 deletions src/dss/ss1/serialize.rs
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/dss/ss1/share.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
6 changes: 3 additions & 3 deletions src/dss/thss/scheme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/dss/thss/serialize.rs
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/dss/thss/share.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/dss/utils.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 12cefb1

Please sign in to comment.