1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\XMLSecurity\XML; |
6
|
|
|
|
7
|
|
|
use DOMElement; |
8
|
|
|
use SimpleSAML\XMLSecurity\XML\ds\Signature; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Abstract class to be implemented by all signed classes |
12
|
|
|
* |
13
|
|
|
* @package simplesamlphp/xml-security |
14
|
|
|
*/ |
15
|
|
|
abstract class AbstractSignedXMLElement implements SignedElementInterface |
16
|
|
|
{ |
17
|
|
|
use SignedElementTrait; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* The signed DOM structure. |
21
|
|
|
* |
22
|
|
|
* @var \DOMElement |
23
|
|
|
*/ |
24
|
|
|
protected DOMElement $structure; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* The unsigned elelement. |
28
|
|
|
* |
29
|
|
|
* @var \SimpleSAML\XMLSecurity\XML\SignableElementInterface |
30
|
|
|
*/ |
31
|
|
|
protected SignableElementInterface $element; |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Create/parse an alg:SigningMethod element. |
36
|
|
|
* |
37
|
|
|
* @param \DOMElement $xml |
38
|
|
|
* @param \SimpleSAML\XMLSecurity\XML\SignableElementInterface $elt |
39
|
|
|
* @param \SimpleSAML\XMLSecurity\XML\ds\Signature $signature |
40
|
|
|
*/ |
41
|
|
|
protected function __construct(DOMElement $xml, SignableElementInterface $elt, Signature $signature) |
42
|
|
|
{ |
43
|
|
|
$this->setStructure($xml); |
44
|
|
|
$this->setElement($elt); |
45
|
|
|
$this->setSignature($signature); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Output the class as an XML-formatted string |
51
|
|
|
* |
52
|
|
|
* @return string |
53
|
|
|
public function __toString(): string |
54
|
|
|
{ |
55
|
|
|
return $this->structure->ownerDocument->saveXML(); |
56
|
|
|
$xml = $this->toXML(); |
57
|
|
|
// @psalm-var \DOMDocument $xml->ownerDocument |
58
|
|
|
$xml->ownerDocument->formatOutput = true; |
59
|
|
|
return $xml->ownerDocument->saveXML($xml); |
60
|
|
|
} |
61
|
|
|
*/ |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Collect the value of the unsigned element |
66
|
|
|
* |
67
|
|
|
* @return \SimpleSAML\XMLSecurity\XML\SignableElementInterface |
68
|
|
|
*/ |
69
|
|
|
public function getElement(): SignableElementInterface |
70
|
|
|
{ |
71
|
|
|
return $this->element; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Set the value of the elment-property |
77
|
|
|
* |
78
|
|
|
* @param \SimpleSAML\XMLSecurity\XML\SignableElementInterface $elt |
79
|
|
|
*/ |
80
|
|
|
private function setElement(SignableElementInterface $elt): void |
81
|
|
|
{ |
82
|
|
|
$this->element = $elt; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Collect the value of the structure-property |
88
|
|
|
* |
89
|
|
|
* @return \DOMElement |
90
|
|
|
*/ |
91
|
|
|
public function getStructure(): DOMElement |
92
|
|
|
{ |
93
|
|
|
return $this->structure; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Set the value of the structure-property |
99
|
|
|
* |
100
|
|
|
* @param \DOMElement $structure |
101
|
|
|
*/ |
102
|
|
|
private function setStructure(DOMElement $structure): void |
103
|
|
|
{ |
104
|
|
|
$this->structure = $structure; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Create XML from this class |
110
|
|
|
* |
111
|
|
|
* @param \DOMElement|null $parent |
112
|
|
|
* @return \DOMElement |
113
|
|
|
*/ |
114
|
|
|
public function toXML(DOMElement $parent = null): DOMElement |
|
|
|
|
115
|
|
|
{ |
116
|
|
|
return $this->structure; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Create a class from XML |
122
|
|
|
* |
123
|
|
|
* @param \DOMElement $xml |
124
|
|
|
* @return self |
125
|
|
|
*/ |
126
|
|
|
abstract public static function fromXML(DOMElement $xml): object; |
127
|
|
|
} |
128
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.