From 041f61edaadb674b032af1128e52a03f8114ab06 Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Thu, 5 Dec 2024 18:56:25 +0100 Subject: [PATCH] Add xenc11:ConcatKDFParams element --- composer.json | 4 +- .../xenc11/AbstractConcatKDFParamsType.php | 173 ++++++++++++++++++ src/XML/xenc11/ConcatKDFParams.php | 14 ++ tests/XML/xenc11/ConcatKDFParamsTest.php | 76 ++++++++ .../resources/xml/xenc11_ConcatKDFParams.xml | 5 + 5 files changed, 270 insertions(+), 2 deletions(-) create mode 100644 src/XML/xenc11/AbstractConcatKDFParamsType.php create mode 100644 src/XML/xenc11/ConcatKDFParams.php create mode 100644 tests/XML/xenc11/ConcatKDFParamsTest.php create mode 100644 tests/resources/xml/xenc11_ConcatKDFParams.xml diff --git a/composer.json b/composer.json index f891a767..bf372b1a 100644 --- a/composer.json +++ b/composer.json @@ -43,8 +43,8 @@ "ext-pcre": "*", "ext-spl": "*", - "simplesamlphp/assert": "^1.5", - "simplesamlphp/xml-common": "^1.20.0" + "simplesamlphp/assert": "^1.6", + "simplesamlphp/xml-common": "^1.21.0" }, "require-dev": { "simplesamlphp/simplesamlphp-test-framework": "^1.7" diff --git a/src/XML/xenc11/AbstractConcatKDFParamsType.php b/src/XML/xenc11/AbstractConcatKDFParamsType.php new file mode 100644 index 00000000..f916d180 --- /dev/null +++ b/src/XML/xenc11/AbstractConcatKDFParamsType.php @@ -0,0 +1,173 @@ +. + * + * @package simplesamlphp/xml-security + */ +abstract class AbstractConcatKDFParamsType extends AbstractXenc11Element +{ + /** + * ConcatKDFParams constructor. + * + * @param \SimpleSAML\XMLSecurity\XML\ds\DigestMethod $digestMethod + * @param string|null $AlgorithmID + * @param string|null $PartyUInfo + * @param string|null $PartyVInfo + * @param string|null $SuppPubInfo + * @param string|null $SuppPrivInfo + */ + final public function __construct( + protected DigestMethod $digestMethod, + protected ?string $AlgorithmID = null, + protected ?string $PartyUInfo = null, + protected ?string $PartyVInfo = null, + protected ?string $SuppPubInfo = null, + protected ?string $SuppPrivInfo = null, + ) { + Assert::validHexBinary($AlgorithmID, SchemaViolationException::class); + Assert::validHexBinary($PartyUInfo, SchemaViolationException::class); + Assert::validHexBinary($PartyVInfo, SchemaViolationException::class); + Assert::validHexBinary($SuppPubInfo, SchemaViolationException::class); + Assert::validHexBinary($SuppPrivInfo, SchemaViolationException::class); + } + + + /** + * Get the value of the $digestMethod property. + * + * @return \SimpleSAML\XMLSecurity\XML\ds\DigestMethod + */ + public function getDigestMethod(): DigestMethod + { + return $this->digestMethod; + } + + + /** + * Get the value of the $AlgorithmID property. + * + * @return string|null + */ + public function getAlgorithmID(): ?string + { + return $this->AlgorithmID; + } + + + /** + * Get the value of the $PartyUInfo property. + * + * @return string|null + */ + public function getPartyUInfo(): ?string + { + return $this->PartyUInfo; + } + + + /** + * Get the value of the $PartyVInfo property. + * + * @return string|null + */ + public function getPartyVInfo(): ?string + { + return $this->PartyVInfo; + } + + + /** + * Get the value of the $SuppPubInfo property. + * + * @return string|null + */ + public function getSuppPubInfo(): ?string + { + return $this->SuppPubInfo; + } + + + /** + * Get the value of the $SuppPrivInfo property. + * + * @return string|null + */ + public function getSuppPrivInfo(): ?string + { + return $this->SuppPrivInfo; + } + + + /** + * @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); + + $digestMethod = DigestMethod::getChildrenOfClass($xml); + Assert::minCount($digestMethod, 1, MissingElementException::class); + Assert::maxCount($digestMethod, 1, TooManyElementsException::class); + + return new static( + array_pop($digestMethod), + self::getOptionalAttribute($xml, 'AlgorithmID', null), + self::getOptionalAttribute($xml, 'PartyUInfo', null), + self::getOptionalAttribute($xml, 'PartyVInfo', null), + self::getOptionalAttribute($xml, 'SuppPubInfo', null), + self::getOptionalAttribute($xml, 'SuppPrivInfo', null), + ); + } + + + /** + * @inheritDoc + */ + public function toXML(?DOMElement $parent = null): DOMElement + { + $e = $this->instantiateParentElement($parent); + + if ($this->getAlgorithmID() !== null) { + $e->setAttribute('AlgorithmID', $this->getAlgorithmID()); + } + + if ($this->getPartyUInfo() !== null) { + $e->setAttribute('PartyUInfo', $this->getPartyUInfo()); + } + + if ($this->getPartyVInfo() !== null) { + $e->setAttribute('PartyVInfo', $this->getPartyVInfo()); + } + + if ($this->getSuppPubInfo() !== null) { + $e->setAttribute('SuppPubInfo', $this->getSuppPubInfo()); + } + + if ($this->getSuppPrivInfo() !== null) { + $e->setAttribute('SuppPrivInfo', $this->getSuppPrivInfo()); + } + + $this->getDigestMethod()->toXML($e); + + return $e; + } +} diff --git a/src/XML/xenc11/ConcatKDFParams.php b/src/XML/xenc11/ConcatKDFParams.php new file mode 100644 index 00000000..aa73011a --- /dev/null +++ b/src/XML/xenc11/ConcatKDFParams.php @@ -0,0 +1,14 @@ +Random', + )->documentElement), + ], + ); + + $concatKdfParams = new ConcatKDFParams( + $digestMethod, + 'a1b2', + 'b2c3', + 'c3d4', + 'd4e5', + 'e5f6', + ); + + $this->assertEquals( + self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), + strval($concatKdfParams), + ); + } +} diff --git a/tests/resources/xml/xenc11_ConcatKDFParams.xml b/tests/resources/xml/xenc11_ConcatKDFParams.xml new file mode 100644 index 00000000..0d43622b --- /dev/null +++ b/tests/resources/xml/xenc11_ConcatKDFParams.xml @@ -0,0 +1,5 @@ + + + Random + +