-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathAbstractKeyInfoType.php
More file actions
138 lines (121 loc) · 3.79 KB
/
AbstractKeyInfoType.php
File metadata and controls
138 lines (121 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
declare(strict_types=1);
namespace SimpleSAML\XMLSecurity\XML\ds;
use DOMElement;
use SimpleSAML\XML\Exception\SchemaViolationException;
use SimpleSAML\XML\ExtendableElementTrait;
use SimpleSAML\XML\SerializableElementInterface;
use SimpleSAML\XML\XsNamespace as NS;
use SimpleSAML\XMLSecurity\Assert\Assert;
use SimpleSAML\XMLSecurity\Constants as C;
use SimpleSAML\XMLSecurity\Exception\InvalidArgumentException;
use SimpleSAML\XMLSecurity\XML\dsig11\AbstractDsig11Element;
use SimpleSAML\XMLSecurity\XML\dsig11\DEREncodedKeyValue;
/**
* Abstract class representing the KeyInfoType.
*
* @package simplesamlphp/xml-security
*/
abstract class AbstractKeyInfoType extends AbstractDsElement
{
use ExtendableElementTrait;
/** @var \SimpleSAML\XML\XsNamespace */
public const XS_ANY_ELT_NAMESPACE = NS::OTHER;
/**
* Initialize a KeyInfo element.
*
* @param (
* \SimpleSAML\XMLSecurity\XML\ds\KeyName|
* \SimpleSAML\XMLSecurity\XML\ds\KeyValue|
* \SimpleSAML\XMLSecurity\XML\ds\RetrievalMethod|
* \SimpleSAML\XMLSecurity\XML\ds\X509Data|
* \SimpleSAML\XMLSecurity\XML\ds\PGPData|
* \SimpleSAML\XMLSecurity\XML\ds\SPKIData|
* \SimpleSAML\XMLSecurity\XML\ds\MgmtData|
* \SimpleSAML\XMLSecurity\XML\dsig11\DEREncodedKeyValue|
* \SimpleSAML\XML\SerializableElementInterface
* )[] $info
* @param string|null $Id
*/
final public function __construct(
protected array $info,
protected ?string $Id = null,
) {
Assert::notEmpty(
$info,
sprintf(
'%s:%s cannot be empty',
static::getNamespacePrefix(),
static::getLocalName(),
),
InvalidArgumentException::class,
);
Assert::maxCount($info, C::UNBOUNDED_LIMIT);
Assert::allIsInstanceOf(
$info,
SerializableElementInterface::class,
InvalidArgumentException::class,
);
Assert::nullOrValidNCName($Id);
foreach ($info as $item) {
if ($item instanceof AbstractDsElement) {
Assert::isInstanceOfAny(
$item,
[
KeyName::class,
KeyValue::class,
RetrievalMethod::class,
X509Data::class,
PGPData::class,
SPKIData::class,
MgmtData::class,
],
SchemaViolationException::class,
);
} elseif ($item instanceof AbstractDsig11Element) {
Assert::isInstanceOfAny(
$item,
[
DEREncodedKeyValue::class,
],
SchemaViolationException::class,
);
}
}
}
/**
* Collect the value of the Id-property
*
* @return string|null
*/
public function getId(): ?string
{
return $this->Id;
}
/**
* Collect the value of the info-property
*
* @return list<\SimpleSAML\XML\SerializableElementInterface>
*/
public function getInfo(): array
{
return $this->info;
}
/**
* Convert this KeyInfo to XML.
*
* @param \DOMElement|null $parent The element we should append this KeyInfo to.
* @return \DOMElement
*/
public function toXML(?DOMElement $parent = null): DOMElement
{
$e = $this->instantiateParentElement($parent);
if ($this->getId() !== null) {
$e->setAttribute('Id', $this->getId());
}
foreach ($this->getInfo() as $elt) {
$elt->toXML($e);
}
return $e;
}
}