Issues (81)

src/XML/dsig11/ECKeyValue.php (1 issue)

Severity
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\{SchemaValidatableElementInterface, SchemaValidatableElementTrait};
10
use SimpleSAML\XMLSchema\Exception\{InvalidDOMElementException, MissingElementException, TooManyElementsException};
11
use SimpleSAML\XMLSchema\Type\IDValue;
12
13
use function array_pop;
14
15
/**
16
 * Class representing a dsig11:ECKeyValue element.
17
 *
18
 * @package simplesaml/xml-security
19
 */
20
final class ECKeyValue extends AbstractECKeyValueType implements SchemaValidatableElementInterface
21
{
22
    use SchemaValidatableElementTrait;
0 ignored issues
show
The trait SimpleSAML\XML\SchemaValidatableElementTrait requires some properties which are not provided by SimpleSAML\XMLSecurity\XML\dsig11\ECKeyValue: $message, $line
Loading history...
23
24
    /**
25
     * Convert XML into a ECKeyValue element
26
     *
27
     * @param \DOMElement $xml The XML element we should load
28
     * @return static
29
     *
30
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
31
     *   If the qualified name of the supplied element is wrong
32
     */
33
    public static function fromXML(DOMElement $xml): static
34
    {
35
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
36
        Assert::same($xml->namespaceURI, static::getNamespaceURI(), InvalidDOMElementException::class);
37
38
        $publicKey = PublicKey::getChildrenOfClass($xml);
39
        Assert::minCount($publicKey, 1, MissingElementException::class);
40
        Assert::maxCount($publicKey, 1, TooManyElementsException::class);
41
42
        $ecParameters = ECParameters::getChildrenOfClass($xml);
43
        Assert::maxCount($ecParameters, 1, TooManyElementsException::class);
44
45
        $namedCurve = NamedCurve::getChildrenOfClass($xml);
46
        Assert::maxCount($namedCurve, 1, TooManyElementsException::class);
47
48
        return new static(
49
            array_pop($publicKey),
50
            self::getOptionalAttribute($xml, 'Id', IDValue::class, null),
51
            array_pop($ecParameters),
52
            array_pop($namedCurve),
53
        );
54
    }
55
}
56