1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\XMLSecurity\XML\ds; |
6
|
|
|
|
7
|
|
|
use DOMElement; |
8
|
|
|
use SimpleSAML\Assert\Assert; |
9
|
|
|
use SimpleSAML\XML\Exception\InvalidDOMElementException; |
10
|
|
|
use SimpleSAML\XML\XMLBase64ElementTrait; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class representing a ds:SignatureValue element. |
14
|
|
|
* |
15
|
|
|
* @package simplesaml/xml-security |
16
|
|
|
*/ |
17
|
|
|
final class SignatureValue extends AbstractDsElement |
18
|
|
|
{ |
19
|
|
|
use XMLBase64ElementTrait; |
|
|
|
|
20
|
|
|
|
21
|
|
|
/** @var string|null */ |
22
|
|
|
protected ?string $Id; |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param string $content |
27
|
|
|
* @param string|null $id |
28
|
|
|
*/ |
29
|
|
|
public function __construct(string $content, ?string $id = null) |
30
|
|
|
{ |
31
|
|
|
$this->setContent($content); |
32
|
|
|
$this->setId($id); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Get the Id used for this signature value. |
38
|
|
|
* |
39
|
|
|
* @return string|null |
40
|
|
|
*/ |
41
|
|
|
public function getId(): ?string |
42
|
|
|
{ |
43
|
|
|
return $this->Id; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Set the Id used for this signature value. |
49
|
|
|
* |
50
|
|
|
* @param string|null $Id |
51
|
|
|
*/ |
52
|
|
|
protected function setId(?string $Id): void |
53
|
|
|
{ |
54
|
|
|
Assert::nullOrValidNCName($Id); |
55
|
|
|
$this->Id = $Id; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Convert XML into a SignatureValue element |
61
|
|
|
* |
62
|
|
|
* @param \DOMElement $xml |
63
|
|
|
* @return \SimpleSAML\XML\AbstractXMLElement |
64
|
|
|
* |
65
|
|
|
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException |
66
|
|
|
* If the qualified name of the supplied element is wrong |
67
|
|
|
*/ |
68
|
|
|
public static function fromXML(DOMElement $xml): self |
69
|
|
|
{ |
70
|
|
|
Assert::same($xml->localName, 'SignatureValue', InvalidDOMElementException::class); |
71
|
|
|
Assert::same($xml->namespaceURI, SignatureValue::NS, InvalidDOMElementException::class); |
72
|
|
|
|
73
|
|
|
$Id = self::getAttribute($xml, 'Id', null); |
74
|
|
|
|
75
|
|
|
return new self($xml->textContent, $Id); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Convert this SignatureValue element to XML. |
81
|
|
|
* |
82
|
|
|
* @param \DOMElement|null $parent The element we should append this SignatureValue element to. |
83
|
|
|
* @return \DOMElement |
84
|
|
|
*/ |
85
|
|
|
public function toXML(DOMElement $parent = null): DOMElement |
86
|
|
|
{ |
87
|
|
|
$e = $this->instantiateParentElement($parent); |
88
|
|
|
$e->textContent = $this->getContent(); |
89
|
|
|
|
90
|
|
|
if ($this->Id !== null) { |
91
|
|
|
$e->setAttribute('Id', $this->Id); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
return $e; |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|