-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
270 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\XMLSecurity\XML\xenc11; | ||
|
||
use DOMElement; | ||
use SimpleSAML\Assert\Assert; | ||
use SimpleSAML\XML\Exception\InvalidDOMElementException; | ||
use SimpleSAML\XML\Exception\MissingElementException; | ||
use SimpleSAML\XML\Exception\SchemaViolationException; | ||
use SimpleSAML\XML\Exception\TooManyElementsException; | ||
use SimpleSAML\XMLSecurity\XML\ds\DigestMethod; | ||
|
||
use function array_pop; | ||
|
||
/** | ||
* Class representing <xenc11:ConcatKDFParamsType>. | ||
* | ||
* @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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\XMLSecurity\XML\xenc11; | ||
|
||
/** | ||
* A class implementing the xenc11:ConcatKDFParams element. | ||
* | ||
* @package simplesamlphp/xml-security | ||
*/ | ||
final class ConcatKDFParams extends AbstractConcatKDFParamsType | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\XMLSecurity\Test\XML\xenc11; | ||
|
||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\TestCase; | ||
use SimpleSAML\XML\Chunk; | ||
use SimpleSAML\XML\DOMDocumentFactory; | ||
use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; | ||
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; | ||
use SimpleSAML\XMLSecurity\Constants as C; | ||
use SimpleSAML\XMLSecurity\XML\ds\DigestMethod; | ||
use SimpleSAML\XMLSecurity\XML\xenc11\AbstractConcatKDFParamsType; | ||
use SimpleSAML\XMLSecurity\XML\xenc11\AbstractXenc11Element; | ||
use SimpleSAML\XMLSecurity\XML\xenc11\ConcatKDFParams; | ||
|
||
use function dirname; | ||
use function strval; | ||
|
||
/** | ||
* Class \SimpleSAML\XMLSecurity\XML\Test\xenc11\ConcatKDFParamsTest | ||
* | ||
* @package simplesamlphp/xml-security | ||
*/ | ||
#[CoversClass(AbstractXenc11Element::class)] | ||
#[CoversClass(AbstractConcatKDFParamsType::class)] | ||
#[CoversClass(ConcatKDFParams::class)] | ||
final class ConcatKDFParamsTest extends TestCase | ||
{ | ||
use SchemaValidationTestTrait; | ||
use SerializableElementTestTrait; | ||
|
||
/** | ||
*/ | ||
public static function setUpBeforeClass(): void | ||
{ | ||
self::$testedClass = ConcatKDFParams::class; | ||
|
||
self::$schemaFile = dirname(__FILE__, 4) . '/resources/schemas/xenc-schema-11.xsd'; | ||
|
||
self::$xmlRepresentation = DOMDocumentFactory::fromFile( | ||
dirname(__FILE__, 3) . '/resources/xml/xenc11_ConcatKDFParams.xml', | ||
); | ||
} | ||
|
||
|
||
/** | ||
*/ | ||
public function testMarshalling(): void | ||
{ | ||
$digestMethod = new DigestMethod( | ||
C::DIGEST_SHA256, | ||
[ | ||
new Chunk(DOMDocumentFactory::fromString( | ||
'<some:Chunk xmlns:some="urn:test:some">Random</some:Chunk>', | ||
)->documentElement), | ||
], | ||
); | ||
|
||
$concatKdfParams = new ConcatKDFParams( | ||
$digestMethod, | ||
'a1b2', | ||
'b2c3', | ||
'c3d4', | ||
'd4e5', | ||
'e5f6', | ||
); | ||
|
||
$this->assertEquals( | ||
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), | ||
strval($concatKdfParams), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<xenc11:ConcatKDFParams xmlns:xenc11="http://www.w3.org/2009/xmlenc11#" AlgorithmID="a1b2" PartyUInfo="b2c3" PartyVInfo="c3d4" SuppPubInfo="d4e5" SuppPrivInfo="e5f6"> | ||
<ds:DigestMethod xmlns:ds="http://www.w3.org/2000/09/xmldsig#" Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"> | ||
<some:Chunk xmlns:some="urn:test:some">Random</some:Chunk> | ||
</ds:DigestMethod> | ||
</xenc11:ConcatKDFParams> |