summaryrefslogtreecommitdiffstats
path: root/lib/SAML2/XML/ds/X509Data.php
blob: e6b3c066f59461fb335cd337ee87a08ae19c364c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php

/**
 * Class representing a ds:X509Data element.
 *
 * @package simpleSAMLphp
 * @version $Id$
 */
class SAML2_XML_ds_X509Data {

	/**
	 * The various X509 data elements.
	 *
	 * Array with various elements describing this certificate.
	 * Unknown elements will be represented by SAML2_XML_Chunk.
	 *
	 * @var array
	 */
	public $data = array();


	/**
	 * Initialize a X509Data.
	 *
	 * @param DOMElement|NULL $xml  The XML element we should load.
	 */
	public function __construct(DOMElement $xml = NULL) {

		if ($xml === NULL) {
			return;
		}

		for ($n = $xml->firstChild; $n !== NULL; $n = $n->nextSibling) {
			if (!($n instanceof DOMElement)) {
				continue;
			}

			if ($n->namespaceURI !== XMLSecurityDSig::XMLDSIGNS) {
				$this->data[] = new SAML2_XML_Chunk($n);
				continue;
			}
			switch ($n->localName) {
			case 'X509Certificate':
				$this->data[] = new SAML2_XML_ds_X509Certificate($n);
				break;
			default:
				$this->data[] = new SAML2_XML_Chunk($n);
				break;
			}
		}
	}


	/**
	 * Convert this X509Data element to XML.
	 *
	 * @param DOMElement $parent  The element we should append this X509Data element to.
	 */
	public function toXML(DOMElement $parent) {
		assert('is_array($this->data)');

		$doc = $parent->ownerDocument;

		$e = $doc->createElementNS(XMLSecurityDSig::XMLDSIGNS, 'ds:X509Data');
		$parent->appendChild($e);

		foreach ($this->data as $n) {
			$n->toXML($e);
		}

		return $e;
	}

}