Skip to content

Commit e51226a

Browse files
committed
Fix nits
1 parent 20bcbd0 commit e51226a

File tree

5 files changed

+18
-9
lines changed

5 files changed

+18
-9
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: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use SimpleSAML\XMLSecurity\Exception\NoSignatureFound;
1414
use SimpleSAML\XMLSecurity\Exception\RuntimeException;
1515
use SimpleSAML\XMLSecurity\Key\AbstractKey;
16+
use SimpleSAML\XMLSecurity\Key\X509Certificate;
1617
use SimpleSAML\XMLSecurity\Utils\Security;
1718
use SimpleSAML\XMLSecurity\Utils\XML;
1819
use SimpleSAML\XMLSecurity\Utils\XPath;
@@ -21,6 +22,10 @@
2122
use SimpleSAML\XMLSecurity\XML\ds\X509Certificate;
2223
use SimpleSAML\XMLSecurity\XML\ds\X509Data;
2324

25+
use function array_pop;
26+
use function base64_decode;
27+
use function in_array;
28+
2429
/**
2530
* Helper trait for processing signed elements.
2631
*
@@ -132,14 +137,14 @@ private function validateReference(): SignedElementInterface
132137
$this->validateReferenceUri($reference, $xml);
133138

134139
$xp = XPath::getXPath($xml->ownerDocument);
135-
$sigNode = $xp->query('child::ds:Signature', $xml);
140+
$sigNode = XPath::xpQuery($xml, 'child::ds:Signature', $xp);
136141
Assert::count(
137142
$sigNode,
138143
1,
139144
'None or more than one signature found in object.',
140145
RuntimeException::class
141146
);
142-
$xml->removeChild($sigNode->item(0));
147+
$xml->removeChild($sigNode[0]);
143148

144149
$data = XML::processTransforms($reference->getTransforms(), $xml);
145150
$digest = Security::hash($reference->getDigestMethod()->getAlgorithm(), $data, false);
@@ -266,11 +271,11 @@ public function verify(SignatureAlgorithm $verifier = null): SignedElementInterf
266271
}
267272

268273
// build a valid PEM for the certificate
269-
$cert = \SimpleSAML\XMLSecurity\Key\X509Certificate::PEM_HEADER . "\n" .
274+
$cert = X509Certificate::PEM_HEADER . "\n" .
270275
$data->getRawContent() . "\n" .
271-
\SimpleSAML\XMLSecurity\Key\X509Certificate::PEM_FOOTER;
276+
X509Certificate::PEM_FOOTER;
272277

273-
$key = new \SimpleSAML\XMLSecurity\Key\X509Certificate($cert);
278+
$key = new X509Certificate($cert);
274279
$verifier = $factory->getAlgorithm($algId, $key);
275280

276281
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)