|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace SimpleSAML\XMLSecurity\XML\xenc; |
|
6
|
|
|
|
|
7
|
|
|
use DOMElement; |
|
8
|
|
|
use SimpleSAML\XML\Constants as C; |
|
9
|
|
|
use SimpleSAML\XML\ExtendableAttributesTrait; |
|
10
|
|
|
use SimpleSAML\XML\ExtendableElementTrait; |
|
11
|
|
|
use SimpleSAML\XML\SchemaValidatableElementInterface; |
|
12
|
|
|
use SimpleSAML\XML\SchemaValidatableElementTrait; |
|
13
|
|
|
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException; |
|
14
|
|
|
use SimpleSAML\XMLSchema\Exception\MissingElementException; |
|
15
|
|
|
use SimpleSAML\XMLSchema\Type\AnyURIValue; |
|
16
|
|
|
use SimpleSAML\XMLSchema\Type\IDValue; |
|
17
|
|
|
use SimpleSAML\XMLSchema\XML\Constants\NS; |
|
18
|
|
|
use SimpleSAML\XMLSecurity\Assert\Assert; |
|
19
|
|
|
|
|
20
|
|
|
use function strval; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Class representing <xenc:EncryptionPropertyType>. |
|
24
|
|
|
* |
|
25
|
|
|
* @package simplesamlphp/xml-security |
|
26
|
|
|
*/ |
|
27
|
|
|
abstract class AbstractEncryptionPropertyType extends AbstractXencElement implements |
|
28
|
|
|
SchemaValidatableElementInterface |
|
29
|
|
|
{ |
|
30
|
|
|
use ExtendableAttributesTrait; |
|
|
|
|
|
|
31
|
|
|
use ExtendableElementTrait; |
|
32
|
|
|
use SchemaValidatableElementTrait; |
|
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
/** The namespace-attribute for the xs:anyAttribute element */ |
|
36
|
|
|
public const XS_ANY_ATTR_NAMESPACE = [C::NS_XML]; |
|
37
|
|
|
|
|
38
|
|
|
/** The namespace-attribute for the xs:any element */ |
|
39
|
|
|
public const XS_ANY_ELT_NAMESPACE = NS::OTHER; |
|
40
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* EncryptionProperty constructor. |
|
44
|
|
|
* |
|
45
|
|
|
* @param \SimpleSAML\XML\SerializableElementInterface[] $children |
|
46
|
|
|
* @param \SimpleSAML\XMLSchema\Type\AnyURIValue|null $Target |
|
47
|
|
|
* @param \SimpleSAML\XMLSchema\Type\IDValue|null $Id |
|
48
|
|
|
* @param \SimpleSAML\XML\Attribute[] $namespacedAttributes |
|
49
|
|
|
*/ |
|
50
|
|
|
final public function __construct( |
|
51
|
|
|
array $children, |
|
52
|
|
|
protected ?AnyURIValue $Target = null, |
|
53
|
|
|
protected ?IDValue $Id = null, |
|
54
|
|
|
array $namespacedAttributes = [], |
|
55
|
|
|
) { |
|
56
|
|
|
Assert::minCount($children, 1, MissingElementException::class); |
|
57
|
|
|
|
|
58
|
|
|
$this->setElements($children); |
|
59
|
|
|
$this->setAttributesNS($namespacedAttributes); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Get the value of the $Target property. |
|
65
|
|
|
* |
|
66
|
|
|
* @return \SimpleSAML\XMLSchema\Type\AnyURIValue|null |
|
67
|
|
|
*/ |
|
68
|
|
|
public function getTarget(): ?AnyURIValue |
|
69
|
|
|
{ |
|
70
|
|
|
return $this->Target; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Get the value of the $Id property. |
|
76
|
|
|
* |
|
77
|
|
|
* @return \SimpleSAML\XMLSchema\Type\IDValue |
|
78
|
|
|
*/ |
|
79
|
|
|
public function getId(): ?IDValue |
|
80
|
|
|
{ |
|
81
|
|
|
return $this->Id; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @inheritDoc |
|
87
|
|
|
* |
|
88
|
|
|
* @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException |
|
89
|
|
|
* If the qualified name of the supplied element is wrong |
|
90
|
|
|
*/ |
|
91
|
|
|
public static function fromXML(DOMElement $xml): static |
|
92
|
|
|
{ |
|
93
|
|
|
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); |
|
94
|
|
|
Assert::same($xml->namespaceURI, static::getNamespaceURI(), InvalidDOMElementException::class); |
|
95
|
|
|
|
|
96
|
|
|
return new static( |
|
97
|
|
|
self::getChildElementsFromXML($xml), |
|
98
|
|
|
self::getOptionalAttribute($xml, 'Target', AnyURIValue::class, null), |
|
99
|
|
|
self::getOptionalAttribute($xml, 'Id', IDValue::class, null), |
|
100
|
|
|
self::getAttributesNSFromXML($xml), |
|
101
|
|
|
); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @inheritDoc |
|
107
|
|
|
*/ |
|
108
|
|
|
public function toXML(?DOMElement $parent = null): DOMElement |
|
109
|
|
|
{ |
|
110
|
|
|
$e = $this->instantiateParentElement($parent); |
|
111
|
|
|
|
|
112
|
|
|
if ($this->getTarget() !== null) { |
|
113
|
|
|
$e->setAttribute('Target', strval($this->getTarget())); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
if ($this->getId() !== null) { |
|
117
|
|
|
$e->setAttribute('Id', strval($this->getId())); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
foreach ($this->getAttributesNS() as $attr) { |
|
121
|
|
|
$attr->toXML($e); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
foreach ($this->getElements() as $child) { |
|
125
|
|
|
if (!$child->isEmptyElement()) { |
|
126
|
|
|
$child->toXML($e); |
|
127
|
|
|
} |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
return $e; |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
|