From 7f89ab9785e764d4b460711598182190ce455c3b Mon Sep 17 00:00:00 2001
From: Olav Morken <olav.morken@uninett.no>
Date: Thu, 5 Nov 2009 11:26:51 +0000
Subject: [PATCH] SAMLParser: Seperate out RoleDescriptorType parsing from
 SSODescriptor parsing.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1958 44740490-163a-0410-bde0-09ae8108e29a
---
 lib/SimpleSAML/Metadata/SAMLParser.php | 71 ++++++++++++++++----------
 1 file changed, 45 insertions(+), 26 deletions(-)

diff --git a/lib/SimpleSAML/Metadata/SAMLParser.php b/lib/SimpleSAML/Metadata/SAMLParser.php
index 986717f2d..a760c83cf 100644
--- a/lib/SimpleSAML/Metadata/SAMLParser.php
+++ b/lib/SimpleSAML/Metadata/SAMLParser.php
@@ -722,26 +722,24 @@ class SimpleSAML_Metadata_SAMLParser {
 	}
 
 
-
 	/**
-	 * This function extracts metadata from a SSODescriptor element.
+	 * Parse a RoleDescriptorType element.
 	 *
 	 * The returned associative array has the following elements:
-	 * - 'protocols': Array with the protocols this SSODescriptor supports.
-	 * - 'SingleLogoutService': Array with the single logout service endpoints. Each endpoint is stored
-	 *   as an associative array with the elements that parseGenericEndpoint returns.
-	 * - 'nameIDFormats': The NameIDFormats supported by this SSODescriptor. This may be an empty array.
-	 * - 'keys': Array of associative arrays with the elements from parseKeyDescriptor:
+	 * - 'protocols': Array with the protocols supported.
+         * - 'expire': Timestamp for when this descriptor expires.
+	 * - 'keys': Array of associative arrays with the elements from parseKeyDescriptor.
 	 *
-	 * @param $element The element we should extract metadata from.
+	 * @param DOMElement $element  The element we should extract metadata from.
 	 * @param int|NULL $expireTime  The unix timestamp for when this element should expire, or
 	 *                              NULL if unknwon.
 	 * @return Associative array with metadata we have extracted from this element.
 	 */
-	private static function parseSSODescriptor($element, $expireTime) {
-		assert('$element instanceof DOMElement');
+	private static function parseRoleDescriptorType(DOMElement $element, $expireTime) {
 		assert('is_null($expireTime) || is_int($expireTime)');
 
+		$ret = array();
+
 		if ($expireTime === NULL) {
 			/* No expiry time defined by a parent element. Check if this element defines
 			 * one.
@@ -750,17 +748,49 @@ class SimpleSAML_Metadata_SAMLParser {
 		}
 
 
-		$sd = array();
-
 		if ($expireTime !== NULL) {
 			/* We have got an expire timestamp, either from this element, or one of the
 			 * parent elements.
 			 */
-			$sd['expire'] = $expireTime;
+			$ret['expire'] = $expireTime;
 		}
 
-		$sd['protocols'] = self::getSupportedProtocols($element);
-		
+		$ret['protocols'] = self::getSupportedProtocols($element);
+
+		/* Process KeyDescriptor elements. */
+		$ret['keys'] = array();
+		$keys = SimpleSAML_Utilities::getDOMChildren($element, 'KeyDescriptor', '@md');
+		foreach($keys as $kd) {
+			$key = self::parseKeyDescriptor($kd);
+			if($key !== NULL) {
+				$ret['keys'][] = $key;
+			}
+		}
+
+		return $ret;
+	}
+
+
+	/**
+	 * This function extracts metadata from a SSODescriptor element.
+	 *
+	 * The returned associative array has the following elements:
+	 * - 'protocols': Array with the protocols this SSODescriptor supports.
+	 * - 'SingleLogoutService': Array with the single logout service endpoints. Each endpoint is stored
+	 *   as an associative array with the elements that parseGenericEndpoint returns.
+	 * - 'nameIDFormats': The NameIDFormats supported by this SSODescriptor. This may be an empty array.
+	 * - 'keys': Array of associative arrays with the elements from parseKeyDescriptor:
+	 *
+	 * @param $element The element we should extract metadata from.
+	 * @param int|NULL $expireTime  The unix timestamp for when this element should expire, or
+	 *                              NULL if unknwon.
+	 * @return Associative array with metadata we have extracted from this element.
+	 */
+	private static function parseSSODescriptor($element, $expireTime) {
+		assert('$element instanceof DOMElement');
+		assert('is_null($expireTime) || is_int($expireTime)');
+
+		$sd = self::parseRoleDescriptorType($element, $expireTime);
 
 		/* Find all SingleLogoutService elements. */
 		$sd['SingleLogoutService'] = array();
@@ -784,17 +814,6 @@ class SimpleSAML_Metadata_SAMLParser {
 			$sd['nameIDFormats'][] = self::parseNameIDFormat($nif[0]);
 		}
 
-		/* Process KeyDescriptor elements. */
-		$sd['keys'] = array();
-		$keys = SimpleSAML_Utilities::getDOMChildren($element, 'KeyDescriptor', '@md');
-		foreach($keys as $kd) {
-			$key = self::parseKeyDescriptor($kd);
-			if($key !== NULL) {
-				$sd['keys'][] = $key;
-			}
-		}
-
-
 		return $sd;
 	}
 
-- 
GitLab