OriginatorKeyInfo   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 24
dl 0
loc 46
rs 10
c 1
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A fromXML() 0 28 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XMLSecurity\XML\xenc;
6
7
use DOMElement;
8
use SimpleSAML\Assert\Assert;
9
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
10
use SimpleSAML\XMLSchema\Type\IDValue;
11
use SimpleSAML\XMLSecurity\Constants as C;
12
use SimpleSAML\XMLSecurity\XML\ds\AbstractKeyInfoType;
13
use SimpleSAML\XMLSecurity\XML\ds\KeyName;
14
use SimpleSAML\XMLSecurity\XML\ds\KeyValue;
15
use SimpleSAML\XMLSecurity\XML\ds\MgmtData;
16
use SimpleSAML\XMLSecurity\XML\ds\PGPData;
17
use SimpleSAML\XMLSecurity\XML\ds\RetrievalMethod;
18
use SimpleSAML\XMLSecurity\XML\ds\SPKIData;
19
use SimpleSAML\XMLSecurity\XML\ds\X509Data;
20
21
use function array_merge;
22
23
/**
24
 * Class representing a xenc:OriginatorKeyInfo element.
25
 *
26
 * @package simplesamlphp/xml-security
27
 */
28
final class OriginatorKeyInfo extends AbstractKeyInfoType
29
{
30
    /** @var string */
31
    public const NS = C::NS_XENC;
32
33
    /** @var string */
34
    public const NS_PREFIX = 'xenc';
35
36
37
    /**
38
     * Convert XML into a OriginatorKeyInfo
39
     *
40
     * @param \DOMElement $xml The XML element we should load
41
     * @return static
42
     *
43
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
44
     *   If the qualified name of the supplied element is wrong
45
     */
46
    public static function fromXML(DOMElement $xml): static
47
    {
48
        Assert::same($xml->localName, 'OriginatorKeyInfo', InvalidDOMElementException::class);
49
        Assert::same($xml->namespaceURI, OriginatorKeyInfo::NS, InvalidDOMElementException::class);
50
51
        $keyName = KeyName::getChildrenOfClass($xml);
52
        $keyValue = KeyValue::getChildrenOfClass($xml);
53
        $retrievalMethod = RetrievalMethod::getChildrenOfClass($xml);
54
        $x509Data = X509Data::getChildrenOfClass($xml);
55
        $pgpData = PGPData::getChildrenOfClass($xml);
56
        $spkiData = SPKIData::getChildrenOfClass($xml);
57
        $mgmtData = MgmtData::getChildrenOfClass($xml);
58
        $other = self::getChildElementsFromXML($xml);
59
60
        $info = array_merge(
61
            $keyName,
62
            $keyValue,
63
            $retrievalMethod,
64
            $x509Data,
65
            $pgpData,
66
            $spkiData,
67
            $mgmtData,
68
            $other,
69
        );
70
71
        return new static(
72
            $info,
73
            self::getOptionalAttribute($xml, 'Id', IDValue::class, null),
74
        );
75
    }
76
}
77