Skip to content

Commit fb03fa4

Browse files
committed
CI: add clippy and rustfmt
1 parent 28bf292 commit fb03fa4

3 files changed

Lines changed: 67 additions & 49 deletions

File tree

.github/workflows/test.yml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,24 @@ jobs:
6969
- uses: actions/checkout@v6
7070
- uses: dtolnay/rust-toolchain@nightly
7171
- run: rustup component add miri && cargo miri setup
72-
- run: cargo miri test --target ${{ matrix.target }} --all-features --lib
72+
- run: cargo miri test --target ${{ matrix.target }} --all-features --lib
73+
74+
clippy:
75+
runs-on: ubuntu-latest
76+
steps:
77+
- uses: actions/checkout@v6
78+
- uses: dtolnay/rust-toolchain@master
79+
with:
80+
toolchain: 1.92.0 # Pinned to prevent breakages
81+
components: clippy
82+
- run: cargo clippy --workspace --all-features --lib --bins --tests -- -D warnings
83+
84+
rustfmt:
85+
runs-on: ubuntu-latest
86+
steps:
87+
- uses: actions/checkout@v6
88+
- uses: dtolnay/rust-toolchain@master
89+
with:
90+
toolchain: stable
91+
components: rustfmt
92+
- run: cargo fmt --all -- --check

src/lib.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// - Henry de Valence <hdevalence@hdevalence.ca>
1010

1111
#![no_std]
12+
#![allow(clippy::inline_fn_without_body)]
1213
#![deny(missing_docs)]
1314
#![doc(html_logo_url = "https://doc.dalek.rs/assets/dalek-logo-clear.png")]
1415

@@ -88,9 +89,9 @@
8889
//! [rust-timing-shield]: https://www.chosenplaintext.ca/open-source/rust-timing-shield/security
8990
9091
use core::cmp;
92+
use core::hint::black_box;
9193
use core::ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Neg, Not};
9294
use core::option::Option;
93-
use core::hint::black_box;
9495

9596
/// The `Choice` struct represents a choice for use in conditional assignment.
9697
///
@@ -436,7 +437,7 @@ pub trait ConditionallySelectable: Copy {
436437
#[inline]
437438
fn conditional_swap(a: &mut Self, b: &mut Self, choice: Choice) {
438439
let t: Self = *a;
439-
a.conditional_assign(&b, choice);
440+
a.conditional_assign(b, choice);
440441
b.conditional_assign(&t, choice);
441442
}
442443
}
@@ -642,10 +643,7 @@ impl<T> CtOption<T> {
642643
/// exposed.
643644
#[inline]
644645
pub fn new(value: T, is_some: Choice) -> CtOption<T> {
645-
CtOption {
646-
value: value,
647-
is_some: is_some,
648-
}
646+
CtOption { value, is_some }
649647
}
650648

651649
/// Returns the contained value, consuming the `self` value.

tests/mod.rs

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@ fn slices_equal_different_lengths() {
1010
let a: [u8; 3] = [0, 0, 0];
1111
let b: [u8; 4] = [0, 0, 0, 0];
1212

13-
assert_eq!((&a).ct_eq(&b).unwrap_u8(), 1);
13+
assert_eq!(a.ct_eq(&b).unwrap_u8(), 1);
1414
}
1515

1616
#[test]
1717
fn slices_equal() {
1818
let a: [u8; 8] = [1, 2, 3, 4, 5, 6, 7, 8];
1919
let b: [u8; 8] = [1, 2, 3, 4, 4, 3, 2, 1];
2020

21-
let a_eq_a = (&a).ct_eq(&a);
22-
let a_eq_b = (&a).ct_eq(&b);
21+
let a_eq_a = a.ct_eq(&a);
22+
let a_eq_b = a.ct_eq(&b);
2323

2424
assert_eq!(a_eq_a.unwrap_u8(), 1);
2525
assert_eq!(a_eq_b.unwrap_u8(), 0);
2626

2727
let c: [u8; 16] = [0u8; 16];
2828

29-
let a_eq_c = (&a).ct_eq(&c);
29+
let a_eq_c = a.ct_eq(&c);
3030
assert_eq!(a_eq_c.unwrap_u8(), 0);
3131
}
3232

@@ -141,18 +141,18 @@ fn conditional_select_choice() {
141141
let t = Choice::from(1);
142142
let f = Choice::from(0);
143143

144-
assert_eq!(bool::from(Choice::conditional_select(&t, &f, f)), true);
145-
assert_eq!(bool::from(Choice::conditional_select(&t, &f, t)), false);
146-
assert_eq!(bool::from(Choice::conditional_select(&f, &t, f)), false);
147-
assert_eq!(bool::from(Choice::conditional_select(&f, &t, t)), true);
144+
assert!(bool::from(Choice::conditional_select(&t, &f, f)));
145+
assert!(!bool::from(Choice::conditional_select(&t, &f, t)));
146+
assert!(!bool::from(Choice::conditional_select(&f, &t, f)));
147+
assert!(bool::from(Choice::conditional_select(&f, &t, t)));
148148
}
149149

150150
#[test]
151151
fn choice_equal() {
152-
assert!(Choice::from(0).ct_eq(&Choice::from(0)).unwrap_u8() == 1);
153-
assert!(Choice::from(0).ct_eq(&Choice::from(1)).unwrap_u8() == 0);
154-
assert!(Choice::from(1).ct_eq(&Choice::from(0)).unwrap_u8() == 0);
155-
assert!(Choice::from(1).ct_eq(&Choice::from(1)).unwrap_u8() == 1);
152+
assert_eq!(Choice::from(0).ct_eq(&Choice::from(0)).unwrap_u8(), 1);
153+
assert_eq!(Choice::from(0).ct_eq(&Choice::from(1)).unwrap_u8(), 0);
154+
assert_eq!(Choice::from(1).ct_eq(&Choice::from(0)).unwrap_u8(), 0);
155+
assert_eq!(Choice::from(1).ct_eq(&Choice::from(1)).unwrap_u8(), 1);
156156
}
157157

158158
#[test]
@@ -284,65 +284,65 @@ fn test_ctoption() {
284284
));
285285

286286
// Test (in)equality
287-
assert!(
287+
assert_eq!(
288288
CtOption::new(1, Choice::from(0))
289289
.ct_eq(&CtOption::new(1, Choice::from(1)))
290-
.unwrap_u8()
291-
== 0
290+
.unwrap_u8(),
291+
0
292292
);
293-
assert!(
293+
assert_eq!(
294294
CtOption::new(1, Choice::from(1))
295295
.ct_eq(&CtOption::new(1, Choice::from(0)))
296-
.unwrap_u8()
297-
== 0
296+
.unwrap_u8(),
297+
0
298298
);
299-
assert!(
299+
assert_eq!(
300300
CtOption::new(1, Choice::from(0))
301301
.ct_eq(&CtOption::new(2, Choice::from(1)))
302-
.unwrap_u8()
303-
== 0
302+
.unwrap_u8(),
303+
0
304304
);
305-
assert!(
305+
assert_eq!(
306306
CtOption::new(1, Choice::from(1))
307307
.ct_eq(&CtOption::new(2, Choice::from(0)))
308-
.unwrap_u8()
309-
== 0
308+
.unwrap_u8(),
309+
0
310310
);
311-
assert!(
311+
assert_eq!(
312312
CtOption::new(1, Choice::from(0))
313313
.ct_eq(&CtOption::new(1, Choice::from(0)))
314-
.unwrap_u8()
315-
== 1
314+
.unwrap_u8(),
315+
1
316316
);
317-
assert!(
317+
assert_eq!(
318318
CtOption::new(1, Choice::from(0))
319319
.ct_eq(&CtOption::new(2, Choice::from(0)))
320-
.unwrap_u8()
321-
== 1
320+
.unwrap_u8(),
321+
1
322322
);
323-
assert!(
323+
assert_eq!(
324324
CtOption::new(1, Choice::from(1))
325325
.ct_eq(&CtOption::new(2, Choice::from(1)))
326-
.unwrap_u8()
327-
== 0
326+
.unwrap_u8(),
327+
0
328328
);
329-
assert!(
329+
assert_eq!(
330330
CtOption::new(1, Choice::from(1))
331331
.ct_eq(&CtOption::new(2, Choice::from(1)))
332-
.unwrap_u8()
333-
== 0
332+
.unwrap_u8(),
333+
0
334334
);
335-
assert!(
335+
assert_eq!(
336336
CtOption::new(1, Choice::from(1))
337337
.ct_eq(&CtOption::new(1, Choice::from(1)))
338-
.unwrap_u8()
339-
== 1
338+
.unwrap_u8(),
339+
1
340340
);
341-
assert!(
341+
assert_eq!(
342342
CtOption::new(1, Choice::from(1))
343343
.ct_eq(&CtOption::new(1, Choice::from(1)))
344-
.unwrap_u8()
345-
== 1
344+
.unwrap_u8(),
345+
1
346346
);
347347
}
348348

0 commit comments

Comments
 (0)