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\Exception\InvalidDOMElementException; |
10
|
|
|
use SimpleSAML\XMLSecurity\Constants; |
11
|
|
|
use SimpleSAML\XMLSecurity\Exception\InvalidArgumentException; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class representing a ds:CanonicalizationMethod element. |
15
|
|
|
* |
16
|
|
|
* @package simplesamlphp/xml-security |
17
|
|
|
*/ |
18
|
|
|
final class CanonicalizationMethod extends AbstractDsElement |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* The algorithm. |
22
|
|
|
* |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
protected string $Algorithm; |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Initialize a CanonicalizationMethod element. |
30
|
|
|
* |
31
|
|
|
* @param string $algorithm |
32
|
|
|
*/ |
33
|
|
|
public function __construct(string $algorithm) |
34
|
|
|
{ |
35
|
|
|
$this->setAlgorithm($algorithm); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Collect the value of the Algorithm-property |
41
|
|
|
* |
42
|
|
|
* @return string |
43
|
|
|
*/ |
44
|
|
|
public function getAlgorithm(): string |
45
|
|
|
{ |
46
|
|
|
return $this->Algorithm; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Set the value of the Algorithm-property |
52
|
|
|
* |
53
|
|
|
* @param string $algorithm |
54
|
|
|
*/ |
55
|
|
|
private function setAlgorithm(string $algorithm): void |
56
|
|
|
{ |
57
|
|
|
Assert::oneOf( |
58
|
|
|
$algorithm, |
59
|
|
|
[ |
60
|
|
|
Constants::C14N_EXCLUSIVE_WITH_COMMENTS, |
61
|
|
|
Constants::C14N_EXCLUSIVE_WITHOUT_COMMENTS, |
62
|
|
|
Constants::C14N_INCLUSIVE_WITH_COMMENTS, |
63
|
|
|
Constants::C14N_INCLUSIVE_WITHOUT_COMMENTS |
64
|
|
|
], |
65
|
|
|
'Invalid canonicalization method', |
66
|
|
|
InvalidArgumentException::class |
67
|
|
|
); |
68
|
|
|
|
69
|
|
|
$this->Algorithm = $algorithm; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Convert XML into a CanonicalizationMethod |
75
|
|
|
* |
76
|
|
|
* @param \DOMElement $xml The XML element we should load |
77
|
|
|
* @return self |
78
|
|
|
* |
79
|
|
|
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException |
80
|
|
|
* If the qualified name of the supplied element is wrong |
81
|
|
|
*/ |
82
|
|
|
public static function fromXML(DOMElement $xml): object |
83
|
|
|
{ |
84
|
|
|
Assert::same($xml->localName, 'CanonicalizationMethod', InvalidDOMElementException::class); |
85
|
|
|
Assert::same($xml->namespaceURI, CanonicalizationMethod::NS, InvalidDOMElementException::class); |
86
|
|
|
|
87
|
|
|
$Algorithm = CanonicalizationMethod::getAttribute($xml, 'Algorithm'); |
88
|
|
|
|
89
|
|
|
return new self($Algorithm); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Convert this CanonicalizationMethod element to XML. |
95
|
|
|
* |
96
|
|
|
* @param \DOMElement|null $parent The element we should append this KeyName element to. |
97
|
|
|
* @return \DOMElement |
98
|
|
|
*/ |
99
|
|
|
public function toXML(DOMElement $parent = null): DOMElement |
100
|
|
|
{ |
101
|
|
|
$e = $this->instantiateParentElement($parent); |
102
|
|
|
$e->setAttribute('Algorithm', $this->Algorithm); |
103
|
|
|
|
104
|
|
|
return $e; |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|