simplesamlphp /
xml-security
| 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\ExtendableElementTrait; |
||
| 10 | use SimpleSAML\XML\SchemaValidatableElementInterface; |
||
| 11 | use SimpleSAML\XML\SchemaValidatableElementTrait; |
||
| 12 | use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException; |
||
| 13 | use SimpleSAML\XMLSchema\Type\AnyURIValue; |
||
| 14 | use SimpleSAML\XMLSchema\XML\Constants\NS; |
||
| 15 | use SimpleSAML\XMLSecurity\Constants as C; |
||
| 16 | use SimpleSAML\XMLSecurity\Exception\InvalidArgumentException; |
||
| 17 | |||
| 18 | use function strval; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Class representing a ds:DigestMethod element. |
||
| 22 | * |
||
| 23 | * @package simplesamlphp/xml-security |
||
| 24 | */ |
||
| 25 | final class DigestMethod extends AbstractDsElement implements SchemaValidatableElementInterface |
||
| 26 | { |
||
| 27 | use ExtendableElementTrait; |
||
| 28 | use SchemaValidatableElementTrait; |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 29 | |||
| 30 | |||
| 31 | /** The namespace-attribute for the xs:any element */ |
||
| 32 | public const XS_ANY_ELT_NAMESPACE = NS::OTHER; |
||
| 33 | |||
| 34 | |||
| 35 | /** |
||
| 36 | * Initialize a DigestMethod element. |
||
| 37 | * |
||
| 38 | * @param \SimpleSAML\XMLSchema\Type\AnyURIValue $Algorithm |
||
| 39 | * @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 Loading history...
|
|||
| 40 | */ |
||
| 41 | public function __construct( |
||
| 42 | protected AnyURIValue $Algorithm, |
||
| 43 | array $elements = [], |
||
| 44 | ) { |
||
| 45 | Assert::oneOf( |
||
| 46 | $Algorithm->getValue(), |
||
| 47 | array_keys(C::$DIGEST_ALGORITHMS), |
||
| 48 | 'Invalid digest method: %s', |
||
| 49 | InvalidArgumentException::class, |
||
| 50 | ); |
||
| 51 | |||
| 52 | $this->setElements($elements); |
||
| 53 | } |
||
| 54 | |||
| 55 | |||
| 56 | /** |
||
| 57 | * Collect the value of the Algorithm-property |
||
| 58 | * |
||
| 59 | * @return \SimpleSAML\XMLSchema\Type\AnyURIValue |
||
| 60 | */ |
||
| 61 | public function getAlgorithm(): AnyURIValue |
||
| 62 | { |
||
| 63 | return $this->Algorithm; |
||
| 64 | } |
||
| 65 | |||
| 66 | |||
| 67 | /** |
||
| 68 | * Convert XML into a DigestMethod |
||
| 69 | * |
||
| 70 | * @param \DOMElement $xml The XML element we should load |
||
| 71 | * @return static |
||
| 72 | * |
||
| 73 | * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException |
||
| 74 | * If the qualified name of the supplied element is wrong |
||
| 75 | */ |
||
| 76 | public static function fromXML(DOMElement $xml): static |
||
| 77 | { |
||
| 78 | Assert::same($xml->localName, 'DigestMethod', InvalidDOMElementException::class); |
||
| 79 | Assert::same($xml->namespaceURI, DigestMethod::NS, InvalidDOMElementException::class); |
||
| 80 | |||
| 81 | $Algorithm = self::getAttribute($xml, 'Algorithm', AnyURIValue::class); |
||
| 82 | $elements = self::getChildElementsFromXML($xml); |
||
| 83 | |||
| 84 | return new static($Algorithm, $elements); |
||
| 85 | } |
||
| 86 | |||
| 87 | |||
| 88 | /** |
||
| 89 | * Convert this DigestMethod element to XML. |
||
| 90 | * |
||
| 91 | * @param \DOMElement|null $parent The element we should append this DigestMethod element to. |
||
| 92 | * @return \DOMElement |
||
| 93 | */ |
||
| 94 | public function toXML(?DOMElement $parent = null): DOMElement |
||
| 95 | { |
||
| 96 | $e = $this->instantiateParentElement($parent); |
||
| 97 | $e->setAttribute('Algorithm', strval($this->getAlgorithm())); |
||
| 98 | |||
| 99 | foreach ($this->elements as $elt) { |
||
| 100 | if (!$elt->isEmptyElement()) { |
||
| 101 | $elt->toXML($e); |
||
| 102 | } |
||
| 103 | } |
||
| 104 | |||
| 105 | return $e; |
||
| 106 | } |
||
| 107 | } |
||
| 108 |