|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace SimpleSAML\XMLSecurity\XML\xenc11; |
| 6 | + |
| 7 | +use DOMElement; |
| 8 | +use SimpleSAML\Assert\Assert; |
| 9 | +use SimpleSAML\XML\Exception\InvalidDOMElementException; |
| 10 | +use SimpleSAML\XML\Exception\MissingElementException; |
| 11 | +use SimpleSAML\XML\Exception\SchemaViolationException; |
| 12 | +use SimpleSAML\XML\ExtendableElementTrait; |
| 13 | +use SimpleSAML\XML\XsNamespace as NS; |
| 14 | + |
| 15 | +/** |
| 16 | + * Class representing <xenc11:KeyDerivationMethodType>. |
| 17 | + * |
| 18 | + * @package simplesamlphp/xml-security |
| 19 | + */ |
| 20 | +abstract class AbstractKeyDerivationMethodType extends AbstractXenc11Element |
| 21 | +{ |
| 22 | + use ExtendableElementTrait; |
| 23 | + |
| 24 | + /** The namespace-attribute for the xs:any element */ |
| 25 | + public const XS_ANY_ELT_NAMESPACE = NS::ANY; |
| 26 | + |
| 27 | + |
| 28 | + /** |
| 29 | + * KeyDerivationMethod constructor. |
| 30 | + * |
| 31 | + * @param string $Algorithm |
| 32 | + * @param \SimpleSAML\XML\SerializableElementInterface[] $children |
| 33 | + */ |
| 34 | + final public function __construct( |
| 35 | + protected string $Algorithm, |
| 36 | + array $children, |
| 37 | + ) { |
| 38 | + Assert::validURI($Algorithm, SchemaViolationException::class); |
| 39 | + |
| 40 | + $this->setElements($children); |
| 41 | + } |
| 42 | + |
| 43 | + |
| 44 | + /** |
| 45 | + * Get the value of the $Algorithm property. |
| 46 | + * |
| 47 | + * @return string |
| 48 | + */ |
| 49 | + public function getAlgorithm(): string |
| 50 | + { |
| 51 | + return $this->Algorithm; |
| 52 | + } |
| 53 | + |
| 54 | + |
| 55 | + /** |
| 56 | + * @inheritDoc |
| 57 | + * |
| 58 | + * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException |
| 59 | + * If the qualified name of the supplied element is wrong |
| 60 | + */ |
| 61 | + public static function fromXML(DOMElement $xml): static |
| 62 | + { |
| 63 | + Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); |
| 64 | + Assert::same($xml->namespaceURI, static::getNamespaceURI(), InvalidDOMElementException::class); |
| 65 | + |
| 66 | + return new static( |
| 67 | + self::getOptionalAttribute($xml, 'Algorithm'), |
| 68 | + self::getChildElementsFromXML($xml), |
| 69 | + ); |
| 70 | + } |
| 71 | + |
| 72 | + |
| 73 | + /** |
| 74 | + * @inheritDoc |
| 75 | + */ |
| 76 | + public function toXML(?DOMElement $parent = null): DOMElement |
| 77 | + { |
| 78 | + $e = $this->instantiateParentElement($parent); |
| 79 | + $e->setAttribute('Algorithm', $this->getAlgorithm()); |
| 80 | + |
| 81 | + foreach ($this->getElements() as $child) { |
| 82 | + if (!$child->isEmptyElement()) { |
| 83 | + $child->toXML($e); |
| 84 | + } |
| 85 | + } |
| 86 | + |
| 87 | + return $e; |
| 88 | + } |
| 89 | +} |
0 commit comments