1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\XMLSecurity\XML; |
6
|
|
|
|
7
|
|
|
use DOMElement; |
8
|
|
|
use SimpleSAML\Assert\Assert; |
9
|
|
|
use SimpleSAML\XML\Exception\MissingElementException; |
10
|
|
|
use SimpleSAML\XML\Exception\TooManyElementsException; |
11
|
|
|
use SimpleSAML\XMLSecurity\XML\ds\Signature; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Abstract class to be implemented by all signed classes |
15
|
|
|
* |
16
|
|
|
* @package simplesamlphp/xml-security |
17
|
|
|
*/ |
18
|
|
|
abstract class AbstractSignedXMLElement implements SignedElementInterface |
19
|
|
|
{ |
20
|
|
|
use SignedElementTrait; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* The signed DOM structure. |
24
|
|
|
* |
25
|
|
|
* @var \DOMElement |
26
|
|
|
*/ |
27
|
|
|
protected DOMElement $structure; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* The unsigned elelement. |
31
|
|
|
* |
32
|
|
|
* @var \SimpleSAML\XMLSecurity\XML\SignableElementInterface |
33
|
|
|
*/ |
34
|
|
|
protected SignableElementInterface $element; |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Create/parse an alg:SigningMethod element. |
39
|
|
|
* |
40
|
|
|
* @param \DOMElement $xml |
41
|
|
|
* @param \SimpleSAML\XMLSecurity\XML\ds\Signature $signature |
42
|
|
|
*/ |
43
|
|
|
protected function __construct(DOMElement $xml, Signature $signature) |
44
|
|
|
{ |
45
|
|
|
$this->setStructure($xml); |
46
|
|
|
$this->setSignature($signature); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Output the class as an XML-formatted string |
52
|
|
|
* |
53
|
|
|
* @return string |
54
|
|
|
*/ |
55
|
|
|
public function __toString(): string |
56
|
|
|
{ |
57
|
|
|
return $this->structure->ownerDocument->saveXML(); |
|
|
|
|
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Collect the value of the structure-property |
63
|
|
|
* |
64
|
|
|
* @return \DOMElement |
65
|
|
|
*/ |
66
|
|
|
public function getStructure(): DOMElement |
67
|
|
|
{ |
68
|
|
|
return $this->structure; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Set the value of the structure-property |
74
|
|
|
* |
75
|
|
|
* @param \DOMElement $structure |
76
|
|
|
*/ |
77
|
|
|
private function setStructure(DOMElement $structure): void |
78
|
|
|
{ |
79
|
|
|
$this->structure = $structure; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Create XML from this class |
85
|
|
|
* |
86
|
|
|
* @param \DOMElement|null $parent |
87
|
|
|
* @return \DOMElement |
88
|
|
|
*/ |
89
|
|
|
public function toXML(DOMElement $parent = null): DOMElement |
|
|
|
|
90
|
|
|
{ |
91
|
|
|
return $this->structure; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Create a class from XML |
97
|
|
|
* |
98
|
|
|
* @param \DOMElement $xml |
99
|
|
|
* @return self |
100
|
|
|
*/ |
101
|
|
|
public static function fromXML(DOMElement $xml): object |
102
|
|
|
{ |
103
|
|
|
$signature = Signature::getChildrenOfClass($xml); |
104
|
|
|
Assert::minCount($signature, 1, MissingElementException::class); |
105
|
|
|
Assert::maxCount($signature, 1, TooManyElementsException::class); |
106
|
|
|
|
107
|
|
|
return new self($xml, array_pop($signature)); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.