Skip to content

Commit 5b82120

Browse files
committed
Add dsig11:Prime-element
1 parent 752e270 commit 5b82120

File tree

4 files changed

+159
-0
lines changed

4 files changed

+159
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\XMLSecurity\XML\dsig11;
6+
7+
use DOMElement;
8+
use SimpleSAML\Assert\Assert;
9+
use SimpleSAML\XML\Base64ElementTrait;
10+
use SimpleSAML\XML\Exception\InvalidDOMElementException;
11+
use SimpleSAML\XML\Exception\SchemaViolationException;
12+
use SimpleSAML\XMLSecurity\Constants as C;
13+
use SimpleSAML\XMLSecurity\Exception\InvalidArgumentException;
14+
15+
/**
16+
* Abstract class representing a dsig11:PrimeFieldParamsType
17+
*
18+
* @package simplesaml/xml-security
19+
*/
20+
abstract class AbstractPrimeFieldParamsType extends AbstractDsig11Element
21+
{
22+
/**
23+
* Initialize a PrimeFieldParamsType element.
24+
*
25+
* @param \SimpleSAML\XML\dsig11\P $p
26+
*/
27+
public function __construct(
28+
protected P $p,
29+
) {
30+
}
31+
32+
33+
/**
34+
* Collect the value of the p-property
35+
*
36+
* @return \SimpleSAML\XMLSecurity\XML\dsig11\P
37+
*/
38+
public function getP(): P
39+
{
40+
return $this->p;
41+
}
42+
43+
44+
/**
45+
* Convert this PrimeFieldParamsType element to XML.
46+
*
47+
* @param \DOMElement|null $parent The element we should append this PrimeFieldParamsType element to.
48+
* @return \DOMElement
49+
*/
50+
public function toXML(?DOMElement $parent = null): DOMElement
51+
{
52+
$e = $this->instantiateParentElement($parent);
53+
$this->getP()->toXML($e);
54+
55+
return $e;
56+
}
57+
}

src/XML/dsig11/Prime.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\XMLSecurity\XML\dsig11;
6+
7+
use SimpleSAML\Assert\Assert;
8+
use SimpleSAML\XML\Exception\InvalidDOMElementException;
9+
use SimpleSAML\XML\SchemaValidatableElementInterface;
10+
use SimpleSAML\XML\SchemaValidatableElementTrait;
11+
12+
/**
13+
* Class representing a dsig11:Prime element.
14+
*
15+
* @package simplesaml/xml-security
16+
*/
17+
final class Prime extends AbstractPrimeFieldParamsType implements SchemaValidatableElementInterface
18+
{
19+
use SchemaValidatableElementTrait;
20+
21+
/**
22+
* Convert XML into a Prime element
23+
*
24+
* @param \DOMElement $xml The XML element we should load
25+
* @return static
26+
*
27+
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
28+
* If the qualified name of the supplied element is wrong
29+
*/
30+
public static function fromXML(DOMElement $xml): static
31+
{
32+
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
33+
Assert::same($xml->namespaceURI, static::getNamespaceURI(), InvalidDOMElementException::class);
34+
35+
return new static(
36+
P::getChildrenOfClass($xml),
37+
);
38+
}
39+
}

tests/XML/dsig11/PrimeTest.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\XMLSecurity\Test\XML\dsig11;
6+
7+
use PHPUnit\Framework\Attributes\CoversClass;
8+
use PHPUnit\Framework\TestCase;
9+
use SimpleSAML\XML\DOMDocumentFactory;
10+
use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait;
11+
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait;
12+
use SimpleSAML\XMLSecurity\Test\XML\XMLDumper;
13+
use SimpleSAML\XMLSecurity\XML\dsig11\AbstractDsig11Element;
14+
use SimpleSAML\XMLSecurity\XML\dsig11\AbstractPrimeFieldParamsType;
15+
use SimpleSAML\XMLSecurity\XML\dsig11\P;
16+
use SimpleSAML\XMLSecurity\XML\dsig11\Prime;
17+
18+
use function dirname;
19+
use function strval;
20+
21+
/**
22+
* Class \SimpleSAML\XMLSecurity\Test\XML\dsig11\PrimeTest
23+
*
24+
* @package simplesamlphp/xml-security
25+
*/
26+
#[CoversClass(AbstractDsig11Element::class)]
27+
#[CoversClass(AbstractPrimeFieldParamsType::class)]
28+
#[CoversClass(P::class)]
29+
#[CoversClass(Prime::class)]
30+
final class PrimeTest extends TestCase
31+
{
32+
use SchemaValidationTestTrait;
33+
use SerializableElementTestTrait;
34+
35+
36+
/**
37+
*/
38+
public static function setUpBeforeClass(): void
39+
{
40+
self::$testedClass = Prime::class;
41+
42+
self::$xmlRepresentation = DOMDocumentFactory::fromFile(
43+
dirname(__FILE__, 3) . '/resources/xml/dsig11_Prime.xml',
44+
);
45+
}
46+
47+
48+
/**
49+
*/
50+
public function testMarshalling(): void
51+
{
52+
$p = new P('6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE=');
53+
$prime = new Prime($p);
54+
55+
$this->assertEquals(
56+
XMLDumper::dumpDOMDocumentXMLWithBase64Content(self::$xmlRepresentation),
57+
strval($prime),
58+
);
59+
}
60+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<dsig11:Prime xmlns:dsig11="http://www.w3.org/2009/xmldsig11#">
2+
<dsig11:P>6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE=</dsig11:P>
3+
</dsig11:Prime>

0 commit comments

Comments
 (0)