Skip to content

jam.saml.xml

xml

Functions:

Name Description
canonicalize_xml

Inclusive XML canonicalization (C14N) of an Element.

fmt_instant

Format a datetime as SAML-style UTC string (2024-01-15T12:00:00Z).

make_element

Create an Element with the given namespace-qualified tag.

make_id

Generate a unique SAML identifier (_<hex>).

parse_instant

Parse a SAML-style UTC string into a datetime.

register_namespaces

Register SAML and DS namespace prefixes with ElementTree.

safe_fromstring

Parse XML string with XXE and entity expansion protection.

canonicalize_xml

canonicalize_xml(elem: Element) -> bytes

Inclusive XML canonicalization (C14N) of an Element.

Note: uses standard (non-exclusive) C14N for Python 3.10 compatibility.

fmt_instant

fmt_instant(dt: datetime | None = None) -> str

Format a datetime as SAML-style UTC string (2024-01-15T12:00:00Z).

make_element

make_element(
    tag: str, ns: str, attrib: dict[str, str] | None = None
) -> Element

Create an Element with the given namespace-qualified tag.

make_id

make_id() -> str

Generate a unique SAML identifier (_<hex>).

parse_instant

parse_instant(text: str) -> datetime

Parse a SAML-style UTC string into a datetime.

register_namespaces

register_namespaces() -> None

Register SAML and DS namespace prefixes with ElementTree.

safe_fromstring

safe_fromstring(xml_str: str) -> Element

Parse XML string with XXE and entity expansion protection.

Rejects XML containing DTD/DOCTYPE declarations (required for XXE). Python 3.8+ already limits entity expansion by default in ElementTree.

Parameters:

Name Type Description Default
xml_str str

XML string to parse.

required

Returns:

Type Description
Element

Root element.

Raises:

Type Description
JamSAMLValidationError

If XML is malformed or contains unsafe entities.

sub_element

sub_element(
    parent: Element,
    tag: str,
    ns: str,
    text: str | None = None,
    attrib: dict[str, str] | None = None,
) -> Element

Add a child Element with namespace-qualified tag and optional text.