|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace SimpleSAML\SAML2\XML\alg; |
|
6
|
|
|
|
|
7
|
|
|
use DOMElement; |
|
8
|
|
|
use SimpleSAML\SAML2\Assert\Assert; |
|
9
|
|
|
use SimpleSAML\SAML2\Type\SAMLAnyURIValue; |
|
10
|
|
|
use SimpleSAML\XML\ExtendableElementTrait; |
|
11
|
|
|
use SimpleSAML\XML\SchemaValidatableElementInterface; |
|
12
|
|
|
use SimpleSAML\XML\SchemaValidatableElementTrait; |
|
13
|
|
|
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException; |
|
14
|
|
|
use SimpleSAML\XMLSchema\XML\Constants\NS; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Class for handling the alg:DigestMethod element. |
|
18
|
|
|
* |
|
19
|
|
|
* @link http://docs.oasis-open.org/security/saml/Post2.0/sstc-saml-metadata-algsupport.pdf |
|
20
|
|
|
* |
|
21
|
|
|
* @package simplesamlphp/saml2 |
|
22
|
|
|
*/ |
|
23
|
|
|
final class DigestMethod extends AbstractAlgElement implements SchemaValidatableElementInterface |
|
24
|
|
|
{ |
|
25
|
|
|
use ExtendableElementTrait; |
|
26
|
|
|
use SchemaValidatableElementTrait; |
|
27
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
/** The namespace-attribute for the xs:any element */ |
|
30
|
|
|
public const string XS_ANY_ELT_NAMESPACE = NS::ANY; |
|
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Create/parse an alg:DigestMethod element. |
|
35
|
|
|
* |
|
36
|
|
|
* @param \SimpleSAML\SAML2\Type\SAMLAnyURIValue $algorithm |
|
37
|
|
|
* @param \SimpleSAML\XML\Chunk[] $elements |
|
38
|
|
|
*/ |
|
39
|
|
|
public function __construct( |
|
40
|
|
|
protected SAMLAnyURIValue $algorithm, |
|
41
|
|
|
array $elements = [], |
|
42
|
|
|
) { |
|
43
|
|
|
$this->setElements($elements); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Collect the value of the algorithm-property |
|
49
|
|
|
* |
|
50
|
|
|
* @return \SimpleSAML\SAML2\Type\SAMLAnyURIValue |
|
51
|
|
|
*/ |
|
52
|
|
|
public function getAlgorithm(): SAMLAnyURIValue |
|
53
|
|
|
{ |
|
54
|
|
|
return $this->algorithm; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Convert XML into a DigestMethod |
|
60
|
|
|
* |
|
61
|
|
|
* @param \DOMElement $xml The XML element we should load |
|
62
|
|
|
* |
|
63
|
|
|
* @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException |
|
64
|
|
|
* if the qualified name of the supplied element is wrong |
|
65
|
|
|
* @throws \SimpleSAML\XMLSchema\Exception\MissingAttributeException |
|
66
|
|
|
* if the mandatory Algorithm-attribute is missing |
|
67
|
|
|
*/ |
|
68
|
|
|
public static function fromXML(DOMElement $xml): static |
|
69
|
|
|
{ |
|
70
|
|
|
Assert::same($xml->localName, 'DigestMethod', InvalidDOMElementException::class); |
|
71
|
|
|
Assert::same($xml->namespaceURI, DigestMethod::NS, InvalidDOMElementException::class); |
|
72
|
|
|
|
|
73
|
|
|
return new static( |
|
74
|
|
|
self::getAttribute($xml, 'Algorithm', SAMLAnyURIValue::class), |
|
75
|
|
|
self::getChildElementsFromXML($xml), |
|
76
|
|
|
); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Convert this element to XML. |
|
82
|
|
|
* |
|
83
|
|
|
* @param \DOMElement|null $parent The element we should append to. |
|
84
|
|
|
*/ |
|
85
|
|
|
public function toXML(?DOMElement $parent = null): DOMElement |
|
86
|
|
|
{ |
|
87
|
|
|
$e = $this->instantiateParentElement($parent); |
|
88
|
|
|
$e->setAttribute('Algorithm', $this->getAlgorithm()->getValue()); |
|
89
|
|
|
|
|
90
|
|
|
foreach ($this->getElements() as $element) { |
|
91
|
|
|
/** @var \SimpleSAML\XML\SerializableElementInterface $element */ |
|
92
|
|
|
$element->toXML($e); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
return $e; |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|