Skip to content

Commit

Permalink
Add Clippy and rustfmt CI jobs (#438)
Browse files Browse the repository at this point in the history
  • Loading branch information
newpavlov authored Jun 26, 2024
1 parent e6c4db7 commit fd92bd9
Show file tree
Hide file tree
Showing 17 changed files with 760 additions and 139 deletions.
10 changes: 0 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,6 @@ jobs:
- run: cargo test --release --features getrandom
- run: cargo test --release --features serde

doc:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: RustCrypto/actions/cargo-cache@master
- uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
- run: cargo doc --all-features

minimal-versions:
runs-on: ubuntu-latest
steps:
Expand Down
47 changes: 47 additions & 0 deletions .github/workflows/workspace.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Workspace

on:
pull_request:
paths-ignore:
- README.md
push:
branches: master
paths-ignore:
- README.md

jobs:
clippy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: RustCrypto/actions/cargo-cache@master
- uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.79.0
components: clippy
- run: cargo clippy --all -- -D warnings

fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: RustCrypto/actions/cargo-cache@master
- uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
components: rustfmt
- run: cargo fmt --all -- --check

doc:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: RustCrypto/actions/cargo-cache@master
- uses: dtolnay/rust-toolchain@master
with:
# We need Nightly for doc_auto_cfg
toolchain: nightly-2024-06-25
- uses: Swatinem/rust-cache@v2
- env:
RUSTDOCFLAGS: "-Dwarnings --cfg docsrs"
run: cargo doc --no-deps --features std,pem,serde,hazmat,sha2
62 changes: 55 additions & 7 deletions benches/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,67 @@ use rsa::{Pkcs1v15Encrypt, Pkcs1v15Sign, RsaPrivateKey};
use sha2::{Digest, Sha256};
use test::Bencher;

const DECRYPT_VAL: &'static str =
"XW4qfrpQDarEMBfPyIYE9UvuOFkbBi0tiGYbIOJPLMNe/LWuPD0BQ7ceqlOlPPcKLinYz0DlnqW3It/V7ae59zw9afA3YIWdq0Ut2BnYL+aJixnqaP+PjsQNcHg6axCF11iNQ4jpXrZDiQcI+q9EEzZDTMsiMxtjfgBQUd8LHT87YoQXDWaFPCVpliACMc8aUk442kH1tc4jEuXwjEjFErvAM/J7VizCdU/dnKrlq2mBDzvZ6hxY9TYHFB/zY6DZPJAgEMUxYWCR9xPJ7X256DV1Kt0Ht33DWoFcgh/pPLM1q9pK0HVxCdclXfZOeCqlrLgZ5Gxv5DM4BtV7Z4m85w==";
const DECRYPT_VAL: &str = "\
XW4qfrpQDarEMBfPyIYE9UvuOFkbBi0tiGYbIOJPLMNe/LWuPD0BQ7ceqlOlPPcK\
LinYz0DlnqW3It/V7ae59zw9afA3YIWdq0Ut2BnYL+aJixnqaP+PjsQNcHg6axCF\
11iNQ4jpXrZDiQcI+q9EEzZDTMsiMxtjfgBQUd8LHT87YoQXDWaFPCVpliACMc8a\
Uk442kH1tc4jEuXwjEjFErvAM/J7VizCdU/dnKrlq2mBDzvZ6hxY9TYHFB/zY6DZ\
PJAgEMUxYWCR9xPJ7X256DV1Kt0Ht33DWoFcgh/pPLM1q9pK0HVxCdclXfZOeCql\
rLgZ5Gxv5DM4BtV7Z4m85w==";

fn get_key() -> RsaPrivateKey {
RsaPrivateKey::from_components(
BigUint::from_str_radix("14314132931241006650998084889274020608918049032671858325988396851334124245188214251956198731333464217832226406088020736932173064754214329009979944037640912127943488972644697423190955557435910767690712778463524983667852819010259499695177313115447116110358524558307947613422897787329221478860907963827160223559690523660574329011927531289655711860504630573766609239332569210831325633840174683944553667352219670930408593321661375473885147973879086994006440025257225431977751512374815915392249179976902953721486040787792801849818254465486633791826766873076617116727073077821584676715609985777563958286637185868165868520557", 10).unwrap(),
BigUint::from_str_radix(
"1431413293124100665099808488927402060891804903267185832598839685\
1334124245188214251956198731333464217832226406088020736932173064\
7542143290099799440376409121279434889726446974231909555574359107\
6769071277846352498366785281901025949969517731311544711611035852\
4558307947613422897787329221478860907963827160223559690523660574\
3290119275312896557118605046305737666092393325692108313256338401\
7468394455366735221967093040859332166137547388514797387908699400\
6440025257225431977751512374815915392249179976902953721486040787\
7928018498182544654866337918267668730766171167270730778215846767\
15609985777563958286637185868165868520557",
10,
)
.unwrap(),
BigUint::from_u32(3).unwrap(),
BigUint::from_str_radix("9542755287494004433998723259516013739278699355114572217325597900889416163458809501304132487555642811888150937392013824621448709836142886006653296025093941418628992648429798282127303704957273845127141852309016655778568546006839666463451542076964744073572349705538631742281931858219480985907271975884773482372966847639853897890615456605598071088189838676728836833012254065983259638538107719766738032720239892094196108713378822882383694456030043492571063441943847195939549773271694647657549658603365629458610273821292232646334717612674519997533901052790334279661754176490593041941863932308687197618671528035670452762731", 10).unwrap(),
BigUint::from_str_radix(
"9542755287494004433998723259516013739278699355114572217325597900\
8894161634588095013041324875556428118881509373920138246214487098\
3614288600665329602509394141862899264842979828212730370495727384\
5127141852309016655778568546006839666463451542076964744073572349\
7055386317422819318582194809859072719758847734823729668476398538\
9789061545660559807108818983867672883683301225406598325963853810\
7719766738032720239892094196108713378822882383694456030043492571\
0634419438471959395497732716946476575496586033656294586102738212\
9223264633471761267451999753390105279033427966175417649059304194\
1863932308687197618671528035670452762731",
10,
)
.unwrap(),
vec![
BigUint::from_str_radix("130903255182996722426771613606077755295583329135067340152947172868415809027537376306193179624298874215608270802054347609836776473930072411958753044562214537013874103802006369634761074377213995983876788718033850153719421695468704276694983032644416930879093914927146648402139231293035971427838068945045019075433",10).unwrap(),
BigUint::from_str_radix("109348945610485453577574767652527472924289229538286649661240938988020367005475727988253438647560958573506159449538793540472829815903949343191091817779240101054552748665267574271163617694640513549693841337820602726596756351006149518830932261246698766355347898158548465400674856021497190430791824869615170301029", 10).unwrap()
BigUint::from_str_radix(
"1309032551829967224267716136060777552955833291350673401529471728\
6841580902753737630619317962429887421560827080205434760983677647\
3930072411958753044562214537013874103802006369634761074377213995\
9838767887180338501537194216954687042766949830326444169308790939\
14927146648402139231293035971427838068945045019075433",
10,
)
.unwrap(),
BigUint::from_str_radix(
"1093489456104854535775747676525274729242892295382866496612409389\
8802036700547572798825343864756095857350615944953879354047282981\
5903949343191091817779240101054552748665267574271163617694640513\
5496938413378206027265967563510061495188309322612466987663553478\
98158548465400674856021497190430791824869615170301029",
10,
)
.unwrap(),
],
).unwrap()
)
.unwrap()
}

#[bench]
Expand Down
4 changes: 2 additions & 2 deletions src/algorithms/mgf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub(crate) fn mgf1_xor(out: &mut [u8], digest: &mut dyn DynDigest, seed: &[u8])
let mut counter = [0u8; 4];
let mut i = 0;

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

while i < out.len() {
Expand Down Expand Up @@ -43,7 +43,7 @@ where
let mut counter = [0u8; 4];
let mut i = 0;

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

while i < out.len() {
Expand Down
6 changes: 4 additions & 2 deletions src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@ use zeroize::Zeroizing;
pub const ID_RSASSA_PSS: ObjectIdentifier = ObjectIdentifier::new_unwrap("1.2.840.113549.1.1.10");

/// Verify that the `AlgorithmIdentifier` for a key is correct.
pub(crate) fn verify_algorithm_id(algorithm: &pkcs8::AlgorithmIdentifierRef) -> pkcs8::spki::Result<()> {
pub(crate) fn verify_algorithm_id(
algorithm: &pkcs8::AlgorithmIdentifierRef,
) -> pkcs8::spki::Result<()> {
match algorithm.oid {
pkcs1::ALGORITHM_OID => {
if algorithm.parameters_any()? != pkcs8::der::asn1::Null.into() {
return Err(pkcs8::spki::Error::KeyMalformed);
}
}
ID_RSASSA_PSS => {
if !algorithm.parameters.is_none() {
if algorithm.parameters.is_some() {
return Err(pkcs8::spki::Error::KeyMalformed);
}
}
Expand Down
Loading

0 comments on commit fd92bd9

Please sign in to comment.