Issues (311)

src/XML/ds/RSAKeyValue.php (3 issues)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XMLSecurity\XML\ds;
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
/**
16
 * Class representing a ds:RSAKeyValue element.
17
 *
18
 * @package simplesamlphp/xml-security
19
 */
20
final class RSAKeyValue extends AbstractDsElement implements SchemaValidatableElementInterface
0 ignored issues
show
The type SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
21
{
22
    use SchemaValidatableElementTrait;
23
24
25
    /**
26
     * Initialize an RSAKeyValue.
27
     *
28
     * @param \SimpleSAML\XMLSecurity\XML\ds\Modulus $modulus
29
     * @param \SimpleSAML\XMLSecurity\XML\ds\Exponent $exponent
30
     */
31
    final public function __construct(
32
        protected Modulus $modulus,
0 ignored issues
show
The type SimpleSAML\XMLSecurity\XML\ds\Modulus was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
33
        protected Exponent $exponent,
0 ignored issues
show
The type SimpleSAML\XMLSecurity\XML\ds\Exponent was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
34
    ) {
35
    }
36
37
38
    /**
39
     * Collect the value of the modulus-property
40
     *
41
     * @return \SimpleSAML\XMLSecurity\XML\ds\Modulus
42
     */
43
    public function getModulus(): Modulus
44
    {
45
        return $this->modulus;
46
    }
47
48
49
    /**
50
     * Collect the value of the exponent-property
51
     *
52
     * @return \SimpleSAML\XMLSecurity\XML\ds\Exponent
53
     */
54
    public function getExponent(): Exponent
55
    {
56
        return $this->exponent;
57
    }
58
59
60
    /**
61
     * Convert XML into a RSAKeyValue
62
     *
63
     * @param \DOMElement $xml The XML element we should load
64
     *
65
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
66
     *   If the qualified name of the supplied element is wrong
67
     */
68
    public static function fromXML(DOMElement $xml): static
69
    {
70
        Assert::same($xml->localName, 'RSAKeyValue', InvalidDOMElementException::class);
71
        Assert::same($xml->namespaceURI, RSAKeyValue::NS, InvalidDOMElementException::class);
72
73
        $modulus = Modulus::getChildrenOfClass($xml);
74
        Assert::minCount(
75
            $modulus,
76
            1,
77
            'An <ds:RSAKeyValue> must contain exactly one <ds:Modulus>',
78
            MissingElementException::class,
79
        );
80
        Assert::maxCount(
81
            $modulus,
82
            1,
83
            'An <ds:RSAKeyValue> must contain exactly one <ds:Modulus>',
84
            TooManyElementsException::class,
85
        );
86
87
        $exponent = Exponent::getChildrenOfClass($xml);
88
        Assert::minCount(
89
            $exponent,
90
            1,
91
            'An <ds:RSAKeyValue> must contain exactly one <ds:Modulus>',
92
            MissingElementException::class,
93
        );
94
        Assert::maxCount(
95
            $exponent,
96
            1,
97
            'An <ds:RSAKeyValue> must contain exactly one <ds:Modulus>',
98
            TooManyElementsException::class,
99
        );
100
101
        return new static(array_pop($modulus), array_pop($exponent));
102
    }
103
104
105
    /**
106
     * Convert this RSAKeyValue element to XML.
107
     *
108
     * @param \DOMElement|null $parent The element we should append this RSAKeyValue element to.
109
     */
110
    public function toXML(?DOMElement $parent = null): DOMElement
111
    {
112
        $e = $this->instantiateParentElement($parent);
113
114
        $this->getModulus()->toXML($e);
115
        $this->getExponent()->toXML($e);
116
117
        return $e;
118
    }
119
}
120