1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\WSSecurity\XML\auth; |
6
|
|
|
|
7
|
|
|
use DOMElement; |
8
|
|
|
use SimpleSAML\WSSecurity\Assert\Assert; |
9
|
|
|
use SimpleSAML\XML\Exception\InvalidDOMElementException; |
10
|
|
|
use SimpleSAML\XML\Exception\MissingElementException; |
11
|
|
|
use SimpleSAML\XML\Exception\SchemaViolationException; |
12
|
|
|
use SimpleSAML\XML\Exception\TooManyElementsException; |
13
|
|
|
use SimpleSAML\XMLSecurity\XML\xenc\EncryptedData; |
14
|
|
|
|
15
|
|
|
use function array_pop; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class representing WS-authorization EncryptedValueType. |
19
|
|
|
* |
20
|
|
|
* @package simplesamlphp/ws-security |
21
|
|
|
*/ |
22
|
|
|
abstract class AbstractEncryptedValueType extends AbstractAuthElement |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* AbstractEncryptedValueType constructor. |
26
|
|
|
* |
27
|
|
|
* @param \SimpleSAML\XMLSecurity\XML\xenc\EncryptedData $encryptedData |
28
|
|
|
* @param string|null $descriptionCondition |
29
|
|
|
*/ |
30
|
|
|
final public function __construct( |
31
|
|
|
protected EncryptedData $encryptedData, |
32
|
|
|
protected ?string $descriptionCondition = null, |
33
|
|
|
) { |
34
|
|
|
Assert::nullOrValidURI($descriptionCondition, SchemaViolationException::class); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Get the value of the $descriptionCondition property. |
40
|
|
|
* |
41
|
|
|
* @return string|null |
42
|
|
|
*/ |
43
|
|
|
public function getDescriptionCondition(): ?string |
44
|
|
|
{ |
45
|
|
|
return $this->descriptionCondition; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Get the value of the $encryptedData property. |
51
|
|
|
* |
52
|
|
|
* @return \SimpleSAML\XMLSecurity\XML\xenc\EncryptedData |
53
|
|
|
*/ |
54
|
|
|
public function getEncryptedData(): EncryptedData |
55
|
|
|
{ |
56
|
|
|
return $this->encryptedData; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Convert XML into a class instance |
62
|
|
|
* |
63
|
|
|
* @param \DOMElement $xml The XML element we should load |
64
|
|
|
* @return static |
65
|
|
|
* |
66
|
|
|
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException |
67
|
|
|
* If the qualified name of the supplied element is wrong |
68
|
|
|
*/ |
69
|
|
|
public static function fromXML(DOMElement $xml): static |
70
|
|
|
{ |
71
|
|
|
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); |
72
|
|
|
Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); |
73
|
|
|
|
74
|
|
|
$encryptedData = EncryptedData::getChildrenOfClass($xml); |
75
|
|
|
Assert::minCount($encryptedData, 1, MissingElementException::class); |
76
|
|
|
Assert::maxCount($encryptedData, 1, TooManyElementsException::class); |
77
|
|
|
|
78
|
|
|
return new static( |
79
|
|
|
array_pop($encryptedData), |
80
|
|
|
self::getOptionalAttribute($xml, 'DescriptionCondition', null), |
81
|
|
|
); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Convert this element to XML. |
87
|
|
|
* |
88
|
|
|
* @param \DOMElement|null $parent The element we should append this element to. |
89
|
|
|
* @return \DOMElement |
90
|
|
|
*/ |
91
|
|
|
public function toXML(?DOMElement $parent = null): DOMElement |
92
|
|
|
{ |
93
|
|
|
$e = $this->instantiateParentElement($parent); |
94
|
|
|
$e->setAttribute('DescriptionCondition', $this->getDescriptionCondition()); |
95
|
|
|
|
96
|
|
|
$this->getEncryptedData()->toXML($e); |
97
|
|
|
|
98
|
|
|
return $e; |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|