From acf1c205bf13f3546ca26c1e89d8d5803860e72a Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Fri, 6 Dec 2024 00:14:30 +0100 Subject: [PATCH] Add xenc11:IterationCount element --- src/XML/xenc11/IterationCount.php | 73 +++++++++++++++++++ tests/XML/xenc11/IterationCountTest.php | 51 +++++++++++++ tests/resources/xml/xenc11_IterationCount.xml | 1 + 3 files changed, 125 insertions(+) create mode 100644 src/XML/xenc11/IterationCount.php create mode 100644 tests/XML/xenc11/IterationCountTest.php create mode 100644 tests/resources/xml/xenc11_IterationCount.xml 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