File tree Expand file tree Collapse file tree 4 files changed +145
-0
lines changed Expand file tree Collapse file tree 4 files changed +145
-0
lines changed Original file line number Diff line number Diff line change 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 \Exception \SchemaViolationException ;
10+
11+ /**
12+ * Abstract class representing a dsig11:NamedCurveType
13+ *
14+ * @package simplesaml/xml-security
15+ */
16+ abstract class AbstractNamedCurveType extends AbstractDsig11Element
17+ {
18+ /**
19+ * Initialize a NamedCurveType element.
20+ *
21+ * @param string $URI
22+ */
23+ public function __construct (
24+ protected string $ URI ,
25+ ) {
26+ Assert::validURI ($ URI , SchemaViolationException::class);
27+ }
28+
29+
30+ /**
31+ * Collect the value of the URI-property
32+ *
33+ * @return string
34+ */
35+ public function getURI (): string
36+ {
37+ return $ this ->URI ;
38+ }
39+
40+
41+ /**
42+ * Convert this NamedCurveType element to XML.
43+ *
44+ * @param \DOMElement|null $parent The element we should append this NamedCurveType element to.
45+ * @return \DOMElement
46+ */
47+ public function toXML (?DOMElement $ parent = null ): DOMElement
48+ {
49+ $ e = $ this ->instantiateParentElement ($ parent );
50+ $ e ->setAttribute ('URI ' , $ this ->getURI ());
51+
52+ return $ e ;
53+ }
54+ }
Original file line number Diff line number Diff line change 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 \Exception \InvalidDOMElementException ;
10+
11+ /**
12+ * Class representing a dsig11:NamedCurve element.
13+ *
14+ * @package simplesaml/xml-security
15+ */
16+ final class NamedCurve extends AbstractNamedCurveType
17+ {
18+ /**
19+ * Convert XML into a NamedCurve element
20+ *
21+ * @param \DOMElement $xml The XML element we should load
22+ * @return static
23+ *
24+ * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
25+ * If the qualified name of the supplied element is wrong
26+ */
27+ public static function fromXML (DOMElement $ xml ): static
28+ {
29+ Assert::same ($ xml ->localName , static ::getLocalName (), InvalidDOMElementException::class);
30+ Assert::same ($ xml ->namespaceURI , static ::getNamespaceURI (), InvalidDOMElementException::class);
31+
32+ return new static (
33+ self ::getAttribute ($ xml , 'URI ' ),
34+ );
35+ }
36+ }
Original file line number Diff line number Diff line change 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 \SerializableElementTestTrait ;
11+ use SimpleSAML \XMLSecurity \XML \dsig11 \AbstractDsig11Element ;
12+ use SimpleSAML \XMLSecurity \XML \dsig11 \AbstractNamedCurveType ;
13+ use SimpleSAML \XMLSecurity \XML \dsig11 \NamedCurve ;
14+
15+ use function dirname ;
16+ use function strval ;
17+
18+ /**
19+ * Class \SimpleSAML\XMLSecurity\Test\XML\dsig11\NamedCurveTest
20+ *
21+ * @package simplesamlphp/xml-security
22+ */
23+ #[CoversClass(AbstractDsig11Element::class)]
24+ #[CoversClass(AbstractNamedCurveType::class)]
25+ #[CoversClass(NamedCurve::class)]
26+ final class NamedCurveTest extends TestCase
27+ {
28+ use SerializableElementTestTrait;
29+
30+
31+ /**
32+ */
33+ public static function setUpBeforeClass (): void
34+ {
35+ self ::$ testedClass = NamedCurve::class;
36+
37+ self ::$ xmlRepresentation = DOMDocumentFactory::fromFile (
38+ dirname (__FILE__ , 3 ) . '/resources/xml/dsig11_NamedCurve.xml ' ,
39+ );
40+ }
41+
42+
43+ /**
44+ */
45+ public function testMarshalling (): void
46+ {
47+ $ namedCurve = new NamedCurve ('urn:x-simplesamlphp:URI ' );
48+
49+ $ this ->assertEquals (
50+ self ::$ xmlRepresentation ->saveXML (self ::$ xmlRepresentation ->documentElement ),
51+ strval ($ namedCurve ),
52+ );
53+ }
54+ }
Original file line number Diff line number Diff line change 1+ <dsig11 : NamedCurve xmlns : dsig11 =" http://www.w3.org/2009/xmldsig11#" URI =" urn:x-simplesamlphp:URI" />
You can’t perform that action at this time.
0 commit comments