EN 16931 · Peppol BIS Billing 3.0 · XRechnung · Factur-X
einvoice-validator
Validation of European e-invoices against the official published validation artefacts, in pure Rust: no JVM, no C library, no FFI. A library and a command-line tool that run the official stylesheets unchanged, with exact decimal arithmetic, and give the same report as Saxon-HE, rule by rule.
What it is
The business rules of EN 16931 and of the specifications built on it (Peppol BIS Billing 3.0, XRechnung, Factur-X, the French e-invoicing rules) are published as Schematron, which validators run compiled to XSLT 2.0 stylesheets. einvoice-validator is an XSLT 2.0 and XPath 2.0 engine, written in Rust, that runs those stylesheets as they are published, with XML Schema validation in front of them, behind a library and a command-line tool. It reads both syntaxes of EN 16931: UBL 2.1 and UN/CEFACT CII D16B, as XML files or embedded in a Factur-X, ZUGFeRD or Order-X PDF file.
- The official artefacts are the rules. No rule is translated into Rust by hand. The CEN artefacts are vendored byte for byte, with their checksums; the other rule sets are downloaded from their publishers at pinned URLs, every file checked against a pinned digest.
- A closed subset. The engine implements the XSLT and XPath the official stylesheets use, nothing more. Anything else is refused when the stylesheet is loaded, never skipped.
- Exact numbers.
xs:decimalandxs:integerare arbitrary precision, as the amount and total rules require; no floating-point stand-in. - The reference engine decides. The expected result is the report Saxon-HE 12.10 produces for the same document: same fired rules, same failed asserts and successful reports, with the same id, flag, location and text, in the same order. On every case and mutation case of the test corpus of every rule set below, with each of its stylesheets, the report is identical (Rule sets).
- Verdicts as the reference validators give them. A Factur-X failed assert without a flag is fatal, as the Mustang validator reads it; XRechnung documents are validated by the scenarios of the KoSIT validator configuration, as the KoSIT validator runs them. On every corpus document, each rule set reads the reports as its reference validator does (the XML schema step of Factur-X and the French rules included, since 0.4.0, #37).
- Bounded. Depth and nesting limits on documents and stylesheets: a hostile input ends with an error, not a crash (Security).
- Pure Rust. No Java runtime, no C library, no FFI, no
unsafecode, no C or assembly file built (Pure Rust). The library also runs onwasm32-unknown-unknown.
Use it
Install the command-line tool from crates.io, with Rust 1.99 or later (rustup):
cargo install --locked einvoice-cli # installs einvoice-validate
or from a clone of the repository, where the toolchain (Rust 1.99.1) is pinned in rust-toolchain.toml and installed by rustup on first use (Build and install from source):
git clone https://github.com/einvoice-validator/einvoice-validator.git
cd einvoice-validator
cargo install --locked --path crates/einvoice-cli # installs einvoice-validate
Two rule sets are built in: cen-ubl, CEN EN 16931 UBL 1.3.17 with the UBL 2.1 schemas, and cen-cii, CEN EN 16931 CII 1.3.17 with the UN/CEFACT CII D16B schemas. Without --rules or --bundle, einvoice-validate picks the rule set of each document from its root element: cen-ubl for a UBL Invoice or CreditNote, cen-cii for a CII CrossIndustryInvoice, cen-ubl for anything else. The other rule sets are fetched on demand (below).
einvoice-validate invoice.xml # cen-ubl or cen-cii, from the root element of the document
einvoice-validate factur-x.pdf # a Factur-X / ZUGFeRD / Order-X PDF: the invoice XML it embeds
einvoice-validate --rules cen-cii invoice.xml # a built-in rule set by name: cen-ubl or cen-cii
einvoice-validate --rules xrechnung invoice.xml # a rule set fetched on demand (rules fetch xrechnung first)
einvoice-validate --format json --jobs 4 invoices/*.xml > report.json
einvoice-validate --format svrl - < invoice.xml # the SVRL report, as the stylesheet wrote it
einvoice-validate --bundle DIR invoice.xml # a rule-set bundle: DIR/bundle.toml and its stylesheets
einvoice-validate --fail-closed invoice.xml # a finding of no known severity is fatal
einvoice-validate --max-depth 1000 deep.xml # accept elements nested up to 1000 deep (default 256)
einvoice-validate --licences # the licences of everything the binary embeds, in full
A UBL invoice, a CII invoice and the same CII invoice with its sum of line net amounts one cent too high, in one run:
$ einvoice-validate ubl-invoice.xml cii-invoice.xml cii-broken.xml
ubl-invoice.xml: valid
cii-invoice.xml: valid
cii-broken.xml: invalid: 2 fatal
fatal BR-CO-10: [BR-CO-10]-Sum of Invoice line net amount (BT-106) = Σ Invoice line net amount (BT-131).
at /*:CrossIndustryInvoice[namespace-uri()='urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100'][1]/*:SupplyChainTradeTransaction[namespace-uri()='urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100'][1]/*:ApplicableHeaderTradeSettlement[namespace-uri()='urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100'][1]/*:SpecifiedTradeSettlementHeaderMonetarySummation[namespace-uri()='urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100'][1]
fatal BR-CO-13: [BR-CO-13]-Invoice total amount without VAT (BT-109) = Σ Invoice line net amount (BT-131) - Sum of allowances on document level (BT-107) + Sum of charges on document level (BT-108).
at /*:CrossIndustryInvoice[namespace-uri()='urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100'][1]/...
3 documents: 2 valid, 1 invalid, 0 not validated
In the JSON report, each document names the rule set it was validated with (documents[].rule_set). A UBL document with schema errors:
$ einvoice-validate invoice.xml broken.xml
invoice.xml: valid
broken.xml: invalid: 1 schema error, 11 fatal
schema 2:1: missing-element: element ubl:Invoice: content incomplete; expected: ext:UBLExtensions, cbc:UBLVersionID, cbc:CustomizationID, cbc:ProfileID, cbc:ProfileExecutionID, cbc:ID
...
fatal BR-02: [BR-02]-An Invoice shall have an Invoice number (BT-1).
at /*:Invoice[namespace-uri()='urn:oasis:names:specification:ubl:schema:xsd:Invoice-2'][1]
...
2 documents: 1 valid, 1 invalid, 0 not validated
Exit status, the highest that applies: 0 every document is valid (no schema error, no fatal finding); 1 a document is invalid (schema errors, fatal findings, not well-formed XML, or, for XRechnung, no matching scenario); 2 usage error, or a file or bundle that cannot be read or is not valid (a PDF file without one embedded invoice included); 3 a construct the engine does not support (an encrypted PDF file included), a document beyond a limit, a stylesheet error on a document, or an internal error. Output as text (for people), json (a versioned format, for scripts) or svrl; with --jobs N, N threads share one loaded rule set and the output keeps the order of the command line. Options and the JSON format: crates/einvoice-cli/README.md.
PDF files
A file or standard input that starts with %PDF- is read as a Factur-X, ZUGFeRD or Order-X PDF/A-3 file, by the crate einvoice-pdf, in pure Rust: the embedded invoice XML is extracted byte for byte and validated with the rule set of its root element (or the one named), and the output adds what the PDF states about it: the embedded file, its /AFRelationship, the PDF/A identification and the Factur-X / ZUGFeRD properties of its XMP metadata. The reader takes only the part of PDF on the path to embedded files and bounds every resource against hostile input; an encrypted file or a PDF feature outside that part is refused (exit status 3). In the library: the feature pdf, on by default, and pdf::extract.
Deeply nested documents
A document with an element nested deeper than 256 levels (the document element is at depth 1; libxml2's default limit) is refused before it is validated, with the line and column of that element: an error of kind unsupported and exit status 3 in einvoice-validate, Error::Limit in the library. --max-depth N (at most 100000) and ValidateOptions::max_depth set another maximum. The other limits are listed under Security.
$ einvoice-validate deep.xml
deep.xml: error (unsupported): limit exceeded: document, 2:838: element nested deeper than the maximum depth of 256
Rule sets fetched on demand
Peppol BIS Billing 3.0, XRechnung, Factur-X and the French e-invoicing rules may not be redistributed, so they are not part of the crates. einvoice-validate downloads them from their publishers only when asked (rules fetch NAME, a family, an alias or --all; or --fetch in a validation run), at pinned URLs, checks every file against its pinned digest, assembles their bundles in a local cache (EINVOICE_VALIDATOR_CACHE, by default the platform cache directory) and then works offline. rules list shows the rule sets, their sources and what is cached.
einvoice-validate rules fetch xrechnung # once, from KoSIT's package registry
einvoice-validate --rules xrechnung invoice.xml # xrechnung-ubl or xrechnung-cii, from the document's syntax
einvoice-validate rules fetch peppol # the Peppol Schematron, compiled here, in Rust
einvoice-validate --rules peppol invoice.xml
einvoice-validate --rules factur-x-en16931 --fetch invoice.pdf # fetch in this run if missing
einvoice-validate rules list # every rule set, its source, cached or not
einvoice-validate rules path factur-x-en16931 # the bundle directory, for --bundle
- Peppol, without Java. OpenPeppol publishes the rules as Schematron only.
rules fetch peppolcompiles them as ph-schematron 10.3.1 compiles them for the reference validators, in this program: the ISO Schematron skeleton, taken from the pinned jar of ph-schematron-isosch on Maven Central, is run by the engine (crateeinvoice-schematron), and both stylesheets come out byte for byte those of ph-schematron, their SHA-256 pinned. - XRechnung, as the KoSIT validator runs it. The bundles hold every scenario of the KoSIT validator configuration for their syntax (7 for UBL, 4 for CII): the
matchexpression of each scenario is evaluated on the document, the one that matches names the stylesheets that run (the CEN rules alone, or the CEN and XRechnung rules) and the levels it gives some rule ids, and a document that matches no scenario, or several, is invalid. The document is first validated against the XML schema of its scenario: UBL 2.1, or UN/CEFACT CII D16B. - Verdicts as the reference validators give them. A Factur-X failed assert without a flag (most have none) is fatal, as the Mustang validator reads it, and so is an XRechnung one, as the KoSIT validator reads it. On every document of the test corpora, each bundle reads the Saxon-HE reports as the reference validator does, and the XRechnung bundles validate the XML schema of the scenario first, as the KoSIT validator does. Since 0.4.0, the Factur-X and French bundles validate the XML schema their reference validator runs too (the Factur-X schema of the profile as Mustang selects it; UN/CEFACT CII D22B, CDAR D22B or the Factur-X schema, as the FNFE-MPE package documents it), fetched with the rule sets and not redistributed, so that on every corpus document their verdict is the reference validator's, schema step included (#37).
--fail-closed(ValidateOptions::fail_closed) makes every other finding of no known severity fatal. - Downloads in pure Rust. HTTPS through rustls, on a cryptography provider built on the RustCrypto crates: no C, no assembly file. It is the feature
fetchofeinvoice-cli, on by default;cargo install einvoice-cli --no-default-featuresbuilds a tool without network code.
Library
A Validator is built once from a rule set (schemas loaded, stylesheets prepared), is Send + Sync, and validates any number of documents. Add it from crates.io (API documentation on docs.rs):
[dependencies]
einvoice-validator = "0.4"
use einvoice_validator::{Validator, Verdict};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Built once: the UBL 2.1 schemas loaded, the CEN stylesheet prepared.
// A Validator is Send + Sync: share it between threads.
let validator = Validator::cen_ubl()?;
let report = validator.validate(&std::fs::read("invoice.xml")?)?;
for error in &report.schema_errors {
println!("schema {}:{}: {}", error.line, error.column, error.message);
}
for finding in report.findings() {
let id = finding.id.as_deref().unwrap_or("-");
println!("{:?} {id}: {} (at {})", finding.severity, finding.text, finding.location);
}
println!("{}", if report.verdict() == Verdict::Valid { "valid" } else { "invalid" });
Ok(())
}
Validator::cen_cii() is the CII rule set, and Syntax::detect tells from a document's root element which of the two built-in rule sets is its own:
use einvoice_validator::{Syntax, Validator, Verdict};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let document = std::fs::read("invoice.xml")?;
// From the root element: cen-ubl for a UBL Invoice or CreditNote,
// cen-cii for a CII CrossIndustryInvoice.
let rule_set = Syntax::detect(&document).map_or("cen-ubl", Syntax::builtin_rule_set);
let validator = Validator::builtin(rule_set)?;
let report = validator.validate(&document)?;
let verdict = if report.verdict() == Verdict::Valid { "valid" } else { "invalid" };
println!("{rule_set}: {verdict}");
Ok(())
}
Validator::from_bundle_dir loads a bundle directory, and with the feature fetch, Validator::from_cache a rule set fetched on demand (RuleSetCache, fetched_rule_sets). A Validator is Clone, sharing the loaded rule set. The Report also gives the raw and canonical SVRL, the number of fired rules of each stylesheet, the scenario a document matched and the rule-set version; validate_owned takes the document as an owned buffer and avoids a copy of its text.
Why run the official stylesheets
The validation artefacts are the reference definition of the rules. Running them unchanged means a new release of the rules is new data to vendor and test, not code to rewrite, and a result can always be traced back to the published rule that produced it.
How it works
einvoice-validator and the command-line tool einvoice-validate: the document (or the invoice XML a PDF file embeds) is checked as XML, then against the XML schema of the rule set, UBL 2.1 or UN/CEFACT CII D16B, then each stylesheet of the rule set runs on it (for XRechnung, those of the scenario the document matches). The rule set is chosen from the root element unless one is named: CEN UBL for a UBL invoice or credit note, CEN CII for a CII invoice. SVRL (Schematron Validation Report Language) is the report format the official stylesheets write.| Stage | What | Status |
|---|---|---|
| Read | A streaming XML 1.0 parser with namespaces that builds no tree, checked against roxmltree and Saxon-HE: the XML check and the schema validation in one pass, then the stylesheets' input tree (einvoice-xml, #18); the invoice XML of a Factur-X, ZUGFeRD or Order-X PDF file (einvoice-pdf) | done |
| Schema check | XML Schema validation in Rust against the official OASIS UBL 2.1 and UN/CEFACT CII D16B schemas, which are embedded, limited to the XSD features they use; compared with xmllint (einvoice-xsd, #6, #32) | done |
| Load | The stylesheet is parsed, its XPath expressions and patterns with it; constructs outside the subset are refused, and so are expressions and instructions nested beyond a limit (einvoice-xslt, einvoice-xpath) | done |
| Values | XPath 2.0 atomic values: exact decimals, big integers (einvoice-bigint, safe Rust, no assembly), doubles, dates, casts, comparisons, regular expressions, as Saxon-HE 12.10 behaves (einvoice-xdm) | done |
| Evaluate | XPath 2.0 evaluator over the invoice, with the static types Saxon-HE infers for variables and function results (#21); unknown functions and variables are refused when an expression is compiled; the current date and time come from a clock the caller can give (einvoice-xpath-eval, #1) | done |
| Execute and report | XSLT executor: template rules, modes, priorities, imports, xsl:next-match, functions, parameters, the stylesheets of the ISO Schematron skeleton and of SchXslt; SVRL output, kept compactly and read as it is written. The stylesheet is prepared once and run on any number of documents; template and function invocations are bounded in nesting and in stack (einvoice-xslt-exec, #2, #29) | done |
| Schematron | Schematron compiled to XSLT as ph-schematron 10.3.1 compiles it, byte for byte, by running the ISO Schematron skeleton on the engine: how the Peppol rule set is built without Java (einvoice-schematron) | done |
| Library and tool | Rule-set bundles (a bundle.toml manifest with the SHA-256 of each stylesheet and of each file it reads, severities, KoSIT scenarios), the built-in rule sets cen-ubl and cen-cii, rule sets fetched on demand, the Validator and its Report, Syntax detection from the root element (einvoice-validator); the einvoice-validate command-line tool with text, JSON and SVRL output, the rule set picked per document, and documented exit codes (einvoice-cli, #10, #35) | done |
| WebAssembly and npm | The library on wasm32-unknown-unknown, the date and time given by the caller. The npm package einvoice-validator (JavaScript and TypeScript bindings for Node.js 22, browsers and bundlers, with cen-ubl and cen-cii) is built and tested: the Saxon-HE findings on every case of the CEN UBL and CII corpora under Node.js and in headless Chrome and Firefox. Build it from the repository with crates/einvoice-wasm/npm.sh; it is not published on npm. | built, not published |
| Release | 0.4.0: the thirteen published crates of the workspace on crates.io, each with its licence texts, and a signed tag with its GitHub release; earlier releases 0.3.0, 0.2.0 and 0.1.0 | done |
Rule sets
Two rule sets are built in. The others may not be redistributed: einvoice-validate rules fetch NAME downloads them from their publishers, at pinned URLs, checks every file against its pinned digest and assembles (for Peppol, compiles) their bundles on your machine. For each, a test corpus of official documents and mutation cases of our own carries the report Saxon-HE 12.10 gives with each stylesheet; the corpora of the fetched rule sets are built locally, like the rule sets.
| Rule set | Release | How to get it | Checked against Saxon-HE |
|---|---|---|---|
| CEN EN 16931, UBL syntax | 1.3.17 | built in cen-ubl: the compiled XSLT published by CEN, vendored unmodified, after the UBL 2.1 schema | 1179 cases (examples, test files, VEFA unit tests) and 508 mutation cases: every report identical (#3) |
| CEN EN 16931, UN/CEFACT CII D16B syntax | 1.3.17 | built in cen-cii: the compiled XSLT published by CEN, vendored unmodified, after the UN/CEFACT CII D16B schema (#32) | 24 cases and 808 mutation cases: every report identical (#12) |
| Peppol BIS Billing 3.0, UBL syntax | 3.0.22 | fetched rules fetch peppol: the Schematron of the pinned release, compiled in pure Rust, without Java, as ph-schematron 10.3.1 compiles it, both stylesheets (the Peppol rules and the CEN rules the release embeds) byte for byte, their SHA-256 pinned | 707 cases and 509 mutation cases, with each of the two stylesheets: every report identical (#5) |
| Factur-X / ZUGFeRD, CII syntax, five profiles | Factur-X 1.09.2 (ZUGFeRD 2.5.2) | fetched rules fetch factur-x: the stylesheets and code lists of the five profiles as the Mustang validator 2.26.0 ships them (Maven Central); a failed assert without a flag is fatal, as Mustang reads it. On main: the XML schema of the profile first, as Mustang runs it | 42 cases and 808 mutation cases, with each of the five stylesheets: every report identical (#26) |
| XRechnung, UBL and CII syntaxes | 3.0.2 | fetched rules fetch xrechnung: the KoSIT validator configuration (the CEN and XRechnung rules), run as the KoSIT validator runs it: its scenarios, their levels and their XML schema | 1196 UBL and 686 CII cases (the test suite and the expanded unit tests of the XRechnung Schematron) and 508 + 808 mutation cases, with both stylesheets of each syntax: every report identical (#27) |
| French e-invoicing rules (XP Z12-012): CII, UBL, EXTENDED-CTC-FR, Factur-X, life-cycle statuses (CDAR), e-reporting | FNFE-MPE package 1.4.0.04 | fetched rules fetch fr-ctc: fourteen bundles from the package published by FNFE-MPE; UBL 2.1 first for UBL. On main: UN/CEFACT CII D22B, CDAR D22B or the Factur-X schema first, as the package documents it | 53 CII, 75 UBL and 70 CDAR cases and 808 + 508 mutation cases, with each stylesheet that runs on them: every report identical (e-reporting has no test corpus) (#28) |
| UBL 2.1 XML Schema (Invoice, CreditNote) | 2.1 | built in the OASIS schemas, vendored unmodified and embedded (the two ETSI XAdES schemas excepted: signature content is validated laxly) | Compared with xmllint (libxml2): every corpus document agrees; every other difference is listed with its cause (#6) |
| UN/CEFACT CII D16B XML Schema (CrossIndustryInvoice) | D16B | built in UNECE's files, uncoupled code lists, vendored unmodified and embedded | Compared with xmllint on the CEN CII corpus: every case agrees, the 4 mutation cases that differ are listed with their cause; the same on the CII corpora of XRechnung, Factur-X and the French rules (#32) |
On every document of these corpora, each rule set reads the Saxon-HE reports as its reference validator does; the XML schema step of the Factur-X and French bundles included, since 0.4.0 (#37). Need another official rule set? Open an issue.
Performance
einvoice-validate against Saxon-HE 12.10 running the same official stylesheets on the same documents: the whole corpus of each rule set (every document, mutation cases included), one process per job, process start and rule-set load included. There are 23 jobs, one per rule set exactly as einvoice-validate --rules NAME runs it (#41): the rule set read from the cache rules fetch fills, the XML schema step, the XRechnung scenarios, the stylesheets and the verdicts, which must be the reference verdicts on every document and every run. Median of 5 runs, measured with cargo xtask bench at commit f07b7a8 (in 0.4.0), on a 20-core desktop machine (load average 1.3 before the run, 6.5 after, the run's own processes included); the full tables, the method and every run are in docs/benchmarks.md.
| Rule set | Documents | 1 thread: einvoice-validate | Saxon-HE | Speed-up | Speed-up, JVM start excluded | 8 threads: einvoice-validate | Saxon-HE | Speed-up | Peak memory, 1 thread (ratio) |
|---|---|---|---|---|---|---|---|---|---|
| CEN EN 16931 UBL 1.3.17 | 1687 | 1.32 s | 2.29 s | 1.7× | 1.6× | 0.225 s | 1.12 s | 5.0× | 34.7 MiB / 853 MiB (25×) |
| CEN EN 16931 CII 1.3.17 | 832 | 0.579 s | 1.66 s | 2.9× | 2.6× | 0.106 s | 0.971 s | 9.2× | 22.6 MiB / 855 MiB (38×) |
| Peppol BIS Billing 3.0.22 (UBL) | 1216 | 1.44 s | 3.55 s | 2.5× | 2.2× | 0.251 s | 1.95 s | 7.8× | 35.6 MiB / 888 MiB (25×) |
| Factur-X 1.09.2 MINIMUM | 850 | 0.301 s | 1.69 s | 5.6× | 5.1× | 0.049 s | 1.02 s | 21× | 8.65 MiB / 807 MiB (93×) |
| Factur-X 1.09.2 BASIC WL | 850 | 1.17 s | 3.60 s | 3.1× | 2.9× | 0.178 s | 1.46 s | 8.2× | 15.7 MiB / 903 MiB (58×) |
| Factur-X 1.09.2 BASIC | 850 | 1.67 s | 4.91 s | 2.9× | 2.9× | 0.247 s | 1.76 s | 7.1× | 20.2 MiB / 1110 MiB (55×) |
| Factur-X 1.09.2 EN16931 | 850 | 1.74 s | 5.31 s | 3.1× | 3.0× | 0.265 s | 1.79 s | 6.7× | 23.2 MiB / 898 MiB (39×) |
| Factur-X 1.09.2 EXTENDED | 850 | 2.24 s | 6.82 s | 3.0× | 3.0× | 0.361 s | 2.16 s | 6.0× | 44.9 MiB / 1033 MiB (23×) |
| XRechnung 3.0.2 UBL | 1704 | 2.75 s | 5.79 s | 2.1× | 1.3× | 0.415 s | 2.50 s | 6.0× | 36.7 MiB / 874 MiB (24×) |
| XRechnung 3.0.2 CII | 1494 | 2.36 s | 4.90 s | 2.1× | 1.6× | 0.351 s | 2.35 s | 6.7× | 25.2 MiB / 869 MiB (34×) |
| French rules 1.4.0.04, EN 16931 CII | 861 | 1.90 s | 4.92 s | 2.6× | 2.4× | 0.293 s | 2.31 s | 7.9× | 23.2 MiB / 1083 MiB (47×) |
| French rules 1.4.0.04, EN 16931 CII (WARNING version) | 861 | 1.91 s | 4.83 s | 2.5× | 2.3× | 0.291 s | 2.35 s | 8.1× | 23.1 MiB / 1071 MiB (46×) |
| French rules 1.4.0.04, EXTENDED-CTC-FR CII | 861 | 1.97 s | 4.95 s | 2.5× | 2.3× | 0.305 s | 2.40 s | 7.9× | 26.4 MiB / 1074 MiB (41×) |
| French rules 1.4.0.04, EXTENDED-CTC-FR CII (WARNING version) | 861 | 1.99 s | 5.00 s | 2.5× | 2.3× | 0.304 s | 2.38 s | 7.8× | 25.9 MiB / 1094 MiB (42×) |
| French rules 1.4.0.04, Factur-X BASIC WL | 861 | 2.50 s | 6.82 s | 2.7× | 2.6× | 0.357 s | 2.68 s | 7.5× | 20.0 MiB / 1078 MiB (54×) |
| French rules 1.4.0.04, Factur-X EN16931 | 861 | 3.11 s | 8.84 s | 2.8× | 2.7× | 0.466 s | 3.44 s | 7.4× | 24.4 MiB / 1082 MiB (44×) |
| French rules 1.4.0.04, Factur-X EXTENDED | 861 | 3.41 s | 9.75 s | 2.9× | 2.7× | 0.518 s | 3.30 s | 6.4× | 43.7 MiB / 1093 MiB (25×) |
| French rules 1.4.0.04, EN 16931 UBL | 583 | 2.73 s | 5.55 s | 2.0× | 1.9× | 0.434 s | 2.55 s | 5.9× | 35.1 MiB / 1008 MiB (29×) |
| French rules 1.4.0.04, EN 16931 UBL (WARNING version) | 583 | 2.73 s | 5.57 s | 2.0× | 1.9× | 0.433 s | 2.61 s | 6.0× | 35.5 MiB / 1003 MiB (28×) |
| French rules 1.4.0.04, EXTENDED-CTC-FR UBL | 583 | 2.69 s | 5.69 s | 2.1× | 2.0× | 0.433 s | 2.55 s | 5.9× | 36.6 MiB / 1098 MiB (30×) |
| French rules 1.4.0.04, EXTENDED-CTC-FR UBL (WARNING version) | 583 | 2.66 s | 5.58 s | 2.1× | 1.9× | 0.434 s | 2.59 s | 6.0× | 36.7 MiB / 1087 MiB (30×) |
| French rules 1.4.0.04, life-cycle statuses (CDAR) | 70 | 0.036 s | 0.599 s | 17× | 13× | 0.012 s | 0.577 s | 46× | 11.3 MiB / 312 MiB (28×) |
| French rules 1.4.0.04, life-cycle statuses (CDAR, WARNING version) | 70 | 0.036 s | 0.621 s | 17× | 13× | 0.013 s | 0.568 s | 43× | 11.2 MiB / 313 MiB (28×) |
| All 23 jobs | 19682 | 43.2 s | 109 s | 2.5× | 2.3× | 6.74 s | 47.4 s | 7.0× | 23× to 93× lower |
- The whole job. The 23 jobs together, 19682 documents: on one thread 43.2 s against 109 s for Saxon-HE, 2.5 times faster (2.3 times against Saxon-HE without its JVM start); on eight threads 6.74 s against 47.4 s, 7.0 times faster. Peak memory 23 to 93 times lower on one thread, 23 to 71 times on eight.
- XRechnung now faster than Saxon-HE. On one thread, XRechnung UBL and CII take 2.75 s and 2.36 s against 5.79 s and 4.90 s; doing exactly Saxon-HE's work, they are 1.3 and 1.6 times faster than Saxon-HE without its JVM start, where they were about as fast before (#40).
- One small invoice in a new process (5.8 kB, CEN UBL): 45 ms with the UBL 2.1 schema, 32 ms without, against 599 ms for Saxon-HE, 450 ms without its JVM start; 34 MiB of peak memory against 246 MiB.
- What is compared.
einvoice-validatedoes more than Saxon-HE: the XML schema of the rule set, the scenario selection of XRechnung and the verdicts. A run doing exactly Saxon-HE's work (each stylesheet alone, on every document, no schema) is in the full tables; the column "JVM start excluded" compares that run with the compilation and execution times Saxon-HE reports itself. Saxon-HE runs one stylesheet per JVM, so a rule set of k stylesheets costs k JVM starts.
Security
Documents, PDF files and rule-set bundles may come from anyone; each is bounded so that a hostile one ends with an error, not a crash or an unbounded allocation.
- Document depth. An element nested deeper than 256 levels (libxml2's default limit;
--max-depth,ValidateOptions::max_depth, at most 100000) is refused before the document is validated (#29). At the default maximum, a validation runs on a thread with the default 2 MiB stack, in a debug build too. - Stylesheet recursion. Template and function invocations are bounded in nesting and in the stack they use (
ValidateOptions::max_stack, 1.5 MiB by default; 256 KiB on WebAssembly), and tail calls of named templates to 65536 in a row: a rule set that recurses without end fails withError::Limitinstead of overflowing the stack. - Stylesheet nesting (new in 0.3.0, #33). A bundle whose XPath expressions or patterns nest deeper than 128 levels, or whose instructions nest deeper than 64, is refused when it is loaded, rather than overflowing the stack; the official stylesheets need 32 and 9.
- WebAssembly (new in 0.4.0, #34).
max_depthis capped at 400 andmax_stackat 256 KiB (WASM_MAX_DEPTH,WASM_MAX_STACK; more isError::OptionOutOfRange): measured in Chrome, Firefox and Node.js, on the main thread and in a Web Worker, a recursion then ends with the library's stack limit, never with an overflow of the engine's stack. - PDF files. Only the part of PDF on the path to embedded files is read, with every resource bounded; encrypted files and anything else are refused.
- Bundles and downloads. Every stylesheet and every file a stylesheet reads is named in the bundle's manifest with its SHA-256, checked when the bundle is loaded, and
document()reads nothing else. Downloaded rule sets are checked against pinned digests, with size limits, and their archives are read with path checks.
Report a vulnerability through the repository's security policy.
Pure Rust
- No C, no assembly in our code. No crate of the workspace contains
unsafecode (unsafe_code = "forbid"), and no C or C++ file is compiled and no assembly file assembled or linked, on any target. Big integers are our owneinvoice-bigint, safe Rust without assembly. - Downloads on a pure-Rust TLS stack. rustls with a cryptography provider of the project on the RustCrypto crates, instead of the C and assembly of
ringoraws-lc-rs; the crates that build native code are banned indeny.toml. What is downloaded is checked against its pinned digest; TLS is a second line of defence. - Audited dependencies.
docs/dependencies.mdlists, crate by crate, the third-partyunsafe, build scripts and inline assembly compiled into the binary, the library and the WebAssembly module (which has no inline assembly), and a test keeps it in step with the dependency graphs.
Quality
- Reference results. For each rule set, the official examples, test files and unit tests, each with the SVRL report Saxon-HE 12.10 produces, in a canonical text form. They are cross-checked against the expectations written in the official unit tests, with no disagreement (1131 CEN UBL, 9 CEN CII and 678 Peppol unit-test cases, and the expectations of the XRechnung Schematron's unit tests). CI runs Saxon again and the committed CEN UBL and CII results must not change; the corpora of the fetched rule sets are rebuilt and checked in CI.
- Mutation cases. A catalogue of edits of the official examples, aimed at what the rules check and where engines can diverge: totals and rounding, decimal precision, number and date forms, VAT categories, code lists, check digits, namespaces, repeated elements, element order. 508 UBL cases make 973 of the 982 distinct CEN UBL asserts fire, against 235 with the official cases alone. A second catalogue does the same for CII: 808 cases, in which 785 of the 810 assert ids of the CII stylesheet fail at least once; the corpus README says why the 25 others cannot. Where Saxon-HE stops with a dynamic error, the engine stops with the same error code.
- Same reports as Saxon-HE. On every case of every corpus, the canonical report of the engine is identical to Saxon's, line for line, and the verdicts and findings of the library and of
einvoice-validateagree with them. Each crate is also checked on its own: the atomic values against Saxon-HE on over 5000 operations, the evaluator on every distinct expression of the CEN stylesheet at nodes of corpus documents, the executor on synthetic probe stylesheets, the Schematron compiler against ph-schematron at each step. - Schema validation compared with xmllint on the UBL and CII corpora, synthetic documents and mutations of them; every difference is listed with its cause: cases where libxml2 departs from XML Schema 1.0 (decimals beyond its 24 digits, for instance), and signature content checked loosely because the two ETSI XAdES schemas are not shipped.
- Memory. A test fails when the peak heap of a validation exceeds its recorded budget. On a synthetic invoice of 5000 lines (4.1 MB), a validation peaks at 2.1 times the document, the stylesheet's input tree alone being 1.9 times.
- Integrity. Vendored artefacts are checked against their SHA-256 sums, and so are every fetched rule set, the compiled Peppol stylesheets and every file of a bundle; Saxon-HE and the XML Resolver it needs, used only in tests, are downloaded from Maven Central and their checksums verified.
- Lints. Every warning is an error; clippy
allandpedanticare denied;unwrap,expectandpanicare denied outside tests;unsafecode is forbidden. - Tests. Unit, golden and property-based tests (proptest); on Linux for every push to
main, also on macOS and Windows for pull requests; the library without its built-in rule sets, onwasm32-unknown-unknownunder wasmtime, and the npm package under Node.js and in headless browsers. - Supply chain. Toolchain pinned (Rust 1.99.1),
Cargo.lockcommitted and every cargo command--locked; licences, advisories, bans and sources checked bycargo-deny; GitHub Actions pinned by commit SHA, linted by actionlint and audited by zizmor; signed commits. Dependabot and a weekly check report newer versions of the pinned upstreams: rule sets, Saxon-HE, toolchain, CI tools. - Releases. A changelog checked on every pull request, and a release script and workflow that check the tag, the workspace version and the changelog agree. Each release states the rule-set versions it was tested against; the latest, 0.4.0, was tested against the CEN EN 16931 validation artefacts 1.3.17, Peppol BIS Billing 3.0.22, Factur-X 1.09.2, XRechnung 3.0.2 and the French e-invoicing rules (FNFE-MPE) 1.4.0.04.
- Same checks everywhere. CI and a local run use the same script: see Build and test.
Licences
- The code: MIT.
- The vendored CEN artefacts (
artefacts/cen-en16931-ubl-1.3.17/andartefacts/cen-en16931-cii-1.3.17/) and the test corpora derived from them, their mutation cases included (corpus/cen-en16931-ubl-1.3.17/andcorpus/cen-en16931-cii-1.3.17/), keep their upstream licence, the European Union Public Licence 1.2 (EUPL-1.2). einvoice-xsdembeds the OASIS UBL 2.1 schemas (schemas/oasis-ubl-2.1/) and the UN/CEFACT CII D16B schemas (schemas/uncefact-cii-d16b/), vendored unmodified; they are not under the MIT licence, each keeps the terms in its own header (OASIS, UN/CEFACT, W3C), with their texts incrates/einvoice-xsd/LICENSES/. The two ETSI XAdES schemas of the OASIS package carry no licence and are not included; XAdES signature content is therefore validated laxly. The UN/CEFACT CII D22B schemas carry no notice or licence and are not redistributed.einvoice-validatorembeds the two CEN stylesheets through its default featurescen-ublandcen-cii, and the schemas througheinvoice-xsd; so do theeinvoice-validatebinary and the npm package: they are licensedMIT AND EUPL-1.2 AND LicenseRef-OASIS-Copyright-Notice AND LicenseRef-UN-CEFACT-Copyright-Notice AND W3C-19980720. Built withdefault-features = false, the library embeds no rule set and uses only the bundles it is given.einvoice-validate --licencesprints all of these licences in full, then the notice of every crate from crates.io compiled into the binary.- Peppol BIS Billing 3.0, XRechnung, Factur-X and the French rules are downloaded on demand from their publishers and not redistributed: neither they nor anything derived from them (compiled stylesheets, extracted documents, Saxon-HE results) is committed or part of a crate.
- Saxon-HE 12.10 (MPL-2.0) and the XML Resolver (Apache-2.0) are not part of the repository: the tests download them. xmllint is the reference of the schema tests only.