AbstractConcatKDFParamsType   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 148
Duplicated Lines 0 %

Importance

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