1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\XMLSecurity\XML\dsig11; |
6
|
|
|
|
7
|
|
|
use DOMElement; |
8
|
|
|
use SimpleSAML\XML\Exception\InvalidDOMElementException; |
9
|
|
|
use SimpleSAML\XML\Exception\SchemaViolationException; |
10
|
|
|
use SimpleSAML\XML\SchemaValidatableElementInterface; |
11
|
|
|
use SimpleSAML\XML\SchemaValidatableElementTrait; |
12
|
|
|
use SimpleSAML\XMLSecurity\Assert\Assert; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class representing a dsig11:KeyInfoReference element. |
16
|
|
|
* |
17
|
|
|
* @package simplesamlphp/xml-security |
18
|
|
|
*/ |
19
|
|
|
final class KeyInfoReference extends AbstractDsig11Element implements SchemaValidatableElementInterface |
20
|
|
|
{ |
21
|
|
|
use SchemaValidatableElementTrait; |
|
|
|
|
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Initialize a KeyInfoReference element. |
25
|
|
|
* |
26
|
|
|
* @param string $URI |
27
|
|
|
* @param string|null $Id |
28
|
|
|
*/ |
29
|
|
|
public function __construct( |
30
|
|
|
protected string $URI, |
31
|
|
|
protected ?string $Id = null, |
32
|
|
|
) { |
33
|
|
|
Assert::validURI($URI, SchemaViolationException::class); |
34
|
|
|
Assert::nullOrValidNCName($Id); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Collect the value of the URI-property |
40
|
|
|
* |
41
|
|
|
* @return string |
42
|
|
|
*/ |
43
|
|
|
public function getURI(): string |
44
|
|
|
{ |
45
|
|
|
return $this->URI; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Collect the value of the Id-property |
51
|
|
|
* |
52
|
|
|
* @return string|null |
53
|
|
|
*/ |
54
|
|
|
public function getId(): ?string |
55
|
|
|
{ |
56
|
|
|
return $this->Id; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Convert XML into a KeyInfoReference |
62
|
|
|
* |
63
|
|
|
* @param \DOMElement $xml The XML element we should load |
64
|
|
|
* @return static |
65
|
|
|
* |
66
|
|
|
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException |
67
|
|
|
* If the qualified name of the supplied element is wrong |
68
|
|
|
*/ |
69
|
|
|
public static function fromXML(DOMElement $xml): static |
70
|
|
|
{ |
71
|
|
|
Assert::same($xml->localName, 'KeyInfoReference', InvalidDOMElementException::class); |
72
|
|
|
Assert::same($xml->namespaceURI, KeyInfoReference::NS, InvalidDOMElementException::class); |
73
|
|
|
|
74
|
|
|
$URI = KeyInfoReference::getAttribute($xml, 'URI'); |
75
|
|
|
$Id = KeyInfoReference::getOptionalAttribute($xml, 'Id', null); |
76
|
|
|
|
77
|
|
|
return new static($URI, $Id); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Convert this KeyInfoReference element to XML. |
83
|
|
|
* |
84
|
|
|
* @param \DOMElement|null $parent The element we should append this KeyInfoReference element to. |
85
|
|
|
* @return \DOMElement |
86
|
|
|
*/ |
87
|
|
|
public function toXML(?DOMElement $parent = null): DOMElement |
88
|
|
|
{ |
89
|
|
|
$e = $this->instantiateParentElement($parent); |
90
|
|
|
$e->setAttribute('URI', $this->getURI()); |
91
|
|
|
|
92
|
|
|
if ($this->getId() !== null) { |
93
|
|
|
$e->setAttribute('Id', $this->getId()); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
return $e; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|