Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix clippy lints #137

Merged
merged 1 commit into from
Jul 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions benches/groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use bls12_381::*;

use criterion::{black_box, Criterion};

#[allow(clippy::many_single_char_names)]
fn criterion_benchmark(c: &mut Criterion) {
// Pairings
{
Expand Down
2 changes: 1 addition & 1 deletion src/fp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ fn test_conditional_selection() {
fn test_equality() {
fn is_equal(a: &Fp, b: &Fp) -> bool {
let eq = a == b;
let ct_eq = a.ct_eq(&b);
let ct_eq = a.ct_eq(b);

assert_eq!(eq, bool::from(ct_eq));

Expand Down
2 changes: 1 addition & 1 deletion src/fp2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ fn test_conditional_selection() {
fn test_equality() {
fn is_equal(a: &Fp2, b: &Fp2) -> bool {
let eq = a == b;
let ct_eq = a.ct_eq(&b);
let ct_eq = a.ct_eq(b);

assert_eq!(eq, bool::from(ct_eq));

Expand Down
23 changes: 16 additions & 7 deletions src/g1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1760,15 +1760,24 @@ fn test_commutative_scalar_subgroup_multiplication() {
let g1_a = G1Affine::generator();
let g1_p = G1Projective::generator();

// By reference.
assert_eq!(&g1_a * &a, &a * &g1_a);
assert_eq!(&g1_p * &a, &a * &g1_p);
// By reference. In subfunction to avoid "needlessly taken reference" lint.
fn by_ref(g1_a: &G1Affine, g1_p: &G1Projective, a: &Scalar) {
assert_eq!(g1_a * a, a * g1_a);
assert_eq!(g1_p * a, a * g1_p);
}
by_ref(&g1_a, &g1_p, &a);

// Mixed
assert_eq!(&g1_a * a.clone(), a.clone() * &g1_a);
assert_eq!(&g1_p * a.clone(), a.clone() * &g1_p);
assert_eq!(g1_a.clone() * &a, &a * g1_a.clone());
assert_eq!(g1_p.clone() * &a, &a * g1_p.clone());
fn group_ref(g1_a: &G1Affine, g1_p: &G1Projective, a: Scalar) {
assert_eq!(g1_a * a, a * g1_a);
assert_eq!(g1_p * a, a * g1_p);
}
fn scalar_ref(g1_a: G1Affine, g1_p: G1Projective, a: &Scalar) {
assert_eq!(g1_a * a, a * g1_a);
assert_eq!(g1_p * a, a * g1_p);
}
group_ref(&g1_a, &g1_p, a);
scalar_ref(g1_a, g1_p, &a);

// By value.
assert_eq!(g1_p * a, a * g1_p);
Expand Down
23 changes: 16 additions & 7 deletions src/g2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2163,15 +2163,24 @@ fn test_commutative_scalar_subgroup_multiplication() {
let g2_a = G2Affine::generator();
let g2_p = G2Projective::generator();

// By reference.
assert_eq!(&g2_a * &a, &a * &g2_a);
assert_eq!(&g2_p * &a, &a * &g2_p);
// By reference. In subfunction to avoid "needlessly taken reference" lint.
fn by_ref(g2_a: &G2Affine, g2_p: &G2Projective, a: &Scalar) {
assert_eq!(g2_a * a, a * g2_a);
assert_eq!(g2_p * a, a * g2_p);
}
by_ref(&g2_a, &g2_p, &a);

// Mixed
assert_eq!(&g2_a * a.clone(), a.clone() * &g2_a);
assert_eq!(&g2_p * a.clone(), a.clone() * &g2_p);
assert_eq!(g2_a.clone() * &a, &a * g2_a.clone());
assert_eq!(g2_p.clone() * &a, &a * g2_p.clone());
fn group_ref(g2_a: &G2Affine, g2_p: &G2Projective, a: Scalar) {
assert_eq!(g2_a * a, a * g2_a);
assert_eq!(g2_p * a, a * g2_p);
}
fn scalar_ref(g2_a: G2Affine, g2_p: G2Projective, a: &Scalar) {
assert_eq!(g2_a * a, a * g2_a);
assert_eq!(g2_p * a, a * g2_p);
}
group_ref(&g2_a, &g2_p, a);
scalar_ref(g2_a, g2_p, &a);

// By value.
assert_eq!(g2_p * a, a * g2_p);
Expand Down
12 changes: 6 additions & 6 deletions src/hash_to_curve/map_g1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -788,14 +788,14 @@ pub const P_M1_OVER2: Fp = Fp::from_raw_unchecked([

#[test]
fn test_sgn0() {
assert_eq!(bool::from(Fp::zero().sgn0()), false);
assert_eq!(bool::from(Fp::one().sgn0()), true);
assert_eq!(bool::from((-Fp::one()).sgn0()), false);
assert_eq!(bool::from((-Fp::zero()).sgn0()), false);
assert_eq!(bool::from(P_M1_OVER2.sgn0()), true);
assert!(!bool::from(Fp::zero().sgn0()));
assert!(bool::from(Fp::one().sgn0()));
assert!(!bool::from((-Fp::one()).sgn0()));
assert!(!bool::from((-Fp::zero()).sgn0()));
assert!(bool::from(P_M1_OVER2.sgn0()));

let p_p1_over2 = P_M1_OVER2 + Fp::one();
assert_eq!(bool::from(p_p1_over2.sgn0()), false);
assert!(!bool::from(p_p1_over2.sgn0()));

let neg_p_p1_over2 = {
let mut tmp = p_p1_over2;
Expand Down
Loading
Loading