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