|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace SimpleSAML\WSSecurity\XML\wst_200502; |
|
6
|
|
|
|
|
7
|
|
|
use DOMElement; |
|
8
|
|
|
use SimpleSAML\WSSecurity\Assert\Assert; |
|
9
|
|
|
use SimpleSAML\XML\ExtendableAttributesTrait; |
|
10
|
|
|
use SimpleSAML\XML\TypedTextContentTrait; |
|
11
|
|
|
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException; |
|
12
|
|
|
use SimpleSAML\XMLSchema\Exception\SchemaViolationException; |
|
13
|
|
|
use SimpleSAML\XMLSchema\Type\Base64BinaryValue; |
|
14
|
|
|
use SimpleSAML\XMLSchema\Type\StringValue; |
|
15
|
|
|
use SimpleSAML\XMLSchema\XML\Constants\NS; |
|
16
|
|
|
|
|
17
|
|
|
use function array_map; |
|
18
|
|
|
use function explode; |
|
19
|
|
|
use function implode; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* A BinarySecertType element |
|
23
|
|
|
* |
|
24
|
|
|
* @package simplesamlphp/ws-security |
|
25
|
|
|
*/ |
|
26
|
|
|
abstract class AbstractBinarySecretType extends AbstractWstElement |
|
27
|
|
|
{ |
|
28
|
|
|
use ExtendableAttributesTrait; |
|
29
|
|
|
use TypedTextContentTrait; |
|
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
/** @var string|\SimpleSAML\XML\XsNamespace */ |
|
33
|
|
|
public const XS_ANY_ATTR_NAMESPACE = NS::OTHER; |
|
34
|
|
|
|
|
35
|
|
|
/** @var string */ |
|
36
|
|
|
public const TEXTCONTENT_TYPE = Base64BinaryValue::class; |
|
37
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
/** @var string[]|null */ |
|
40
|
|
|
protected ?array $Type; |
|
41
|
|
|
|
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @param \SimpleSAML\XMLSchema\Type\Base64BinaryValue $content |
|
45
|
|
|
* @param (\SimpleSAML\WSSecurity\XML\wst_200502\BinarySecretTypeEnum|string)[]|null $Type |
|
46
|
|
|
* @param array<\SimpleSAML\XML\Attribute> $namespacedAttributes |
|
47
|
|
|
*/ |
|
48
|
|
|
final public function __construct( |
|
49
|
|
|
Base64BinaryValue $content, |
|
50
|
|
|
?array $Type = null, |
|
51
|
|
|
array $namespacedAttributes = [], |
|
52
|
|
|
) { |
|
53
|
|
|
if ($Type !== null) { |
|
54
|
|
|
$Type = array_map( |
|
55
|
|
|
function (BinarySecretTypeEnum|string $v): string { |
|
56
|
|
|
return ($v instanceof BinarySecretTypeEnum) ? $v->value : $v; |
|
57
|
|
|
}, |
|
58
|
|
|
$Type, |
|
59
|
|
|
); |
|
60
|
|
|
Assert::allValidURI($Type, SchemaViolationException::class); |
|
61
|
|
|
$this->Type = $Type; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
$this->setContent($content); |
|
65
|
|
|
$this->setAttributesNS($namespacedAttributes); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Get the Type property. |
|
71
|
|
|
* |
|
72
|
|
|
* @return string[]|null |
|
73
|
|
|
*/ |
|
74
|
|
|
public function getType(): ?array |
|
75
|
|
|
{ |
|
76
|
|
|
return $this->Type; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Convert XML into a class instance |
|
82
|
|
|
* |
|
83
|
|
|
* @param \DOMElement $xml The XML element we should load |
|
84
|
|
|
* @return static |
|
85
|
|
|
* |
|
86
|
|
|
* @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException |
|
87
|
|
|
* If the qualified name of the supplied element is wrong |
|
88
|
|
|
*/ |
|
89
|
|
|
public static function fromXML(DOMElement $xml): static |
|
90
|
|
|
{ |
|
91
|
|
|
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); |
|
92
|
|
|
Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); |
|
93
|
|
|
|
|
94
|
|
|
return new static( |
|
95
|
|
|
Base64BinaryValue::fromString($xml->textContent), |
|
96
|
|
|
explode(' ', self::getAttribute($xml, 'Type', StringValue::class)->getValue()), |
|
97
|
|
|
self::getAttributesNSFromXML($xml), |
|
98
|
|
|
); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Convert this element to XML. |
|
104
|
|
|
* |
|
105
|
|
|
* @param \DOMElement|null $parent The element we should append this element to. |
|
106
|
|
|
* @return \DOMElement |
|
107
|
|
|
*/ |
|
108
|
|
|
public function toXML(?DOMElement $parent = null): DOMElement |
|
109
|
|
|
{ |
|
110
|
|
|
$e = $this->instantiateParentElement($parent); |
|
111
|
|
|
$e->textContent = $this->getContent()->getValue(); |
|
112
|
|
|
|
|
113
|
|
|
if ($this->getType() !== null) { |
|
114
|
|
|
$e->setAttribute('Type', implode(' ', $this->getType())); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
foreach ($this->getAttributesNS() as $attr) { |
|
118
|
|
|
$attr->toXML($e); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
return $e; |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
|