Passed
Push — master ( 2d3781...f48916 )
by Tim
11:07 queued 06:44
created

AbstractConcatKDFParamsType   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 150
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 36
c 1
b 0
f 0
dl 0
loc 150
rs 10
wmc 14

9 Methods

Rating   Name   Duplication   Size   Complexity  
A getPartyUInfo() 0 3 1
A getSuppPrivInfo() 0 3 1
A fromXML() 0 16 1
A toXML() 0 27 6
A __construct() 0 13 1
A getAlgorithmID() 0 3 1
A getDigestMethod() 0 3 1
A getPartyVInfo() 0 3 1
A getSuppPubInfo() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XMLSecurity\XML\xenc11;
6
7
use DOMElement;
8
use SimpleSAML\Assert\Assert;
9
use SimpleSAML\XML\Exception\InvalidDOMElementException;
10
use SimpleSAML\XML\Exception\MissingElementException;
11
use SimpleSAML\XML\Exception\SchemaViolationException;
12
use SimpleSAML\XML\Exception\TooManyElementsException;
13
use SimpleSAML\XMLSecurity\XML\ds\DigestMethod;
14
15
use function array_pop;
16
17
/**
18
 * Class representing <xenc11:ConcatKDFParamsType>.
19
 *
20
 * @package simplesamlphp/xml-security
21
 */
22
abstract class AbstractConcatKDFParamsType extends AbstractXenc11Element
23
{
24
    /**
25
     * ConcatKDFParams constructor.
26
     *
27
     * @param \SimpleSAML\XMLSecurity\XML\ds\DigestMethod $digestMethod
28
     * @param string|null $AlgorithmID
29
     * @param string|null $PartyUInfo
30
     * @param string|null $PartyVInfo
31
     * @param string|null $SuppPubInfo
32
     * @param string|null $SuppPrivInfo
33
     */
34
    final public function __construct(
35
        protected DigestMethod $digestMethod,
36
        protected ?string $AlgorithmID = null,
37
        protected ?string $PartyUInfo = null,
38
        protected ?string $PartyVInfo = null,
39
        protected ?string $SuppPubInfo = null,
40
        protected ?string $SuppPrivInfo = null,
41
    ) {
42
        Assert::validHexBinary($AlgorithmID, SchemaViolationException::class);
43
        Assert::validHexBinary($PartyUInfo, SchemaViolationException::class);
44
        Assert::validHexBinary($PartyVInfo, SchemaViolationException::class);
45
        Assert::validHexBinary($SuppPubInfo, SchemaViolationException::class);
46
        Assert::validHexBinary($SuppPrivInfo, SchemaViolationException::class);
47
    }
48
49
50
    /**
51
     * Get the value of the $digestMethod property.
52
     *
53
     * @return \SimpleSAML\XMLSecurity\XML\ds\DigestMethod
54
     */
55
    public function getDigestMethod(): DigestMethod
56
    {
57
        return $this->digestMethod;
58
    }
59
60
61
    /**
62
     * Get the value of the $AlgorithmID property.
63
     *
64
     * @return string|null
65
     */
66
    public function getAlgorithmID(): ?string
67
    {
68
        return $this->AlgorithmID;
69
    }
70
71
72
    /**
73
     * Get the value of the $PartyUInfo property.
74
     *
75
     * @return string|null
76
     */
77
    public function getPartyUInfo(): ?string
78
    {
79
        return $this->PartyUInfo;
80
    }
81
82
83
    /**
84
     * Get the value of the $PartyVInfo property.
85
     *
86
     * @return string|null
87
     */
88
    public function getPartyVInfo(): ?string
89
    {
90
        return $this->PartyVInfo;
91
    }
92
93
94
    /**
95
     * Get the value of the $SuppPubInfo property.
96
     *
97
     * @return string|null
98
     */
99
    public function getSuppPubInfo(): ?string
100
    {
101
        return $this->SuppPubInfo;
102
    }
103
104
105
    /**
106
     * Get the value of the $SuppPrivInfo property.
107
     *
108
     * @return string|null
109
     */
110
    public function getSuppPrivInfo(): ?string
111
    {
112
        return $this->SuppPrivInfo;
113
    }
114
115
116
    /**
117
     * @inheritDoc
118
     *
119
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
120
     *   If the qualified name of the supplied element is wrong
121
     */
122
    public static function fromXML(DOMElement $xml): static
123
    {
124
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
125
        Assert::same($xml->namespaceURI, static::getNamespaceURI(), InvalidDOMElementException::class);
126
127
        $digestMethod = DigestMethod::getChildrenOfClass($xml);
128
        Assert::minCount($digestMethod, 1, MissingElementException::class);
129
        Assert::maxCount($digestMethod, 1, TooManyElementsException::class);
130
131
        return new static(
132
            array_pop($digestMethod),
133
            self::getOptionalAttribute($xml, 'AlgorithmID', null),
134
            self::getOptionalAttribute($xml, 'PartyUInfo', null),
135
            self::getOptionalAttribute($xml, 'PartyVInfo', null),
136
            self::getOptionalAttribute($xml, 'SuppPubInfo', null),
137
            self::getOptionalAttribute($xml, 'SuppPrivInfo', null),
138
        );
139
    }
140
141
142
    /**
143
     * @inheritDoc
144
     */
145
    public function toXML(?DOMElement $parent = null): DOMElement
146
    {
147
        $e = $this->instantiateParentElement($parent);
148
149
        if ($this->getAlgorithmID() !== null) {
150
            $e->setAttribute('AlgorithmID', $this->getAlgorithmID());
151
        }
152
153
        if ($this->getPartyUInfo() !== null) {
154
            $e->setAttribute('PartyUInfo', $this->getPartyUInfo());
155
        }
156
157
        if ($this->getPartyVInfo() !== null) {
158
            $e->setAttribute('PartyVInfo', $this->getPartyVInfo());
159
        }
160
161
        if ($this->getSuppPubInfo() !== null) {
162
            $e->setAttribute('SuppPubInfo', $this->getSuppPubInfo());
163
        }
164
165
        if ($this->getSuppPrivInfo() !== null) {
166
            $e->setAttribute('SuppPrivInfo', $this->getSuppPrivInfo());
167
        }
168
169
        $this->getDigestMethod()->toXML($e);
170
171
        return $e;
172
    }
173
}
174