-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstractPasswordString.php
More file actions
90 lines (76 loc) · 2.56 KB
/
AbstractPasswordString.php
File metadata and controls
90 lines (76 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
declare(strict_types=1);
namespace SimpleSAML\WebServices\Security\XML\wsse;
use DOMElement;
use SimpleSAML\WebServices\Security\Assert\Assert;
use SimpleSAML\WebServices\Security\Constants as C;
use SimpleSAML\WebServices\Security\Type\IDValue;
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
use SimpleSAML\XMLSchema\Type\AnyURIValue;
use SimpleSAML\XMLSchema\Type\StringValue;
/**
* Abstract class defining the PasswordString type
*
* @package simplesamlphp/xml-wss-core
*/
abstract class AbstractPasswordString extends AbstractAttributedString
{
/**
* AbstractPasswordString constructor
*
* @param \SimpleSAML\XMLSchema\Type\StringValue $content
* @param \SimpleSAML\WebServices\Security\Type\IDValue|null $Id
* @param array<\SimpleSAML\XML\Attribute> $namespacedAttributes
* @param \SimpleSAML\XMLSchema\Type\AnyURIValue|null $Type
*/
final public function __construct(
#[\SensitiveParameter]
StringValue $content,
?IDValue $Id = null,
array $namespacedAttributes = [],
protected ?AnyURIValue $Type = null,
) {
parent::__construct($content, $Id, $namespacedAttributes);
}
/**
* @return \SimpleSAML\XMLSchema\Type\AnyURIValue|null
*/
public function getType(): ?AnyURIValue
{
return $this->Type;
}
/**
* Create an instance of this object from its XML representation.
*
* @param \DOMElement $xml
*
* @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
* if the qualified name of the supplied element is wrong
*/
public static function fromXML(DOMElement $xml): static
{
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
$Id = null;
if ($xml->hasAttributeNS(C::NS_SEC_UTIL, 'Id')) {
$Id = IDValue::fromString($xml->getAttributeNS(C::NS_SEC_UTIL, 'Id'));
}
return new static(
StringValue::fromString($xml->textContent),
$Id,
self::getAttributesNSFromXML($xml),
self::getOptionalAttribute($xml, 'Type', AnyURIValue::class, null),
);
}
/**
* @param \DOMElement|null $parent
*/
public function toXML(?DOMElement $parent = null): DOMElement
{
$e = parent::toXML($parent);
if ($this->getType() !== null) {
$e->setAttribute('Type', $this->getType()->getValue());
}
return $e;
}
}