diff --git a/bls12_381/src/fp.rs b/bls12_381/src/fp.rs index 02d1d7855..dfe884995 100644 --- a/bls12_381/src/fp.rs +++ b/bls12_381/src/fp.rs @@ -47,7 +47,7 @@ impl Eq for Fp {} impl PartialEq for Fp { #[inline] fn eq(&self, other: &Self) -> bool { - self.ct_eq(other).unwrap_u8() == 1 + bool::from(self.ct_eq(other)) } } @@ -566,7 +566,7 @@ fn test_equality() { let eq = a == b; let ct_eq = a.ct_eq(&b); - assert_eq!(eq, ct_eq.unwrap_u8() == 1); + assert_eq!(eq, bool::from(ct_eq)); eq } @@ -762,18 +762,16 @@ fn test_from_bytes() { .unwrap() ); - assert!( + assert!(bool::from( Fp::from_bytes(&[ 27, 1, 17, 234, 57, 127, 230, 154, 75, 27, 167, 182, 67, 75, 172, 215, 100, 119, 75, 132, 243, 133, 18, 191, 103, 48, 210, 160, 246, 176, 246, 36, 30, 171, 255, 254, 177, 83, 255, 255, 185, 254, 255, 255, 255, 255, 170, 170 ]) .is_none() - .unwrap_u8() - == 1 - ); + )); - assert!(Fp::from_bytes(&[0xff; 48]).is_none().unwrap_u8() == 1); + assert!(bool::from(Fp::from_bytes(&[0xff; 48]).is_none())); } #[test] @@ -823,7 +821,7 @@ fn test_inversion() { ]); assert_eq!(a.invert().unwrap(), b); - assert!(Fp::zero().invert().is_none().unwrap_u8() == 1); + assert!(bool::from(Fp::zero().invert().is_none())); } #[test] diff --git a/bls12_381/src/fp2.rs b/bls12_381/src/fp2.rs index 3890d31b3..1f5370845 100644 --- a/bls12_381/src/fp2.rs +++ b/bls12_381/src/fp2.rs @@ -44,7 +44,7 @@ impl Eq for Fp2 {} impl PartialEq for Fp2 { #[inline] fn eq(&self, other: &Self) -> bool { - self.ct_eq(other).unwrap_u8() == 1 + bool::from(self.ct_eq(other)) } } @@ -361,7 +361,7 @@ fn test_equality() { let eq = a == b; let ct_eq = a.ct_eq(&b); - assert_eq!(eq, ct_eq.unwrap_u8() == 1); + assert_eq!(eq, bool::from(ct_eq)); eq } @@ -788,7 +788,7 @@ fn test_inversion() { assert_eq!(a.invert().unwrap(), b); - assert!(Fp2::zero().invert().is_none().unwrap_u8() == 1); + assert!(bool::from(Fp2::zero().invert().is_none())); } #[test] diff --git a/bls12_381/src/scalar.rs b/bls12_381/src/scalar.rs index 5bbfec5c4..c9c385d2d 100644 --- a/bls12_381/src/scalar.rs +++ b/bls12_381/src/scalar.rs @@ -54,7 +54,7 @@ impl ConstantTimeEq for Scalar { impl PartialEq for Scalar { #[inline] fn eq(&self, other: &Self) -> bool { - self.ct_eq(other).unwrap_u8() == 1 + bool::from(self.ct_eq(other)) } } @@ -834,55 +834,45 @@ fn test_from_bytes() { ); // -1 should work - assert!( + assert!(bool::from( Scalar::from_bytes(&[ 0, 0, 0, 0, 255, 255, 255, 255, 254, 91, 254, 255, 2, 164, 189, 83, 5, 216, 161, 9, 8, 216, 57, 51, 72, 125, 157, 41, 83, 167, 237, 115 ]) .is_some() - .unwrap_u8() - == 1 - ); + )); // modulus is invalid - assert!( + assert!(bool::from( Scalar::from_bytes(&[ 1, 0, 0, 0, 255, 255, 255, 255, 254, 91, 254, 255, 2, 164, 189, 83, 5, 216, 161, 9, 8, 216, 57, 51, 72, 125, 157, 41, 83, 167, 237, 115 ]) .is_none() - .unwrap_u8() - == 1 - ); + )); // Anything larger than the modulus is invalid - assert!( + assert!(bool::from( Scalar::from_bytes(&[ 2, 0, 0, 0, 255, 255, 255, 255, 254, 91, 254, 255, 2, 164, 189, 83, 5, 216, 161, 9, 8, 216, 57, 51, 72, 125, 157, 41, 83, 167, 237, 115 ]) .is_none() - .unwrap_u8() - == 1 - ); - assert!( + )); + assert!(bool::from( Scalar::from_bytes(&[ 1, 0, 0, 0, 255, 255, 255, 255, 254, 91, 254, 255, 2, 164, 189, 83, 5, 216, 161, 9, 8, 216, 58, 51, 72, 125, 157, 41, 83, 167, 237, 115 ]) .is_none() - .unwrap_u8() - == 1 - ); - assert!( + )); + assert!(bool::from( Scalar::from_bytes(&[ 1, 0, 0, 0, 255, 255, 255, 255, 254, 91, 254, 255, 2, 164, 189, 83, 5, 216, 161, 9, 8, 216, 57, 51, 72, 125, 157, 41, 83, 167, 237, 116 ]) .is_none() - .unwrap_u8() - == 1 - ); + )); } #[test] @@ -1083,7 +1073,7 @@ fn test_squaring() { #[test] fn test_inversion() { - assert_eq!(Scalar::zero().invert().is_none().unwrap_u8(), 1); + assert!(bool::from(Scalar::zero().invert().is_none())); assert_eq!(Scalar::one().invert().unwrap(), Scalar::one()); assert_eq!((-&Scalar::one()).invert().unwrap(), -&Scalar::one()); @@ -1143,7 +1133,7 @@ fn test_sqrt() { for _ in 0..100 { let square_root = square.sqrt(); - if square_root.is_none().unwrap_u8() == 1 { + if bool::from(square_root.is_none()) { none_count += 1; } else { assert_eq!(square_root.unwrap() * square_root.unwrap(), square);