Skip to content

Commit 07a5864

Browse files
authored
"Replace mb_* functions with equivalent non-multibyte functions" (#578)
This commit replaces mb_* functions with non-multibyte equivalent functions, which don't require mbstring extension. It also adjusts the required PHP version in composer.json from 8.3 to 8.2. This change reduces dependencies and broadens compatibility without impacting functionality. It is part of an overall code simplification and optimization effort.
1 parent 1ae6f55 commit 07a5864

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed

KeyEncryption/Chacha20Poly1305.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use RuntimeException;
1414
use function in_array;
1515
use function is_string;
16+
use function strlen;
1617
use const OPENSSL_RAW_DATA;
1718

1819
final readonly class Chacha20Poly1305 implements KeyEncryption
@@ -68,7 +69,7 @@ public function decryptKey(JWK $key, string $encrypted_cek, array $header): stri
6869
isset($header['nonce']) || throw new InvalidArgumentException('The header parameter "nonce" is missing.');
6970
is_string($header['nonce']) || throw new InvalidArgumentException('The header parameter "nonce" is not valid.');
7071
$nonce = Base64UrlSafe::decodeNoPadding($header['nonce']);
71-
if (mb_strlen($nonce, '8bit') !== 12) {
72+
if (strlen($nonce) !== 12) {
7273
throw new InvalidArgumentException('The header parameter "nonce" is not valid.');
7374
}
7475

Signature/Blake2b.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@
1313
use function extension_loaded;
1414
use function in_array;
1515
use function is_string;
16+
use function strlen;
1617

1718
/**
1819
* @see \Jose\Tests\Component\Signature\Algorithm\Blake2bTest
1920
*/
2021
final readonly class Blake2b implements MacAlgorithm
2122
{
22-
private const int MINIMUM_KEY_LENGTH = 32;
23+
private const MINIMUM_KEY_LENGTH = 32;
2324

2425
public function __construct()
2526
{
@@ -67,7 +68,7 @@ private function getKey(JWK $key): string
6768
throw new InvalidArgumentException('The key parameter "k" is invalid.');
6869
}
6970
$key = Base64UrlSafe::decodeNoPadding($k);
70-
if (mb_strlen($key, '8bit') < self::MINIMUM_KEY_LENGTH) {
71+
if (strlen($key) < self::MINIMUM_KEY_LENGTH) {
7172
throw new InvalidArgumentException('Key provided is shorter than 256 bits.');
7273
}
7374

Signature/HS256_64.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function hash(JWK $key, string $input): string
1515
{
1616
$signature = parent::hash($key, $input);
1717

18-
return mb_substr($signature, 0, 8, '8bit');
18+
return substr($signature, 0, 8);
1919
}
2020

2121
#[Override]

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
}
3939
},
4040
"require": {
41-
"php": ">=8.3",
41+
"php": ">=8.2",
4242
"ext-openssl": "*",
4343
"web-token/jwt-library": "^4.0"
4444
}

0 commit comments

Comments
 (0)