diff --git a/.travis.yml b/.travis.yml index 8a0d399..628a360 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: rust rust: - - 1.30.0 + - 1.31.0 cache: cargo: true timeout: 1200 diff --git a/Cargo.toml b/Cargo.toml index c3c8700..f086a84 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/benches/bench.rs b/benches/bench.rs index 1ffaead..f042783 100644 --- a/benches/bench.rs +++ b/benches/bench.rs @@ -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; @@ -79,7 +74,7 @@ mod poly_benches { ); } - criterion_group!{ + criterion_group! { name = poly_benches; config = Criterion::default(); targets = multiplication, interpolate, addition, subtraction, @@ -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) @@ -119,7 +115,7 @@ mod public_key_set_benches { ); } - criterion_group!{ + criterion_group! { name = public_key_set_benches; config = Criterion::default(); targets = combine_signatures, diff --git a/examples/basic_pkc.rs b/examples/basic_pkc.rs index a8095d7..84e499e 100644 --- a/examples/basic_pkc.rs +++ b/examples/basic_pkc.rs @@ -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}; diff --git a/examples/threshold_enc.rs b/examples/threshold_enc.rs index c9b4faf..1e59821 100644 --- a/examples/threshold_enc.rs +++ b/examples/threshold_enc.rs @@ -1,6 +1,3 @@ -extern crate rand; -extern crate threshold_crypto; - use std::collections::BTreeMap; use threshold_crypto::{ @@ -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 } } diff --git a/examples/threshold_sig.rs b/examples/threshold_sig.rs index e5ffe4e..0bb4c74 100644 --- a/examples/threshold_sig.rs +++ b/examples/threshold_sig.rs @@ -1,6 +1,3 @@ -extern crate rand; -extern crate threshold_crypto; - use std::collections::BTreeMap; use threshold_crypto::{ @@ -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, @@ -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 diff --git a/src/lib.rs b/src/lib.rs index 0d2f28e..a36a6de 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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; @@ -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}; @@ -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, }; @@ -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 { @@ -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); } @@ -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 { diff --git a/src/mock/mod.rs b/src/mock/mod.rs index edcca1a..706c2d8 100644 --- a/src/mock/mod.rs +++ b/src/mock/mod.rs @@ -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() { diff --git a/src/mock/ms8.rs b/src/mock/ms8.rs index 9f27f8a..7c758d6 100644 --- a/src/mock/ms8.rs +++ b/src/mock/ms8.rs @@ -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; diff --git a/src/poly.rs b/src/poly.rs index ca62bc2..0c55a75 100644 --- a/src/poly.rs +++ b/src/poly.rs @@ -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)] @@ -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> ops::AddAssign for Poly { fn add_assign(&mut self, rhs: B) { let len = self.coeff.len(); @@ -139,7 +139,7 @@ impl> ops::Sub 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 for Poly { type Output = Poly; @@ -158,7 +158,7 @@ impl<'a> ops::Sub 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> ops::Mul for &'a Poly { type Output = Poly; @@ -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; @@ -608,7 +608,8 @@ impl BivarPoly { result.add_assign(&summand); } result - }).collect(); + }) + .collect(); Poly::from(coeff) } @@ -692,7 +693,8 @@ impl BivarCommitment { result.add_assign(&summand); } result - }).collect(); + }) + .collect(); Commitment { coeff } } @@ -710,7 +712,8 @@ fn powers(into_x: T, degree: usize) -> Vec { .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 diff --git a/src/secret.rs b/src/secret.rs index 3767720..1745946 100644 --- a/src/secret.rs +++ b/src/secret.rs @@ -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. diff --git a/src/serde_impl.rs b/src/serde_impl.rs index d0a4e1e..d79c839 100644 --- a/src/serde_impl.rs +++ b/src/serde_impl.rs @@ -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"; @@ -24,7 +24,8 @@ impl Serialize for BivarCommitment { WireBivarCommitment { degree: self.degree, coeff: Cow::Borrowed(&self.coeff), - }.serialize(s) + } + .serialize(s) } } @@ -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); @@ -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 {