AbstractECKeyValueType::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 1
b 0
f 0
nc 1
nop 4
dl 0
loc 12
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XMLSecurity\XML\dsig11;
6
7
use DOMElement;
8
use SimpleSAML\XML\Assert\Assert;
9
use SimpleSAML\XML\Exception\SchemaViolationException;
10
11
/**
12
 * Abstract class representing a dsig11:ECKeyValueType
13
 *
14
 * @package simplesaml/xml-security
15
 */
16
abstract class AbstractECKeyValueType extends AbstractDsig11Element
17
{
18
    /**
19
     * Initialize a FieldIDType element.
20
     *
21
     * @param \SimpleSAML\XMLSecurity\XML\dsig11\PublicKey $publicKey
22
     * @param string|null $id
23
     * @param \SimpleSAML\XMLSecurity\XML\dsig11\ECParameters|null $ecParameters
24
     * @param \SimpleSAML\XMLSecurity\XML\dsig11\NamedCurve|null $namedCurve
25
     */
26
    public function __construct(
27
        protected PublicKey $publicKey,
28
        protected ?string $id = null,
29
        protected ?ECParameters $ecParameters = null,
30
        protected ?NamedCurve $namedCurve = null,
31
    ) {
32
        Assert::validNCName($id, SchemaViolationException::class);
33
        Assert::oneOf(
34
            null,
35
            [$ecParameters, $namedCurve],
36
            'The ECParameters and NamedCurve are mutually exclusive; please specify one or the other.',
37
            SchemaViolationException::class,
38
        );
39
    }
40
41
42
    /**
43
     * Collect the value of the ecParameters-property
44
     *
45
     * @return \SimpleSAML\XMLSecurity\XML\dsig11\ECParameters|null
46
     */
47
    public function getECParameters(): ?ECParameters
48
    {
49
        return $this->ecParameters;
50
    }
51
52
53
    /**
54
     * Collect the value of the namedCurve-property
55
     *
56
     * @return \SimpleSAML\XMLSecurity\XML\dsig11\NamedCurve|null
57
     */
58
    public function getNamedCurve(): ?NamedCurve
59
    {
60
        return $this->namedCurve;
61
    }
62
63
64
    /**
65
     * Collect the value of the publicKey-property
66
     *
67
     * @return \SimpleSAML\XMLSecurity\XML\dsig11\PublicKey
68
     */
69
    public function getPublicKey(): PublicKey
70
    {
71
        return $this->publicKey;
72
    }
73
74
75
    /**
76
     * Collect the value of the id-property
77
     *
78
     * @return string|null
79
     */
80
    public function getId(): ?string
81
    {
82
        return $this->id;
83
    }
84
85
86
    /**
87
     * Convert this ECKeyValueType element to XML.
88
     *
89
     * @param \DOMElement|null $parent The element we should append this ECKeyValueType element to.
90
     * @return \DOMElement
91
     */
92
    public function toXML(?DOMElement $parent = null): DOMElement
93
    {
94
        $e = $this->instantiateParentElement($parent);
95
96
        if ($this->getId() !== null) {
97
            $e->setAttribute('Id', $this->getId());
98
        }
99
100
        $this->getECParameters()?->toXML($e);
101
        $this->getNamedCurve()?->toXML($e);
102
        $this->getPublicKey()->toXML($e);
103
104
        return $e;
105
    }
106
}
107