1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SAML2\XML\xenc; |
6
|
|
|
|
7
|
|
|
use DOMElement; |
8
|
|
|
use Webmozart\Assert\Assert; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* A class containing a list of references to either encrypted data or encryption keys. |
12
|
|
|
* |
13
|
|
|
* @package simplesamlphp/saml2 |
14
|
|
|
*/ |
15
|
|
|
class ReferenceList extends AbstractXencElement |
16
|
|
|
{ |
17
|
|
|
/** @var \SAML2\XML\xenc\DataReference[] */ |
18
|
|
|
protected $dataReferences; |
19
|
|
|
|
20
|
|
|
/** @var \SAML2\XML\xenc\KeyReference[] */ |
21
|
|
|
protected $keyreferences; |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* ReferenceList constructor. |
26
|
|
|
* |
27
|
|
|
* @param \SAML2\XML\xenc\DataReference[] $dataReferences |
28
|
|
|
* @param \SAML2\XML\xenc\KeyReference[] $keyreferences |
29
|
|
|
*/ |
30
|
|
|
public function __construct(array $dataReferences, array $keyreferences = []) |
31
|
|
|
{ |
32
|
|
|
$this->setDataReferences($dataReferences); |
33
|
|
|
$this->setKeyReferences($keyreferences); |
34
|
|
|
Assert::minCount( |
35
|
|
|
array_merge($this->dataReferences, $this->keyreferences), |
36
|
|
|
1, |
37
|
|
|
'At least one <xenc:DataReference> or <xenc:KeyReference> element required in <xenc:ReferenceList>.' |
38
|
|
|
); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Get the list of DataReference objects. |
44
|
|
|
* |
45
|
|
|
* @return \SAML2\XML\xenc\DataReference[] |
46
|
|
|
*/ |
47
|
|
|
public function getDataReferences(): array |
48
|
|
|
{ |
49
|
|
|
return $this->dataReferences; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param \SAML2\XML\xenc\DataReference[] $dataReferences |
55
|
|
|
*/ |
56
|
|
|
protected function setDataReferences(array $dataReferences): void |
57
|
|
|
{ |
58
|
|
|
Assert::allIsInstanceOf( |
59
|
|
|
$dataReferences, |
60
|
|
|
DataReference::class, |
61
|
|
|
'All data references must be an instance of <xenc:DataReference>.' |
62
|
|
|
); |
63
|
|
|
$this->dataReferences = $dataReferences; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Get the list of KeyReference objects. |
69
|
|
|
* |
70
|
|
|
* @return \SAML2\XML\xenc\KeyReference[] |
71
|
|
|
*/ |
72
|
|
|
public function getKeyReferences(): array |
73
|
|
|
{ |
74
|
|
|
return $this->keyreferences; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param \SAML2\XML\xenc\KeyReference[] $keyReferences |
80
|
|
|
*/ |
81
|
|
|
protected function setKeyReferences(array $keyReferences): void |
82
|
|
|
{ |
83
|
|
|
Assert::allIsInstanceOf( |
84
|
|
|
$keyReferences, |
85
|
|
|
KeyReference::class, |
86
|
|
|
'All key references must be an instance of <xenc:KeyReference>.' |
87
|
|
|
); |
88
|
|
|
$this->keyreferences = $keyReferences; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @inheritDoc |
93
|
|
|
*/ |
94
|
|
|
public static function fromXML(DOMElement $xml): object |
95
|
|
|
{ |
96
|
|
|
Assert::same($xml->localName, 'ReferenceList'); |
97
|
|
|
Assert::same($xml->namespaceURI, ReferenceList::NS); |
98
|
|
|
|
99
|
|
|
$dataReferences = DataReference::getChildrenOfClass($xml); |
100
|
|
|
$keyReferences = KeyReference::getChildrenOfClass($xml); |
101
|
|
|
|
102
|
|
|
return new self($dataReferences, $keyReferences); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @inheritDoc |
108
|
|
|
*/ |
109
|
|
|
public function toXML(DOMElement $parent = null): DOMElement |
110
|
|
|
{ |
111
|
|
|
$e = $this->instantiateParentElement($parent); |
112
|
|
|
|
113
|
|
|
foreach ($this->dataReferences as $dref) { |
114
|
|
|
$dref->toXML($e); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
foreach ($this->keyreferences as $kref) { |
118
|
|
|
$kref->toXML($e); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
return $e; |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|