|
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\Constants as C; |
|
10
|
|
|
use SimpleSAML\XML\SchemaValidatableElementInterface; |
|
11
|
|
|
use SimpleSAML\XML\SchemaValidatableElementTrait; |
|
12
|
|
|
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException; |
|
13
|
|
|
use SimpleSAML\XMLSchema\Exception\SchemaViolationException; |
|
14
|
|
|
use SimpleSAML\XMLSchema\Type\AnyURIValue; |
|
15
|
|
|
use SimpleSAML\XMLSecurity\XML\xenc\Transforms; |
|
16
|
|
|
|
|
17
|
|
|
use function strval; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Class representing a CipherReference. |
|
21
|
|
|
* |
|
22
|
|
|
* @package simplesamlphp/xml-security |
|
23
|
|
|
*/ |
|
24
|
|
|
final class CipherReference extends AbstractXencElement implements SchemaValidatableElementInterface |
|
25
|
|
|
{ |
|
26
|
|
|
use SchemaValidatableElementTrait; |
|
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* AbstractReference constructor. |
|
31
|
|
|
* |
|
32
|
|
|
* @param \SimpleSAML\XMLSchema\Type\AnyURIValue $uri |
|
33
|
|
|
* @param \SimpleSAML\XMLSecurity\XML\xenc\Transforms[] $transforms |
|
34
|
|
|
*/ |
|
35
|
|
|
final public function __construct( |
|
36
|
|
|
protected AnyURIValue $uri, |
|
37
|
|
|
protected array $transforms = [], |
|
38
|
|
|
) { |
|
39
|
|
|
Assert::maxCount($transforms, C::UNBOUNDED_LIMIT); |
|
40
|
|
|
Assert::allIsInstanceOf($transforms, Transforms::class, SchemaViolationException::class); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Get the value of the URI attribute of this reference. |
|
46
|
|
|
* |
|
47
|
|
|
* @return \SimpleSAML\XMLSchema\Type\AnyURIValue |
|
48
|
|
|
*/ |
|
49
|
|
|
public function getURI(): AnyURIValue |
|
50
|
|
|
{ |
|
51
|
|
|
return $this->uri; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @inheritDoc |
|
57
|
|
|
* |
|
58
|
|
|
* @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException |
|
59
|
|
|
* if the qualified name of the supplied element is wrong |
|
60
|
|
|
* @throws \SimpleSAML\XMLSchema\Exception\MissingAttributeException |
|
61
|
|
|
* if the supplied element is missing one of the mandatory attributes |
|
62
|
|
|
*/ |
|
63
|
|
|
public static function fromXML(DOMElement $xml): static |
|
64
|
|
|
{ |
|
65
|
|
|
Assert::same($xml->localName, static::getClassName(static::class), InvalidDOMElementException::class); |
|
66
|
|
|
Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); |
|
67
|
|
|
|
|
68
|
|
|
return new static( |
|
69
|
|
|
self::getAttribute($xml, 'URI', AnyURIValue::class), |
|
70
|
|
|
Transforms::getChildrenOfClass($xml), |
|
71
|
|
|
); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @inheritDoc |
|
77
|
|
|
*/ |
|
78
|
|
|
public function toXML(?DOMElement $parent = null): DOMElement |
|
79
|
|
|
{ |
|
80
|
|
|
$e = $this->instantiateParentElement($parent); |
|
81
|
|
|
$e->setAttribute('URI', strval($this->getUri())); |
|
82
|
|
|
|
|
83
|
|
|
foreach ($this->transforms as $transforms) { |
|
84
|
|
|
$transforms->toXML($e); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
return $e; |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|