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\SchemaViolationException; |
10
|
|
|
use SimpleSAML\XML\ExtendableElementTrait; |
11
|
|
|
use SimpleSAML\XML\SerializableElementInterface; |
12
|
|
|
use SimpleSAML\XML\XsNamespace as NS; |
13
|
|
|
use SimpleSAML\XMLSecurity\Constants as C; |
14
|
|
|
use SimpleSAML\XMLSecurity\Exception\InvalidArgumentException; |
15
|
|
|
use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Abstract class representing the KeyInfoType. |
19
|
|
|
* |
20
|
|
|
* @package simplesamlphp/xml-security |
21
|
|
|
*/ |
22
|
|
|
abstract class AbstractKeyInfoType extends AbstractDsElement |
23
|
|
|
{ |
24
|
|
|
use ExtendableElementTrait; |
|
|
|
|
25
|
|
|
|
26
|
|
|
/** @var \SimpleSAML\XML\XsNamespace */ |
27
|
|
|
public const XS_ANY_ELT_NAMESPACE = NS::OTHER; |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Initialize a KeyInfo element. |
32
|
|
|
* |
33
|
|
|
* @param ( |
34
|
|
|
* \SimpleSAML\XMLSecurity\XML\ds\KeyName| |
35
|
|
|
* \SimpleSAML\XMLSecurity\XML\ds\KeyValue| |
36
|
|
|
* \SimpleSAML\XMLSecurity\XML\ds\RetrievalMethod| |
37
|
|
|
* \SimpleSAML\XMLSecurity\XML\ds\X509Data| |
38
|
|
|
* \SimpleSAML\XML\SerializableElementInterface |
39
|
|
|
* )[] $info |
40
|
|
|
* @param string|null $Id |
41
|
|
|
*/ |
42
|
|
|
final public function __construct( |
43
|
|
|
protected array $info, |
44
|
|
|
protected ?string $Id = null, |
45
|
|
|
) { |
46
|
|
|
Assert::notEmpty( |
47
|
|
|
$info, |
48
|
|
|
sprintf( |
49
|
|
|
'%s:%s cannot be empty', |
50
|
|
|
static::getNamespacePrefix(), |
51
|
|
|
static::getLocalName(), |
52
|
|
|
), |
53
|
|
|
InvalidArgumentException::class, |
54
|
|
|
); |
55
|
|
|
Assert::maxCount($info, C::UNBOUNDED_LIMIT); |
56
|
|
|
Assert::allIsInstanceOf( |
57
|
|
|
$info, |
58
|
|
|
SerializableElementInterface::class, |
59
|
|
|
InvalidArgumentException::class, |
60
|
|
|
); |
61
|
|
|
Assert::nullOrValidNCName($Id); |
62
|
|
|
|
63
|
|
|
foreach ($info as $item) { |
64
|
|
|
if ($item instanceof AbstractDsElement) { |
65
|
|
|
Assert::isInstanceOfAny( |
66
|
|
|
$item, |
67
|
|
|
[KeyName::class, KeyValue::class, RetrievalMethod::class, X509Data::class], |
68
|
|
|
SchemaViolationException::class, |
69
|
|
|
); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Collect the value of the Id-property |
77
|
|
|
* |
78
|
|
|
* @return string|null |
79
|
|
|
*/ |
80
|
|
|
public function getId(): ?string |
81
|
|
|
{ |
82
|
|
|
return $this->Id; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Collect the value of the info-property |
88
|
|
|
* |
89
|
|
|
* @return list<\SimpleSAML\XML\SerializableElementInterface> |
|
|
|
|
90
|
|
|
*/ |
91
|
|
|
public function getInfo(): array |
92
|
|
|
{ |
93
|
|
|
return $this->info; |
|
|
|
|
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Convert this KeyInfo to XML. |
99
|
|
|
* |
100
|
|
|
* @param \DOMElement|null $parent The element we should append this KeyInfo to. |
101
|
|
|
* @return \DOMElement |
102
|
|
|
*/ |
103
|
|
|
public function toXML(DOMElement $parent = null): DOMElement |
104
|
|
|
{ |
105
|
|
|
$e = $this->instantiateParentElement($parent); |
106
|
|
|
|
107
|
|
|
if ($this->getId() !== null) { |
108
|
|
|
$e->setAttribute('Id', $this->getId()); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
foreach ($this->getInfo() as $elt) { |
112
|
|
|
$elt->toXML($e); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
return $e; |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|