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\XML\Exception\SchemaViolationException; |
||
11 | use SimpleSAML\XML\ExtendableElementTrait; |
||
12 | use SimpleSAML\XML\SchemaValidatableElementInterface; |
||
13 | use SimpleSAML\XML\SchemaValidatableElementTrait; |
||
14 | use SimpleSAML\XML\XsNamespace as NS; |
||
15 | use SimpleSAML\XMLSecurity\Constants as C; |
||
16 | use SimpleSAML\XMLSecurity\Exception\InvalidArgumentException; |
||
17 | |||
18 | /** |
||
19 | * Class representing a ds:DigestMethod element. |
||
20 | * |
||
21 | * @package simplesamlphp/xml-security |
||
22 | */ |
||
23 | final class DigestMethod extends AbstractDsElement implements SchemaValidatableElementInterface |
||
24 | { |
||
25 | use ExtendableElementTrait; |
||
26 | use SchemaValidatableElementTrait; |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
27 | |||
28 | public const XS_ANY_ELT_NAMESPACE = NS::OTHER; |
||
29 | |||
30 | /** |
||
31 | * Initialize a DigestMethod element. |
||
32 | * |
||
33 | * @param string $Algorithm |
||
34 | * @param list<\SimpleSAML\XML\SerializableElementInterface> $elements |
||
0 ignored issues
–
show
The type
SimpleSAML\XMLSecurity\XML\ds\list was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
35 | */ |
||
36 | public function __construct( |
||
37 | protected string $Algorithm, |
||
38 | array $elements = [], |
||
39 | ) { |
||
40 | Assert::validURI($Algorithm, SchemaViolationException::class); |
||
41 | Assert::oneOf( |
||
42 | $Algorithm, |
||
43 | array_keys(C::$DIGEST_ALGORITHMS), |
||
44 | 'Invalid digest method: %s', |
||
45 | InvalidArgumentException::class, |
||
46 | ); |
||
47 | |||
48 | $this->setElements($elements); |
||
49 | } |
||
50 | |||
51 | |||
52 | /** |
||
53 | * Collect the value of the Algorithm-property |
||
54 | * |
||
55 | * @return string |
||
56 | */ |
||
57 | public function getAlgorithm(): string |
||
58 | { |
||
59 | return $this->Algorithm; |
||
60 | } |
||
61 | |||
62 | |||
63 | /** |
||
64 | * Convert XML into a DigestMethod |
||
65 | * |
||
66 | * @param \DOMElement $xml The XML element we should load |
||
67 | * @return static |
||
68 | * |
||
69 | * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException |
||
70 | * If the qualified name of the supplied element is wrong |
||
71 | */ |
||
72 | public static function fromXML(DOMElement $xml): static |
||
73 | { |
||
74 | Assert::same($xml->localName, 'DigestMethod', InvalidDOMElementException::class); |
||
75 | Assert::same($xml->namespaceURI, DigestMethod::NS, InvalidDOMElementException::class); |
||
76 | |||
77 | $Algorithm = DigestMethod::getAttribute($xml, 'Algorithm'); |
||
78 | $elements = self::getChildElementsFromXML($xml); |
||
79 | |||
80 | return new static($Algorithm, $elements); |
||
81 | } |
||
82 | |||
83 | |||
84 | /** |
||
85 | * Convert this DigestMethod element to XML. |
||
86 | * |
||
87 | * @param \DOMElement|null $parent The element we should append this DigestMethod element to. |
||
88 | * @return \DOMElement |
||
89 | */ |
||
90 | public function toXML(?DOMElement $parent = null): DOMElement |
||
91 | { |
||
92 | $e = $this->instantiateParentElement($parent); |
||
93 | $e->setAttribute('Algorithm', $this->getAlgorithm()); |
||
94 | |||
95 | foreach ($this->elements as $elt) { |
||
96 | if (!$elt->isEmptyElement()) { |
||
97 | $elt->toXML($e); |
||
98 | } |
||
99 | } |
||
100 | |||
101 | return $e; |
||
102 | } |
||
103 | } |
||
104 |