AbstractPBKDF2ParameterType   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 115
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 30
c 1
b 0
f 0
dl 0
loc 115
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getKeyLength() 0 3 1
A getPRF() 0 3 1
A getIterationCount() 0 3 1
A getSalt() 0 3 1
A toXML() 0 10 1
A __construct() 0 6 1
A fromXML() 0 26 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\SchemaValidatableElementInterface;
10
use SimpleSAML\XML\SchemaValidatableElementTrait;
11
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
12
use SimpleSAML\XMLSchema\Exception\MissingElementException;
13
use SimpleSAML\XMLSchema\Exception\TooManyElementsException;
14
15
use function array_pop;
16
17
/**
18
 * Class representing <xenc11:PBKDF2ParameterType>.
19
 *
20
 * @package simplesamlphp/xml-security
21
 */
22
abstract class AbstractPBKDF2ParameterType extends AbstractXenc11Element implements SchemaValidatableElementInterface
23
{
24
    use SchemaValidatableElementTrait;
0 ignored issues
show
introduced by
The trait SimpleSAML\XML\SchemaValidatableElementTrait requires some properties which are not provided by SimpleSAML\XMLSecurity\X...ractPBKDF2ParameterType: $message, $line
Loading history...
25
26
27
    /**
28
     * PBKDF2ParameterType constructor.
29
     *
30
     * @param \SimpleSAML\XMLSecurity\XML\xenc11\Salt $salt
31
     * @param \SimpleSAML\XMLSecurity\XML\xenc11\IterationCount $iterationCount
32
     * @param \SimpleSAML\XMLSecurity\XML\xenc11\KeyLength $keyLength
33
     * @param \SimpleSAML\XMLSecurity\XML\xenc11\PRF $prf
34
     */
35
    final public function __construct(
36
        protected Salt $salt,
37
        protected IterationCount $iterationCount,
38
        protected KeyLength $keyLength,
39
        protected PRF $prf,
40
    ) {
41
    }
42
43
44
    /**
45
     * Get the value of the $salt property.
46
     *
47
     * @return \SimpleSAML\XMLSecurity\XML\xenc11\Salt
48
     */
49
    public function getSalt(): Salt
50
    {
51
        return $this->salt;
52
    }
53
54
55
    /**
56
     * Get the value of the $iterationCount property.
57
     *
58
     * @return \SimpleSAML\XMLSecurity\XML\xenc11\IterationCount
59
     */
60
    public function getIterationCount(): IterationCount
61
    {
62
        return $this->iterationCount;
63
    }
64
65
66
    /**
67
     * Get the value of the $keyLength property.
68
     *
69
     * @return \SimpleSAML\XMLSecurity\XML\xenc11\KeyLength
70
     */
71
    public function getKeyLength(): KeyLength
72
    {
73
        return $this->keyLength;
74
    }
75
76
77
    /**
78
     * Get the value of the $prf property.
79
     *
80
     * @return \SimpleSAML\XMLSecurity\XML\xenc11\PRF
81
     */
82
    public function getPRF(): PRF
83
    {
84
        return $this->prf;
85
    }
86
87
88
    /**
89
     * @inheritDoc
90
     *
91
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
92
     *   If the qualified name of the supplied element is wrong
93
     */
94
    public static function fromXML(DOMElement $xml): static
95
    {
96
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
97
        Assert::same($xml->namespaceURI, static::getNamespaceURI(), InvalidDOMElementException::class);
98
99
        $salt = Salt::getChildrenOfClass($xml);
100
        Assert::minCount($salt, 1, MissingElementException::class);
101
        Assert::maxCount($salt, 1, TooManyElementsException::class);
102
103
        $iterationCount = IterationCount::getChildrenOfClass($xml);
104
        Assert::minCount($iterationCount, 1, MissingElementException::class);
105
        Assert::maxCount($iterationCount, 1, TooManyElementsException::class);
106
107
        $keyLength = KeyLength::getChildrenOfClass($xml);
108
        Assert::minCount($keyLength, 1, MissingElementException::class);
109
        Assert::maxCount($keyLength, 1, TooManyElementsException::class);
110
111
        $prf = PRF::getChildrenOfClass($xml);
112
        Assert::minCount($prf, 1, MissingElementException::class);
113
        Assert::maxCount($prf, 1, TooManyElementsException::class);
114
115
        return new static(
116
            array_pop($salt),
117
            array_pop($iterationCount),
118
            array_pop($keyLength),
119
            array_pop($prf),
120
        );
121
    }
122
123
124
    /**
125
     * @inheritDoc
126
     */
127
    public function toXML(?DOMElement $parent = null): DOMElement
128
    {
129
        $e = $this->instantiateParentElement($parent);
130
131
        $this->getSalt()->toXML($e);
132
        $this->getIterationCount()->toXML($e);
133
        $this->getKeyLength()->toXML($e);
134
        $this->getPRF()->toXML($e);
135
136
        return $e;
137
    }
138
}
139