diff --git a/src/XML/xenc11/IterationCount.php b/src/XML/xenc11/IterationCount.php new file mode 100644 index 00000000..f57fa2a3 --- /dev/null +++ b/src/XML/xenc11/IterationCount.php @@ -0,0 +1,73 @@ +iterationCount; + } + + + /** + * Convert XML into a class instance + * + * @param \DOMElement $xml The XML element we should load + * @return static + * + * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException + * If the qualified name of the supplied element is wrong + */ + public static function fromXML(DOMElement $xml): static + { + Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); + Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); + Assert::numeric($xml->textContent); + + return new static(intval($xml->textContent)); + } + + + /** + * Convert this element to XML. + * + * @param \DOMElement|null $parent The element we should append this element to. + * @return \DOMElement + */ + public function toXML(?DOMElement $parent = null): DOMElement + { + $e = $this->instantiateParentElement($parent); + $e->textContent = strval($this->getIterationCount()); + + return $e; + } +} diff --git a/tests/XML/xenc11/IterationCountTest.php b/tests/XML/xenc11/IterationCountTest.php new file mode 100644 index 00000000..2138b88f --- /dev/null +++ b/tests/XML/xenc11/IterationCountTest.php @@ -0,0 +1,51 @@ +assertEquals( + self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), + strval($iterationCount), + ); + } +} diff --git a/tests/resources/xml/xenc11_IterationCount.xml b/tests/resources/xml/xenc11_IterationCount.xml new file mode 100644 index 00000000..55139a18 --- /dev/null +++ b/tests/resources/xml/xenc11_IterationCount.xml @@ -0,0 +1 @@ +3