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
|
|
|
|
11
|
|
|
debug_backtrace(); |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class representing a ds:SignatureValue element. |
15
|
|
|
* |
16
|
|
|
* @package simplesaml/xml-security |
17
|
|
|
*/ |
18
|
|
|
final class SignatureValue extends AbstractDsElement |
19
|
|
|
{ |
20
|
|
|
/** @var string */ |
21
|
|
|
protected string $value; |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Initialize a SignatureValue element. |
26
|
|
|
* |
27
|
|
|
* @param string $value |
28
|
|
|
*/ |
29
|
|
|
public function __construct(string $value) { |
30
|
|
|
$this->setValue($value); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Get the signature value. |
36
|
|
|
* |
37
|
|
|
* @return string |
38
|
|
|
*/ |
39
|
|
|
public function getValue(): string |
40
|
|
|
{ |
41
|
|
|
return $this->value; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Set the value. |
47
|
|
|
* |
48
|
|
|
* @param string $value |
49
|
|
|
*/ |
50
|
|
|
private function setValue(string $value): void |
51
|
|
|
{ |
52
|
|
|
Assert::notEmpty($value, 'SignatureValue cannot be empty'); |
53
|
|
|
Assert::stringPlausibleBase64($value, 'SignatureValue is not a valid Base64 encoded string'); |
54
|
|
|
$this->value = $value; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Convert XML into a SignatureValue |
60
|
|
|
* |
61
|
|
|
* @param DOMElement $xml The XML element we should load |
62
|
|
|
* @return self |
63
|
|
|
* |
64
|
|
|
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException If the qualified name of the supplied element is |
65
|
|
|
* wrong. |
66
|
|
|
*/ |
67
|
|
|
public static function fromXML(DOMElement $xml): object |
68
|
|
|
{ |
69
|
|
|
Assert::same($xml->localName, 'SignatureValue', InvalidDOMElementException::class); |
70
|
|
|
Assert::same($xml->namespaceURI, SignatureValue::NS, InvalidDOMElementException::class); |
71
|
|
|
|
72
|
|
|
return new self($xml->textContent); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Convert this SignatureValue to XML. |
78
|
|
|
* |
79
|
|
|
* @param DOMElement|null $parent The element we should append this SignatureValue element to. |
80
|
|
|
* @return DOMElement |
81
|
|
|
*/ |
82
|
|
|
public function toXML(DOMElement $parent = null): \DOMElement |
83
|
|
|
{ |
84
|
|
|
$e = $this->instantiateParentElement($parent); |
85
|
|
|
$e->textContent = $this->value; |
86
|
|
|
|
87
|
|
|
return $e; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|