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 as C; |
10
|
|
|
use SimpleSAML\XML\Exception\InvalidDOMElementException; |
11
|
|
|
use SimpleSAML\XML\Exception\SchemaViolationException; |
12
|
|
|
use SimpleSAML\XML\XMLStringElementTrait; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class representing a ds:X509SerialNumber element. |
16
|
|
|
* |
17
|
|
|
* @package simplesaml/xml-security |
18
|
|
|
*/ |
19
|
|
|
final class X509SerialNumber extends AbstractDsElement |
20
|
|
|
{ |
21
|
|
|
use XMLStringElementTrait; |
|
|
|
|
22
|
|
|
|
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @param string $content |
26
|
|
|
*/ |
27
|
|
|
public function __construct(string $content) |
28
|
|
|
{ |
29
|
|
|
$this->setContent($content); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Validate the content of the element. |
35
|
|
|
* |
36
|
|
|
* @param string $content The value to go in the XML textContent |
37
|
|
|
* @throws \Exception on failure |
38
|
|
|
* @return void |
39
|
|
|
*/ |
40
|
|
|
protected function validateContent(/** @scrutinizer ignore-unused */ string $content): void |
41
|
|
|
{ |
42
|
|
|
Assert::integerish($content, SchemaViolationException::class); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Convert XML into a X509SerialNumber |
48
|
|
|
* |
49
|
|
|
* @param \DOMElement $xml The XML element we should load |
50
|
|
|
* @return self |
51
|
|
|
* |
52
|
|
|
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException |
53
|
|
|
* If the qualified name of the supplied element is wrong |
54
|
|
|
*/ |
55
|
|
|
public static function fromXML(DOMElement $xml): self |
56
|
|
|
{ |
57
|
|
|
Assert::same($xml->localName, 'X509SerialNumber', InvalidDOMElementException::class); |
58
|
|
|
Assert::same($xml->namespaceURI, X509SerialNumber::NS, InvalidDOMElementException::class); |
59
|
|
|
|
60
|
|
|
return new self($xml->textContent); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Convert this X509SerialNumber element to XML. |
66
|
|
|
* |
67
|
|
|
* @param \DOMElement|null $parent The element we should append this X509SerialNumber element to. |
68
|
|
|
* @return \DOMElement |
69
|
|
|
*/ |
70
|
|
|
public function toXML(DOMElement $parent = null): DOMElement |
71
|
|
|
{ |
72
|
|
|
$e = $this->instantiateParentElement($parent); |
73
|
|
|
$e->textContent = $this->getContent(); |
74
|
|
|
|
75
|
|
|
return $e; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|