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