From 7f6fdb9cf7ca9e1ade50fda4916843ab6bb96a23 Mon Sep 17 00:00:00 2001 From: Igor Novgorodov Date: Sat, 25 May 2024 19:10:13 +0200 Subject: [PATCH] fix docs --- Cargo.lock | 9 ++++++++- Cargo.toml | 7 +++++-- README_CARGO.md => README_DOCS.md | 2 +- build.rs | 19 +++++++++++++++++++ src/lib.rs | 1 + src/stapler.rs | 11 ++++++++--- 6 files changed, 42 insertions(+), 7 deletions(-) rename README_CARGO.md => README_DOCS.md (99%) create mode 100644 build.rs diff --git a/Cargo.lock b/Cargo.lock index a4ff344..53c4384 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1029,7 +1029,7 @@ dependencies = [ [[package]] name = "ocsp-stapler" -version = "0.3.0" +version = "0.3.1" dependencies = [ "anyhow", "arc-swap", @@ -1044,6 +1044,7 @@ dependencies = [ "rasn", "rasn-ocsp", "rasn-pkix", + "readme-rustdocifier", "reqwest", "rustls 0.23.8", "rustls-pemfile", @@ -1275,6 +1276,12 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "readme-rustdocifier" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08ad765b21a08b1a8e5cdce052719188a23772bcbefb3c439f0baaf62c56ceac" + [[package]] name = "redox_syscall" version = "0.5.1" diff --git a/Cargo.toml b/Cargo.toml index 017c3aa..92caa4a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ocsp-stapler" -version = "0.3.0" +version = "0.3.1" edition = "2021" license = "MPL-2.0" description = "OCSP stapler & client with support for Rustls" @@ -15,7 +15,7 @@ categories = [ "web-programming::http-server", ] -readme = "README_CARGO.md" +readme = "README_DOCS.md" [dependencies] anyhow = "1.0" @@ -51,3 +51,6 @@ num-bigint = "0.4" [lib] doctest = false + +[build-dependencies] +readme-rustdocifier = "0.1.0" diff --git a/README_CARGO.md b/README_DOCS.md similarity index 99% rename from README_CARGO.md rename to README_DOCS.md index e75df29..3115540 100644 --- a/README_CARGO.md +++ b/README_DOCS.md @@ -43,7 +43,7 @@ Other notes: Stapler supports a few Prometheus metrics - create it using one of `new_..._with_registry()` constructors and provide a Prometheus `Registry` reference to register the metrics in. -# Example +### Example ```rust,ignore // Inner service that provides certificates to Rustls, can be anything diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..898e900 --- /dev/null +++ b/build.rs @@ -0,0 +1,19 @@ +use std::{env, error::Error, fs, path::PathBuf}; + +const CRATE_NAME: &str = "ocsp-stapler"; + +fn main() -> Result<(), Box> { + println!("cargo:rerun-if-changed=README_DOCS.md"); + + fs::write( + PathBuf::from(env::var("OUT_DIR")?).join("README-rustdocified.md"), + readme_rustdocifier::rustdocify( + &fs::read_to_string("README_DOCS.md")?, + &env::var("CARGO_PKG_NAME")?, + Some(&env::var("CARGO_PKG_VERSION")?), + Some(CRATE_NAME), + )?, + )?; + + Ok(()) +} diff --git a/src/lib.rs b/src/lib.rs index ffc6c80..b0917bb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,6 @@ #![warn(clippy::all)] #![warn(clippy::nursery)] +#![doc = include_str!(concat!(env!("OUT_DIR"), "/README-rustdocified.md"))] pub mod client; pub mod stapler; diff --git a/src/stapler.rs b/src/stapler.rs index aed861e..cc94c9e 100644 --- a/src/stapler.rs +++ b/src/stapler.rs @@ -355,11 +355,16 @@ impl StaplerActor { .context("unable to parse certificate as X.509")? .1; - let cert_validity = - Validity::try_from(&cert.validity).context("unable to parse certificate validity")?; + let cert_validity = Validity::try_from(&cert.validity).context(format!( + "unable to parse certificate [{}] validity", + cert.subject + ))?; if !cert_validity.valid(Utc::now().into()) { - return Err(anyhow!("The certificate is not valid at current time")); + return Err(anyhow!( + "the certificate [{}] is not valid at current time", + cert.subject + )); } let cert = Cert {