Rust added support for the ? operator on Option in 1.22

This converts a few instances of an early-returning unwrap to it.
This commit is contained in:
François Garillot 2019-10-05 11:41:13 -07:00
parent cf03d39f0f
commit 023fdf2a2c
No known key found for this signature in database
GPG key ID: 3E1EA1A9D2044742
6 changed files with 16 additions and 36 deletions

View file

@ -101,12 +101,10 @@ impl VartimeMultiscalarMul for Pippenger {
.into_iter() .into_iter()
.map(|p| p.map(|P| P.to_projective_niels())); .map(|p| p.map(|P| P.to_projective_niels()));
let scalars_points = scalars.zip(points).map(|(s,maybe_p)| maybe_p.map(|p| (s,p) ) ) let scalars_points = scalars
.collect::<Option<Vec<_>>>(); .zip(points)
let scalars_points = match scalars_points { .map(|(s, maybe_p)| maybe_p.map(|p| (s, p)))
Some(sp) => sp, .collect::<Option<Vec<_>>>()?;
None => return None,
};
// Prepare 2^w/2 buckets. // Prepare 2^w/2 buckets.
// buckets[i] corresponds to a multiplication factor (i+1). // buckets[i] corresponds to a multiplication factor (i+1).

View file

@ -67,14 +67,10 @@ impl VartimePrecomputedMultiscalarMul for VartimePrecomputedStraus {
.map(|c| c.borrow().non_adjacent_form(5)) .map(|c| c.borrow().non_adjacent_form(5))
.collect::<Vec<_>>(); .collect::<Vec<_>>();
let dynamic_lookup_tables = match dynamic_points let dynamic_lookup_tables = dynamic_points
.into_iter() .into_iter()
.map(|P_opt| P_opt.map(|P| NafLookupTable5::<ProjectiveNielsPoint>::from(&P))) .map(|P_opt| P_opt.map(|P| NafLookupTable5::<ProjectiveNielsPoint>::from(&P)))
.collect::<Option<Vec<_>>>() .collect::<Option<Vec<_>>>()?;
{
Some(x) => x,
None => return None,
};
let sp = self.static_lookup_tables.len(); let sp = self.static_lookup_tables.len();
let dp = dynamic_lookup_tables.len(); let dp = dynamic_lookup_tables.len();

View file

@ -168,14 +168,10 @@ impl VartimeMultiscalarMul for Straus {
.map(|c| c.borrow().non_adjacent_form(5)) .map(|c| c.borrow().non_adjacent_form(5))
.collect(); .collect();
let lookup_tables = match points let lookup_tables = points
.into_iter() .into_iter()
.map(|P_opt| P_opt.map(|P| NafLookupTable5::<ProjectiveNielsPoint>::from(&P))) .map(|P_opt| P_opt.map(|P| NafLookupTable5::<ProjectiveNielsPoint>::from(&P)))
.collect::<Option<Vec<_>>>() .collect::<Option<Vec<_>>>()?;
{
Some(x) => x,
None => return None,
};
let mut r = ProjectivePoint::identity(); let mut r = ProjectivePoint::identity();

View file

@ -58,12 +58,10 @@ impl VartimeMultiscalarMul for Pippenger {
.into_iter() .into_iter()
.map(|p| p.map(|P| CachedPoint::from(ExtendedPoint::from(P)))); .map(|p| p.map(|P| CachedPoint::from(ExtendedPoint::from(P))));
let scalars_points = scalars.zip(points).map(|(s,maybe_p)| maybe_p.map(|p| (s,p) ) ) let scalars_points = scalars
.collect::<Option<Vec<_>>>(); .zip(points)
let scalars_points = match scalars_points { .map(|(s, maybe_p)| maybe_p.map(|p| (s, p)))
Some(sp) => sp, .collect::<Option<Vec<_>>>()?;
None => return None,
};
// Prepare 2^w/2 buckets. // Prepare 2^w/2 buckets.
// buckets[i] corresponds to a multiplication factor (i+1). // buckets[i] corresponds to a multiplication factor (i+1).

View file

@ -66,14 +66,10 @@ impl VartimePrecomputedMultiscalarMul for VartimePrecomputedStraus {
.map(|c| c.borrow().non_adjacent_form(5)) .map(|c| c.borrow().non_adjacent_form(5))
.collect::<Vec<_>>(); .collect::<Vec<_>>();
let dynamic_lookup_tables = match dynamic_points let dynamic_lookup_tables = dynamic_points
.into_iter() .into_iter()
.map(|P_opt| P_opt.map(|P| NafLookupTable5::<CachedPoint>::from(&P))) .map(|P_opt| P_opt.map(|P| NafLookupTable5::<CachedPoint>::from(&P)))
.collect::<Option<Vec<_>>>() .collect::<Option<Vec<_>>>()?;
{
Some(x) => x,
None => return None,
};
let sp = self.static_lookup_tables.len(); let sp = self.static_lookup_tables.len();
let dp = dynamic_lookup_tables.len(); let dp = dynamic_lookup_tables.len();

View file

@ -83,14 +83,10 @@ impl VartimeMultiscalarMul for Straus {
.into_iter() .into_iter()
.map(|c| c.borrow().non_adjacent_form(5)) .map(|c| c.borrow().non_adjacent_form(5))
.collect(); .collect();
let lookup_tables: Vec<_> = match points let lookup_tables: Vec<_> = points
.into_iter() .into_iter()
.map(|P_opt| P_opt.map(|P| NafLookupTable5::<CachedPoint>::from(&P))) .map(|P_opt| P_opt.map(|P| NafLookupTable5::<CachedPoint>::from(&P)))
.collect::<Option<Vec<_>>>() .collect::<Option<Vec<_>>>()?;
{
Some(x) => x,
None => return None,
};
let mut Q = ExtendedPoint::identity(); let mut Q = ExtendedPoint::identity();