1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\XMLSecurity\XML\ds; |
6
|
|
|
|
7
|
|
|
use DOMElement; |
8
|
|
|
use SimpleSAML\Assert\Assert; |
9
|
|
|
use SimpleSAML\XML\Constants; |
10
|
|
|
use SimpleSAML\XML\Exception\InvalidDOMElementException; |
11
|
|
|
use SimpleSAML\XML\XMLStringElementTrait; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class representing a ds:X509SerialNumber element. |
15
|
|
|
* |
16
|
|
|
* @package simplesaml/xml-security |
17
|
|
|
*/ |
18
|
|
|
final class X509SerialNumber extends AbstractDsElement |
19
|
|
|
{ |
20
|
|
|
use XMLStringElementTrait; |
|
|
|
|
21
|
|
|
|
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @param string $content |
25
|
|
|
*/ |
26
|
|
|
public function __construct(string $content) |
27
|
|
|
{ |
28
|
|
|
$this->setContent($content); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Convert XML into a X509SerialNumber |
34
|
|
|
* |
35
|
|
|
* @param \DOMElement $xml The XML element we should load |
36
|
|
|
* @return self |
37
|
|
|
* |
38
|
|
|
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException |
39
|
|
|
* If the qualified name of the supplied element is wrong |
40
|
|
|
*/ |
41
|
|
|
public static function fromXML(DOMElement $xml): object |
42
|
|
|
{ |
43
|
|
|
Assert::same($xml->localName, 'X509SerialNumber', InvalidDOMElementException::class); |
44
|
|
|
Assert::same($xml->namespaceURI, X509SerialNumber::NS, InvalidDOMElementException::class); |
45
|
|
|
Assert::same($xml->getAttributeNS(Constants::NS_XSI, "type"), 'xs:integer'); |
46
|
|
|
|
47
|
|
|
return new self($xml->textContent); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Convert this X509SerialNumber element to XML. |
53
|
|
|
* |
54
|
|
|
* @param \DOMElement|null $parent The element we should append this X509SerialNumber element to. |
55
|
|
|
* @return \DOMElement |
56
|
|
|
*/ |
57
|
|
|
public function toXML(DOMElement $parent = null): DOMElement |
58
|
|
|
{ |
59
|
|
|
$e = $this->instantiateParentElement($parent); |
60
|
|
|
$e->textContent = $this->content; |
61
|
|
|
$e->setAttributeNS(Constants::NS_XSI, 'xsi:type', 'xs:integer'); |
62
|
|
|
|
63
|
|
|
return $e; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|