fmt/clippy

This commit is contained in:
Luke Parker
2022-09-17 04:35:08 -04:00
parent fd6c58805f
commit 65c20638ce
11 changed files with 15 additions and 24 deletions

View File

@@ -165,8 +165,7 @@ impl FieldElement {
let mut bits = 0;
for (i, bit) in other.to_le_bits().iter().rev().enumerate() {
bits <<= 1;
let bit = *bit as u8;
assert_eq!(bit | 1, 1);
let bit = u8::from(*bit);
bits |= bit;
if ((i + 1) % 4) == 0 {

View File

@@ -37,9 +37,7 @@ pub mod field;
// Convert a boolean to a Choice in a *presumably* constant time manner
fn choice(value: bool) -> Choice {
let bit = value as u8;
debug_assert_eq!(bit | 1, 1);
Choice::from(bit)
Choice::from(u8::from(value))
}
macro_rules! deref_borrow {

View File

@@ -226,8 +226,7 @@ where
break;
}
let mut bit = *raw_bit as u8;
debug_assert_eq!(bit | 1, 1);
let mut bit = u8::from(*raw_bit);
*raw_bit = false;
// Accumulate this bit
@@ -246,7 +245,7 @@ where
these_bits,
&mut blinding_key,
));
these_bits = 0;
these_bits.zeroize();
}
}
debug_assert_eq!(bits.len(), capacity / bits_per_group);

View File

@@ -34,9 +34,8 @@ pub fn scalar_normalize<F0: PrimeFieldBits + Zeroize, F1: PrimeFieldBits>(
res1 = res1.double();
res2 = res2.double();
let mut bit = *raw_bit as u8;
debug_assert_eq!(bit | 1, 1);
*raw_bit = false;
let mut bit = u8::from(*raw_bit);
*raw_bit = 0;
res1 += F0::from(bit.into());
res2 += F1::from(bit.into());

View File

@@ -61,8 +61,7 @@ macro_rules! field {
let mut bits = 0;
for (i, bit) in other.to_le_bits().iter().rev().enumerate() {
bits <<= 1;
let bit = *bit as u8;
assert_eq!(bit | 1, 1);
let bit = u8::from(*bit);
bits |= bit;
if ((i + 1) % 4) == 0 {

View File

@@ -227,8 +227,7 @@ impl Mul<Scalar> for Point {
let mut bits = 0;
for (i, bit) in other.to_le_bits().iter().rev().enumerate() {
bits <<= 1;
let bit = *bit as u8;
assert_eq!(bit | 1, 1);
let bit = u8::from(*bit);
bits |= bit;
if ((i + 1) % 4) == 0 {
@@ -320,7 +319,7 @@ fn addition_multiplication_serialization() {
let mut accum = Point::identity();
for x in 1 .. 10 {
accum += Point::generator();
let mul = Point::generator() * Scalar::from(x as u8);
let mul = Point::generator() * Scalar::from(u8::try_from(x).unwrap());
assert_eq!(accum, mul);
assert_eq!(Point::from_bytes(&mul.to_bytes()).unwrap(), mul);
}

View File

@@ -128,7 +128,8 @@ fn ed448_non_ietf() {
"e7c423399b36a33ece81aaa75e419a9dc4387edc99682f9e4742c9b1",
"a9c2392cfe30510fd33f069a42dde987544dabd7ad307a62ae1c6b13",
"00"
).to_string()
)
.to_string(),
},
);
}

View File

@@ -31,8 +31,7 @@ where
#[allow(unused_assignments)]
for (i, mut raw_bit) in bits.iter_mut().enumerate() {
let mut bit = *raw_bit as u8;
debug_assert_eq!(bit | 1, 1);
let mut bit = u8::from(*raw_bit);
*raw_bit = false;
groupings[p][i / w_usize] |= bit << (i % w_usize);