1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\XMLSecurity\XML\xenc11; |
6
|
|
|
|
7
|
|
|
use DOMElement; |
8
|
|
|
use SimpleSAML\XML\Exception\InvalidDOMElementException; |
9
|
|
|
use SimpleSAML\XML\Exception\MissingElementException; |
10
|
|
|
use SimpleSAML\XML\Exception\SchemaViolationException; |
11
|
|
|
use SimpleSAML\XML\Exception\TooManyElementsException; |
12
|
|
|
use SimpleSAML\XML\SchemaValidatableElementInterface; |
13
|
|
|
use SimpleSAML\XML\SchemaValidatableElementTrait; |
14
|
|
|
use SimpleSAML\XMLSecurity\Assert\Assert; |
15
|
|
|
use SimpleSAML\XMLSecurity\XML\ds\DigestMethod; |
16
|
|
|
|
17
|
|
|
use function array_pop; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class representing <xenc11:ConcatKDFParamsType>. |
21
|
|
|
* |
22
|
|
|
* @package simplesamlphp/xml-security |
23
|
|
|
*/ |
24
|
|
|
abstract class AbstractConcatKDFParamsType extends AbstractXenc11Element implements |
25
|
|
|
SchemaValidatableElementInterface |
26
|
|
|
{ |
27
|
|
|
use SchemaValidatableElementTrait; |
|
|
|
|
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* ConcatKDFParams constructor. |
31
|
|
|
* |
32
|
|
|
* @param \SimpleSAML\XMLSecurity\XML\ds\DigestMethod $digestMethod |
33
|
|
|
* @param string|null $AlgorithmID |
34
|
|
|
* @param string|null $PartyUInfo |
35
|
|
|
* @param string|null $PartyVInfo |
36
|
|
|
* @param string|null $SuppPubInfo |
37
|
|
|
* @param string|null $SuppPrivInfo |
38
|
|
|
*/ |
39
|
|
|
final public function __construct( |
40
|
|
|
protected DigestMethod $digestMethod, |
41
|
|
|
protected ?string $AlgorithmID = null, |
42
|
|
|
protected ?string $PartyUInfo = null, |
43
|
|
|
protected ?string $PartyVInfo = null, |
44
|
|
|
protected ?string $SuppPubInfo = null, |
45
|
|
|
protected ?string $SuppPrivInfo = null, |
46
|
|
|
) { |
47
|
|
|
Assert::validHexBinary($AlgorithmID, SchemaViolationException::class); |
48
|
|
|
Assert::validHexBinary($PartyUInfo, SchemaViolationException::class); |
49
|
|
|
Assert::validHexBinary($PartyVInfo, SchemaViolationException::class); |
50
|
|
|
Assert::validHexBinary($SuppPubInfo, SchemaViolationException::class); |
51
|
|
|
Assert::validHexBinary($SuppPrivInfo, SchemaViolationException::class); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Get the value of the $digestMethod property. |
57
|
|
|
* |
58
|
|
|
* @return \SimpleSAML\XMLSecurity\XML\ds\DigestMethod |
59
|
|
|
*/ |
60
|
|
|
public function getDigestMethod(): DigestMethod |
61
|
|
|
{ |
62
|
|
|
return $this->digestMethod; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Get the value of the $AlgorithmID property. |
68
|
|
|
* |
69
|
|
|
* @return string|null |
70
|
|
|
*/ |
71
|
|
|
public function getAlgorithmID(): ?string |
72
|
|
|
{ |
73
|
|
|
return $this->AlgorithmID; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Get the value of the $PartyUInfo property. |
79
|
|
|
* |
80
|
|
|
* @return string|null |
81
|
|
|
*/ |
82
|
|
|
public function getPartyUInfo(): ?string |
83
|
|
|
{ |
84
|
|
|
return $this->PartyUInfo; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Get the value of the $PartyVInfo property. |
90
|
|
|
* |
91
|
|
|
* @return string|null |
92
|
|
|
*/ |
93
|
|
|
public function getPartyVInfo(): ?string |
94
|
|
|
{ |
95
|
|
|
return $this->PartyVInfo; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Get the value of the $SuppPubInfo property. |
101
|
|
|
* |
102
|
|
|
* @return string|null |
103
|
|
|
*/ |
104
|
|
|
public function getSuppPubInfo(): ?string |
105
|
|
|
{ |
106
|
|
|
return $this->SuppPubInfo; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Get the value of the $SuppPrivInfo property. |
112
|
|
|
* |
113
|
|
|
* @return string|null |
114
|
|
|
*/ |
115
|
|
|
public function getSuppPrivInfo(): ?string |
116
|
|
|
{ |
117
|
|
|
return $this->SuppPrivInfo; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @inheritDoc |
123
|
|
|
* |
124
|
|
|
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException |
125
|
|
|
* If the qualified name of the supplied element is wrong |
126
|
|
|
*/ |
127
|
|
|
public static function fromXML(DOMElement $xml): static |
128
|
|
|
{ |
129
|
|
|
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); |
130
|
|
|
Assert::same($xml->namespaceURI, static::getNamespaceURI(), InvalidDOMElementException::class); |
131
|
|
|
|
132
|
|
|
$digestMethod = DigestMethod::getChildrenOfClass($xml); |
133
|
|
|
Assert::minCount($digestMethod, 1, MissingElementException::class); |
134
|
|
|
Assert::maxCount($digestMethod, 1, TooManyElementsException::class); |
135
|
|
|
|
136
|
|
|
return new static( |
137
|
|
|
array_pop($digestMethod), |
138
|
|
|
self::getOptionalAttribute($xml, 'AlgorithmID', null), |
139
|
|
|
self::getOptionalAttribute($xml, 'PartyUInfo', null), |
140
|
|
|
self::getOptionalAttribute($xml, 'PartyVInfo', null), |
141
|
|
|
self::getOptionalAttribute($xml, 'SuppPubInfo', null), |
142
|
|
|
self::getOptionalAttribute($xml, 'SuppPrivInfo', null), |
143
|
|
|
); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @inheritDoc |
149
|
|
|
*/ |
150
|
|
|
public function toXML(?DOMElement $parent = null): DOMElement |
151
|
|
|
{ |
152
|
|
|
$e = $this->instantiateParentElement($parent); |
153
|
|
|
|
154
|
|
|
if ($this->getAlgorithmID() !== null) { |
155
|
|
|
$e->setAttribute('AlgorithmID', $this->getAlgorithmID()); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
if ($this->getPartyUInfo() !== null) { |
159
|
|
|
$e->setAttribute('PartyUInfo', $this->getPartyUInfo()); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
if ($this->getPartyVInfo() !== null) { |
163
|
|
|
$e->setAttribute('PartyVInfo', $this->getPartyVInfo()); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
if ($this->getSuppPubInfo() !== null) { |
167
|
|
|
$e->setAttribute('SuppPubInfo', $this->getSuppPubInfo()); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
if ($this->getSuppPrivInfo() !== null) { |
171
|
|
|
$e->setAttribute('SuppPrivInfo', $this->getSuppPrivInfo()); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
$this->getDigestMethod()->toXML($e); |
175
|
|
|
|
176
|
|
|
return $e; |
177
|
|
|
} |
178
|
|
|
} |
179
|
|
|
|