Pure Rust XML Security library. Drop-in replacement for libxmlsec1.
No C dependencies. No cmake. No system libraries. Just cargo add xml-sec.
Warning
Early-stage pre-release. The API is unstable, XMLDSig/XMLEnc coverage is still incomplete, and this crate should not yet be used in production.
- C14N — XML Canonicalization (inclusive + exclusive, W3C compliant)
- XMLDSig — XML Digital Signatures (verify and signing pipelines, X.509
KeyInfo, and xmlsec1 CLI interoperability) - XMLEnc — XML Encryption (symmetric + asymmetric)
- X.509 — Certificate-based key extraction and validation
Every SAML, SOAP, and WS-Security implementation depends on libxmlsec1 — a C library that:
- Requires cmake + libxml2 + OpenSSL/NSS/GnuTLS to build
- Breaks on Alpine/musl static linking
- Has decades of CVEs in XML parsing and signature validation
- Cannot cross-compile easily
xml-sec is a ground-up Rust rewrite using roxmltree for parsing, quick-xml for writing, RustCrypto for RSA/ECDSA/SHA, and x509-parser for certificates. Single cargo build, works everywhere Rust works.
Pre-release. API is unstable. Not ready for production use.
Currently implemented (core paths):
- C14N 1.0, C14N 1.1, and Exclusive C14N
- XMLDSig parsing, same-document URI dereference, transform chains, and digest verification
- XMLDSig full verify pipeline (
SignedInfocanonicalization +SignatureValueverification) - XMLDSig template signing pipeline (
DigestValuefill +SignedInfocanonicalization +SignatureValuefill), including enveloped SAML Response templates - XMLDSig signing KeyInfo writer for embedded X.509 certificates
- Built-in verification-key resolution from embedded X.509/DER/
KeyValuesources and configuredKeyName, X.509 subject, issuer/serial, SKI, or digest selectors - RSA PKCS#1 v1.5 verification helpers for SHA-1 / SHA-256 / SHA-384 / SHA-512
- ECDSA verification helpers for P-256/SHA-256 and P-384/SHA-384
- RSA PKCS#1 v1.5 and ECDSA P-256/P-384 signing from PKCS#8 private keys
- Opt-in X.509 certificate-chain validation with explicit trust anchors, validity checks, CA constraints, and CRLs
Still in progress:
- Broader XMLDSig donor/CLI interop coverage
- XMLEnc encryption/decryption pipeline
examples/sign.rs builds an enveloped RSA-SHA256 signature with an embedded
X.509 certificate. examples/verify.rs verifies a document through
DefaultKeyResolver using that embedded certificate:
cargo run --example sign --all-features > signed.xml
cargo run --example verify --all-features -- signed.xmlFor production verification, configure KeyResolverConfig with explicit trust
anchors when certificate-chain validation is required. A Valid status means
the cryptographic and reference checks succeeded; Invalid(reason) means the
document was processed successfully but did not validate.
Malformed XMLDSig structure, unsupported algorithms, disallowed reference
URIs, and inconsistent KeyInfo metadata are processing errors rather than
validity statuses. Treat both Invalid(reason) and an API error as a rejected
document; never continue an authentication flow after either outcome.
Current toolchain target: latest stable Rust. Current MSRV: Rust 1.92.
| Spec | Status |
|---|---|
| Canonical XML 1.0 | Partially implemented |
| Canonical XML 1.1 | Partially implemented |
| Exclusive C14N | Partially implemented |
| XMLDSig | Partially implemented |
| XMLEnc | Planned |
Apache-2.0
If xml-sec is useful in your stack, you can help fund continued implementation and maintenance.
USDT (TRC-20): TFDsezHa1cBkoeZT5q2T49Wp66K8t2DmdA