Skip to main content

openszigno_core/
lib.rs

1//! Structural parsing and bounded payload decoding for Microsec e-Szignó dossiers.
2//!
3//! This crate does not perform XMLDSig or XAdES verification. A successfully
4//! parsed dossier is not necessarily authentic.
5
6mod decode;
7mod decrypt;
8mod error;
9mod inventory;
10mod model;
11mod parse;
12mod scan;
13mod sniff;
14mod text;
15mod xml;
16
17pub use decode::{DecodeOutcome, DecodedDocument, UnsupportedReason, decode_document_with};
18pub use decrypt::{DecryptOptions, RecipientKey};
19pub use error::{Error, ErrorCode};
20pub use model::{
21    Document, Dossier, Limits, MAX_INVENTORIED_CLAIMED_ROLE_CHARS, MAX_INVENTORIED_CLAIMED_ROLES,
22    MAX_INVENTORIED_DIGEST_METHODS, MAX_INVENTORIED_REFERENCE_URIS, MAX_INVENTORIED_SIGNATURES,
23    MAX_INVENTORIED_TIMESTAMPS, MAX_INVENTORIED_XADES_PROPERTIES, MimeType, ParseOptions,
24    SignatureEvidence, SignaturePlacement, SignatureSummary, StructuralWarning,
25    StructuralWarningCode, TimestampPlacement, TimestampSummary,
26};
27pub use sniff::{DetectedType, sniff};
28pub use text::{MAX_DISPLAY_CHARS, sanitize_display};
29pub use xml::{EncodingDeclaration, XmlSource, declared_encoding, id_map};
30
31/// The XML parser this crate builds every tree with. Re-exported so that a
32/// verifier operates on exactly the same tree the structural parser saw.
33pub use roxmltree;
34
35pub const ESZIGNO_NAMESPACE: &str = "https://www.microsec.hu/ds/e-szigno30#";
36pub const XMLDSIG_NAMESPACE: &str = "http://www.w3.org/2000/09/xmldsig#";
37
38/// The XAdES namespaces the signature inventory recognises: 1.1.1, 1.2.2,
39/// 1.3.2, and 1.4.1. A qualifying-properties element in any other namespace is
40/// not described, because its element names would not mean what they say.
41pub const XADES_NAMESPACES: &[&str] = &[
42    "http://uri.etsi.org/01903/v1.1.1#",
43    "http://uri.etsi.org/01903/v1.2.2#",
44    "http://uri.etsi.org/01903/v1.3.2#",
45    "http://uri.etsi.org/01903/v1.4.1#",
46];
47
48/// Namespaces whose `Dossier` root element this crate accepts by default.
49///
50/// The specification allows a dossier profile to use its own namespace as long
51/// as it stays compliant with the default schema. These are the default
52/// Microsec namespace and the four Hungarian company-court (e-cégeljárás)
53/// generations seen in practice. Anything else is a `wrong_root` error unless
54/// the caller adds it to [`ParseOptions::allowed_namespaces`].
55pub const KNOWN_COMPATIBLE_NAMESPACES: &[&str] = &[
56    ESZIGNO_NAMESPACE,
57    "http://www.e-cegjegyzek.hu/2007/e-cegeljaras#",
58    "http://www.e-cegjegyzek.hu/2009/e-cegeljaras#",
59    "http://www.e-cegjegyzek.hu/2012/e-cegeljaras#",
60    "http://www.e-cegjegyzek.hu/2014/e-cegeljaras#",
61];
62
63/// Parse a bounded e-dossier from memory, accepting the known-compatible
64/// namespaces only.
65pub fn parse(bytes: &[u8], limits: &Limits) -> Result<Dossier, Error> {
66    parse_with_options(bytes, &ParseOptions::with_limits(limits.clone()))
67}
68
69/// Parse a bounded e-dossier from memory with an explicit namespace policy.
70pub fn parse_with_options(bytes: &[u8], options: &ParseOptions) -> Result<Dossier, Error> {
71    parse::parse(bytes, options)
72}