Skip to content

Commit 8123f41

Browse files
committed
Fix phpcs issues
1 parent 0f1f17c commit 8123f41

15 files changed

Lines changed: 121 additions & 100 deletions

src/Alg/Signature/SignatureAlgorithmFactory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ public static function registerAlgorithm(string $className): void
114114
Assert::subclassOf(
115115
$className,
116116
AbstractSigner::class,
117-
'Cannot register algorithm "' . $className . '", must implement ' . "\SimpleSAML\XMLSecurity\Alg\SignatureInterface.",
117+
'Cannot register algorithm "' . $className . '", must implement '
118+
. "\SimpleSAML\XMLSecurity\Alg\SignatureInterface.",
118119
InvalidArgumentException::class
119120
);
120121

src/Key/PublicKey.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,14 @@ protected static function makeASN1Segment(int $type, string $string): ?string
9595
} elseif ($length < self::ASN1_SIZE_256) {
9696
$output = sprintf("%c%c%c%s", $type, self::ASN1_SIZE_128 + 1, $length, $string);
9797
} else { // ($length < self::ASN1_SIZE_65535)
98-
$output = sprintf("%c%c%c%c%s", $type, self::ASN1_SIZE_128 +2, $length / 0x0100, $length % 0x0100, $string);
98+
$output = sprintf(
99+
"%c%c%c%c%s",
100+
$type,
101+
self::ASN1_SIZE_128 + 2,
102+
$length / 0x0100,
103+
$length % 0x0100,
104+
$string
105+
);
99106
}
100107

101108
return $output;

src/XML/CanonicalizableElementTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,4 @@ public function serialize(): string
5555
$xml = $this->getOriginalXML();
5656
return $xml->ownerDocument->saveXML($xml);
5757
}
58-
}
58+
}

src/XML/SignedElementTrait.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,15 @@ protected function setSignature(Signature $signature): void
7676
*/
7777
private function validateReferenceUri(Reference $reference, \DOMElement $xml): void
7878
{
79-
if (in_array(
79+
if (
80+
in_array(
8081
$this->signature->getSignedInfo()->getCanonicalizationMethod()->getAlgorithm(),
8182
[
8283
Constants::C14N_INCLUSIVE_WITH_COMMENTS,
8384
Constants::C14N_EXCLUSIVE_WITH_COMMENTS,
8485
]
85-
) && !$reference->isXPointer()
86+
)
87+
&& !$reference->isXPointer()
8688
) { // canonicalization with comments used, but reference wasn't an xpointer!
8789
throw new RuntimeException('Invalid reference for canonicalization algorithm.');
8890
}
@@ -95,7 +97,6 @@ private function validateReferenceUri(Reference $reference, \DOMElement $xml): v
9597
$xml->isSameNode($xml->ownerDocument->documentElement),
9698
'Cannot use document reference when element is not the root of the document.',
9799
RuntimeException::class
98-
99100
);
100101
} else { // short-name or scheme-based xpointer
101102
Assert::notEmpty(
@@ -178,10 +179,12 @@ private function verifyInternal(SignatureAlgorithm $verifier): SignedElementInte
178179
/** @var SignedElementInterface $ref */
179180
$ref = $this->validateReference();
180181

181-
if ($verifier->verify(
182-
$c14nSignedInfo, // the canonicalized ds:SignedInfo element (plaintext)
183-
base64_decode($this->signature->getSignatureValue()->getRawContent()) // the actual signature
184-
)) {
182+
if (
183+
$verifier->verify(
184+
$c14nSignedInfo, // the canonicalized ds:SignedInfo element (plaintext)
185+
base64_decode($this->signature->getSignatureValue()->getRawContent()) // the actual signature
186+
)
187+
) {
185188
/*
186189
* validateReference() returns an object of the same class using this trait. This means the validatingKey
187190
* property is available, and we can set it on the newly created object because we are in the same class,

src/XML/ds/DigestMethod.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ public function getElements(): array
9595
* Set the value of the elements-property
9696
*
9797
* @param \SimpleSAML\XML\Chunk[] $elements
98-
* @throws \SimpleSAML\Assert\AssertionFailedException if the supplied array contains anything other than Chunk objects
98+
* @throws \SimpleSAML\Assert\AssertionFailedException
99+
* if the supplied array contains anything other than Chunk objects
99100
*/
100101
private function setElements(array $elements): void
101102
{

src/XML/ds/SignedInfo.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,11 @@ public static function fromXML(DOMElement $xml): object
185185
$Id = self::getAttribute($xml, 'Id', null);
186186

187187
$canonicalizationMethod = CanonicalizationMethod::getChildrenOfClass($xml);
188-
Assert::count($canonicalizationMethod, 1, 'A ds:SignedInfo element must contain exactly one ds:CanonicalizationMethod');
188+
Assert::count(
189+
$canonicalizationMethod,
190+
1,
191+
'A ds:SignedInfo element must contain exactly one ds:CanonicalizationMethod'
192+
);
189193

190194
$signatureMethod = SignatureMethod::getChildrenOfClass($xml);
191195
Assert::count($signatureMethod, 1, 'A ds:SignedInfo element must contain exactly one ds:SignatureMethod');

src/XML/ec/AbstractEcElement.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77
use SimpleSAML\XML\AbstractXMLElement;
88
use SimpleSAML\XMLSecurity\Constants;
99

10-
1110
/**
1211
* Abstract class to be implemented by all the classes in this namespace
13-
12+
*
1413
* @package simplesamlphp/xml-security
1514
*/
1615
abstract class AbstractEcElement extends AbstractXMLElement

tests/XML/CustomSignable.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ class CustomSignable extends AbstractXMLElement implements SignableElementInterf
4747
*
4848
* @param \DOMElement $xml
4949
*/
50-
private function __construct(DOMElement $xml, ?string $id) {
50+
private function __construct(DOMElement $xml, ?string $id)
51+
{
5152
$this->setXML($xml);
5253
$this->id = $id;
5354
}
@@ -121,7 +122,8 @@ protected function getOriginalXML(): DOMElement
121122
* @param \DOMElement $xml The XML element we should load
122123
* @return \SimpleSAML\XMLSecurity\Test\XML\CustomSignable
123124
*
124-
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException if the qualified name of the supplied element is wrong
125+
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
126+
* if the qualified name of the supplied element is wrong
125127
*/
126128
public static function fromXML(DOMElement $xml): object
127129
{

tests/XML/SignableElementTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,4 @@ public function testSigningWithDifferentRoot(): void
256256
);
257257
$customSignable->toXML($doc->documentElement);
258258
}
259-
260-
261-
262259
}
263-

tests/XML/SignedElementTest.php

Lines changed: 73 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -79,104 +79,103 @@ public function testUnmarshalling(): void
7979
$this->signedDocument->ownerDocument->saveXML($this->signedDocument),
8080
strval($customSigned)
8181
);
82-
}
82+
}
8383

8484

8585
/**
8686
* Test the verification of a signature with a given key.
8787
*/
88-
public function testSuccessfulVerifyingWithGivenKey(): void
89-
{
90-
$customSigned = CustomSignable::fromXML($this->signedDocument);
91-
92-
$this->assertTrue($customSigned->isSigned());
93-
$signature = $customSigned->getSignature();
94-
$this->assertInstanceOf(Signature::class, $signature);
95-
$sigAlg = $signature->getSignedInfo()->getSignatureMethod()->getAlgorithm();
96-
$this->assertEquals(Constants::SIG_RSA_SHA256, $sigAlg);
97-
$factory = new SignatureAlgorithmFactory();
98-
$certificate = new X509Certificate($this->certificate);
99-
$verifier = $factory->getAlgorithm($sigAlg, $certificate);
100-
101-
$verified = $customSigned->verify($verifier);
102-
$this->assertInstanceOf(CustomSignable::class, $verified);
103-
$this->assertFalse($verified->isSigned());
104-
$this->assertEquals(
105-
'<ssp:CustomSignable xmlns:ssp="urn:ssp:custom"><ssp:Some>Chunk</ssp:Some></ssp:CustomSignable>',
106-
strval($verified)
107-
);
108-
$this->assertEquals($certificate, $verified->getValidatingKey());
109-
}
88+
public function testSuccessfulVerifyingWithGivenKey(): void
89+
{
90+
$customSigned = CustomSignable::fromXML($this->signedDocument);
91+
92+
$this->assertTrue($customSigned->isSigned());
93+
$signature = $customSigned->getSignature();
94+
$this->assertInstanceOf(Signature::class, $signature);
95+
$sigAlg = $signature->getSignedInfo()->getSignatureMethod()->getAlgorithm();
96+
$this->assertEquals(Constants::SIG_RSA_SHA256, $sigAlg);
97+
$factory = new SignatureAlgorithmFactory();
98+
$certificate = new X509Certificate($this->certificate);
99+
$verifier = $factory->getAlgorithm($sigAlg, $certificate);
100+
101+
$verified = $customSigned->verify($verifier);
102+
$this->assertInstanceOf(CustomSignable::class, $verified);
103+
$this->assertFalse($verified->isSigned());
104+
$this->assertEquals(
105+
'<ssp:CustomSignable xmlns:ssp="urn:ssp:custom"><ssp:Some>Chunk</ssp:Some></ssp:CustomSignable>',
106+
strval($verified)
107+
);
108+
$this->assertEquals($certificate, $verified->getValidatingKey());
109+
}
110110

111111

112112
/**
113113
* Test the verification of a signature without passing a key, just what's in KeyInfo
114114
*/
115-
public function testSuccessfulVerifyingWithoutKey(): void
116-
{
117-
$customSigned = CustomSignable::fromXML($this->signedDocument);
118-
119-
$this->assertTrue($customSigned->isSigned());
120-
$signature = $customSigned->getSignature();
121-
$this->assertInstanceOf(Signature::class, $signature);
122-
$sigAlg = $signature->getSignedInfo()->getSignatureMethod()->getAlgorithm();
123-
$this->assertEquals(Constants::SIG_RSA_SHA256, $sigAlg);
124-
$certificate = new X509Certificate($this->certificate);
125-
126-
$verified = $customSigned->verify();
127-
$this->assertInstanceOf(CustomSignable::class, $verified);
128-
$this->assertFalse($verified->isSigned());
129-
$this->assertEquals(
130-
'<ssp:CustomSignable xmlns:ssp="urn:ssp:custom"><ssp:Some>Chunk</ssp:Some></ssp:CustomSignable>',
131-
strval($verified)
132-
);
133-
$validatingKey = $verified->getValidatingKey();
134-
$this->assertInstanceOf(X509Certificate::class, $validatingKey);
135-
/** @var \SimpleSAML\XMLSecurity\Key\X509Certificate $validatingKey */
136-
$this->assertEquals($certificate->getCertificate(), $validatingKey->getCertificate());
137-
}
115+
public function testSuccessfulVerifyingWithoutKey(): void
116+
{
117+
$customSigned = CustomSignable::fromXML($this->signedDocument);
118+
119+
$this->assertTrue($customSigned->isSigned());
120+
$signature = $customSigned->getSignature();
121+
$this->assertInstanceOf(Signature::class, $signature);
122+
$sigAlg = $signature->getSignedInfo()->getSignatureMethod()->getAlgorithm();
123+
$this->assertEquals(Constants::SIG_RSA_SHA256, $sigAlg);
124+
$certificate = new X509Certificate($this->certificate);
125+
126+
$verified = $customSigned->verify();
127+
$this->assertInstanceOf(CustomSignable::class, $verified);
128+
$this->assertFalse($verified->isSigned());
129+
$this->assertEquals(
130+
'<ssp:CustomSignable xmlns:ssp="urn:ssp:custom"><ssp:Some>Chunk</ssp:Some></ssp:CustomSignable>',
131+
strval($verified)
132+
);
133+
$validatingKey = $verified->getValidatingKey();
134+
$this->assertInstanceOf(X509Certificate::class, $validatingKey);
135+
/** @var \SimpleSAML\XMLSecurity\Key\X509Certificate $validatingKey */
136+
$this->assertEquals($certificate->getCertificate(), $validatingKey->getCertificate());
137+
}
138138

139139

140140
/**
141141
* Test that verifying a tampered signature, without giving a key for verification, fails as expected.
142142
*/
143-
public function testVerifyingTamperedSignatureWithoutKeyFails(): void
144-
{
145-
$customSigned = CustomSignable::fromXML($this->tamperedDocument);
143+
public function testVerifyingTamperedSignatureWithoutKeyFails(): void
144+
{
145+
$customSigned = CustomSignable::fromXML($this->tamperedDocument);
146146

147-
$this->assertTrue($customSigned->isSigned());
148-
$signature = $customSigned->getSignature();
149-
$this->assertInstanceOf(Signature::class, $signature);
150-
$sigAlg = $signature->getSignedInfo()->getSignatureMethod()->getAlgorithm();
151-
$this->assertEquals(Constants::SIG_RSA_SHA256, $sigAlg);
147+
$this->assertTrue($customSigned->isSigned());
148+
$signature = $customSigned->getSignature();
149+
$this->assertInstanceOf(Signature::class, $signature);
150+
$sigAlg = $signature->getSignedInfo()->getSignatureMethod()->getAlgorithm();
151+
$this->assertEquals(Constants::SIG_RSA_SHA256, $sigAlg);
152152

153-
$this->expectException(RuntimeException::class);
154-
$this->expectDeprecationMessage('Failed to validate signature.');
155-
$customSigned->verify();
156-
}
153+
$this->expectException(RuntimeException::class);
154+
$this->expectDeprecationMessage('Failed to validate signature.');
155+
$customSigned->verify();
156+
}
157157

158158

159159
/**
160160
* Test that verifying a tampered signature with a given key fails as expected.
161161
*/
162-
public function testVerifyingTamperedSignatureWithKeyFails(): void
163-
{
164-
$customSigned = CustomSignable::fromXML($this->tamperedDocument);
165-
162+
public function testVerifyingTamperedSignatureWithKeyFails(): void
163+
{
164+
$customSigned = CustomSignable::fromXML($this->tamperedDocument);
166165

167-
$this->assertTrue($customSigned->isSigned());
168-
$signature = $customSigned->getSignature();
169-
$this->assertInstanceOf(Signature::class, $signature);
170-
$sigAlg = $signature->getSignedInfo()->getSignatureMethod()->getAlgorithm();
171-
$this->assertEquals(Constants::SIG_RSA_SHA256, $sigAlg);
172-
$factory = new SignatureAlgorithmFactory();
173-
$certificate = new X509Certificate($this->certificate);
174-
$verifier = $factory->getAlgorithm($sigAlg, $certificate);
166+
$this->assertTrue($customSigned->isSigned());
167+
$signature = $customSigned->getSignature();
168+
$this->assertInstanceOf(Signature::class, $signature);
169+
$sigAlg = $signature->getSignedInfo()->getSignatureMethod()->getAlgorithm();
170+
$this->assertEquals(Constants::SIG_RSA_SHA256, $sigAlg);
171+
$factory = new SignatureAlgorithmFactory();
172+
$certificate = new X509Certificate($this->certificate);
173+
$verifier = $factory->getAlgorithm($sigAlg, $certificate);
175174

176-
$this->expectException(RuntimeException::class);
177-
$this->expectDeprecationMessage('Failed to validate signature.');
178-
$customSigned->verify($verifier);
179-
}
175+
$this->expectException(RuntimeException::class);
176+
$this->expectDeprecationMessage('Failed to validate signature.');
177+
$customSigned->verify($verifier);
178+
}
180179

181180

182181

@@ -215,4 +214,3 @@ public function testSuccessfulVerifyingDocumentWithComments(): void
215214
$this->assertEquals($certificate, $verified->getValidatingKey());
216215
}
217216
}
218-

0 commit comments

Comments
 (0)