Issues (88)

src/XML/ds/KeyInfo.php (1 issue)

Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XMLSecurity\XML\ds;
6
7
use DOMElement;
8
use SimpleSAML\Assert\Assert;
9
use SimpleSAML\XML\Exception\InvalidDOMElementException;
10
use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait};
11
use SimpleSAML\XMLSecurity\XML\dsig11\DEREncodedKeyValue;
12
13
use function array_merge;
14
15
/**
16
 * Class representing a ds:KeyInfo element.
17
 *
18
 * @package simplesamlphp/xml-security
19
 */
20
final class KeyInfo extends AbstractKeyInfoType 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\ds\KeyInfo: $message, $line
Loading history...
23
24
    /**
25
     * Convert XML into a KeyInfo
26
     *
27
     * @param \DOMElement $xml The XML element we should load
28
     * @return static
29
     *
30
     * @throws \SimpleSAML\XML\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, 'KeyInfo', InvalidDOMElementException::class);
36
        Assert::same($xml->namespaceURI, KeyInfo::NS, InvalidDOMElementException::class);
37
38
        $Id = self::getOptionalAttribute($xml, 'Id', null);
39
40
        $keyName = KeyName::getChildrenOfClass($xml);
41
        $keyValue = KeyValue::getChildrenOfClass($xml);
42
        $retrievalMethod = RetrievalMethod::getChildrenOfClass($xml);
43
        $x509Data = X509Data::getChildrenOfClass($xml);
44
        $pgpData = PGPData::getChildrenOfClass($xml);
45
        $spkiData = SPKIData::getChildrenOfClass($xml);
46
        $mgmtData = MgmtData::getChildrenOfClass($xml);
47
        $derEncodedKeyValue = DEREncodedKeyValue::getChildrenOfClass($xml);
48
        $other = self::getChildElementsFromXML($xml);
49
50
        $info = array_merge(
51
            $keyName,
52
            $keyValue,
53
            $retrievalMethod,
54
            $x509Data,
55
            $pgpData,
56
            $spkiData,
57
            $mgmtData,
58
            $derEncodedKeyValue,
59
            $other,
60
        );
61
62
        return new static($info, $Id);
63
    }
64
}
65