1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\XMLSecurity\XML\ds; |
6
|
|
|
|
7
|
|
|
use DOMElement; |
8
|
|
|
use SimpleSAML\XML\Constants as C; |
9
|
|
|
use SimpleSAML\XML\Exception\InvalidDOMElementException; |
10
|
|
|
use SimpleSAML\XML\Exception\MissingElementException; |
11
|
|
|
use SimpleSAML\XML\Exception\SchemaViolationException; |
12
|
|
|
use SimpleSAML\XML\SchemaValidatableElementInterface; |
13
|
|
|
use SimpleSAML\XML\SchemaValidatableElementTrait; |
14
|
|
|
use SimpleSAML\XMLSecurity\Assert\Assert; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class representing a ds:SignatureProperties element. |
18
|
|
|
* |
19
|
|
|
* @package simplesamlphp/xml-security |
20
|
|
|
*/ |
21
|
|
|
final class SignatureProperties extends AbstractDsElement implements SchemaValidatableElementInterface |
22
|
|
|
{ |
23
|
|
|
use SchemaValidatableElementTrait; |
|
|
|
|
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Initialize a ds:SignatureProperties |
27
|
|
|
* |
28
|
|
|
* @param \SimpleSAML\XMLSecurity\XML\ds\SignatureProperty[] $signatureProperty |
29
|
|
|
* @param string|null $Id |
30
|
|
|
*/ |
31
|
|
|
public function __construct( |
32
|
|
|
protected array $signatureProperty, |
33
|
|
|
protected ?string $Id = null, |
34
|
|
|
) { |
35
|
|
|
Assert::maxCount($signatureProperty, C::UNBOUNDED_LIMIT); |
36
|
|
|
Assert::allIsInstanceOf($signatureProperty, SignatureProperty::class, SchemaViolationException::class); |
37
|
|
|
Assert::nullOrValidNCName($Id); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @return \SimpleSAML\XMLSecurity\XML\ds\SignatureProperty[] |
43
|
|
|
*/ |
44
|
|
|
public function getSignatureProperty(): array |
45
|
|
|
{ |
46
|
|
|
return $this->signatureProperty; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @return string|null |
52
|
|
|
*/ |
53
|
|
|
public function getId(): ?string |
54
|
|
|
{ |
55
|
|
|
return $this->Id; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Convert XML into a SignatureProperties element |
61
|
|
|
* |
62
|
|
|
* @param \DOMElement $xml The XML element we should load |
63
|
|
|
* @return static |
64
|
|
|
* |
65
|
|
|
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException |
66
|
|
|
* If the qualified name of the supplied element is wrong |
67
|
|
|
*/ |
68
|
|
|
public static function fromXML(DOMElement $xml): static |
69
|
|
|
{ |
70
|
|
|
Assert::same($xml->localName, 'SignatureProperties', InvalidDOMElementException::class); |
71
|
|
|
Assert::same($xml->namespaceURI, SignatureProperties::NS, InvalidDOMElementException::class); |
72
|
|
|
|
73
|
|
|
$signatureProperty = SignatureProperty::getChildrenOfClass($xml); |
74
|
|
|
$Id = self::getOptionalAttribute($xml, 'Id', null); |
75
|
|
|
|
76
|
|
|
Assert::minCount( |
77
|
|
|
$signatureProperty, |
78
|
|
|
1, |
79
|
|
|
'A <ds:SignatureProperties> must contain at least one <ds:SignatureProperty>.', |
80
|
|
|
MissingElementException::class, |
81
|
|
|
); |
82
|
|
|
|
83
|
|
|
return new static( |
84
|
|
|
$signatureProperty, |
85
|
|
|
$Id, |
86
|
|
|
); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Convert this SignatureProperties element to XML. |
92
|
|
|
* |
93
|
|
|
* @param \DOMElement|null $parent The element we should append this SignatureProperties element to. |
94
|
|
|
* @return \DOMElement |
95
|
|
|
*/ |
96
|
|
|
public function toXML(?DOMElement $parent = null): DOMElement |
97
|
|
|
{ |
98
|
|
|
$e = $this->instantiateParentElement($parent); |
99
|
|
|
|
100
|
|
|
if ($this->getId() !== null) { |
101
|
|
|
$e->setAttribute('Id', $this->getId()); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
foreach ($this->getSignatureProperty() as $signatureProperty) { |
105
|
|
|
$signatureProperty->toXML($e); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
return $e; |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|