From 51eea1334c5e7278696c6ac6d8c8fecde39397ff Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Mon, 21 Sep 2020 20:21:32 +0300 Subject: [PATCH 1/2] fix edition and prepare publish (#19) --- src/arith.rs | 16 ++++++++-------- src/fields/fp.rs | 8 ++++---- src/fields/fq12.rs | 4 ++-- src/fields/fq2.rs | 6 +++--- src/fields/fq6.rs | 2 +- src/fields/mod.rs | 4 ++-- src/groups/mod.rs | 26 +++++++++++++------------- src/groups/tests.rs | 2 +- src/lib.rs | 6 +++--- 9 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/arith.rs b/src/arith.rs index 0f47a3c1..69435f65 100644 --- a/src/arith.rs +++ b/src/arith.rs @@ -151,14 +151,14 @@ impl U512 { #[cfg(feature = "rustc-serialize")] impl Encodable for U512 { fn encode(&self, s: &mut S) -> Result<(), S::Error> { - let mut buf = [0; (4 * 16)]; + let mut buf = [0; 4 * 16]; for (l, i) in (0..4).rev().zip((0..4).map(|i| i * 16)) { BigEndian::write_u128(&mut buf[i..], self.0[l]); } for i in 0..(4 * 16) { - try!(s.emit_u8(buf[i])); + s.emit_u8(buf[i])?; } Ok(()) @@ -168,10 +168,10 @@ impl Encodable for U512 { #[cfg(feature = "rustc-serialize")] impl Decodable for U512 { fn decode(s: &mut S) -> Result { - let mut buf = [0; (4 * 16)]; + let mut buf = [0; 4 * 16]; for i in 0..(4 * 16) { - buf[i] = try!(s.read_u8()); + buf[i] = s.read_u8()?; } Ok(U512::interpret(&buf)) @@ -181,14 +181,14 @@ impl Decodable for U512 { #[cfg(feature = "rustc-serialize")] impl Encodable for U256 { fn encode(&self, s: &mut S) -> Result<(), S::Error> { - let mut buf = [0; (2 * 16)]; + let mut buf = [0; 2 * 16]; for (l, i) in (0..2).rev().zip((0..2).map(|i| i * 16)) { BigEndian::write_u128(&mut buf[i..], self.0[l]); } for i in 0..(2 * 16) { - try!(s.emit_u8(buf[i])); + s.emit_u8(buf[i])?; } Ok(()) @@ -198,10 +198,10 @@ impl Encodable for U256 { #[cfg(feature = "rustc-serialize")] impl Decodable for U256 { fn decode(s: &mut S) -> Result { - let mut buf = [0; (2 * 16)]; + let mut buf = [0; 2 * 16]; for i in 0..(2 * 16) { - buf[i] = try!(s.read_u8()); + buf[i] = s.read_u8()?; } U256::from_slice(&buf).map_err(|_| s.error("Invalid input length; Also unreachable;")) diff --git a/src/fields/fp.rs b/src/fields/fp.rs index f867296d..715ebf23 100644 --- a/src/fields/fp.rs +++ b/src/fields/fp.rs @@ -1,8 +1,8 @@ use alloc::vec::Vec; use core::ops::{Add, Mul, Neg, Sub}; use rand::Rng; -use fields::FieldElement; -use arith::{U256, U512}; +use crate::fields::FieldElement; +use crate::arith::{U256, U512}; #[cfg(feature = "rustc-serialize")] use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; @@ -34,7 +34,7 @@ macro_rules! field_impl { #[cfg(feature = "rustc-serialize")] impl Decodable for $name { fn decode(s: &mut S) -> Result<$name, S::Error> { - $name::new(try!(U256::decode(s))).ok_or_else(|| s.error("integer is not less than modulus")) + $name::new(U256::decode(s)?).ok_or_else(|| s.error("integer is not less than modulus")) } } @@ -312,4 +312,4 @@ fn sqrt_fq() { let fq2 = Fq::from_str("348579348568").unwrap(); assert_eq!(fq1, fq2.sqrt().expect("348579348568 is quadratic residue")); -} \ No newline at end of file +} diff --git a/src/fields/fq12.rs b/src/fields/fq12.rs index 9939fa0f..e86f239f 100644 --- a/src/fields/fq12.rs +++ b/src/fields/fq12.rs @@ -1,7 +1,7 @@ use core::ops::{Add, Mul, Neg, Sub}; use rand::Rng; -use fields::{const_fq, FieldElement, Fq, Fq2, Fq6}; -use arith::U256; +use crate::fields::{const_fq, FieldElement, Fq, Fq2, Fq6}; +use crate::arith::U256; fn frobenius_coeffs_c1(power: usize) -> Fq2 { match power % 12 { diff --git a/src/fields/fq2.rs b/src/fields/fq2.rs index 3e05a575..7f0f4d11 100644 --- a/src/fields/fq2.rs +++ b/src/fields/fq2.rs @@ -1,7 +1,7 @@ use core::ops::{Add, Mul, Neg, Sub}; use rand::Rng; -use fields::{const_fq, FieldElement, Fq}; -use arith::{U256, U512}; +use crate::fields::{const_fq, FieldElement, Fq}; +use crate::arith::{U256, U512}; #[cfg(feature = "rustc-serialize")] use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; @@ -56,7 +56,7 @@ impl Encodable for Fq2 { #[cfg(feature = "rustc-serialize")] impl Decodable for Fq2 { fn decode(s: &mut S) -> Result { - let combined = try!(U512::decode(s)); + let combined = U512::decode(s)?; match combined.divrem(&Fq::modulus()) { (Some(c1), c0) => Ok(Fq2::new(Fq::new(c0).unwrap(), Fq::new(c1).unwrap())), diff --git a/src/fields/fq6.rs b/src/fields/fq6.rs index 0d2e597d..5cb3d85a 100644 --- a/src/fields/fq6.rs +++ b/src/fields/fq6.rs @@ -1,4 +1,4 @@ -use fields::{const_fq, FieldElement, Fq, Fq2}; +use crate::fields::{const_fq, FieldElement, Fq, Fq2}; use core::ops::{Add, Mul, Neg, Sub}; use rand::Rng; diff --git a/src/fields/mod.rs b/src/fields/mod.rs index 071cb282..ae014895 100644 --- a/src/fields/mod.rs +++ b/src/fields/mod.rs @@ -3,7 +3,7 @@ mod fq2; mod fq6; mod fq12; -use arith::U256; +use crate::arith::U256; use rand::Rng; use core::ops::{Add, Mul, Neg, Sub}; use alloc::fmt::Debug; @@ -26,7 +26,7 @@ pub trait FieldElement + Debug { fn zero() -> Self; fn one() -> Self; - fn random(&mut R) -> Self; + fn random(_: &mut R) -> Self; fn is_zero(&self) -> bool; fn squared(&self) -> Self { (*self) * (*self) diff --git a/src/groups/mod.rs b/src/groups/mod.rs index c07d2381..6d86a882 100644 --- a/src/groups/mod.rs +++ b/src/groups/mod.rs @@ -1,5 +1,5 @@ -use fields::{const_fq, FieldElement, Fq, Fq12, Fq2, Fr, fq2_nonresidue}; -use arith::U256; +use crate::fields::{const_fq, FieldElement, Fq, Fq12, Fq2, Fr, fq2_nonresidue}; +use crate::arith::U256; use core::{fmt, ops::{Add, Mul, Neg, Sub}}; use rand::Rng; use alloc::vec::Vec; @@ -238,7 +238,7 @@ impl Encodable for G

{ l.encode(s) } else { let l: u8 = 4; - try!(l.encode(s)); + l.encode(s)?; self.to_affine().unwrap().encode(s) } } @@ -247,8 +247,8 @@ impl Encodable for G

{ #[cfg(feature = "rustc-serialize")] impl Encodable for AffineG

{ fn encode(&self, s: &mut S) -> Result<(), S::Error> { - try!(self.x.encode(s)); - try!(self.y.encode(s)); + self.x.encode(s)?; + self.y.encode(s)?; Ok(()) } @@ -257,11 +257,11 @@ impl Encodable for AffineG

{ #[cfg(feature = "rustc-serialize")] impl Decodable for G

{ fn decode(s: &mut S) -> Result, S::Error> { - let l = try!(u8::decode(s)); + let l = u8::decode(s)?; if l == 0 { Ok(G::zero()) } else if l == 4 { - Ok(try!(AffineG::decode(s)).to_jacobian()) + Ok(AffineG::decode(s)?.to_jacobian()) } else { Err(s.error("invalid leading byte for uncompressed group element")) } @@ -271,8 +271,8 @@ impl Decodable for G

{ #[cfg(feature = "rustc-serialize")] impl Decodable for AffineG

{ fn decode(s: &mut S) -> Result, S::Error> { - let x = try!(P::Base::decode(s)); - let y = try!(P::Base::decode(s)); + let x = P::Base::decode(s)?; + let y = P::Base::decode(s)?; Self::new(x, y).map_err(|e| match e { Error::NotOnCurve => s.error("point is not on the curve"), @@ -696,7 +696,7 @@ pub fn miller_loop_batch(g2_precomputes: &Vec, g1_vec: &Vec Fq12 { if exists { p_affines.push(p.to_affine().unwrap()); - q_precomputes.push(q.to_affine().unwrap().precompute()); + q_precomputes.push(q.to_affine().unwrap().precompute()); } } if q_precomputes.len() == 0 { @@ -982,7 +982,7 @@ pub fn pairing_batch(ps: &[G1], qs: &[G2]) -> Fq12 { #[test] fn test_reduced_pairing() { - use fields::Fq6; + use crate::fields::Fq6; let g1 = G1::one() * Fr::from_str( @@ -1129,7 +1129,7 @@ fn test_batch_bilinearity_fifty() { let mut q_vec : Vec = Vec::new(); let mut sp_vec : Vec = Vec::new(); let mut sq_vec : Vec = Vec::new(); - + for _ in 0..50 { let p = G1::random(&mut rng); let q = G2::random(&mut rng); diff --git a/src/groups/tests.rs b/src/groups/tests.rs index b460a589..5e70516a 100644 --- a/src/groups/tests.rs +++ b/src/groups/tests.rs @@ -1,5 +1,5 @@ use super::GroupElement; -use fields::{FieldElement, Fr}; +use crate::fields::{FieldElement, Fr}; use rand::Rng; fn random_test_addition(rng: &mut R) { diff --git a/src/lib.rs b/src/lib.rs index cd0d60fc..b79308c7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,8 +14,8 @@ pub mod arith; mod fields; mod groups; -use fields::FieldElement; -use groups::{GroupElement, G1Params, G2Params, GroupParams}; +use crate::fields::FieldElement; +use crate::groups::{GroupElement, G1Params, G2Params, GroupParams}; use alloc::vec::Vec; use core::ops::{Add, Mul, Neg, Sub}; @@ -129,7 +129,7 @@ impl From for CurveError { } } -pub use groups::Error as GroupError; +pub use crate::groups::Error as GroupError; #[derive(Copy, Clone, Debug, PartialEq, Eq)] #[cfg_attr(feature = "rustc-serialize", derive(RustcDecodable, RustcEncodable))] From b048fe1d84f1265e061dd4a6e4c44e2fd0e088b4 Mon Sep 17 00:00:00 2001 From: girazoki Date: Wed, 21 Apr 2021 14:45:48 +0200 Subject: [PATCH 2/2] update rand pacakge to 0.8.3 (#20) --- Cargo.toml | 4 ++-- src/fields/tests.rs | 2 +- src/groups/mod.rs | 6 +++--- src/groups/tests.rs | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f31bcaf2..ffa09b1a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ default = ["rustc-serialize"] name = "api" [dependencies] -rand = { version = "0.5", features = ["i128_support"], default-features = false } +rand = { version = "0.8.3", default-features = false } rustc-serialize = { version = "0.3", optional = true } byteorder = { version = "1.0", features = ["i128"], default-features = false } crunchy = "0.2.1" @@ -24,7 +24,7 @@ lazy_static = { version = "1.4.0", features = ["spin_no_std"] } rustc-hex = { version = "2", default-features = false } [dev-dependencies] -rand = { version = "0.5", features = ["i128_support"] } +rand = { version = "0.8.3", features = ["std_rng"] } [dev-dependencies.bincode] version = "0.6" diff --git a/src/fields/tests.rs b/src/fields/tests.rs index 28a51f20..2d92a5b3 100644 --- a/src/fields/tests.rs +++ b/src/fields/tests.rs @@ -1,4 +1,4 @@ -use rand::{Rng, SeedableRng, StdRng}; +use rand::{Rng, SeedableRng, rngs::StdRng}; use super::FieldElement; fn can_invert() { diff --git a/src/groups/mod.rs b/src/groups/mod.rs index 6d86a882..1f999f96 100644 --- a/src/groups/mod.rs +++ b/src/groups/mod.rs @@ -1096,7 +1096,7 @@ fn test_batch_bilinearity_empty() { #[test] fn test_batch_bilinearity_one() { - use rand::{SeedableRng, StdRng}; + use rand::{SeedableRng, rngs::StdRng}; let seed = [ 0, 0, 0, 0, 0, 0, 64, 13, // 103245 0, 0, 0, 0, 0, 0, 176, 2, // 191922 @@ -1116,7 +1116,7 @@ fn test_batch_bilinearity_one() { #[test] fn test_batch_bilinearity_fifty() { - use rand::{SeedableRng, StdRng}; + use rand::{SeedableRng, rngs::StdRng}; let seed = [ 0, 0, 0, 0, 0, 0, 64, 13, // 103245 0, 0, 0, 0, 0, 0, 176, 2, // 191922 @@ -1148,7 +1148,7 @@ fn test_batch_bilinearity_fifty() { #[test] fn test_bilinearity() { - use rand::{SeedableRng, StdRng}; + use rand::{SeedableRng, rngs::StdRng}; let seed = [ 0, 0, 0, 0, 0, 0, 64, 13, // 103245 0, 0, 0, 0, 0, 0, 176, 2, // 191922 diff --git a/src/groups/tests.rs b/src/groups/tests.rs index 5e70516a..c66dbb41 100644 --- a/src/groups/tests.rs +++ b/src/groups/tests.rs @@ -90,7 +90,7 @@ pub fn group_trials() { assert!((G::one() * (-Fr::one()) + G::one()).is_zero()); - use rand::{SeedableRng, StdRng}; + use rand::{SeedableRng, rngs::StdRng}; let seed = [ 0, 0, 0, 0, 0, 0, 64, 13, // 103245 0, 0, 0, 0, 0, 0, 176, 2, // 191922