1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\XMLSecurity\XML\ds; |
6
|
|
|
|
7
|
|
|
use DOMElement; |
8
|
|
|
use SimpleSAML\Assert\Assert; |
9
|
|
|
use SimpleSAML\XMLSchema\Exception\{ |
10
|
|
|
InvalidDOMElementException, |
11
|
|
|
MissingElementException, |
12
|
|
|
SchemaViolationException, |
13
|
|
|
TooManyElementsException, |
14
|
|
|
}; |
15
|
|
|
use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait}; |
16
|
|
|
|
17
|
|
|
use function array_pop; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* A class implementing the ds:AbstractDSAKeyValueType element. |
21
|
|
|
* |
22
|
|
|
* @package simplesamlphp/xml-security |
23
|
|
|
*/ |
24
|
|
|
abstract class AbstractDSAKeyValueType extends AbstractDsElement implements SchemaValidatableElementInterface |
25
|
|
|
{ |
26
|
|
|
use SchemaValidatableElementTrait; |
|
|
|
|
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* DSAKeyValueType constructor. |
30
|
|
|
* |
31
|
|
|
* @param \SimpleSAML\XMLSecurity\XML\ds\Y $y |
32
|
|
|
* @param \SimpleSAML\XMLSecurity\XML\ds\G|null $g |
33
|
|
|
* @param \SimpleSAML\XMLSecurity\XML\ds\J|null $j |
34
|
|
|
* @param \SimpleSAML\XMLSecurity\XML\ds\P|null $p |
35
|
|
|
* @param \SimpleSAML\XMLSecurity\XML\ds\Q|null $q |
36
|
|
|
* @param \SimpleSAML\XMLSecurity\XML\ds\Seed|null $seed |
37
|
|
|
* @param \SimpleSAML\XMLSecurity\XML\ds\PgenCounter|null $pgenCounter |
38
|
|
|
*/ |
39
|
|
|
final public function __construct( |
40
|
|
|
protected Y $y, |
41
|
|
|
protected ?G $g = null, |
42
|
|
|
protected ?J $j = null, |
43
|
|
|
protected ?P $p = null, |
44
|
|
|
protected ?Q $q = null, |
45
|
|
|
protected ?Seed $seed = null, |
46
|
|
|
protected ?PgenCounter $pgenCounter = null, |
47
|
|
|
) { |
48
|
|
|
if ($p !== null || $q !== null) { |
49
|
|
|
Assert::allNotNull([$p, $q], SchemaViolationException::class); |
50
|
|
|
} else { |
51
|
|
|
Assert::allNull([$p, $q], SchemaViolationException::class); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
if ($seed !== null || $pgenCounter !== null) { |
55
|
|
|
Assert::allNotNull([$seed, $pgenCounter], SchemaViolationException::class); |
56
|
|
|
} else { |
57
|
|
|
Assert::allNull([$seed, $pgenCounter], SchemaViolationException::class); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Get the Y. |
64
|
|
|
* |
65
|
|
|
* @return \SimpleSAML\XMLSecurity\XML\ds\Y |
66
|
|
|
*/ |
67
|
|
|
public function getY(): Y |
68
|
|
|
{ |
69
|
|
|
return $this->y; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Get the G. |
75
|
|
|
* |
76
|
|
|
* @return \SimpleSAML\XMLSecurity\XML\ds\G|null |
77
|
|
|
*/ |
78
|
|
|
public function getG(): ?G |
79
|
|
|
{ |
80
|
|
|
return $this->g; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Get the J. |
86
|
|
|
* |
87
|
|
|
* @return \SimpleSAML\XMLSecurity\XML\ds\J|null |
88
|
|
|
*/ |
89
|
|
|
public function getJ(): ?J |
90
|
|
|
{ |
91
|
|
|
return $this->j; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Get the P. |
97
|
|
|
* |
98
|
|
|
* @return \SimpleSAML\XMLSecurity\XML\ds\P|null |
99
|
|
|
*/ |
100
|
|
|
public function getP(): ?P |
101
|
|
|
{ |
102
|
|
|
return $this->p; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Get the Q. |
108
|
|
|
* |
109
|
|
|
* @return \SimpleSAML\XMLSecurity\XML\ds\Q|null |
110
|
|
|
*/ |
111
|
|
|
public function getQ(): ?Q |
112
|
|
|
{ |
113
|
|
|
return $this->q; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Get the Seed. |
119
|
|
|
* |
120
|
|
|
* @return \SimpleSAML\XMLSecurity\XML\ds\Seed|null |
121
|
|
|
*/ |
122
|
|
|
public function getSeed(): ?Seed |
123
|
|
|
{ |
124
|
|
|
return $this->seed; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Get the PgenCounter. |
130
|
|
|
* |
131
|
|
|
* @return \SimpleSAML\XMLSecurity\XML\ds\PgenCounter|null |
132
|
|
|
*/ |
133
|
|
|
public function getPgenCounter(): ?PgenCounter |
134
|
|
|
{ |
135
|
|
|
return $this->pgenCounter; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Initialize an DSAKeyValue object from an existing XML. |
141
|
|
|
* |
142
|
|
|
* @param \DOMElement $xml |
143
|
|
|
* @return static |
144
|
|
|
* |
145
|
|
|
* @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException |
146
|
|
|
* if the qualified name of the supplied element is wrong |
147
|
|
|
* @throws \SimpleSAML\XMLSchema\Exception\MissingAttributeException |
148
|
|
|
* if the supplied element is missing one of the mandatory attributes |
149
|
|
|
* @throws \SimpleSAML\XMLSchema\Exception\TooManyElementsException |
150
|
|
|
* if too many child-elements of a type are specified |
151
|
|
|
*/ |
152
|
|
|
public static function fromXML(DOMElement $xml): static |
153
|
|
|
{ |
154
|
|
|
Assert::same($xml->localName, 'DSAKeyValue', InvalidDOMElementException::class); |
155
|
|
|
Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); |
156
|
|
|
|
157
|
|
|
$y = Y::getChildrenOfClass($xml); |
158
|
|
|
Assert::minCount($y, 1, MissingElementException::class); |
159
|
|
|
Assert::maxCount($y, 1, TooManyElementsException::class); |
160
|
|
|
|
161
|
|
|
$g = G::getChildrenOfClass($xml); |
162
|
|
|
Assert::maxCount($g, 1, TooManyElementsException::class); |
163
|
|
|
|
164
|
|
|
$j = J::getChildrenOfClass($xml); |
165
|
|
|
Assert::maxCount($j, 1, TooManyElementsException::class); |
166
|
|
|
|
167
|
|
|
$p = P::getChildrenOfClass($xml); |
168
|
|
|
Assert::maxCount($p, 1, TooManyElementsException::class); |
169
|
|
|
|
170
|
|
|
$q = Q::getChildrenOfClass($xml); |
171
|
|
|
Assert::maxCount($q, 1, TooManyElementsException::class); |
172
|
|
|
|
173
|
|
|
$seed = Seed::getChildrenOfClass($xml); |
174
|
|
|
Assert::maxCount($seed, 1, TooManyElementsException::class); |
175
|
|
|
|
176
|
|
|
$pgenCounter = PgenCounter::getChildrenOfClass($xml); |
177
|
|
|
Assert::maxCount($pgenCounter, 1, TooManyElementsException::class); |
178
|
|
|
|
179
|
|
|
return new static( |
180
|
|
|
array_pop($y), |
181
|
|
|
array_pop($g), |
182
|
|
|
array_pop($j), |
183
|
|
|
array_pop($p), |
184
|
|
|
array_pop($q), |
185
|
|
|
array_pop($seed), |
186
|
|
|
array_pop($pgenCounter), |
187
|
|
|
); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* Convert this DSAKeyValue object to XML. |
193
|
|
|
* |
194
|
|
|
* @param \DOMElement|null $parent The element we should append this DSAKeyValue to. |
195
|
|
|
* @return \DOMElement |
196
|
|
|
*/ |
197
|
|
|
public function toXML(?DOMElement $parent = null): DOMElement |
198
|
|
|
{ |
199
|
|
|
$e = $this->instantiateParentElement($parent); |
200
|
|
|
|
201
|
|
|
$this->getP()?->toXML($e); |
202
|
|
|
$this->getQ()?->toXML($e); |
203
|
|
|
$this->getG()?->toXML($e); |
204
|
|
|
$this->getY()->toXML($e); |
205
|
|
|
$this->getJ()?->toXML($e); |
206
|
|
|
$this->getSeed()?->toXML($e); |
207
|
|
|
$this->getPgenCounter()?->toXML($e); |
208
|
|
|
|
209
|
|
|
return $e; |
210
|
|
|
} |
211
|
|
|
} |
212
|
|
|
|