From f0981435c097f8c4fb9dfbfd0052184e99bbb4fd Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Sat, 7 Dec 2024 23:31:36 +0100 Subject: [PATCH] Add xenc11:Salt element --- src/XML/xenc11/Salt.php | 77 +++++++++++++++++++++++++++++ tests/XML/xenc11/SaltTest.php | 68 +++++++++++++++++++++++++ tests/resources/xml/xenc11_Salt.xml | 7 +++ 3 files changed, 152 insertions(+) create mode 100644 src/XML/xenc11/Salt.php create mode 100644 tests/XML/xenc11/SaltTest.php create mode 100644 tests/resources/xml/xenc11_Salt.xml diff --git a/src/XML/xenc11/Salt.php b/src/XML/xenc11/Salt.php new file mode 100644 index 00000000..444d75a9 --- /dev/null +++ b/src/XML/xenc11/Salt.php @@ -0,0 +1,77 @@ +. + * + * @package simplesamlphp/xml-security + */ +final class Salt extends AbstractXenc11Element +{ + /** + * Salt constructor. + * + * @param \SimpleSAML\XMLSecurity\XML\xenc11\OtherSource|\SimpleSAML\XMLSecurity\XML\xenc11\Specified $content + */ + public function __construct( + protected OtherSource|Specified $content, + ) { + } + + + /** + * Get the value of the $content property. + * + * @return \SimpleSAML\XMLSecurity\XML\xenc11\OtherSource|\SimpleSAML\XMLSecurity\XML\xenc11\Specified + */ + public function getContent(): OtherSource|Specified + { + return $this->content; + } + + + /** + * @inheritDoc + * + * @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::getNamespaceURI(), InvalidDOMElementException::class); + + $otherSource = OtherSource::getChildrenOfClass($xml); + $specified = Specified::getChildrenOfClass($xml); + + $content = array_merge($otherSource, $specified); + Assert::minCount($content, 1, MissingElementException::class); + Assert::maxCount($content, 1, TooManyElementsException::class); + + return new static(array_pop($content)); + } + + + /** + * @inheritDoc + */ + public function toXML(?DOMElement $parent = null): DOMElement + { + $e = $this->instantiateParentElement($parent); + $this->getContent()->toXML($e); + + return $e; + } +} diff --git a/tests/XML/xenc11/SaltTest.php b/tests/XML/xenc11/SaltTest.php new file mode 100644 index 00000000..dda8c842 --- /dev/null +++ b/tests/XML/xenc11/SaltTest.php @@ -0,0 +1,68 @@ +Some', + ); + + $parameters = new Parameters( + [new Chunk($someDoc->documentElement)], + [new XMLAttribute('urn:x-simplesamlphp:namespace', 'ssp', 'attr1', 'testval1')], + ); + + $otherSource = new OtherSource('urn:x-simplesamlphp:algorithm', $parameters); + $salt = new Salt($otherSource); + + $this->assertEquals( + self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), + strval($salt), + ); + } +} diff --git a/tests/resources/xml/xenc11_Salt.xml b/tests/resources/xml/xenc11_Salt.xml new file mode 100644 index 00000000..ce5c7dac --- /dev/null +++ b/tests/resources/xml/xenc11_Salt.xml @@ -0,0 +1,7 @@ + + + + Some + + +