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\Constants as C; |
||
|
0 ignored issues
–
show
|
|||
| 9 | use SimpleSAML\XML\SchemaValidatableElementInterface; |
||
| 10 | use SimpleSAML\XML\SchemaValidatableElementTrait; |
||
| 11 | use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException; |
||
| 12 | use SimpleSAML\XMLSchema\Exception\MissingElementException; |
||
| 13 | use SimpleSAML\XMLSchema\Exception\TooManyElementsException; |
||
| 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 | use SimpleSAML\XMLSecurity\Exception\InvalidArgumentException; |
||
| 17 | use SimpleSAML\XMLSecurity\XML\CanonicalizableElementInterface; |
||
| 18 | use SimpleSAML\XMLSecurity\XML\CanonicalizableElementTrait; |
||
| 19 | |||
| 20 | use function array_pop; |
||
| 21 | use function strval; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Class representing a ds:SignedInfo element. |
||
| 25 | * |
||
| 26 | * @package simplesamlphp/xml-security |
||
| 27 | */ |
||
| 28 | final class SignedInfo extends AbstractDsElement implements |
||
|
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...
|
|||
| 29 | CanonicalizableElementInterface, |
||
| 30 | SchemaValidatableElementInterface |
||
| 31 | { |
||
| 32 | use CanonicalizableElementTrait; |
||
| 33 | use SchemaValidatableElementTrait; |
||
| 34 | |||
| 35 | |||
| 36 | protected ?DOMElement $xml = null; |
||
| 37 | |||
| 38 | |||
| 39 | /** |
||
| 40 | * Initialize a SignedInfo. |
||
| 41 | * |
||
| 42 | * @param \SimpleSAML\XMLSecurity\XML\ds\CanonicalizationMethod $canonicalizationMethod |
||
| 43 | * @param \SimpleSAML\XMLSecurity\XML\ds\SignatureMethod $signatureMethod |
||
| 44 | * @param \SimpleSAML\XMLSecurity\XML\ds\Reference[] $references |
||
| 45 | * @param \SimpleSAML\XMLSchema\Type\IDValue|null $Id |
||
| 46 | */ |
||
| 47 | public function __construct( |
||
| 48 | protected CanonicalizationMethod $canonicalizationMethod, |
||
| 49 | protected SignatureMethod $signatureMethod, |
||
|
0 ignored issues
–
show
The type
SimpleSAML\XMLSecurity\XML\ds\SignatureMethod 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...
|
|||
| 50 | protected array $references, |
||
| 51 | protected ?IDValue $Id = null, |
||
| 52 | ) { |
||
| 53 | Assert::maxCount($references, C::UNBOUNDED_LIMIT); |
||
| 54 | Assert::allIsInstanceOf($references, Reference::class, InvalidArgumentException::class); |
||
| 55 | } |
||
| 56 | |||
| 57 | |||
| 58 | /** |
||
| 59 | * Collect the value of the canonicalizationMethod-property |
||
| 60 | * |
||
| 61 | * @return \SimpleSAML\XMLSecurity\XML\ds\CanonicalizationMethod |
||
| 62 | */ |
||
| 63 | public function getCanonicalizationMethod(): CanonicalizationMethod |
||
| 64 | { |
||
| 65 | return $this->canonicalizationMethod; |
||
| 66 | } |
||
| 67 | |||
| 68 | |||
| 69 | /** |
||
| 70 | * Collect the value of the signatureMethod-property |
||
| 71 | * |
||
| 72 | * @return \SimpleSAML\XMLSecurity\XML\ds\SignatureMethod |
||
| 73 | */ |
||
| 74 | public function getSignatureMethod(): SignatureMethod |
||
| 75 | { |
||
| 76 | return $this->signatureMethod; |
||
| 77 | } |
||
| 78 | |||
| 79 | |||
| 80 | /** |
||
| 81 | * Collect the value of the references-property |
||
| 82 | * |
||
| 83 | * @return \SimpleSAML\XMLSecurity\XML\ds\Reference[] |
||
| 84 | */ |
||
| 85 | public function getReferences(): array |
||
| 86 | { |
||
| 87 | return $this->references; |
||
| 88 | } |
||
| 89 | |||
| 90 | |||
| 91 | /** |
||
| 92 | * Collect the value of the Id-property |
||
| 93 | * |
||
| 94 | * @return \SimpleSAML\XMLSchema\Type\IDValue|null |
||
| 95 | */ |
||
| 96 | public function getId(): ?IDValue |
||
| 97 | { |
||
| 98 | return $this->Id; |
||
| 99 | } |
||
| 100 | |||
| 101 | |||
| 102 | /** |
||
| 103 | * @inheritDoc |
||
| 104 | */ |
||
| 105 | protected function getOriginalXML(): DOMElement |
||
| 106 | { |
||
| 107 | if ($this->xml !== null) { |
||
| 108 | return $this->xml; |
||
| 109 | } |
||
| 110 | |||
| 111 | return $this->toXML(); |
||
| 112 | } |
||
| 113 | |||
| 114 | |||
| 115 | /** |
||
| 116 | * Convert XML into a SignedInfo instance |
||
| 117 | * |
||
| 118 | * @param \DOMElement $xml The XML element we should load |
||
| 119 | * |
||
| 120 | * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException |
||
| 121 | * If the qualified name of the supplied element is wrong |
||
| 122 | */ |
||
| 123 | public static function fromXML(DOMElement $xml): static |
||
| 124 | { |
||
| 125 | Assert::same($xml->localName, 'SignedInfo', InvalidDOMElementException::class); |
||
| 126 | Assert::same($xml->namespaceURI, SignedInfo::NS, InvalidDOMElementException::class); |
||
| 127 | |||
| 128 | $canonicalizationMethod = CanonicalizationMethod::getChildrenOfClass($xml); |
||
| 129 | Assert::minCount( |
||
| 130 | $canonicalizationMethod, |
||
| 131 | 1, |
||
| 132 | 'A ds:SignedInfo element must contain exactly one ds:CanonicalizationMethod', |
||
| 133 | MissingElementException::class, |
||
| 134 | ); |
||
| 135 | Assert::maxCount( |
||
| 136 | $canonicalizationMethod, |
||
| 137 | 1, |
||
| 138 | 'A ds:SignedInfo element must contain exactly one ds:CanonicalizationMethod', |
||
| 139 | TooManyElementsException::class, |
||
| 140 | ); |
||
| 141 | |||
| 142 | $signatureMethod = SignatureMethod::getChildrenOfClass($xml); |
||
| 143 | Assert::minCount( |
||
| 144 | $signatureMethod, |
||
| 145 | 1, |
||
| 146 | 'A ds:SignedInfo element must contain exactly one ds:SignatureMethod', |
||
| 147 | MissingElementException::class, |
||
| 148 | ); |
||
| 149 | Assert::maxCount( |
||
| 150 | $signatureMethod, |
||
| 151 | 1, |
||
| 152 | 'A ds:SignedInfo element must contain exactly one ds:SignatureMethod', |
||
| 153 | TooManyElementsException::class, |
||
| 154 | ); |
||
| 155 | |||
| 156 | $references = Reference::getChildrenOfClass($xml); |
||
| 157 | Assert::minCount( |
||
| 158 | $references, |
||
| 159 | 1, |
||
| 160 | 'A ds:SignedInfo element must contain at least one ds:Reference', |
||
| 161 | MissingElementException::class, |
||
| 162 | ); |
||
| 163 | |||
| 164 | $signedInfo = new static( |
||
| 165 | array_pop($canonicalizationMethod), |
||
| 166 | array_pop($signatureMethod), |
||
| 167 | $references, |
||
| 168 | self::getOptionalAttribute($xml, 'Id', IDValue::class, null), |
||
| 169 | ); |
||
| 170 | |||
| 171 | $signedInfo->xml = $xml; |
||
| 172 | return $signedInfo; |
||
| 173 | } |
||
| 174 | |||
| 175 | |||
| 176 | /** |
||
| 177 | * Convert this SignedInfo element to XML. |
||
| 178 | * |
||
| 179 | * @param \DOMElement|null $parent The element we should append this SignedInfo element to. |
||
| 180 | */ |
||
| 181 | public function toXML(?DOMElement $parent = null): DOMElement |
||
| 182 | { |
||
| 183 | $e = $this->instantiateParentElement($parent); |
||
| 184 | |||
| 185 | if ($this->getId() !== null) { |
||
| 186 | $e->setAttribute('Id', strval($this->getId())); |
||
| 187 | } |
||
| 188 | |||
| 189 | $this->getCanonicalizationMethod()->toXML($e); |
||
| 190 | $this->getSignatureMethod()->toXML($e); |
||
| 191 | |||
| 192 | foreach ($this->getReferences() as $ref) { |
||
| 193 | $ref->toXML($e); |
||
| 194 | } |
||
| 195 | |||
| 196 | return $e; |
||
| 197 | } |
||
| 198 | } |
||
| 199 |
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