Skip to content

Commit 629d6a8

Browse files
committed
update exception messages
1 parent faf490c commit 629d6a8

File tree

7 files changed

+13
-14
lines changed

7 files changed

+13
-14
lines changed

src/Cryptography/Algorithms/Eddsa/EdDsaSigner.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ public function sign(string $message): string
2929
try {
3030
return sodium_crypto_sign_detached($message, $this->privateKey->getContent());
3131
} catch (SodiumException $e) {
32-
throw new SigningException("Cannot sign using Sodium extension", 0, $e);
32+
throw new SigningException("Cannot sign using Sodium extension.", 0, $e);
3333
}
3434
}
3535

36-
throw new RuntimeException('The sodium_crypto_sign_detached function is not available');
36+
throw new RuntimeException('The sodium_crypto_sign_detached function is not available.');
3737
}
3838

3939
public function name(): string

src/Cryptography/Algorithms/Eddsa/EdDsaVerifier.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ public function verify(string $plain, string $signature): void
2727
if (function_exists('sodium_crypto_sign_verify_detached')) {
2828
try {
2929
if (!sodium_crypto_sign_verify_detached($signature, $plain, $this->publicKey->getContent())) {
30-
throw new InvalidSignatureException('Signature is to verified');
30+
throw new InvalidSignatureException('Signature is to verified.');
3131
}
3232
} catch (SodiumException $e) {
33-
throw new InvalidSignatureException('Sodium cannot verify the signature', 0, $e);
33+
throw new InvalidSignatureException('Sodium cannot verify the signature.', 0, $e);
3434
}
3535
} else {
36-
throw new RuntimeException('sodium_crypto_sign_verify_detached function is not available');
36+
throw new RuntimeException('sodium_crypto_sign_verify_detached function is not available.');
3737
}
3838
}
3939

src/Cryptography/Algorithms/Hmac/AbstractHmac.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ public function sign(string $message): string
2828
{
2929
try {
3030
if (strlen($this->key->getContent()) < 32 || strlen($this->key->getContent()) > 6144) {
31-
throw new InvalidKeyException('Key length must be between 32 and 6144');
31+
throw new InvalidKeyException('Key length must be between 32 and 6144.');
3232
}
3333
return hash_hmac($this->algorithm(), $message, $this->key->getContent(), true);
3434
} catch (ValueError | InvalidKeyException $e) {
35-
throw new SigningException('Cannot sign the signature', 0, $e);
35+
throw new SigningException('Cannot sign the signature.', 0, $e);
3636
}
3737
}
3838

src/Parser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ private function split(string $jwt): array
7676
$sections = explode('.', $jwt);
7777

7878
if (count($sections) !== 3) {
79-
throw new Exceptions\InvalidTokenException('JWT format is not valid');
79+
throw new Exceptions\InvalidTokenException('JWT format is not valid.');
8080
}
8181

8282
return $sections;
@@ -151,7 +151,7 @@ public function validateHeader(string $header): void
151151
throw new InvalidTokenException('JWT header does not have `typ` field.');
152152
}
153153
if ($fields['typ'] !== 'JWT') {
154-
throw new InvalidTokenException("JWT of type {$fields['typ']} is not supported.");
154+
throw new InvalidTokenException("JWT of type `{$fields['typ']}` is not supported.");
155155
}
156156

157157
if (isset($fields['kid'])) {

src/VerifierFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function getVerifier(string $jwt): Verifier
5757
return $this->verifiers[$header['kid']];
5858
}
5959

60-
throw new VerifierNotFoundException("No verifier found for {$header['kid']}");
60+
throw new VerifierNotFoundException("No verifier found for kid `{$header['kid']}`.");
6161
}
6262

6363
throw new NoKidException();
@@ -73,7 +73,7 @@ private function extractHeader(string $jwt): string
7373
$sections = explode('.', $jwt);
7474

7575
if (count($sections) !== 3) {
76-
throw new Exceptions\InvalidTokenException('JWT format is not valid');
76+
throw new Exceptions\InvalidTokenException('JWT format is not valid,');
7777
}
7878

7979
return $sections[0];

tests/ExamplesTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,10 @@ public function test_multiple_keys()
129129
// Generate tokens
130130

131131
$signer1 = new RS256Signer($privateKey1);
132-
$signer2 = new ES384Signer($privateKey2);
133-
134132
$generator1 = new Generator($signer1);
135133
$jwt1 = $generator1->generate(['id' => 13, 'is-admin' => true]);
136134

135+
$signer2 = new ES384Signer($privateKey2);
137136
$generator2 = new Generator($signer2);
138137
$jwt2 = $generator2->generate(['id' => 13, 'is-admin' => true]);
139138

tests/ParserTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public function test_parse_with_a_jwt_with_non_jwt_typ()
141141
$parser = new Parser($this->verifier);
142142

143143
$this->expectException(InvalidTokenException::class);
144-
$this->expectExceptionMessage('JWT of type x is not supported.');
144+
$this->expectExceptionMessage('JWT of type `x` is not supported.');
145145
$parser->parse($noTypJwt);
146146
}
147147

0 commit comments

Comments
 (0)