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