canonicalizeDocument function

Uint8List canonicalizeDocument(
  1. XmlLiteDocument document, {
  2. required XmlC14nMethod method,
  3. XmlLiteElement? omit,
  4. List<String> inclusivePrefixes = const [],
})

Canonicalizes the whole document (comments dropped), leaving out the subtree omit - the enveloped-signature transform.

Implementation

Uint8List canonicalizeDocument(XmlLiteDocument document,
    {required XmlC14nMethod method,
    XmlLiteElement? omit,
    List<String> inclusivePrefixes = const []}) {
  final out = StringBuffer();
  var beforeRoot = true;
  for (final node in document.children) {
    switch (node) {
      case XmlLiteElement():
        _Canonicalizer(method, omit, inclusivePrefixes)
            .element(node, out, apex: true);
        beforeRoot = false;
      case XmlLiteProcessingInstruction():
        if (!beforeRoot) out.write('\n');
        _writePi(node, out);
        if (beforeRoot) out.write('\n');
      default: // comments are dropped
    }
  }
  return Uint8List.fromList(utf8.encode(out.toString()));
}