|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace SimpleSAML\WSSecurity\XML\fed; |
|
6
|
|
|
|
|
7
|
|
|
use DOMElement; |
|
8
|
|
|
use SimpleSAML\WSSecurity\Assert\Assert; |
|
9
|
|
|
use SimpleSAML\XML\Base64ElementTrait; |
|
10
|
|
|
use SimpleSAML\XML\Exception\InvalidDOMElementException; |
|
11
|
|
|
use SimpleSAML\XML\ExtendableAttributesTrait; |
|
12
|
|
|
use SimpleSAML\XML\XsNamespace as NS; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* An AbstractReferenceDigestType element |
|
16
|
|
|
* |
|
17
|
|
|
* @package simplesamlphp/ws-security |
|
18
|
|
|
*/ |
|
19
|
|
|
abstract class AbstractReferenceDigestType extends AbstractFedElement |
|
20
|
|
|
{ |
|
21
|
|
|
use ExtendableAttributesTrait; |
|
22
|
|
|
use Base64ElementTrait; |
|
23
|
|
|
|
|
24
|
|
|
/** The namespace-attribute for the xs:anyAttribute element */ |
|
25
|
|
|
public const XS_ANY_ATTR_NAMESPACE = NS::OTHER; |
|
26
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @param string $content |
|
30
|
|
|
* @param \SimpleSAML\XML\Attribute[] $namespacedAttributes |
|
31
|
|
|
*/ |
|
32
|
|
|
final public function __construct(string $content, array $namespacedAttributes) |
|
33
|
|
|
{ |
|
34
|
|
|
$this->setContent($content); |
|
35
|
|
|
$this->setAttributesNS($namespacedAttributes); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Create a class from XML |
|
41
|
|
|
* |
|
42
|
|
|
* @param \DOMElement $xml |
|
43
|
|
|
* @return static |
|
44
|
|
|
*/ |
|
45
|
|
|
public static function fromXML(DOMElement $xml): static |
|
46
|
|
|
{ |
|
47
|
|
|
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); |
|
|
|
|
|
|
48
|
|
|
Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); |
|
49
|
|
|
|
|
50
|
|
|
return new static( |
|
51
|
|
|
$xml->textContent, |
|
52
|
|
|
self::getAttributesNSFromXML($xml), |
|
53
|
|
|
); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Create XML from this class |
|
59
|
|
|
* |
|
60
|
|
|
* @param \DOMElement|null $parent |
|
61
|
|
|
* @return \DOMElement |
|
62
|
|
|
*/ |
|
63
|
|
|
public function toXML(?DOMElement $parent = null): DOMElement |
|
64
|
|
|
{ |
|
65
|
|
|
$e = $this->instantiateParentElement($parent); |
|
66
|
|
|
$e->textContent = $this->getContent(); |
|
67
|
|
|
|
|
68
|
|
|
foreach ($this->getAttributesNS() as $attr) { |
|
69
|
|
|
$attr->toXML($e); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
return $e; |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|