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, SchemaValidatableElementTrait}; |
||
11 | use SimpleSAML\XMLSchema\Exception\{InvalidDOMElementException, SchemaViolationException}; |
||
12 | use SimpleSAML\XMLSchema\Type\AnyURIValue; |
||
13 | use SimpleSAML\XMLSecurity\XML\xenc\Transforms; |
||
14 | |||
15 | use function strval; |
||
16 | |||
17 | /** |
||
18 | * Class representing a CipherReference. |
||
19 | * |
||
20 | * @package simplesamlphp/xml-security |
||
21 | */ |
||
22 | final class CipherReference extends AbstractXencElement implements SchemaValidatableElementInterface |
||
23 | { |
||
24 | use SchemaValidatableElementTrait; |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
25 | |||
26 | /** |
||
27 | * AbstractReference constructor. |
||
28 | * |
||
29 | * @param \SimpleSAML\XMLSchema\Type\AnyURIValue $uri |
||
30 | * @param \SimpleSAML\XMLSecurity\XML\xenc\Transforms[] $transforms |
||
31 | */ |
||
32 | final public function __construct( |
||
33 | protected AnyURIValue $uri, |
||
34 | protected array $transforms = [], |
||
35 | ) { |
||
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 \SimpleSAML\XMLSchema\Type\AnyURIValue |
||
45 | */ |
||
46 | public function getURI(): AnyURIValue |
||
47 | { |
||
48 | return $this->uri; |
||
49 | } |
||
50 | |||
51 | |||
52 | /** |
||
53 | * @inheritDoc |
||
54 | * |
||
55 | * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException |
||
56 | * if the qualified name of the supplied element is wrong |
||
57 | * @throws \SimpleSAML\XMLSchema\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 | return new static( |
||
66 | self::getAttribute($xml, 'URI', AnyURIValue::class), |
||
67 | Transforms::getChildrenOfClass($xml), |
||
68 | ); |
||
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', strval($this->getUri())); |
||
79 | |||
80 | foreach ($this->transforms as $transforms) { |
||
81 | $transforms->toXML($e); |
||
82 | } |
||
83 | |||
84 | return $e; |
||
85 | } |
||
86 | } |
||
87 |