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