Subject: Add a workaround to canonicalization to address performance
 problems in PHP >= 5.2.
 https://bugs.php.net/bug.php?id=53655
 https://simplesamlphp.org/metaprocessing
Origin: upstream release 1.13.2 
Bug-Debian: http://bugs.debian.org/772121

diff --git a/xmlseclibs.php b/xmlseclibs.php
index 76a14e3..5fc561e 100644
--- a/vendor/robrichards/xmlseclibs/xmlseclibs.php
+++ b/vendor/robrichards/xmlseclibs/xmlseclibs.php
@@ -792,7 +792,11 @@ private function canonicalizeData($node, $canonicalmethod, $arXPath=NULL, $prefi
             }
             return C14NGeneral($node, $exclusive, $withComments);
         }
-        return $node->C14N($exclusive, $withComments, $arXPath, $prefixList);
+        $element = $node;
+        if ($node instanceof DOMNode && $node->ownerDocument !== NULL && $node->isSameNode($node->ownerDocument->documentElement)) {
+            $element = $node->ownerDocument;
+        }
+        return $element->C14N($exclusive, $withComments, $arXPath, $prefixList);
     }
 
     public function canonicalizeSignedInfo() {
