Skip to content
Open
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
15 changes: 15 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@ on:
- cron: "0 18 * * *"

jobs:
pre_commit:
Comment thread
cpu marked this conversation as resolved.
timeout-minutes: 5
name: prek
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
# tools used in pre-commit hooks
- id: cargo-rdme
uses: rusticata/ci-action-rdme@v2
with:
rdme-args: --intralinks-features validate,verify,verify-aws

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd make for a tidier commit history if this were folded into the commit that added the pre-commit config 👼

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be done, I just thought of these commits as slightly different (one for pre-commit and one for rdme) which could have been independant

# /tools
- id: prek
uses: rusticata/ci-action-prek@v1

check:
name: Check
runs-on: ubuntu-latest
Expand Down
40 changes: 40 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
fail_fast: true

exclude: |
(?x)^(
.*/(assets)/.*|
)$

repos:
- repo: 'https://github.com/pre-commit/pre-commit-hooks'
rev: v6.0.0
hooks:
- id: trailing-whitespace
#- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files

- repo: local
hooks:
- id: cargo-fmt
name: cargo fmt
entry: cargo fmt --
language: system
types: [rust]
pass_filenames: false # This makes it a lot faster

- id: cargo-clippy
name: cargo clippy
language: system
types: [rust]
pass_filenames: false
entry: cargo clippy --all-targets --features validate,verify,verify-aws -- -D warnings

- id: cargo-rdme
name: cargo rdme
language: system
types: [rust]
pass_filenames: false
entry: cargo rdme --intralinks-features validate,verify,verify-aws -c
23 changes: 23 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,26 @@ time = { version="0.3.41", features=["formatting"] }
[dev-dependencies]
hex-literal = "0.4"

[lints.rust]
unsafe_code = "forbid"
#missing_docs = "warn"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same feedback to consider here RE: not adding commented out config.

unstable_features = "deny"
unused_import_braces = "deny"
unused_qualifications = "deny"
missing_debug_implementations = "warn"
unreachable_pub = "warn"

[lints.rustdoc]
broken_intra_doc_links = "deny"

[lints.clippy]
#pedantic = { level = "warn", priority = -1 }

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why land commented-out config? I think it'd be tidier to remove this and the other print_stdout/print_stderr entries if they're not being used.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the objective is to un-comment them progressively. If we activate the warnings right now, there are a lot of fixes

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand not wanting to activate it immediately, but I don't know that I see the value in leaving it commented out as some kind of reminder. Wouldn't a GitHub issue be better for tracking the work required to enable pedantic clippy if that's a goal?

unwrap_used = "warn"
expect_used = "warn"
panic = "warn"
todo = "warn"
unimplemented = "warn"
unreachable = "warn"
dbg_macro = "warn"
#print_stdout = "warn"
#print_stderr = "warn"
3 changes: 3 additions & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
allow-unwrap-in-tests = true
allow-expect-in-tests = true
allow-panic-in-tests = true
8 changes: 5 additions & 3 deletions examples/print-cert.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::expect_used)]
#![allow(clippy::unwrap_used)]
use asn1_rs::Any;
use asn1_rs::Input;
use asn1_rs::Oid;
Expand All @@ -18,7 +20,7 @@ const VALIDATE_ERRORS_FATAL: bool = false;

fn print_hex_dump(bytes: &[u8], max_len: usize) {
let m = min(bytes.len(), max_len);
print!("{}", &bytes[..m].to_hex(16));
print!("{}", bytes[..m].to_hex(16));
if bytes.len() > max_len {
println!("... <continued>");
}
Expand Down Expand Up @@ -208,7 +210,7 @@ fn print_x509_info(x509: &X509Certificate) -> io::Result<()> {
}
println!();
if VALIDATE_ERRORS_FATAL && !logger.errors().is_empty() {
return Err(io::Error::new(io::ErrorKind::Other, "validation failed"));
return Err(io::Error::other("validation failed"));
}
}
#[cfg(not(feature = "validate"))]
Expand Down Expand Up @@ -390,7 +392,7 @@ fn handle_certificate(file_name: &str, data: &[u8]) -> io::Result<()> {
Err(e) => {
let s = format!("Error while parsing {file_name}: {e}");
if PARSE_ERRORS_FATAL {
Err(io::Error::new(io::ErrorKind::Other, s))
Err(io::Error::other(s))
} else {
eprintln!("{s}");
Ok(())
Expand Down
7 changes: 5 additions & 2 deletions examples/print-crl.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#![allow(clippy::unimplemented)]
#![allow(clippy::unwrap_used)]
#![allow(clippy::expect_used)]
use asn1_rs::Oid;
use nom::HexDisplay;
use std::cmp::min;
Expand All @@ -7,7 +10,7 @@ use x509_parser::prelude::*;

fn print_hex_dump(bytes: &[u8], max_len: usize) {
let m = min(bytes.len(), max_len);
print!("{}", &bytes[..m].to_hex(16));
print!("{}", bytes[..m].to_hex(16));
if bytes.len() > max_len {
println!("... <continued>");
}
Expand All @@ -29,7 +32,7 @@ fn print_authority_key_identifier(aki: &AuthorityKeyIdentifier, level: usize) {
}
if let Some(serial) = &aki.authority_cert_serial {
let s = format_serial(serial.as_raw_slice().unwrap());
println!("{:indent$}serial: {}", "", &s, indent = level);
println!("{:indent$}serial: {}", "", s, indent = level);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/extensions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,7 @@ mod tests {
assert!(!ku.decipher_only());
}

#[expect(clippy::unreachable)]
#[test]
fn test_extensions1() {
let crt = crate::parse_x509_certificate(include_bytes!("../../assets/extension1.der"))
Expand Down
1 change: 1 addition & 0 deletions src/extensions/sct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ pub(crate) fn parse_ct_signed_certificate_timestamp_content(
}

// Safety: cannot fail, take() returns exactly 32 bytes
#[expect(clippy::expect_used)]
fn parse_log_id(i: &[u8]) -> IResult<&[u8], CtLogID<'_>, Error> {
let (i, key_id) = take(32usize)(i)?;
Ok((
Expand Down
11 changes: 0 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,6 @@
//!
//! [RFC5280]: https://tools.ietf.org/html/rfc5280

#![deny(/*missing_docs,*/
unstable_features,
unused_import_braces, unused_qualifications)]
#![warn(
missing_debug_implementations,
/* missing_docs,
rust_2018_idioms,*/
unreachable_pub
)]
#![forbid(unsafe_code)]
#![deny(rustdoc::broken_intra_doc_links)]
#![doc(test(
no_crate_inject,
attr(deny(warnings, rust_2018_idioms), allow(dead_code, unused_variables))
Expand Down
2 changes: 2 additions & 0 deletions tests/readcrl.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::expect_used)]
#![allow(clippy::panic)]
use x509_parser::prelude::*;

#[cfg(any(
Expand Down
22 changes: 12 additions & 10 deletions tests/readcsr.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#![allow(clippy::unreachable)]
use asn1_rs::{oid, Oid, Set};
use oid_registry::{
OID_PKCS1_SHA256WITHRSA, OID_PKCS9_CHALLENGE_PASSWORD, OID_PKCS9_EXTENSION_REQUEST,
OID_SIG_ECDSA_WITH_SHA256, OID_X509_COMMON_NAME,
};
use x509_parser::prelude::*;
use x509_parser::{pem::parse_x509_pem, prelude::*};

const CSR_DATA_EMPTY_ATTRIB: &[u8] = include_bytes!("../assets/csr-empty-attributes.csr");
const CSR_DATA: &[u8] = include_bytes!("../assets/test.csr");
Expand All @@ -25,7 +26,7 @@ fn read_csr_empty_attrib() {

#[test]
fn read_csr_with_san() {
let der = pem::parse_x509_pem(CSR_DATA).unwrap().1;
let der = parse_x509_pem(CSR_DATA).unwrap().1;
let (rem, csr) =
X509CertificationRequest::from_der(&der.contents).expect("could not parse CSR");

Expand Down Expand Up @@ -67,7 +68,7 @@ fn read_csr_with_san() {

#[test]
fn read_csr_with_challenge_password() {
let der = pem::parse_x509_pem(CSR_CHALLENGE_PASSWORD).unwrap().1;
let der = parse_x509_pem(CSR_CHALLENGE_PASSWORD).unwrap().1;
let (rem, csr) = X509CertificationRequest::from_der(&der.contents)
.expect("Could not parse CSR with challenge password");

Expand Down Expand Up @@ -117,7 +118,7 @@ fn read_csr_with_challenge_password() {

#[test]
fn test_iter_raw_values() {
let der = pem::parse_x509_pem(CSR_CHALLENGE_PASSWORD).unwrap().1;
let der = parse_x509_pem(CSR_CHALLENGE_PASSWORD).unwrap().1;
let (_, csr) = X509CertificationRequest::from_der(&der.contents)
.expect("Could not parse CSR with challenge password");

Expand All @@ -139,7 +140,7 @@ fn test_iter_raw_values() {
// Verify raw DER: tag should be UTF8String (0x0C), not SET (0x31)
assert_eq!(
any_val.header.tag(),
x509_parser::asn1_rs::Tag::Utf8String,
asn1_rs::Tag::Utf8String,
"iter_raw_values should yield individual values inside the SET, not the SET itself"
);
let s = std::str::from_utf8(any_val.data.as_bytes2())
Expand All @@ -162,7 +163,7 @@ fn test_iter_raw_values() {
// Verify raw DER: tag should be SEQUENCE (0x30), not SET (0x31)
assert_eq!(
any_val.header.tag(),
x509_parser::asn1_rs::Tag::Sequence,
asn1_rs::Tag::Sequence,
"iter_raw_values should yield SET contents, not the SET envelope"
);
}
Expand All @@ -174,11 +175,11 @@ fn test_iter_raw_values() {
))]
#[test]
fn read_csr_verify() {
let pem = pem::parse_x509_pem(CSR_DATA).unwrap().1;
let pem = parse_x509_pem(CSR_DATA).unwrap().1;
let (_, csr) = X509CertificationRequest::from_der(&pem.contents).expect("could not parse CSR");
csr.verify_signature().unwrap();

let mut der = pem::parse_x509_pem(CSR_DATA).unwrap().1;
let mut der = parse_x509_pem(CSR_DATA).unwrap().1;
assert_eq!(&der.contents[28..37], b"rusticata");
for (i, b) in b"foobarbaz".iter().enumerate() {
der.contents[28 + i] = *b;
Expand All @@ -192,14 +193,15 @@ fn read_csr_verify() {
assert_eq!(csr.as_raw(), &der.contents);
}

#[expect(clippy::unreachable)]
#[test]
fn read_csr_with_custom_extension() {
let der = pem::parse_x509_pem(CSR_CUSTOM_EXTENSION).unwrap().1;
let der = parse_x509_pem(CSR_CUSTOM_EXTENSION).unwrap().1;
let (rem, csr) = X509CertificationRequest::from_der(&der.contents)
.expect("Could not parse CSR with custom extension");

assert!(rem.is_empty());
dbg!(csr.certification_request_info.attributes());
//dbg!(csr.certification_request_info.attributes());

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would vote to remove this line instead of commenting it out.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed, I will update

let cri = &csr.certification_request_info;
assert_eq!(cri.version, X509Version(0));
assert_eq!(cri.attributes().len(), 1);
Expand Down
1 change: 1 addition & 0 deletions tests/run_all_fuzz_files.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(clippy::unwrap_used)]
use std::fs::{self, DirEntry};
use x509_parser::parse_x509_certificate;

Expand Down
Loading