diff --git a/src/XML/ds/AbstractKeyInfoType.php b/src/XML/ds/AbstractKeyInfoType.php new file mode 100644 index 00000000..b266045f --- /dev/null +++ b/src/XML/ds/AbstractKeyInfoType.php @@ -0,0 +1,117 @@ +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; + } +} diff --git a/src/XML/ds/KeyInfo.php b/src/XML/ds/KeyInfo.php index 1c013590..5f499345 100644 --- a/src/XML/ds/KeyInfo.php +++ b/src/XML/ds/KeyInfo.php @@ -7,86 +7,16 @@ use DOMElement; use SimpleSAML\Assert\Assert; use SimpleSAML\XML\Exception\InvalidDOMElementException; -use SimpleSAML\XML\Exception\SchemaViolationException; -use SimpleSAML\XML\ExtendableElementTrait; -use SimpleSAML\XML\SerializableElementInterface; -use SimpleSAML\XML\XsNamespace as NS; -use SimpleSAML\XMLSecurity\Constants as C; -use SimpleSAML\XMLSecurity\Exception\InvalidArgumentException; -use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; + +use function array_merge; /** * Class representing a ds:KeyInfo element. * * @package simplesamlphp/xml-security */ -final class KeyInfo extends AbstractDsElement +final class KeyInfo extends AbstractKeyInfoType { - 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\XML\SerializableElementInterface - * )[] $info - * @param string|null $Id - */ - public function __construct( - protected array $info, - protected ?string $Id = null, - ) { - Assert::notEmpty($info, 'ds:KeyInfo cannot be empty', 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], - 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 XML into a KeyInfo * @@ -125,26 +55,4 @@ public static function fromXML(DOMElement $xml): static return new static($info, $Id); } - - - /** - * 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; - } }