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\AbstractXMLElement; |
10
|
|
|
use SimpleSAML\XML\Exception\MissingElementException; |
11
|
|
|
use SimpleSAML\XML\Exception\TooManyElementsException; |
12
|
|
|
use SimpleSAML\XMLSecurity\XML\ds\Signature; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Abstract class to be implemented by all signed classes |
16
|
|
|
* |
17
|
|
|
* @package simplesamlphp/xml-security |
18
|
|
|
*/ |
19
|
|
|
abstract class AbstractSignedXMLElement extends AbstractXMLElement implements SignedElementInterface |
20
|
|
|
{ |
21
|
|
|
use SignedElementTrait; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* The signed DOM structure. |
25
|
|
|
* |
26
|
|
|
* @var \DOMElement |
27
|
|
|
*/ |
28
|
|
|
protected DOMElement $structure; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* The unsigned elelement. |
32
|
|
|
* |
33
|
|
|
* @var \SimpleSAML\XMLSecurity\XML\SignableElementInterface |
34
|
|
|
*/ |
35
|
|
|
protected SignableElementInterface $element; |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Create/parse an alg:SigningMethod element. |
40
|
|
|
* |
41
|
|
|
* @param \DOMElement $xml |
42
|
|
|
* @param \SimpleSAML\XMLSecurity\XML\ds\Signature $signature |
43
|
|
|
*/ |
44
|
|
|
public function __construct(DOMElement $xml, Signature $signature) |
45
|
|
|
{ |
46
|
|
|
$this->setStructure($xml); |
47
|
|
|
$this->setSignature($signature); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Output the class as an XML-formatted string |
53
|
|
|
* |
54
|
|
|
* @return string |
55
|
|
|
*/ |
56
|
|
|
public function __toString(): string |
57
|
|
|
{ |
58
|
|
|
return $this->structure->ownerDocument->saveXML(); |
|
|
|
|
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Set the value of the structure-property |
64
|
|
|
* |
65
|
|
|
* @param \DOMElement $structure |
66
|
|
|
*/ |
67
|
|
|
private function setStructure(DOMElement $structure): void |
68
|
|
|
{ |
69
|
|
|
$this->structure = $structure; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Create XML from this class |
75
|
|
|
* |
76
|
|
|
* @param \DOMElement|null $parent |
77
|
|
|
* @return \DOMElement |
78
|
|
|
*/ |
79
|
|
|
public function toXML(DOMElement $parent = null): DOMElement |
80
|
|
|
{ |
81
|
|
|
return $this->structure; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Create a class from XML |
87
|
|
|
* |
88
|
|
|
* @param \DOMElement $xml |
89
|
|
|
* @return self |
90
|
|
|
*/ |
91
|
|
|
public static function fromXML(DOMElement $xml): object |
92
|
|
|
{ |
93
|
|
|
$original = $xml->ownerDocument->cloneNode(true); |
|
|
|
|
94
|
|
|
|
95
|
|
|
$signature = Signature::getChildrenOfClass($xml); |
96
|
|
|
Assert::minCount($signature, 1, MissingElementException::class); |
97
|
|
|
Assert::maxCount($signature, 1, TooManyElementsException::class); |
98
|
|
|
|
99
|
|
|
return new static($original->documentElement, array_pop($signature)); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
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.