|
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\XML\Exception\InvalidDOMElementException; |
|
10
|
|
|
use SimpleSAML\XML\Exception\SchemaViolationException; |
|
11
|
|
|
use SimpleSAML\XMLSecurity\Constants as C; |
|
12
|
|
|
use SimpleSAML\XMLSecurity\Exception\InvalidArgumentException; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Class representing a ds:KeyInfoReference element. |
|
16
|
|
|
* |
|
17
|
|
|
* @package simplesamlphp/xml-security |
|
18
|
|
|
*/ |
|
19
|
|
|
final class KeyInfoReference extends AbstractDsElement |
|
20
|
|
|
{ |
|
21
|
|
|
/** @var string $URI */ |
|
22
|
|
|
protected string $URI; |
|
23
|
|
|
|
|
24
|
|
|
/** @var string|null $Id */ |
|
25
|
|
|
protected ?string $Id = null; |
|
26
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Initialize a KeyInfoReference element. |
|
30
|
|
|
* |
|
31
|
|
|
* @param string $URI |
|
32
|
|
|
* @param string|null $Id |
|
33
|
|
|
*/ |
|
34
|
|
|
public function __construct(string $URI, ?string $Id = null) |
|
35
|
|
|
{ |
|
36
|
|
|
$this->setURI($URI); |
|
37
|
|
|
$this->setId($Id); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Collect the value of the URI-property |
|
43
|
|
|
* |
|
44
|
|
|
* @return string |
|
45
|
|
|
*/ |
|
46
|
|
|
public function getURI(): string |
|
47
|
|
|
{ |
|
48
|
|
|
return $this->URI; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Set the value of the URI-property |
|
54
|
|
|
* |
|
55
|
|
|
* @param string $URI |
|
56
|
|
|
*/ |
|
57
|
|
|
private function setURI(string $URI): void |
|
58
|
|
|
{ |
|
59
|
|
|
Assert::validURI($URI, SchemaViolationException::class); |
|
60
|
|
|
$this->URI = $URI; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Collect the value of the Id-property |
|
66
|
|
|
* |
|
67
|
|
|
* @return string|null |
|
68
|
|
|
*/ |
|
69
|
|
|
public function getId(): ?string |
|
70
|
|
|
{ |
|
71
|
|
|
return $this->Id; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Set the value of the Id-property |
|
77
|
|
|
* |
|
78
|
|
|
* @param string $Id |
|
79
|
|
|
*/ |
|
80
|
|
|
private function setId(?string $Id): void |
|
81
|
|
|
{ |
|
82
|
|
|
$this->Id = $Id; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Convert XML into a KeyInfoReference |
|
88
|
|
|
* |
|
89
|
|
|
* @param \DOMElement $xml The XML element we should load |
|
90
|
|
|
* @return self |
|
91
|
|
|
* |
|
92
|
|
|
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException |
|
93
|
|
|
* If the qualified name of the supplied element is wrong |
|
94
|
|
|
*/ |
|
95
|
|
|
public static function fromXML(DOMElement $xml): self |
|
96
|
|
|
{ |
|
97
|
|
|
Assert::same($xml->localName, 'KeyInfoReference', InvalidDOMElementException::class); |
|
98
|
|
|
Assert::same($xml->namespaceURI, KeyInfoReference::NS, InvalidDOMElementException::class); |
|
99
|
|
|
|
|
100
|
|
|
/** @psalm-var string $URI */ |
|
101
|
|
|
$URI = KeyInfoReference::getAttribute($xml, 'URI'); |
|
102
|
|
|
$Id = KeyInfoReference::getAttribute($xml, 'Id', null); |
|
103
|
|
|
|
|
104
|
|
|
return new self($URI, $Id); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* Convert this KeyInfoReference element to XML. |
|
110
|
|
|
* |
|
111
|
|
|
* @param \DOMElement|null $parent The element we should append this KeyInfoReference element to. |
|
112
|
|
|
* @return \DOMElement |
|
113
|
|
|
*/ |
|
114
|
|
|
public function toXML(DOMElement $parent = null): DOMElement |
|
115
|
|
|
{ |
|
116
|
|
|
$e = $this->instantiateParentElement($parent); |
|
117
|
|
|
$e->setAttribute('URI', $this->URI); |
|
118
|
|
|
|
|
119
|
|
|
if ($this->Id !== null) { |
|
120
|
|
|
$e->setAttribute('Id', $this->Id); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
return $e; |
|
124
|
|
|
} |
|
125
|
|
|
} |
|
126
|
|
|
|