Skip to main content

Crate pdf_signer

Crate pdf_signer 

Source
Expand description

§pdf_signer

Pure-Rust, self-contained library to digitally sign (PAdES) and verify PDF documents with a PKCS#12 (.p12/.pfx) keystore. It replaces the bundled BatchPDFSignPortable.jar (Java/PDFBox) used by the R package signer, removing the Java runtime dependency and the binary blob.

§What it does

  • sign_pdf_file / sign_pdf_bytes: append a signature field (optionally with a visible appearance) and an ETSI.CAdES.detached CMS signature as an incremental update, so any prior signature stays valid. Targets PAdES B-B through B-LTA (RFC 3161 signature & document timestamps, /DSS).
  • verify_pdf_file / verify_pdf_bytes: re-extract the signed byte range, validate the CMS signature cryptographically, check that the document was not modified after the last signature (SignatureReport::document_intact), report signer info, and optionally validate the signer and TSA chains against a TrustStore.

§Notes

  • Keys: RSA (PKCS#1 v1.5), ECDSA (P-256/P-384), Ed25519.
  • 100% pure Rust (RustCrypto) — no OpenSSL, no Java, no system C libraries. An optional https feature (ureq/rustls) enables TLS TSA/CRL/OCSP.
  • Incremental updates support both classic xref tables and xref streams.
  • Encrypted PDFs and documents certified with DocMDP P=1 are refused.
  • The testkit feature exposes fixture builders for tests and demos.

Structs§

Appearance
A visible signature appearance, rendered as the widget’s /AP /N stream.
SignOptions
Options controlling the signature dictionary metadata.
SignatureReport
Report over all signatures and document timestamps found, in file order.
TrustStore
A set of trusted root certificates (e.g. the ICP-Brasil AC Raiz set), plus optional validation parameters.
VerifiedSignature
Outcome of verifying a single signature or document timestamp.

Enums§

Error
Errors that can occur while signing or verifying a PDF.
PadesLevel
PAdES conformance level to produce.

Functions§

sign_pdf_bytes
Sign an in-memory PDF with an in-memory PKCS#12 keystore.
sign_pdf_file
Sign input PDF, writing the signed PDF to output.
verify_certificate_chain
Validate a certificate path directly (decoupled from PDF signing): does leaf_der chain to a trusted root in roots, using pool_ders as candidate intermediates and crl_ders for revocation, at time at? Exposed mainly for conformance testing (e.g. NIST PKITS), so no purpose-specific leaf key-usage check is applied.
verify_pdf_bytes
Verify all signatures of an in-memory PDF (one per /ByteRange).
verify_pdf_bytes_with_roots
Verify an in-memory PDF, validating signer chains against roots.
verify_pdf_file
Verify the signatures of a PDF file.
verify_pdf_file_with_roots
Verify a PDF file, additionally validating each signer certificate chain against roots (e.g. the ICP-Brasil roots).

Type Aliases§

Result
Convenience result type for the crate.