ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
KeyDescriptor.php
Go to the documentation of this file.
1<?php
2
3namespace SAML2\XML\md;
4
9
16{
24 public $use;
25
31 public $KeyInfo;
32
40 public $EncryptionMethod = array();
41
48 public function __construct(\DOMElement $xml = null)
49 {
50 if ($xml === null) {
51 return;
52 }
53
54 if ($xml->hasAttribute('use')) {
55 $this->use = $xml->getAttribute('use');
56 }
57
58 $keyInfo = Utils::xpQuery($xml, './ds:KeyInfo');
59 if (count($keyInfo) > 1) {
60 throw new \Exception('More than one ds:KeyInfo in the KeyDescriptor.');
61 } elseif (empty($keyInfo)) {
62 throw new \Exception('No ds:KeyInfo in the KeyDescriptor.');
63 }
64 $this->KeyInfo = new KeyInfo($keyInfo[0]);
65
66 foreach (Utils::xpQuery($xml, './saml_metadata:EncryptionMethod') as $em) {
67 $this->EncryptionMethod[] = new Chunk($em);
68 }
69 }
70
77 public function toXML(\DOMElement $parent)
78 {
79 assert(is_null($this->use) || is_string($this->use));
80 assert($this->KeyInfo instanceof KeyInfo);
81 assert(is_array($this->EncryptionMethod));
82
83 $doc = $parent->ownerDocument;
84
85 $e = $doc->createElementNS(Constants::NS_MD, 'md:KeyDescriptor');
86 $parent->appendChild($e);
87
88 if (isset($this->use)) {
89 $e->setAttribute('use', $this->use);
90 }
91
92 $this->KeyInfo->toXML($e);
93
94 foreach ($this->EncryptionMethod as $em) {
95 $em->toXML($e);
96 }
97
98 return $e;
99 }
100}
An exception for terminatinating execution or to throw for unit testing.
const NS_MD
The namespace for the SAML 2 metadata.
Definition: Constants.php:225
static xpQuery(\DOMNode $node, $query)
Do an XPath query on an XML node.
Definition: Utils.php:191
__construct(\DOMElement $xml=null)
Initialize an KeyDescriptor.
toXML(\DOMElement $parent)
Convert this KeyDescriptor to XML.
$xml
Definition: metadata.php:240