Skip to content

Commit 415f459

Browse files
committed
Add xenc11:PRF element
1 parent 32043a2 commit 415f459

4 files changed

Lines changed: 122 additions & 0 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\XMLSecurity\XML\xenc11;
6+
7+
use SimpleSAML\Assert\Assert;
8+
use SimpleSAML\XML\Exception\SchemaViolationException;
9+
10+
/**
11+
* Class representing <xenc11:AbstractPRFAlgorithmIdentifierType>.
12+
*
13+
* @package simplesamlphp/xml-security
14+
*/
15+
abstract class AbstractPRFAlgorithmIdentifierType extends AbstractAlgorithmIdentifierType
16+
{
17+
/**
18+
* AlgorithmPRFIdentifierType constructor.
19+
*
20+
* @param string $Algorithm
21+
* @param \SimpleSAML\XMLSecurity\XML\xenc11\Parameters|null $parameters
22+
*/
23+
public function __construct(
24+
string $Algorithm,
25+
?Parameters $parameters = null, // Not used because not allowed by spec
26+
) {
27+
Assert::null($parameters, SchemaViolationException::class);
28+
parent::__construct($Algorithm, null);
29+
}
30+
}

src/XML/xenc11/PRF.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\XMLSecurity\XML\xenc11;
6+
7+
use DOMElement;
8+
use SimpleSAML\Assert\Assert;
9+
use SimpleSAML\XML\Exception\InvalidDOMElementException;
10+
11+
/**
12+
* A class implementing the xenc11:PRF element.
13+
*
14+
* @package simplesamlphp/xml-security
15+
*/
16+
final class PRF extends AbstractPRFAlgorithmIdentifierType
17+
{
18+
/**
19+
* @inheritDoc
20+
*
21+
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
22+
* If the qualified name of the supplied element is wrong
23+
*/
24+
public static function fromXML(DOMElement $xml): static
25+
{
26+
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
27+
Assert::same($xml->namespaceURI, static::getNamespaceURI(), InvalidDOMElementException::class);
28+
29+
return new static(
30+
self::getOptionalAttribute($xml, 'Algorithm', null),
31+
);
32+
}
33+
}

tests/XML/xenc11/PRFTest.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\Test\SAML2\XML\xenc11;
6+
7+
use PHPUnit\Framework\Attributes\CoversClass;
8+
use PHPUnit\Framework\TestCase;
9+
use SimpleSAML\XML\DOMDocumentFactory;
10+
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait;
11+
use SimpleSAML\XMLSecurity\XML\xenc11\AbstractAlgorithmIdentifierType;
12+
use SimpleSAML\XMLSecurity\XML\xenc11\AbstractPRFAlgorithmIdentifierType;
13+
use SimpleSAML\XMLSecurity\XML\xenc11\AbstractXenc11Element;
14+
use SimpleSAML\XMLSecurity\XML\xenc11\PRF;
15+
16+
use function dirname;
17+
use function strval;
18+
19+
/**
20+
* Class \SimpleSAML\XMLSecurity\XML\xenc11\PRFTest
21+
*
22+
* @package simplesamlphp/xml-security
23+
*/
24+
#[CoversClass(PRF::class)]
25+
#[CoversClass(AbstractPRfAlgorithmIdentifierType::class)]
26+
#[CoversClass(AbstractAlgorithmIdentifierType::class)]
27+
#[CoversClass(AbstractXenc11Element::class)]
28+
final class PRFTest extends TestCase
29+
{
30+
use SerializableElementTestTrait;
31+
32+
/**
33+
*/
34+
public static function setUpBeforeClass(): void
35+
{
36+
self::$testedClass = PRF::class;
37+
38+
self::$xmlRepresentation = DOMDocumentFactory::fromFile(
39+
dirname(__FILE__, 3) . '/resources/xml/xenc11_PRF.xml',
40+
);
41+
}
42+
43+
44+
// marshalling
45+
46+
47+
/**
48+
*/
49+
public function testMarshalling(): void
50+
{
51+
$prf = new PRF('urn:x-simplesamlphp:algorithm');
52+
53+
$this->assertEquals(
54+
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
55+
strval($prf),
56+
);
57+
}
58+
}

tests/resources/xml/xenc11_PRF.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<xenc11:PRF xmlns:xenc11="http://www.w3.org/2009/xmlenc11#" Algorithm="urn:x-simplesamlphp:algorithm" />

0 commit comments

Comments
 (0)