Passed
Push — master ( 6e1344...0156f2 )
by Tim
02:07
created

RecipientKeyInfo   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

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