From a4ca96fb7140a58589fdf3f90a5a6bfd455edba7 Mon Sep 17 00:00:00 2001
From: Olav Morken <olav.morken@uninett.no>
Date: Tue, 3 Jun 2008 12:50:19 +0000
Subject: [PATCH] xmlseclibs: Added insertSignature function.

This function behaves like the DOM function insertBefore, and makes it
possible to insert the signature element at a specific place in the DOM tree.


git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@590 44740490-163a-0410-bde0-09ae8108e29a
---
 lib/xmlseclibs.php | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/lib/xmlseclibs.php b/lib/xmlseclibs.php
index 6892306eb..27830a543 100644
--- a/lib/xmlseclibs.php
+++ b/lib/xmlseclibs.php
@@ -1139,6 +1139,31 @@ class XMLSecurityDSig {
 	}
 	
 	
+	/**
+	 * This function inserts the signature element.
+	 *
+	 * The signature element will be appended to the element, unless $beforeNode is specified. If $beforeNode
+	 * is specified, the signature element will be inserted as the last element before $beforeNode.
+	 *
+	 * @param $node  The node the signature element should be inserted into.
+	 * @param $beforeNode  The node the signature element should be located before.
+	 */
+	public function insertSignature($node, $beforeNode = NULL) {
+
+		if($node instanceof DOMDocument) {
+			$node = $node->firstChild;
+		}
+
+		$document = $node->ownerDocument;
+		$signatureElement = $document->importNode($this->sigNode, TRUE);
+
+		if($beforeNode == NULL) {
+			$node->insertBefore($signatureElement);
+		} else {
+			$node->insertBefore($signatureElement, $beforeNode);
+		}
+	}
+
 
 	public function appendSignature($parentNode, $insertBefore = false, $assertion = false) {
 		$baseDoc = ($parentNode instanceof DOMDocument)?$parentNode:$parentNode->ownerDocument;
-- 
GitLab