-
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
4 changed files
with
194 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,92 @@ | ||
<?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\SchemaViolationException; | ||
use SimpleSAML\XML\Exception\TooManyElementsException; | ||
use SimpleSAML\XMLSecurity\XML\ds\DigestMethod; | ||
|
||
use function array_pop; | ||
|
||
/** | ||
* Class representing <xenc11:AlgorithmIdentifierType>. | ||
* | ||
* @package simplesamlphp/xml-security | ||
*/ | ||
abstract class AbstractAlgorithmIdentifierType extends AbstractXenc11Element | ||
{ | ||
/** | ||
* AlgorithmIdentifierType constructor. | ||
* | ||
* @param string $Algorithm | ||
* @param \SimpleSAML\XMLSecurity\XML\xenc11\Parameters|null $parameters | ||
*/ | ||
final public function __construct( | ||
protected string $Algorithm, | ||
protected ?Parameters $parameters = null, | ||
) { | ||
Assert::validURI($Algorithm, SchemaViolationException::class); | ||
} | ||
|
||
|
||
/** | ||
* Get the value of the $Algorithm property. | ||
* | ||
* @return string | ||
*/ | ||
public function getAlgorithm(): string | ||
{ | ||
return $this->Algorithm; | ||
} | ||
|
||
|
||
/** | ||
* Get the value of the $parameters property. | ||
* | ||
* @return \SimpleSAML\XMLSecurity\XML\xenc11\Parameters | ||
*/ | ||
public function getParameters(): Parameters | ||
{ | ||
return $this->parameters; | ||
} | ||
|
||
|
||
/** | ||
* @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); | ||
|
||
$parameter = Parameters::getChildrenOfClass($xml); | ||
Assert::maxCount($parameter, 1, TooManyElementsException::class); | ||
|
||
return new static( | ||
self::getOptionalAttribute($xml, 'Algorithm'), | ||
array_pop($parameter), | ||
); | ||
} | ||
|
||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function toXML(?DOMElement $parent = null): DOMElement | ||
{ | ||
$e = $this->instantiateParentElement($parent); | ||
$e->setAttribute('Algorithm', $this->getAlgorithm()); | ||
|
||
$this->getParameters()?->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:OtherSource element. | ||
* | ||
* @package simplesamlphp/xml-security | ||
*/ | ||
final class OtherSource extends AbstractAlgorithmIdentifierType | ||
{ | ||
} |
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\Test\SAML2\XML\xenc11; | ||
|
||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\TestCase; | ||
use SimpleSAML\XMLSecurity\XML\xenc11\AbstractXenc11Element; | ||
use SimpleSAML\XMLSecurity\XML\xenc11\AbstractAlgorithmIdentifierType; | ||
use SimpleSAML\XMLSecurity\XML\xenc11\OtherSource; | ||
use SimpleSAML\XMLSecurity\XML\xenc11\Parameters; | ||
use SimpleSAML\XML\Attribute as XMLAttribute; | ||
use SimpleSAML\XML\Chunk; | ||
use SimpleSAML\XML\DOMDocumentFactory; | ||
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; | ||
|
||
use function dirname; | ||
use function strval; | ||
|
||
/** | ||
* Class \SimpleSAML\XMLSecurity\XML\xenc11\OtherSourceTest | ||
* | ||
* @package simplesamlphp/xml-security | ||
*/ | ||
#[CoversClass(OtherSource::class)] | ||
#[CoversClass(AbstractAlgorithmIdentifierType::class)] | ||
#[CoversClass(AbstractXenc11Element::class)] | ||
final class OtherSourceTest extends TestCase | ||
{ | ||
use SerializableElementTestTrait; | ||
|
||
/** | ||
*/ | ||
public static function setUpBeforeClass(): void | ||
{ | ||
self::$testedClass = OtherSource::class; | ||
|
||
self::$xmlRepresentation = DOMDocumentFactory::fromFile( | ||
dirname(__FILE__, 3) . '/resources/xml/xenc11_OtherSource.xml', | ||
); | ||
} | ||
|
||
|
||
// marshalling | ||
|
||
|
||
/** | ||
*/ | ||
public function testMarshalling(): void | ||
{ | ||
$chunk = new Chunk(DOMDocumentFactory::fromString( | ||
<<<XML | ||
<ssp:AuthenticationContextDeclaration xmlns:ssp="urn:x-simplesamlphp:namespace"> | ||
<ssp:Identification nym="verinymity"> | ||
<ssp:Extension> | ||
<ssp:NoVerification/> | ||
</ssp:Extension> | ||
</ssp:Identification> | ||
</ssp:AuthenticationContextDeclaration> | ||
XML | ||
, | ||
)->documentElement); | ||
|
||
$parameters = new Parameters( | ||
[$chunk], | ||
[new XMLAttribute('urn:x-simplesamlphp:namespace', 'ssp', 'attr1', 'testval1')], | ||
); | ||
|
||
$otherSource = new OtherSource('urn:x-simplesamlphp:algorithm', $parameters); | ||
|
||
$this->assertEquals( | ||
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), | ||
strval($otherSource), | ||
); | ||
} | ||
} |
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,11 @@ | ||
<xenc11:OtherSource xmlns:xenc11="http://www.w3.org/2009/xmlenc11#" Algorithm="urn:x-simplesamlphp:algorithm"> | ||
<xenc11:Parameters xmlns:ssp="urn:x-simplesamlphp:namespace" ssp:attr1="testval1"> | ||
<ssp:AuthenticationContextDeclaration> | ||
<ssp:Identification nym="verinymity"> | ||
<ssp:Extension> | ||
<ssp:NoVerification/> | ||
</ssp:Extension> | ||
</ssp:Identification> | ||
</ssp:AuthenticationContextDeclaration> | ||
</xenc11:Parameters> | ||
</xenc11:OtherSource> |