Skip to main content

einvoice_validator/
licences.rs

1//! The licences of what the crate embeds in a program, with their texts.
2
3pub use einvoice_xsd::Licence;
4
5/// The MIT licence of the code, from `LICENSES/MIT.txt` (the repository's `LICENSE`).
6const MIT: Licence = Licence {
7    id: "MIT",
8    covers: MIT_COVERS,
9    text: include_str!("../LICENSES/MIT.txt"),
10};
11
12/// What the MIT licence covers in this build: the crates of the project it is built from
13/// (einvoice-pdf with the feature `pdf`, einvoice-schematron with the feature `fetch`,
14/// which is ignored on WebAssembly).
15#[cfg(all(feature = "pdf", feature = "fetch", not(target_family = "wasm")))]
16const MIT_COVERS: &str = "the code of einvoice-validator and of the crates of the project it \
17     is built from (einvoice-bigint, einvoice-pdf, einvoice-schematron, einvoice-svrl, einvoice-xdm, \
18     einvoice-xml, einvoice-xpath, einvoice-xpath-eval, einvoice-xsd, einvoice-xslt, \
19     einvoice-xslt-exec)";
20#[cfg(all(
21    feature = "pdf",
22    not(all(feature = "fetch", not(target_family = "wasm")))
23))]
24const MIT_COVERS: &str = "the code of einvoice-validator and of the crates of the project it \
25     is built from (einvoice-bigint, einvoice-pdf, einvoice-svrl, einvoice-xdm, einvoice-xml, \
26     einvoice-xpath, einvoice-xpath-eval, einvoice-xsd, einvoice-xslt, \
27     einvoice-xslt-exec)";
28#[cfg(all(not(feature = "pdf"), feature = "fetch", not(target_family = "wasm")))]
29const MIT_COVERS: &str = "the code of einvoice-validator and of the crates of the project it \
30     is built from (einvoice-bigint, einvoice-schematron, einvoice-svrl, einvoice-xdm, einvoice-xml, \
31     einvoice-xpath, einvoice-xpath-eval, einvoice-xsd, einvoice-xslt, \
32     einvoice-xslt-exec)";
33#[cfg(all(
34    not(feature = "pdf"),
35    not(all(feature = "fetch", not(target_family = "wasm")))
36))]
37const MIT_COVERS: &str = "the code of einvoice-validator and of the crates of the project it \
38     is built from (einvoice-bigint, einvoice-svrl, einvoice-xdm, einvoice-xml, einvoice-xpath, \
39     einvoice-xpath-eval, einvoice-xsd, einvoice-xslt, einvoice-xslt-exec)";
40
41/// The EUPL-1.2 of the CEN stylesheets of the built-in rule sets `cen-ubl` and `cen-cii`.
42#[cfg(any(feature = "cen-ubl", feature = "cen-cii"))]
43const EUPL: Licence = Licence {
44    id: "EUPL-1.2",
45    covers: EUPL_COVERS,
46    text: include_str!("../LICENSES/EUPL-1.2.txt"),
47};
48
49/// What the EUPL-1.2 covers in this build: the stylesheets of the enabled features.
50#[cfg(all(feature = "cen-ubl", feature = "cen-cii"))]
51const EUPL_COVERS: &str = "the CEN EN 16931 UBL and CII validation stylesheets, release 1.3.17 \
52     (ubl/xslt/EN16931-UBL-validation.xslt and cii/xslt/EN16931-CII-validation.xslt, \
53     unmodified), published by CEN/TC 434 and embedded by einvoice-validator as the built-in \
54     rule sets cen-ubl and cen-cii";
55#[cfg(all(feature = "cen-ubl", not(feature = "cen-cii")))]
56const EUPL_COVERS: &str = "the CEN EN 16931 UBL validation stylesheet, release 1.3.17 \
57     (ubl/xslt/EN16931-UBL-validation.xslt, unmodified), published by CEN/TC 434 and \
58     embedded by einvoice-validator as the built-in rule set cen-ubl";
59#[cfg(all(feature = "cen-cii", not(feature = "cen-ubl")))]
60const EUPL_COVERS: &str = "the CEN EN 16931 CII validation stylesheet, release 1.3.17 \
61     (cii/xslt/EN16931-CII-validation.xslt, unmodified), published by CEN/TC 434 and \
62     embedded by einvoice-validator as the built-in rule set cen-cii";
63
64/// Every licence of what this build of the crate embeds in a program, with its full
65/// text: the MIT licence of the code (of this crate and of the crates of the project
66/// it depends on, which share that licence), the EUPL-1.2 of the CEN stylesheets when
67/// the feature `cen-ubl` or `cen-cii` is on, then the terms of the UBL 2.1 and CII D16B
68/// schemas embedded by [`einvoice_xsd`] (OASIS, UN/CEFACT, W3C).
69///
70/// The W3C licence of the XML Signature schema asks for its full notice "in a location
71/// viewable to users": a program built on this crate can show these texts, as
72/// `einvoice-validate --licences` does. Rule sets loaded from bundles at run time are
73/// not embedded and not listed.
74#[must_use]
75pub fn licences() -> Vec<Licence> {
76    let mut out = vec![MIT];
77    #[cfg(any(feature = "cen-ubl", feature = "cen-cii"))]
78    out.push(EUPL);
79    // einvoice-xsd's MIT text is the same as this crate's (a test checks it).
80    out.extend(
81        einvoice_xsd::LICENCES
82            .iter()
83            .filter(|l| l.id != "MIT")
84            .copied(),
85    );
86    out
87}