-
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
3 changed files
with
152 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?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\TooManyElementsException; | ||
|
||
use function array_merge; | ||
use function array_pop; | ||
|
||
/** | ||
* Class representing <xenc11:Salt>. | ||
* | ||
* @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; | ||
} | ||
} |
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,68 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\Test\SAML2\XML\xenc11; | ||
|
||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\TestCase; | ||
use SimpleSAML\XML\Attribute as XMLAttribute; | ||
use SimpleSAML\XML\Chunk; | ||
use SimpleSAML\XML\DOMDocumentFactory; | ||
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; | ||
use SimpleSAML\XMLSecurity\XML\xenc11\AbstractXenc11Element; | ||
use SimpleSAML\XMLSecurity\XML\xenc11\OtherSource; | ||
use SimpleSAML\XMLSecurity\XML\xenc11\Parameters; | ||
use SimpleSAML\XMLSecurity\XML\xenc11\Salt; | ||
|
||
use function dirname; | ||
use function strval; | ||
|
||
/** | ||
* Class \SimpleSAML\XMLSecurity\XML\xenc11\SaltTest | ||
* | ||
* @package simplesamlphp/xml-security | ||
*/ | ||
#[CoversClass(Salt::class)] | ||
#[CoversClass(AbstractXenc11Element::class)] | ||
final class SaltTest extends TestCase | ||
{ | ||
use SerializableElementTestTrait; | ||
|
||
/** | ||
*/ | ||
public static function setUpBeforeClass(): void | ||
{ | ||
self::$testedClass = Salt::class; | ||
|
||
self::$xmlRepresentation = DOMDocumentFactory::fromFile( | ||
dirname(__FILE__, 3) . '/resources/xml/xenc11_Salt.xml', | ||
); | ||
} | ||
|
||
|
||
// marshalling | ||
|
||
|
||
/** | ||
*/ | ||
public function testMarshalling(): void | ||
{ | ||
$someDoc = DOMDocumentFactory::fromString( | ||
'<ssp:Chunk xmlns:ssp="urn:x-simplesamlphp:namespace">Some</ssp:Chunk>', | ||
); | ||
|
||
$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), | ||
); | ||
} | ||
} |
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,7 @@ | ||
<xenc11:Salt xmlns:xenc11="http://www.w3.org/2009/xmlenc11#"> | ||
<xenc11:OtherSource Algorithm="urn:x-simplesamlphp:algorithm"> | ||
<xenc11:Parameters xmlns:ssp="urn:x-simplesamlphp:namespace" ssp:attr1="testval1"> | ||
<ssp:Chunk>Some</ssp:Chunk> | ||
</xenc11:Parameters> | ||
</xenc11:OtherSource> | ||
</xenc11:Salt> |