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