Skip to main content

xml_sec/
lib.rs

1//! # xml-sec — Pure Rust XML Security
2//!
3//! Drop-in replacement for libxmlsec1. XMLDSig, XMLEnc, C14N — no C dependencies.
4//!
5//! ## Features
6//!
7//! - **C14N** — XML Canonicalization (inclusive + exclusive)
8//! - **XMLDSig** — XML Digital Signatures (sign + verify)
9//! - **XMLEnc** — XML Encryption (encrypt + decrypt)
10//! - **X.509** — Certificate-based key extraction
11//!
12//! ## Quick Start
13//!
14//! ```rust
15//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
16//! use xml_sec::c14n::{C14nAlgorithm, C14nMode, canonicalize_xml};
17//!
18//! let xml = b"<root b=\"2\" a=\"1\"><empty/></root>";
19//! let algo = C14nAlgorithm::new(C14nMode::Inclusive1_0, false);
20//! let canonical = canonicalize_xml(xml, &algo)?;
21//! assert_eq!(
22//!     String::from_utf8(canonical)?,
23//!     "<root a=\"1\" b=\"2\"><empty></empty></root>"
24//! );
25//! # Ok(())
26//! # }
27//! ```
28
29#![deny(unsafe_code)]
30#![deny(clippy::unwrap_used)]
31#![warn(missing_docs)]
32
33#[cfg(not(any(feature = "xml-backend-xmloxide", feature = "xml-backend-roxmltree")))]
34compile_error!(
35    "compile at least one XML backend: `xml-backend-xmloxide` or `xml-backend-roxmltree`"
36);
37
38pub mod c14n;
39pub mod document;
40pub mod encoding;
41pub mod error;
42mod hard_limits;
43#[cfg(any(feature = "xmldsig", feature = "xmlenc"))]
44mod operation;
45#[cfg(any(feature = "xmldsig", feature = "xmlenc"))]
46pub mod policy;
47#[cfg(any(feature = "xmldsig", feature = "xmlenc"))]
48pub mod provider;
49mod xml;
50
51pub use xml::IdAttributeRegistration;
52pub use xml::dom::{
53    Ancestors, Attribute, Attributes, Children, Descendants, Document, Document as XmlDomDocument,
54    ExpandedName, Namespace, Namespaces, Node, Node as XmlDomNode, NodeId, NodeId as XmlDomNodeId,
55    NodeType, PI, ParseError, ParseError as XmlDomParseError, ParsingOptions,
56    ParsingOptions as XmlDomParsingOptions, XmlBackend,
57};
58
59#[cfg(feature = "xmldsig")]
60pub mod xmldsig;
61
62#[cfg(feature = "xmlenc")]
63pub mod xmlenc;
64
65#[cfg(any(feature = "xmldsig", feature = "xmlenc"))]
66pub use document::XmlDocumentPolicy;
67pub use document::{
68    AttributeIdentity, DocumentIdentity, DocumentView, NamespaceIdentity, NodeIdentity,
69    SemanticOrder, XmlDocument, XmlDocumentError,
70};
71pub use error::XmlSecError;