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