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