1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\XMLSecurity\XML\xenc; |
6
|
|
|
|
7
|
|
|
use DOMElement; |
8
|
|
|
use SimpleSAML\Assert\Assert; |
9
|
|
|
use SimpleSAML\XML\Exception\InvalidDOMElementException; |
10
|
|
|
use SimpleSAML\XML\Exception\MissingElementException; |
11
|
|
|
use SimpleSAML\XML\Exception\SchemaViolationException; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class representing <xenc:EncryptionPropertiesType>. |
15
|
|
|
* |
16
|
|
|
* @package simplesamlphp/xml-security |
17
|
|
|
*/ |
18
|
|
|
abstract class AbstractEncryptionPropertiesType extends AbstractXencElement |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* EncryptionProperty constructor. |
22
|
|
|
* |
23
|
|
|
* @param \SimpleSAML\XML\EncryptionProperty[] $encryptionProperty |
24
|
|
|
* @param string|null $Id |
25
|
|
|
*/ |
26
|
|
|
final public function __construct( |
27
|
|
|
protected array $encryptionProperty, |
28
|
|
|
protected ?string $Id = null, |
29
|
|
|
) { |
30
|
|
|
Assert::minCount($encryptionProperty, 1, MissingElementException::class); |
31
|
|
|
Assert::nullOrValidNCName($Id, SchemaViolationException::class); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Get the value of the $encryptionProperty property. |
37
|
|
|
* |
38
|
|
|
* @return \SimpleSAML\XML\EncryptionProperty[] |
39
|
|
|
*/ |
40
|
|
|
public function getEncryptionProperty(): array |
41
|
|
|
{ |
42
|
|
|
return $this->encryptionProperty; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Get the value of the $Id property. |
48
|
|
|
* |
49
|
|
|
* @return string|null |
50
|
|
|
*/ |
51
|
|
|
public function getId(): ?string |
52
|
|
|
{ |
53
|
|
|
return $this->Id; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @inheritDoc |
59
|
|
|
* |
60
|
|
|
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException |
61
|
|
|
* If the qualified name of the supplied element is wrong |
62
|
|
|
*/ |
63
|
|
|
public static function fromXML(DOMElement $xml): static |
64
|
|
|
{ |
65
|
|
|
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); |
66
|
|
|
Assert::same($xml->namespaceURI, static::getNamespaceURI(), InvalidDOMElementException::class); |
67
|
|
|
|
68
|
|
|
return new static( |
69
|
|
|
EncryptionProperty::getChildrenOfClass($xml), |
70
|
|
|
self::getOptionalAttribute($xml, 'Id', null), |
71
|
|
|
); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @inheritDoc |
77
|
|
|
*/ |
78
|
|
|
public function toXML(DOMElement $parent = null): DOMElement |
79
|
|
|
{ |
80
|
|
|
$e = $this->instantiateParentElement($parent); |
81
|
|
|
|
82
|
|
|
foreach ($this->getEncryptionProperty() as $ep) { |
83
|
|
|
$ep->toXML($e); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
if ($this->getId() !== null) { |
87
|
|
|
$e->setAttribute('Id', $this->getId()); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
return $e; |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|