Skip to content

Commit

Permalink
Upgrade to Rust 1.31.0 and edition 2018.
Browse files Browse the repository at this point in the history
  • Loading branch information
afck committed Dec 10, 2018
1 parent c2d63b2 commit 1b1df40
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 78 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: rust
rust:
- 1.30.0
- 1.31.0
cache:
cargo: true
timeout: 1200
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ license = "MIT/Apache-2.0"
readme = "README.md"
repository = "https://github.com/poanetwork/threshold_crypto"
description = "Pairing threshold cryptography"
edition = "2018"

[dependencies]
byteorder = "1.2.7"
Expand Down
12 changes: 4 additions & 8 deletions benches/bench.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
extern crate criterion;
extern crate pairing;
extern crate rand;
extern crate threshold_crypto;

use criterion::{criterion_group, criterion_main, Criterion};
use threshold_crypto::poly::Poly;
use threshold_crypto::Fr;
Expand Down Expand Up @@ -79,7 +74,7 @@ mod poly_benches {
);
}

criterion_group!{
criterion_group! {
name = poly_benches;
config = Criterion::default();
targets = multiplication, interpolate, addition, subtraction,
Expand Down Expand Up @@ -108,7 +103,8 @@ mod public_key_set_benches {
.map(|&i| {
let sig = sk_set.secret_key_share(i).sign(msg);
(i, sig)
}).collect();
})
.collect();
b.iter(|| {
pk_set
.combine_signatures(&sigs)
Expand All @@ -119,7 +115,7 @@ mod public_key_set_benches {
);
}

criterion_group!{
criterion_group! {
name = public_key_set_benches;
config = Criterion::default();
targets = combine_signatures,
Expand Down
4 changes: 0 additions & 4 deletions examples/basic_pkc.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
extern crate bincode;
extern crate serde_derive;
extern crate threshold_crypto;

use bincode::{deserialize, serialize};
use serde_derive::{Deserialize, Serialize};
use threshold_crypto::{PublicKey, SecretKey, Signature};
Expand Down
6 changes: 2 additions & 4 deletions examples/threshold_enc.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
extern crate rand;
extern crate threshold_crypto;

use std::collections::BTreeMap;

use threshold_crypto::{
Expand Down Expand Up @@ -35,7 +32,8 @@ impl SecretSociety {
let sk_share = sk_set.secret_key_share(id);
let pk_share = pk_set.public_key_share(id);
Actor::new(id, sk_share, pk_share)
}).collect();
})
.collect();

SecretSociety { actors, pk_set }
}
Expand Down
9 changes: 3 additions & 6 deletions examples/threshold_sig.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
extern crate rand;
extern crate threshold_crypto;

use std::collections::BTreeMap;

use threshold_crypto::{
Expand Down Expand Up @@ -53,7 +50,8 @@ impl ChatNetwork {
let sk_share = sk_set.secret_key_share(id);
let pk_share = pk_set.public_key_share(id);
Node::new(id, sk_share, pk_share)
}).collect();
})
.collect();

ChatNetwork {
pk_set,
Expand Down Expand Up @@ -98,8 +96,7 @@ impl ChatNetwork {
.iter()
.fold(BTreeMap::new(), |mut all_pending, node| {
for (user_id, signed_msgs) in &node.pending {
let mut user_msgs =
all_pending.entry(*user_id).or_insert_with(BTreeMap::new);
let user_msgs = all_pending.entry(*user_id).or_insert_with(BTreeMap::new);
for (msg, sigs) in signed_msgs.iter() {
let sigs = sigs.iter().cloned();
user_msgs
Expand Down
46 changes: 15 additions & 31 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,15 @@
// Clippy warns that it's dangerous to derive `PartialEq` and explicitly implement `Hash`, but the
// `pairing::bls12_381` types don't implement `Hash`, so we can't derive it.
#![cfg_attr(feature = "cargo-clippy", allow(derive_hash_xor_eq))]
#![allow(clippy::derive_hash_xor_eq)]
// When using the mocktography, the resulting field elements become wrapped `u32`s, suddenly
// triggering pass-by-reference warnings. They are conditionally disabled for this reason:
#![cfg_attr(
all(
feature = "cargo-clippy",
feature = "use-insecure-test-only-mock-crypto"
),
allow(trivially_copy_pass_by_ref)
feature = "use-insecure-test-only-mock-crypto",
allow(clippy::trivially_copy_pass_by_ref)
)]
#![warn(missing_docs)]

#[cfg(test)]
extern crate bincode;
extern crate byteorder;
extern crate errno;
extern crate failure;
extern crate hex_fmt;
extern crate init_with;
extern crate lazy_static;
extern crate log;
extern crate memsec;
extern crate rand;
extern crate rand_derive;
extern crate serde;
extern crate serde_derive;
extern crate tiny_keccak;

pub extern crate pairing;

mod into_fr;
Expand All @@ -50,13 +31,13 @@ use log::debug;
use pairing::{CurveAffine, CurveProjective, EncodedPoint, Engine, Field};
use rand::{ChaChaRng, OsRng, Rand, Rng, SeedableRng};
use rand_derive::Rand;
use serde_derive::{Deserialize, Serialize};
use tiny_keccak::sha3_256;

use error::{Error, FromBytesError, FromBytesResult, Result};
use into_fr::IntoFr;
use poly::{Commitment, Poly};
use secret::{clear_fr, ContainsSecret, MemRange, FR_SIZE};
use serde_derive::{Deserialize, Serialize};
use crate::error::{Error, FromBytesError, FromBytesResult, Result};
use crate::into_fr::IntoFr;
use crate::poly::{Commitment, Poly};
use crate::secret::{clear_fr, ContainsSecret, MemRange, FR_SIZE};

#[cfg(not(feature = "use-insecure-test-only-mock-crypto"))]
pub use pairing::bls12_381::{Bls12 as PEngine, Fr, FrRepr, G1Affine, G2Affine, G1, G2};
Expand All @@ -65,7 +46,7 @@ pub use pairing::bls12_381::{Bls12 as PEngine, Fr, FrRepr, G1Affine, G2Affine, G
mod mock;

#[cfg(feature = "use-insecure-test-only-mock-crypto")]
pub use mock::{
pub use crate::mock::{
Mersenne8 as Fr, Mersenne8 as FrRepr, Mocktography as PEngine, Ms8Affine as G1Affine,
Ms8Affine as G2Affine, Ms8Projective as G1, Ms8Projective as G2, PK_SIZE, SIG_SIZE,
};
Expand Down Expand Up @@ -753,7 +734,8 @@ mod tests {
.map(|&i| {
let sig = sk_set.secret_key_share(i).sign(msg);
(i, sig)
}).collect();
})
.collect();

// Each of the shares is a valid signature matching its public key share.
for (i, sig) in &sigs {
Expand All @@ -770,7 +752,8 @@ mod tests {
.map(|&i| {
let sig = sk_set.secret_key_share(i).sign(msg);
(i, sig)
}).collect();
})
.collect();
let sig2 = pk_set.combine_signatures(&sigs2).expect("signatures match");
assert_eq!(sig, sig2);
}
Expand Down Expand Up @@ -824,7 +807,8 @@ mod tests {
.decrypt_share(&ciphertext)
.expect("ciphertext is invalid");
(i, dec_share)
}).collect();
})
.collect();

// Each of the shares is valid matching its public key share.
for (i, share) in &shares {
Expand Down
4 changes: 2 additions & 2 deletions src/mock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,10 @@ impl EncodedPoint for Ms8Affine {
#[cfg(test)]
mod test {
// There are copy & pasted results of calculations from external programs in these tests.
#![cfg_attr(feature = "cargo-clippy", allow(unreadable_literal))]
#![allow(clippy::unreadable_literal)]

use super::{EncodedPoint, Mersenne8, Mocktography, Ms8Affine, PK_SIZE, SIG_SIZE};
use Engine;
use pairing::Engine;

#[test]
fn example_pairings() {
Expand Down
8 changes: 4 additions & 4 deletions src/mock/ms8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,13 +428,13 @@ fn ext_euclid(a: u32, b: u32) -> (u32, i64, i64) {
#[cfg(test)]
mod tests {
// There are copy & pasted results of calculations from external programs in these tests.
#![cfg_attr(feature = "cargo-clippy", allow(unreadable_literal))]
#![cfg_attr(feature = "cargo-clippy", allow(op_ref))]
#![allow(clippy::unreadable_literal)]
#![allow(clippy::op_ref)]
// We test a few mathematical identities, including `c - c = 0`. Clippy complains about these
// otherwise unusual expressions, so the lint is disabled.
#![cfg_attr(feature = "cargo-clippy", allow(eq_op))]
#![allow(clippy::eq_op)]
// Some test functions contain long lists of assertions. Clippy thinks they are too complex.
#![cfg_attr(feature = "cargo-clippy", allow(cyclomatic_complexity))]
#![allow(clippy::cyclomatic_complexity)]

use super::{ext_euclid, modular_pow, Mersenne8};
use pairing::Field;
Expand Down
25 changes: 14 additions & 11 deletions src/poly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ use pairing::{CurveAffine, CurveProjective, Field};
use rand::Rng;
use serde_derive::{Deserialize, Serialize};

use error::{Error, Result};
use into_fr::IntoFr;
use secret::{clear_fr, ContainsSecret, MemRange, Safe};
use {Fr, G1Affine, G1};
use crate::error::{Error, Result};
use crate::into_fr::IntoFr;
use crate::secret::{clear_fr, ContainsSecret, MemRange, Safe};
use crate::{Fr, G1Affine, G1};

/// A univariate polynomial in the prime field.
#[derive(Serialize, Deserialize, PartialEq, Eq)]
Expand All @@ -53,7 +53,7 @@ impl Debug for Poly {
}
}

#[cfg_attr(feature = "cargo-clippy", allow(suspicious_op_assign_impl))]
#[allow(clippy::suspicious_op_assign_impl)]
impl<B: Borrow<Poly>> ops::AddAssign<B> for Poly {
fn add_assign(&mut self, rhs: B) {
let len = self.coeff.len();
Expand Down Expand Up @@ -139,7 +139,7 @@ impl<B: Borrow<Poly>> ops::Sub<B> for Poly {
}

// Clippy thinks using `+` in a `Sub` implementation is suspicious.
#[cfg_attr(feature = "cargo-clippy", allow(suspicious_arithmetic_impl))]
#[allow(clippy::suspicious_arithmetic_impl)]
impl<'a> ops::Sub<Fr> for Poly {
type Output = Poly;

Expand All @@ -158,7 +158,7 @@ impl<'a> ops::Sub<u64> for Poly {
}

// Clippy thinks using any `+` and `-` in a `Mul` implementation is suspicious.
#[cfg_attr(feature = "cargo-clippy", allow(suspicious_arithmetic_impl))]
#[allow(clippy::suspicious_arithmetic_impl)]
impl<'a, B: Borrow<Poly>> ops::Mul<B> for &'a Poly {
type Output = Poly;

Expand Down Expand Up @@ -406,7 +406,7 @@ impl Poly {
// current value at `x`: Adding it to `poly` will then make it correct for `x`.
let mut diff = *y;
diff.sub_assign(&poly.evaluate(x));
let mut base_val = base.evaluate(x);
let base_val = base.evaluate(x);
diff.mul_assign(&base_val.inverse().expect("sample points must be distinct"));
base *= diff;
poly += &base;
Expand Down Expand Up @@ -608,7 +608,8 @@ impl BivarPoly {
result.add_assign(&summand);
}
result
}).collect();
})
.collect();
Poly::from(coeff)
}

Expand Down Expand Up @@ -692,7 +693,8 @@ impl BivarCommitment {
result.add_assign(&summand);
}
result
}).collect();
})
.collect();
Commitment { coeff }
}

Expand All @@ -710,7 +712,8 @@ fn powers<T: IntoFr>(into_x: T, degree: usize) -> Vec<Fr> {
.chain((0..degree).map(|_| {
x_pow_i.mul_assign(&x);
x_pow_i
})).collect()
}))
.collect()
}

/// Returns the position of coefficient `(i, j)` in the vector describing a symmetric bivariate
Expand Down
2 changes: 1 addition & 1 deletion src/secret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::ops::{Deref, DerefMut};
use lazy_static::lazy_static;
use memsec::memzero;

use Fr;
use crate::Fr;

lazy_static! {
/// The size in bytes of a single field element.
Expand Down
13 changes: 7 additions & 6 deletions src/serde_impl.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use std::borrow::Cow;

use crate::G1;
use serde::de::Error as DeserializeError;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use serde_derive::{Deserialize, Serialize};
use G1;

use poly::{coeff_pos, BivarCommitment};
use crate::poly::{coeff_pos, BivarCommitment};

const ERR_DEG: &str = "commitment degree does not match coefficients";

Expand All @@ -24,7 +24,8 @@ impl Serialize for BivarCommitment {
WireBivarCommitment {
degree: self.degree,
coeff: Cow::Borrowed(&self.coeff),
}.serialize(s)
}
.serialize(s)
}
}

Expand Down Expand Up @@ -160,7 +161,7 @@ pub mod field_vec {
use serde::de::Error as DeserializeError;
use serde::{Deserialize, Deserializer, Serialize, Serializer};

use {Fr, FrRepr};
use crate::{Fr, FrRepr};

/// A wrapper type to facilitate serialization and deserialization of field elements.
pub struct FieldWrap<B>(B);
Expand Down Expand Up @@ -203,8 +204,8 @@ mod tests {
use rand::{self, Rng};
use serde_derive::{Deserialize, Serialize};

use poly::BivarPoly;
use {Fr, G1};
use crate::poly::BivarPoly;
use crate::{Fr, G1};

#[derive(Debug, Serialize, Deserialize)]
pub struct Vecs {
Expand Down

0 comments on commit 1b1df40

Please sign in to comment.