Skip to content

Commit c6f3423

Browse files
committed
Remove unnecessary code
1 parent 760e67d commit c6f3423

File tree

80 files changed

+458
-598
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+458
-598
lines changed

src/XML/AbstractSignedXMLElement.php

Lines changed: 0 additions & 105 deletions
This file was deleted.

src/XML/SignedElementTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ private function verifyInternal(SignatureAlgorithmInterface $verifier): SignedEl
179179
$ref = $this->validateReference();
180180

181181
if (
182-
$verifier->verify(
182+
$verifier?->verify(
183183
$c14nSignedInfo, // the canonicalized ds:SignedInfo element (plaintext)
184184
base64_decode($this->signature->getSignatureValue()->getRawContent()), // the actual signature
185185
)
@@ -240,7 +240,7 @@ public function verify(SignatureAlgorithmInterface $verifier = null): SignedElem
240240
throw new NoSignatureFoundException();
241241
}
242242

243-
$keyInfo = $this->signature->getKeyInfo();
243+
$keyInfo = $this->signature?->getKeyInfo();
244244
$algId = $this->signature->getSignedInfo()->getSignatureMethod()->getAlgorithm();
245245
if ($verifier === null && $keyInfo === null) {
246246
throw new InvalidArgumentException('No key or KeyInfo available for signature verification.');

src/XML/ds/CanonicalizationMethod.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public static function fromXML(DOMElement $xml): static
102102
public function toXML(DOMElement $parent = null): DOMElement
103103
{
104104
$e = $this->instantiateParentElement($parent);
105-
$e->setAttribute('Algorithm', $this->Algorithm);
105+
$e->setAttribute('Algorithm', $this->getAlgorithm());
106106

107107
return $e;
108108
}

src/XML/ds/DigestMethod.php

Lines changed: 10 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use SimpleSAML\XML\Chunk;
1010
use SimpleSAML\XML\Exception\InvalidDOMElementException;
1111
use SimpleSAML\XML\Exception\SchemaViolationException;
12+
use SimpleSAML\XML\ExtendableElementTrait;
1213
use SimpleSAML\XMLSecurity\Constants as C;
1314
use SimpleSAML\XMLSecurity\Exception\InvalidArgumentException;
1415

@@ -19,18 +20,17 @@
1920
*/
2021
final class DigestMethod extends AbstractDsElement
2122
{
23+
use ExtendableElementTrait;
24+
25+
public const NAMESPACE = C::XS_ANY_NS_OTHER;
26+
2227
/**
2328
* The algorithm.
2429
*
2530
* @var string
2631
*/
2732
protected string $Algorithm;
2833

29-
/**
30-
* @var \SimpleSAML\XML\Chunk[]
31-
*/
32-
protected array $elements;
33-
3434

3535
/**
3636
* Initialize a DigestMethod element.
@@ -75,32 +75,6 @@ private function setAlgorithm(string $algorithm): void
7575
}
7676

7777

78-
/**
79-
* Collect the embedded elements
80-
*
81-
* @return \SimpleSAML\XML\Chunk[]
82-
*/
83-
public function getElements(): array
84-
{
85-
return $this->elements;
86-
}
87-
88-
89-
/**
90-
* Set the value of the elements-property
91-
*
92-
* @param \SimpleSAML\XML\Chunk[] $elements
93-
* @throws \SimpleSAML\Assert\AssertionFailedException
94-
* if the supplied array contains anything other than Chunk objects
95-
*/
96-
private function setElements(array $elements): void
97-
{
98-
Assert::allIsInstanceOf($elements, Chunk::class, InvalidArgumentException::class);
99-
100-
$this->elements = $elements;
101-
}
102-
103-
10478
/**
10579
* Convert XML into a DigestMethod
10680
*
@@ -140,10 +114,13 @@ public static function fromXML(DOMElement $xml): static
140114
public function toXML(DOMElement $parent = null): DOMElement
141115
{
142116
$e = $this->instantiateParentElement($parent);
143-
$e->setAttribute('Algorithm', $this->Algorithm);
117+
$e->setAttribute('Algorithm', $this->getAlgorithm());
144118

119+
/** @psalm-var \SimpleSAML\XML\SerializableElementInterface $elt */
145120
foreach ($this->elements as $elt) {
146-
$e->appendChild($e->ownerDocument->importNode($elt->getXML(), true));
121+
if (!$elt->isEmptyElement()) {
122+
$elt->toXML($e);
123+
}
147124
}
148125

149126
return $e;

src/XML/ds/DigestValue.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* Class representing a ds:DigestValue element.
1111
*
1212
* @package simplesaml/xml-security
13+
* @psalm-suppress PropertyNotSetInConstructor $content
1314
*/
1415
final class DigestValue extends AbstractDsElement
1516
{

src/XML/ds/DsObject.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ final class DsObject extends AbstractDsElement
2727
/** @var string */
2828
public const NAMESPACE = Constants::XS_ANY_NS_ANY;
2929

30+
3031
/**
3132
* The Id.
3233
*
@@ -203,20 +204,22 @@ public function toXML(DOMElement $parent = null): DOMElement
203204
$e = $this->instantiateParentElement($parent);
204205

205206
if ($this->Id !== null) {
206-
$e->setAttribute('Id', $this->Id);
207+
$e->setAttribute('Id', $this->getId());
207208
}
208209

209210
if ($this->MimeType !== null) {
210-
$e->setAttribute('MimeType', $this->MimeType);
211+
$e->setAttribute('MimeType', $this->getMimeType());
211212
}
212213

213214
if ($this->Encoding !== null) {
214-
$e->setAttribute('Encoding', $this->Encoding);
215+
$e->setAttribute('Encoding', $this->getEncoding());
215216
}
216217

217218
/** @psalm-var \SimpleSAML\XML\SerializableElementInterface[] $this->elements */
218219
foreach ($this->elements as $elt) {
219-
$elt->toXML($e);
220+
if (!$elt->isEmptyElement()) {
221+
$elt->toXML($e);
222+
}
220223
}
221224

222225
return $e;

src/XML/ds/Exponent.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* Class representing a ds:Exponent element.
1111
*
1212
* @package simplesaml/xml-security
13+
* @psalm-suppress PropertyNotSetInConstructor $content
1314
*/
1415
final class Exponent extends AbstractDsElement
1516
{

src/XML/ds/KeyInfo.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public function toXML(DOMElement $parent = null): DOMElement
201201
$e = $this->instantiateParentElement($parent);
202202

203203
if ($this->Id !== null) {
204-
$e->setAttribute('Id', $this->Id);
204+
$e->setAttribute('Id', $this->getId());
205205
}
206206

207207
foreach ($this->info as $n) {

src/XML/ds/KeyValue.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,13 @@ public function toXML(DOMElement $parent = null): DOMElement
131131
{
132132
$e = $this->instantiateParentElement($parent);
133133

134-
if ($this->RSAKeyValue !== null) {
135-
$this->RSAKeyValue->toXML($e);
136-
}
134+
$this->getRSAKeyValue()?->toXML($e);
137135

138-
/** @psalm-var \SimpleSAML\XML\SerializableElementInterface[] $this->elements */
139-
foreach ($this->elements as $element) {
140-
$e->appendChild($e->ownerDocument->importNode($element->toXML(), true));
136+
/** @psalm-var \SimpleSAML\XML\SerializableElementInterface $elt */
137+
foreach ($this->elements as $elt) {
138+
if (!$elt->isEmptyElement()) {
139+
$elt->toXML($e);
140+
}
141141
}
142142

143143
return $e;

src/XML/ds/Manifest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,11 @@ public function toXML(DOMElement $parent = null): DOMElement
117117
{
118118
$e = $this->instantiateParentElement($parent);
119119

120-
if ($this->Id !== null) {
121-
$e->setAttribute('Id', $this->Id);
120+
if ($this->getId() !== null) {
121+
$e->setAttribute('Id', $this->getId());
122122
}
123123

124-
foreach ($this->references as $reference) {
124+
foreach ($this->getReferences() as $reference) {
125125
$reference->toXML($e);
126126
}
127127

0 commit comments

Comments
 (0)