-
Notifications
You must be signed in to change notification settings - Fork 136
Expand file tree
/
Copy pathDigestMethod.php
More file actions
97 lines (80 loc) · 2.76 KB
/
Copy pathDigestMethod.php
File metadata and controls
97 lines (80 loc) · 2.76 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
91
92
93
94
95
96
97
<?php
declare(strict_types=1);
namespace SimpleSAML\SAML2\XML\alg;
use Dom;
use SimpleSAML\SAML2\Assert\Assert;
use SimpleSAML\SAML2\Type\SAMLAnyURIValue;
use SimpleSAML\XML\ExtendableElementTrait;
use SimpleSAML\XML\SchemaValidatableElementInterface;
use SimpleSAML\XML\SchemaValidatableElementTrait;
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
use SimpleSAML\XMLSchema\XML\Constants\NS;
/**
* Class for handling the alg:DigestMethod element.
*
* @link http://docs.oasis-open.org/security/saml/Post2.0/sstc-saml-metadata-algsupport.pdf
*
* @package simplesamlphp/saml2
*/
final class DigestMethod extends AbstractAlgElement implements SchemaValidatableElementInterface
{
use ExtendableElementTrait;
use SchemaValidatableElementTrait;
/** The namespace-attribute for the xs:any element */
public const string XS_ANY_ELT_NAMESPACE = NS::ANY;
/**
* Create/parse an alg:DigestMethod element.
*
* @param \SimpleSAML\SAML2\Type\SAMLAnyURIValue $algorithm
* @param \SimpleSAML\XML\Chunk[] $elements
*/
public function __construct(
protected SAMLAnyURIValue $algorithm,
array $elements = [],
) {
$this->setElements($elements);
}
/**
* Collect the value of the algorithm-property
*
* @return \SimpleSAML\SAML2\Type\SAMLAnyURIValue
*/
public function getAlgorithm(): SAMLAnyURIValue
{
return $this->algorithm;
}
/**
* Convert XML into a DigestMethod
*
* @param \Dom\Element $xml The XML element we should load
*
* @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
* if the qualified name of the supplied element is wrong
* @throws \SimpleSAML\XMLSchema\Exception\MissingAttributeException
* if the mandatory Algorithm-attribute is missing
*/
public static function fromXML(Dom\Element $xml): static
{
Assert::same($xml->localName, 'DigestMethod', InvalidDOMElementException::class);
Assert::same($xml->namespaceURI, DigestMethod::NS, InvalidDOMElementException::class);
return new static(
self::getAttribute($xml, 'Algorithm', SAMLAnyURIValue::class),
self::getChildElementsFromXML($xml),
);
}
/**
* Convert this element to XML.
*
* @param \Dom\Element|null $parent The element we should append to.
*/
public function toXML(?Dom\Element $parent = null): Dom\Element
{
$e = $this->instantiateParentElement($parent);
$e->setAttribute('Algorithm', $this->getAlgorithm()->getValue());
foreach ($this->getElements() as $element) {
/** @var \SimpleSAML\XML\SerializableElementInterface $element */
$element->toXML($e);
}
return $e;
}
}