Skip to content

Commit fd92bd9

Browse files
authored
Add Clippy and rustfmt CI jobs (RustCrypto#438)
1 parent e6c4db7 commit fd92bd9

File tree

17 files changed

+760
-139
lines changed

17 files changed

+760
-139
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,6 @@ jobs:
4848
- run: cargo test --release --features getrandom
4949
- run: cargo test --release --features serde
5050

51-
doc:
52-
runs-on: ubuntu-latest
53-
steps:
54-
- uses: actions/checkout@v4
55-
- uses: RustCrypto/actions/cargo-cache@master
56-
- uses: dtolnay/rust-toolchain@master
57-
with:
58-
toolchain: stable
59-
- run: cargo doc --all-features
60-
6151
minimal-versions:
6252
runs-on: ubuntu-latest
6353
steps:

.github/workflows/workspace.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Workspace
2+
3+
on:
4+
pull_request:
5+
paths-ignore:
6+
- README.md
7+
push:
8+
branches: master
9+
paths-ignore:
10+
- README.md
11+
12+
jobs:
13+
clippy:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
- uses: RustCrypto/actions/cargo-cache@master
18+
- uses: dtolnay/rust-toolchain@master
19+
with:
20+
toolchain: 1.79.0
21+
components: clippy
22+
- run: cargo clippy --all -- -D warnings
23+
24+
fmt:
25+
runs-on: ubuntu-latest
26+
steps:
27+
- uses: actions/checkout@v4
28+
- uses: RustCrypto/actions/cargo-cache@master
29+
- uses: dtolnay/rust-toolchain@master
30+
with:
31+
toolchain: stable
32+
components: rustfmt
33+
- run: cargo fmt --all -- --check
34+
35+
doc:
36+
runs-on: ubuntu-latest
37+
steps:
38+
- uses: actions/checkout@v4
39+
- uses: RustCrypto/actions/cargo-cache@master
40+
- uses: dtolnay/rust-toolchain@master
41+
with:
42+
# We need Nightly for doc_auto_cfg
43+
toolchain: nightly-2024-06-25
44+
- uses: Swatinem/rust-cache@v2
45+
- env:
46+
RUSTDOCFLAGS: "-Dwarnings --cfg docsrs"
47+
run: cargo doc --no-deps --features std,pem,serde,hazmat,sha2

benches/key.rs

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,67 @@ use rsa::{Pkcs1v15Encrypt, Pkcs1v15Sign, RsaPrivateKey};
1010
use sha2::{Digest, Sha256};
1111
use test::Bencher;
1212

13-
const DECRYPT_VAL: &'static str =
14-
"XW4qfrpQDarEMBfPyIYE9UvuOFkbBi0tiGYbIOJPLMNe/LWuPD0BQ7ceqlOlPPcKLinYz0DlnqW3It/V7ae59zw9afA3YIWdq0Ut2BnYL+aJixnqaP+PjsQNcHg6axCF11iNQ4jpXrZDiQcI+q9EEzZDTMsiMxtjfgBQUd8LHT87YoQXDWaFPCVpliACMc8aUk442kH1tc4jEuXwjEjFErvAM/J7VizCdU/dnKrlq2mBDzvZ6hxY9TYHFB/zY6DZPJAgEMUxYWCR9xPJ7X256DV1Kt0Ht33DWoFcgh/pPLM1q9pK0HVxCdclXfZOeCqlrLgZ5Gxv5DM4BtV7Z4m85w==";
13+
const DECRYPT_VAL: &str = "\
14+
XW4qfrpQDarEMBfPyIYE9UvuOFkbBi0tiGYbIOJPLMNe/LWuPD0BQ7ceqlOlPPcK\
15+
LinYz0DlnqW3It/V7ae59zw9afA3YIWdq0Ut2BnYL+aJixnqaP+PjsQNcHg6axCF\
16+
11iNQ4jpXrZDiQcI+q9EEzZDTMsiMxtjfgBQUd8LHT87YoQXDWaFPCVpliACMc8a\
17+
Uk442kH1tc4jEuXwjEjFErvAM/J7VizCdU/dnKrlq2mBDzvZ6hxY9TYHFB/zY6DZ\
18+
PJAgEMUxYWCR9xPJ7X256DV1Kt0Ht33DWoFcgh/pPLM1q9pK0HVxCdclXfZOeCql\
19+
rLgZ5Gxv5DM4BtV7Z4m85w==";
1520

1621
fn get_key() -> RsaPrivateKey {
1722
RsaPrivateKey::from_components(
18-
BigUint::from_str_radix("14314132931241006650998084889274020608918049032671858325988396851334124245188214251956198731333464217832226406088020736932173064754214329009979944037640912127943488972644697423190955557435910767690712778463524983667852819010259499695177313115447116110358524558307947613422897787329221478860907963827160223559690523660574329011927531289655711860504630573766609239332569210831325633840174683944553667352219670930408593321661375473885147973879086994006440025257225431977751512374815915392249179976902953721486040787792801849818254465486633791826766873076617116727073077821584676715609985777563958286637185868165868520557", 10).unwrap(),
23+
BigUint::from_str_radix(
24+
"1431413293124100665099808488927402060891804903267185832598839685\
25+
1334124245188214251956198731333464217832226406088020736932173064\
26+
7542143290099799440376409121279434889726446974231909555574359107\
27+
6769071277846352498366785281901025949969517731311544711611035852\
28+
4558307947613422897787329221478860907963827160223559690523660574\
29+
3290119275312896557118605046305737666092393325692108313256338401\
30+
7468394455366735221967093040859332166137547388514797387908699400\
31+
6440025257225431977751512374815915392249179976902953721486040787\
32+
7928018498182544654866337918267668730766171167270730778215846767\
33+
15609985777563958286637185868165868520557",
34+
10,
35+
)
36+
.unwrap(),
1937
BigUint::from_u32(3).unwrap(),
20-
BigUint::from_str_radix("9542755287494004433998723259516013739278699355114572217325597900889416163458809501304132487555642811888150937392013824621448709836142886006653296025093941418628992648429798282127303704957273845127141852309016655778568546006839666463451542076964744073572349705538631742281931858219480985907271975884773482372966847639853897890615456605598071088189838676728836833012254065983259638538107719766738032720239892094196108713378822882383694456030043492571063441943847195939549773271694647657549658603365629458610273821292232646334717612674519997533901052790334279661754176490593041941863932308687197618671528035670452762731", 10).unwrap(),
38+
BigUint::from_str_radix(
39+
"9542755287494004433998723259516013739278699355114572217325597900\
40+
8894161634588095013041324875556428118881509373920138246214487098\
41+
3614288600665329602509394141862899264842979828212730370495727384\
42+
5127141852309016655778568546006839666463451542076964744073572349\
43+
7055386317422819318582194809859072719758847734823729668476398538\
44+
9789061545660559807108818983867672883683301225406598325963853810\
45+
7719766738032720239892094196108713378822882383694456030043492571\
46+
0634419438471959395497732716946476575496586033656294586102738212\
47+
9223264633471761267451999753390105279033427966175417649059304194\
48+
1863932308687197618671528035670452762731",
49+
10,
50+
)
51+
.unwrap(),
2152
vec![
22-
BigUint::from_str_radix("130903255182996722426771613606077755295583329135067340152947172868415809027537376306193179624298874215608270802054347609836776473930072411958753044562214537013874103802006369634761074377213995983876788718033850153719421695468704276694983032644416930879093914927146648402139231293035971427838068945045019075433",10).unwrap(),
23-
BigUint::from_str_radix("109348945610485453577574767652527472924289229538286649661240938988020367005475727988253438647560958573506159449538793540472829815903949343191091817779240101054552748665267574271163617694640513549693841337820602726596756351006149518830932261246698766355347898158548465400674856021497190430791824869615170301029", 10).unwrap()
53+
BigUint::from_str_radix(
54+
"1309032551829967224267716136060777552955833291350673401529471728\
55+
6841580902753737630619317962429887421560827080205434760983677647\
56+
3930072411958753044562214537013874103802006369634761074377213995\
57+
9838767887180338501537194216954687042766949830326444169308790939\
58+
14927146648402139231293035971427838068945045019075433",
59+
10,
60+
)
61+
.unwrap(),
62+
BigUint::from_str_radix(
63+
"1093489456104854535775747676525274729242892295382866496612409389\
64+
8802036700547572798825343864756095857350615944953879354047282981\
65+
5903949343191091817779240101054552748665267574271163617694640513\
66+
5496938413378206027265967563510061495188309322612466987663553478\
67+
98158548465400674856021497190430791824869615170301029",
68+
10,
69+
)
70+
.unwrap(),
2471
],
25-
).unwrap()
72+
)
73+
.unwrap()
2674
}
2775

2876
#[bench]

src/algorithms/mgf.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub(crate) fn mgf1_xor(out: &mut [u8], digest: &mut dyn DynDigest, seed: &[u8])
99
let mut counter = [0u8; 4];
1010
let mut i = 0;
1111

12-
const MAX_LEN: u64 = core::u32::MAX as u64 + 1;
12+
const MAX_LEN: u64 = u32::MAX as u64 + 1;
1313
assert!(out.len() as u64 <= MAX_LEN);
1414

1515
while i < out.len() {
@@ -43,7 +43,7 @@ where
4343
let mut counter = [0u8; 4];
4444
let mut i = 0;
4545

46-
const MAX_LEN: u64 = core::u32::MAX as u64 + 1;
46+
const MAX_LEN: u64 = u32::MAX as u64 + 1;
4747
assert!(out.len() as u64 <= MAX_LEN);
4848

4949
while i < out.len() {

src/encoding.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,17 @@ use zeroize::Zeroizing;
1717
pub const ID_RSASSA_PSS: ObjectIdentifier = ObjectIdentifier::new_unwrap("1.2.840.113549.1.1.10");
1818

1919
/// Verify that the `AlgorithmIdentifier` for a key is correct.
20-
pub(crate) fn verify_algorithm_id(algorithm: &pkcs8::AlgorithmIdentifierRef) -> pkcs8::spki::Result<()> {
20+
pub(crate) fn verify_algorithm_id(
21+
algorithm: &pkcs8::AlgorithmIdentifierRef,
22+
) -> pkcs8::spki::Result<()> {
2123
match algorithm.oid {
2224
pkcs1::ALGORITHM_OID => {
2325
if algorithm.parameters_any()? != pkcs8::der::asn1::Null.into() {
2426
return Err(pkcs8::spki::Error::KeyMalformed);
2527
}
2628
}
2729
ID_RSASSA_PSS => {
28-
if !algorithm.parameters.is_none() {
30+
if algorithm.parameters.is_some() {
2931
return Err(pkcs8::spki::Error::KeyMalformed);
3032
}
3133
}

0 commit comments

Comments
 (0)