AbstractConcatKDFParamsType::getPartyVInfo()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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