Skip to content

Commit ed8ca90

Browse files
committed
Fix nits
1 parent 20bcbd0 commit ed8ca90

File tree

5 files changed

+20
-12
lines changed

5 files changed

+20
-12
lines changed

src/XML/SignableElementTrait.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
use SimpleSAML\XMLSecurity\XML\ds\Transform;
2626
use SimpleSAML\XMLSecurity\XML\ds\Transforms;
2727

28+
use function in_array;
29+
2830
/**
2931
* Trait SignableElementTrait
3032
*

src/XML/SignedElementTrait.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use SimpleSAML\XMLSecurity\Exception\InvalidArgumentException;
1313
use SimpleSAML\XMLSecurity\Exception\NoSignatureFound;
1414
use SimpleSAML\XMLSecurity\Exception\RuntimeException;
15-
use SimpleSAML\XMLSecurity\Key\AbstractKey;
15+
use SimpleSAML\XMLSecurity\Key;
1616
use SimpleSAML\XMLSecurity\Utils\Security;
1717
use SimpleSAML\XMLSecurity\Utils\XML;
1818
use SimpleSAML\XMLSecurity\Utils\XPath;
@@ -21,6 +21,10 @@
2121
use SimpleSAML\XMLSecurity\XML\ds\X509Certificate;
2222
use SimpleSAML\XMLSecurity\XML\ds\X509Data;
2323

24+
use function array_pop;
25+
use function base64_decode;
26+
use function in_array;
27+
2428
/**
2529
* Helper trait for processing signed elements.
2630
*
@@ -42,7 +46,7 @@ trait SignedElementTrait
4246
*
4347
* @var \SimpleSAML\XMLSecurity\Key\AbstractKey|null
4448
*/
45-
private ?AbstractKey $validatingKey = null;
49+
private ?Key\AbstractKey $validatingKey = null;
4650

4751

4852
/**
@@ -132,14 +136,14 @@ private function validateReference(): SignedElementInterface
132136
$this->validateReferenceUri($reference, $xml);
133137

134138
$xp = XPath::getXPath($xml->ownerDocument);
135-
$sigNode = $xp->query('child::ds:Signature', $xml);
139+
$sigNode = XPath::xpQuery($xml, 'child::ds:Signature', $xp);
136140
Assert::count(
137141
$sigNode,
138142
1,
139143
'None or more than one signature found in object.',
140144
RuntimeException::class
141145
);
142-
$xml->removeChild($sigNode->item(0));
146+
$xml->removeChild($sigNode[0]);
143147

144148
$data = XML::processTransforms($reference->getTransforms(), $xml);
145149
$digest = Security::hash($reference->getDigestMethod()->getAlgorithm(), $data, false);
@@ -196,7 +200,7 @@ private function verifyInternal(SignatureAlgorithm $verifier): SignedElementInte
196200
*
197201
* @return \SimpleSAML\XMLSecurity\Key\AbstractKey|null The key that successfully validated this signature.
198202
*/
199-
public function getValidatingKey(): ?AbstractKey
203+
public function getValidatingKey(): ?Key\AbstractKey
200204
{
201205
return $this->validatingKey;
202206
}
@@ -266,11 +270,11 @@ public function verify(SignatureAlgorithm $verifier = null): SignedElementInterf
266270
}
267271

268272
// build a valid PEM for the certificate
269-
$cert = \SimpleSAML\XMLSecurity\Key\X509Certificate::PEM_HEADER . "\n" .
273+
$cert = Key\X509Certificate::PEM_HEADER . "\n" .
270274
$data->getRawContent() . "\n" .
271-
\SimpleSAML\XMLSecurity\Key\X509Certificate::PEM_FOOTER;
275+
Key\X509Certificate::PEM_FOOTER;
272276

273-
$key = new \SimpleSAML\XMLSecurity\Key\X509Certificate($cert);
277+
$key = new Key\X509Certificate($cert);
274278
$verifier = $factory->getAlgorithm($algId, $key);
275279

276280
try {

src/XML/ds/Reference.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use SimpleSAML\XML\Exception\InvalidDOMElementException;
1010

1111
use function array_pop;
12+
use function preg_match;
1213

1314
/**
1415
* Class representing a ds:Reference element.

tests/XML/CustomSignable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class CustomSignable extends AbstractXMLElement implements SignableElementInterf
3333
public ?string $id = null;
3434

3535
/** @var \DOMElement $xml */
36-
protected \DOMElement $xml;
36+
protected DOMElement $xml;
3737

3838
/** @var bool */
3939
protected bool $formatOutput = false;

tests/XML/SignedElementTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace SimpleSAML\XMLSecurity\Test\XML;
66

7+
use DOMElement;
78
use PHPUnit\Framework\TestCase;
89
use SimpleSAML\XML\DOMDocumentFactory;
910
use SimpleSAML\XMLSecurity\Alg\Signature\SignatureAlgorithmFactory;
@@ -36,13 +37,13 @@ final class SignedElementTest extends TestCase
3637
private string $certificate;
3738

3839
/** @var \DOMElement */
39-
private \DOMElement $signedDocumentWithComments;
40+
private DOMElement $signedDocumentWithComments;
4041

4142
/** @var \DOMElement */
42-
private \DOMElement $signedDocument;
43+
private DOMElement $signedDocument;
4344

4445
/** @var \DOMElement */
45-
private \DOMElement $tamperedDocument;
46+
private DOMElement $tamperedDocument;
4647

4748

4849
/**

0 commit comments

Comments
 (0)