blob: aeaffe9a53cc424fd19c24cf475f6fa9c010a39d (
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
<?php
/**
* Class representing a KeyDescriptor element.
*
* @package simpleSAMLphp
* @version $Id$
*/
class SAML2_XML_md_KeyDescriptor {
/**
* What this key can be used for.
*
* 'encryption', 'signing' or NULL.
*
* @var string|NULL
*/
public $use;
/**
* The KeyInfo for this key.
*
* @var SAML2_XML_ds_KeyInfo
*/
public $KeyInfo;
/**
* Supported EncryptionMethods.
*
* Array of SAML2_XML_Chunk objects.
*
* @var array
*/
public $EncryptionMethod = array();
/**
* Initialize an KeyDescriptor.
*
* @param DOMElement|NULL $xml The XML element we should load.
*/
public function __construct(DOMElement $xml = NULL) {
if ($xml === NULL) {
return;
}
if ($xml->hasAttribute('use')) {
$this->use = $xml->getAttribute('use');
}
$keyInfo = SAML2_Utils::xpQuery($xml, './ds:KeyInfo');
if (count($keyInfo) > 1) {
throw new Exception('More than one ds:KeyInfo in the KeyDescriptor.');
} elseif (empty($keyInfo)) {
throw new Exception('No ds:KeyInfo in the KeyDescriptor.');
}
$this->KeyInfo = new SAML2_XML_ds_KeyInfo($keyInfo[0]);
foreach (SAML2_Utils::xpQuery($xml, './saml_metadata:EncryptionMethod') as $em) {
$this->EncryptionMethod[] = new SAML2_XML_Chunk($em);
}
}
/**
* Convert this KeyDescriptor to XML.
*
* @param DOMElement $parent The element we should append this KeyDescriptor to.
*/
public function toXML(DOMElement $parent) {
assert('is_null($this->use) || is_string($this->use)');
assert('$this->KeyInfo instanceof SAML2_XML_ds_KeyInfo');
assert('is_array($this->EncryptionMethod)');
$doc = $parent->ownerDocument;
$e = $doc->createElementNS(SAML2_Const::NS_MD, 'md:KeyDescriptor');
$parent->appendChild($e);
if (isset($this->use)) {
$e->setAttribute('use', $this->use);
}
$this->KeyInfo->toXML($e);
foreach ($this->EncryptionMethod as $em) {
$em->toXML($e);
}
return $e;
}
}
|