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