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\XML\SchemaValidatableElementInterface; |
||
| 9 | use SimpleSAML\XML\SchemaValidatableElementTrait; |
||
| 10 | use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException; |
||
| 11 | use SimpleSAML\XMLSchema\Exception\MissingElementException; |
||
| 12 | use SimpleSAML\XMLSchema\Exception\TooManyElementsException; |
||
| 13 | use SimpleSAML\XMLSchema\Type\AnyURIValue; |
||
|
0 ignored issues
–
show
|
|||
| 14 | use SimpleSAML\XMLSchema\Type\IDValue; |
||
|
0 ignored issues
–
show
The type
SimpleSAML\XMLSchema\Type\IDValue 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...
|
|||
| 15 | use SimpleSAML\XMLSecurity\Assert\Assert; |
||
| 16 | |||
| 17 | use function array_pop; |
||
| 18 | use function strval; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Class representing a ds:Reference element. |
||
| 22 | * |
||
| 23 | * @package simplesamlphp/xml-security |
||
| 24 | */ |
||
| 25 | final class Reference extends AbstractDsElement implements SchemaValidatableElementInterface |
||
|
0 ignored issues
–
show
The type
SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement 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...
|
|||
| 26 | { |
||
| 27 | use SchemaValidatableElementTrait; |
||
| 28 | |||
| 29 | |||
| 30 | /** |
||
| 31 | * Initialize a ds:Reference |
||
| 32 | * |
||
| 33 | * @param \SimpleSAML\XMLSecurity\XML\ds\DigestMethod $digestMethod |
||
| 34 | * @param \SimpleSAML\XMLSecurity\XML\ds\DigestValue $digestValue |
||
| 35 | * @param \SimpleSAML\XMLSecurity\XML\ds\Transforms|null $transforms |
||
| 36 | * @param \SimpleSAML\XMLSchema\Type\IDValue|null $Id |
||
| 37 | * @param \SimpleSAML\XMLSchema\Type\AnyURIValue|null $Type |
||
| 38 | * @param \SimpleSAML\XMLSchema\Type\AnyURIValue|null $URI |
||
| 39 | */ |
||
| 40 | public function __construct( |
||
| 41 | protected DigestMethod $digestMethod, |
||
|
0 ignored issues
–
show
The type
SimpleSAML\XMLSecurity\XML\ds\DigestMethod 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...
|
|||
| 42 | protected DigestValue $digestValue, |
||
|
0 ignored issues
–
show
The type
SimpleSAML\XMLSecurity\XML\ds\DigestValue 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...
|
|||
| 43 | protected ?Transforms $transforms = null, |
||
| 44 | protected ?IDValue $Id = null, |
||
| 45 | protected ?AnyURIValue $Type = null, |
||
| 46 | protected ?AnyURIValue $URI = null, |
||
| 47 | ) { |
||
| 48 | } |
||
| 49 | |||
| 50 | |||
| 51 | /** |
||
| 52 | * @return \SimpleSAML\XMLSecurity\XML\ds\Transforms|null |
||
| 53 | */ |
||
| 54 | public function getTransforms(): ?Transforms |
||
| 55 | { |
||
| 56 | return $this->transforms; |
||
| 57 | } |
||
| 58 | |||
| 59 | |||
| 60 | /** |
||
| 61 | * @return \SimpleSAML\XMLSecurity\XML\ds\DigestMethod |
||
| 62 | */ |
||
| 63 | public function getDigestMethod(): DigestMethod |
||
| 64 | { |
||
| 65 | return $this->digestMethod; |
||
| 66 | } |
||
| 67 | |||
| 68 | |||
| 69 | /** |
||
| 70 | * @return \SimpleSAML\XMLSecurity\XML\ds\DigestValue |
||
| 71 | */ |
||
| 72 | public function getDigestValue(): DigestValue |
||
| 73 | { |
||
| 74 | return $this->digestValue; |
||
| 75 | } |
||
| 76 | |||
| 77 | |||
| 78 | /** |
||
| 79 | * @return \SimpleSAML\XMLSchema\Type\IDValue|null |
||
| 80 | */ |
||
| 81 | public function getId(): ?IDValue |
||
| 82 | { |
||
| 83 | return $this->Id; |
||
| 84 | } |
||
| 85 | |||
| 86 | |||
| 87 | /** |
||
| 88 | * @return \SimpleSAML\XMLSchema\Type\AnyURIValue|null |
||
| 89 | */ |
||
| 90 | public function getType(): ?AnyURIValue |
||
| 91 | { |
||
| 92 | return $this->Type; |
||
| 93 | } |
||
| 94 | |||
| 95 | |||
| 96 | /** |
||
| 97 | * @return \SimpleSAML\XMLSchema\Type\AnyURIValue|null |
||
| 98 | */ |
||
| 99 | public function getURI(): ?AnyURIValue |
||
| 100 | { |
||
| 101 | return $this->URI; |
||
| 102 | } |
||
| 103 | |||
| 104 | |||
| 105 | /** |
||
| 106 | * Determine whether this is an xpointer reference. |
||
| 107 | */ |
||
| 108 | public function isXPointer(): bool |
||
| 109 | { |
||
| 110 | return !is_null($this->getURI()) && str_starts_with(strval($this->getURI()), '#xpointer'); |
||
| 111 | } |
||
| 112 | |||
| 113 | |||
| 114 | /** |
||
| 115 | * Convert XML into a Reference element |
||
| 116 | * |
||
| 117 | * @param \DOMElement $xml The XML element we should load |
||
| 118 | * |
||
| 119 | * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException |
||
| 120 | * If the qualified name of the supplied element is wrong |
||
| 121 | */ |
||
| 122 | public static function fromXML(DOMElement $xml): static |
||
| 123 | { |
||
| 124 | Assert::same($xml->localName, 'Reference', InvalidDOMElementException::class); |
||
| 125 | Assert::same($xml->namespaceURI, Reference::NS, InvalidDOMElementException::class); |
||
| 126 | |||
| 127 | $Id = self::getOptionalAttribute($xml, 'Id', IDValue::class, null); |
||
| 128 | $Type = self::getOptionalAttribute($xml, 'Type', AnyURIValue::class, null); |
||
| 129 | $URI = self::getOptionalAttribute($xml, 'URI', AnyURIValue::class, null); |
||
| 130 | |||
| 131 | $transforms = Transforms::getChildrenOfClass($xml); |
||
| 132 | Assert::maxCount( |
||
| 133 | $transforms, |
||
| 134 | 1, |
||
| 135 | 'A <ds:Reference> may contain just one <ds:Transforms>.', |
||
| 136 | TooManyElementsException::class, |
||
| 137 | ); |
||
| 138 | |||
| 139 | $digestMethod = DigestMethod::getChildrenOfClass($xml); |
||
| 140 | Assert::count( |
||
| 141 | $digestMethod, |
||
| 142 | 1, |
||
| 143 | 'A <ds:Reference> must contain a <ds:DigestMethod>.', |
||
| 144 | MissingElementException::class, |
||
| 145 | ); |
||
| 146 | |||
| 147 | $digestValue = DigestValue::getChildrenOfClass($xml); |
||
| 148 | Assert::count( |
||
| 149 | $digestValue, |
||
| 150 | 1, |
||
| 151 | 'A <ds:Reference> must contain a <ds:DigestValue>.', |
||
| 152 | MissingElementException::class, |
||
| 153 | ); |
||
| 154 | |||
| 155 | return new static( |
||
| 156 | array_pop($digestMethod), |
||
| 157 | array_pop($digestValue), |
||
| 158 | empty($transforms) ? null : array_pop($transforms), |
||
| 159 | $Id, |
||
| 160 | $Type, |
||
| 161 | $URI, |
||
| 162 | ); |
||
| 163 | } |
||
| 164 | |||
| 165 | |||
| 166 | /** |
||
| 167 | * Convert this Reference element to XML. |
||
| 168 | * |
||
| 169 | * @param \DOMElement|null $parent The element we should append this Reference element to. |
||
| 170 | */ |
||
| 171 | public function toXML(?DOMElement $parent = null): DOMElement |
||
| 172 | { |
||
| 173 | $e = $this->instantiateParentElement($parent); |
||
| 174 | if ($this->getId() !== null) { |
||
| 175 | $e->setAttribute('Id', strval($this->getId())); |
||
| 176 | } |
||
| 177 | if ($this->getType() !== null) { |
||
| 178 | $e->setAttribute('Type', strval($this->getType())); |
||
| 179 | } |
||
| 180 | if ($this->getURI() !== null) { |
||
| 181 | $e->setAttribute('URI', strval($this->getURI())); |
||
| 182 | } |
||
| 183 | |||
| 184 | $this->getTransforms()?->toXML($e); |
||
| 185 | $this->getDigestMethod()->toXML($e); |
||
| 186 | $this->getDigestValue()->toXML($e); |
||
| 187 | |||
| 188 | return $e; |
||
| 189 | } |
||
| 190 | } |
||
| 191 |
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.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths