ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
KeyDescriptor.php
Go to the documentation of this file.
1 <?php
2 
3 namespace SAML2\XML\md;
4 
6 use SAML2\Utils;
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 }
const NS_MD
The namespace for the SAML 2 metadata.
Definition: Constants.php:230
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.