1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//! Factur-X, `ZUGFeRD` and Order-X PDF files (feature `pdf`, on by default): the invoice
//! XML a PDF/A-3 file embeds, extracted with [`einvoice_pdf`], to be validated as any
//! other document.
//!
//! [`extract`] returns the embedded file named as the specifications require
//! ([`INVOICE_FILE_NAMES`]), byte for byte, with its file specification
//! (`/AFRelationship`, ...) and the XMP metadata of the document (the PDF/A
//! identification, the Factur-X / `ZUGFeRD` properties). [`Syntax::detect`] then tells
//! which built-in rule set the XML is for:
//!
//! ```
//! # #[cfg(all(feature = "cen-ubl", feature = "cen-cii"))]
//! fn validate(file: &[u8]) -> Result<einvoice_validator::Report, einvoice_validator::Error> {
//! use einvoice_validator::{Syntax, Validator, pdf};
//!
//! let xml = if pdf::is_pdf(file) {
//! let embedded = pdf::extract(file)?;
//! println!("{} ({:?})", embedded.xml.file_name, embedded.xml.relationship);
//! embedded.xml.data
//! } else {
//! file.to_vec()
//! };
//! let rule_set = Syntax::detect(&xml).map_or("cen-ubl", Syntax::builtin_rule_set);
//! Validator::builtin(rule_set)?.validate_owned(xml)
//! }
//! ```
//!
//! Only the part of PDF on the path to the embedded files is read (see [`einvoice_pdf`]);
//! anything else met there is refused rather than read approximately. The errors are
//! [`Error::Pdf`].
//!
//! [`Syntax::detect`]: crate::Syntax::detect
pub use ;
use crateError;
/// The start of every PDF file (the header, ISO 32000-2, 7.5.2).
const HEADER: & = b"%PDF-";
/// Whether `bytes` start as a PDF file does (`%PDF-`), which no XML document does.
/// The embedded invoice XML of a Factur-X, `ZUGFeRD` or Order-X PDF, with its file
/// specification and the document's XMP metadata, with the default [`Limits`].
///
/// # Errors
///
/// [`Error::Pdf`]: a file that is not a PDF, is malformed, encrypted, uses a PDF feature
/// outside the subset read, exceeds a limit, has no embedded file with an invoice name or
/// several, or has XMP metadata that is not well-formed.
/// [`extract`] with explicit [`Limits`].
///
/// # Errors
///
/// As [`extract`].