From 7b67eace065cba74e4f0d9ca6207d7c78b1f5187 Mon Sep 17 00:00:00 2001
From: Olav Morken <olav.morken@uninett.no>
Date: Tue, 22 Jan 2008 14:56:37 +0000
Subject: [PATCH] Added getValidatedNodes() function to XMLSecurityDSig class.

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

diff --git a/lib/xmlseclibs.php b/lib/xmlseclibs.php
index 3f192c7f7..46e6f60c3 100644
--- a/lib/xmlseclibs.php
+++ b/lib/xmlseclibs.php
@@ -569,6 +569,10 @@ class XMLSecurityDSig {
     private $prefix = 'ds';
     private $searchpfx = 'secdsig';
 
+
+    /* This variable contains an associative array of validated nodes. */
+    private $validatedNodes = NULL;
+
     public function __construct() {
         $sigdoc = new DOMDocument();
         $sigdoc->loadXML(XMLSecurityDSig::template);
@@ -823,7 +827,20 @@ class XMLSecurityDSig {
             $dataObject = $refNode->ownerDocument;
         }
         $data = $this->processTransforms($refNode, $dataObject);
-        return $this->validateDigest($refNode, $data);
+        if (!$this->validateDigest($refNode, $data)) {
+            return FALSE;
+        }
+
+        if ($dataObject instanceof DOMNode) {
+            /* Add this node to the list of validated nodes. */
+            if($identifier) {
+                $this->validatedNodes[$identifier] = $dataObject;
+            } else {
+                $this->validatedNodes[] = $dataObject;
+            }
+        }
+
+        return TRUE;
     }
 
     public function getRefNodeID($refNode) {
@@ -865,8 +882,15 @@ class XMLSecurityDSig {
         if ($nodeset->length == 0) {
             throw new Exception("Reference nodes not found");
         }
+
+        /* Initialize/reset the list of validated nodes. */
+        $this->validatedNodes = array();
+
         foreach ($nodeset AS $refNode) {
             if (! $this->processRefNode($refNode)) {
+                /* Clear the list of validated nodes. */
+                $this->validatedNodes = NULL;
+
                 throw new Exception("Reference validation failed");
             }
         }
@@ -1226,6 +1250,18 @@ class XMLSecurityDSig {
             self::staticAdd509Cert($this->sigNode, $cert, $isPEMFormat, $isURL, $xpath);
          }
     }
+
+    /* This function retrieves an associative array of the validated nodes.
+     *
+     * The array will contain the id of the referenced node as the key and the node itself
+     * as the value.
+     *
+     * Returns:
+     *  An associative array of validated nodes or NULL if no nodes have been validated.
+     */
+    public function getValidatedNodes() {
+        return $this->validatedNodes;
+    }
 }
 
 class XMLSecEnc {
-- 
GitLab