|
7 | 7 | use DOMElement; |
8 | 8 | use SimpleSAML\Assert\Assert; |
9 | 9 | use SimpleSAML\XML\Exception\InvalidDOMElementException; |
10 | | -use SimpleSAML\XML\Exception\SchemaViolationException; |
11 | | -use SimpleSAML\XML\ExtendableElementTrait; |
12 | | -use SimpleSAML\XML\SerializableElementInterface; |
13 | | -use SimpleSAML\XML\XsNamespace as NS; |
14 | | -use SimpleSAML\XMLSecurity\Constants as C; |
15 | | -use SimpleSAML\XMLSecurity\Exception\InvalidArgumentException; |
16 | | -use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; |
| 10 | + |
| 11 | +use function array_merge; |
17 | 12 |
|
18 | 13 | /** |
19 | 14 | * Class representing a ds:KeyInfo element. |
20 | 15 | * |
21 | 16 | * @package simplesamlphp/xml-security |
22 | 17 | */ |
23 | | -final class KeyInfo extends AbstractDsElement |
| 18 | +final class KeyInfo extends AbstractKeyInfoType |
24 | 19 | { |
25 | | - use ExtendableElementTrait; |
26 | | - |
27 | | - /** @var \SimpleSAML\XML\XsNamespace */ |
28 | | - public const XS_ANY_ELT_NAMESPACE = NS::OTHER; |
29 | | - |
30 | | - |
31 | | - /** |
32 | | - * Initialize a KeyInfo element. |
33 | | - * |
34 | | - * @param ( |
35 | | - * \SimpleSAML\XMLSecurity\XML\ds\KeyName| |
36 | | - * \SimpleSAML\XMLSecurity\XML\ds\KeyValue| |
37 | | - * \SimpleSAML\XMLSecurity\XML\ds\RetrievalMethod| |
38 | | - * \SimpleSAML\XMLSecurity\XML\ds\X509Data| |
39 | | - * \SimpleSAML\XML\SerializableElementInterface |
40 | | - * )[] $info |
41 | | - * @param string|null $Id |
42 | | - */ |
43 | | - public function __construct( |
44 | | - protected array $info, |
45 | | - protected ?string $Id = null, |
46 | | - ) { |
47 | | - Assert::notEmpty($info, 'ds:KeyInfo cannot be empty', InvalidArgumentException::class); |
48 | | - Assert::maxCount($info, C::UNBOUNDED_LIMIT); |
49 | | - Assert::allIsInstanceOf( |
50 | | - $info, |
51 | | - SerializableElementInterface::class, |
52 | | - InvalidArgumentException::class, |
53 | | - ); |
54 | | - Assert::nullOrValidNCName($Id); |
55 | | - |
56 | | - foreach ($info as $item) { |
57 | | - if ($item instanceof AbstractDsElement) { |
58 | | - Assert::isInstanceOfAny( |
59 | | - $item, |
60 | | - [KeyName::class, KeyValue::class, RetrievalMethod::class, X509Data::class], |
61 | | - SchemaViolationException::class, |
62 | | - ); |
63 | | - } |
64 | | - } |
65 | | - } |
66 | | - |
67 | | - |
68 | | - /** |
69 | | - * Collect the value of the Id-property |
70 | | - * |
71 | | - * @return string|null |
72 | | - */ |
73 | | - public function getId(): ?string |
74 | | - { |
75 | | - return $this->Id; |
76 | | - } |
77 | | - |
78 | | - |
79 | | - /** |
80 | | - * Collect the value of the info-property |
81 | | - * |
82 | | - * @return list<\SimpleSAML\XML\SerializableElementInterface> |
83 | | - */ |
84 | | - public function getInfo(): array |
85 | | - { |
86 | | - return $this->info; |
87 | | - } |
88 | | - |
89 | | - |
90 | 20 | /** |
91 | 21 | * Convert XML into a KeyInfo |
92 | 22 | * |
@@ -125,26 +55,4 @@ public static function fromXML(DOMElement $xml): static |
125 | 55 |
|
126 | 56 | return new static($info, $Id); |
127 | 57 | } |
128 | | - |
129 | | - |
130 | | - /** |
131 | | - * Convert this KeyInfo to XML. |
132 | | - * |
133 | | - * @param \DOMElement|null $parent The element we should append this KeyInfo to. |
134 | | - * @return \DOMElement |
135 | | - */ |
136 | | - public function toXML(DOMElement $parent = null): DOMElement |
137 | | - { |
138 | | - $e = $this->instantiateParentElement($parent); |
139 | | - |
140 | | - if ($this->getId() !== null) { |
141 | | - $e->setAttribute('Id', $this->getId()); |
142 | | - } |
143 | | - |
144 | | - foreach ($this->getInfo() as $elt) { |
145 | | - $elt->toXML($e); |
146 | | - } |
147 | | - |
148 | | - return $e; |
149 | | - } |
150 | 58 | } |
0 commit comments