diff --git a/.github/workflows/integrate.yml b/.github/workflows/integrate.yml index 80a20b1a..910d72eb 100644 --- a/.github/workflows/integrate.yml +++ b/.github/workflows/integrate.yml @@ -68,6 +68,7 @@ jobs: operating-system: - "ubuntu-latest" php-version: + - "8.2" - "8.3" dependencies: - "lowest" @@ -196,7 +197,7 @@ jobs: - name: "Install dependencies" uses: "ramsey/composer-install@v3" with: - dependency-versions: "highest" + dependency-versions: "lowest" composer-options: "--optimize-autoloader" - name: "Execute Rector" diff --git a/castor.php b/castor.php index da1a11b6..9109fa55 100644 --- a/castor.php +++ b/castor.php @@ -77,10 +77,13 @@ function cs( } #[AsTask(description: 'Running PHPStan')] -function stan(): void +function stan(bool $baseline = false): void { io()->title('Running PHPStan'); $command = ['php', 'vendor/bin/phpstan', 'analyse']; + if ($baseline) { + $command[] = '--generate-baseline'; + } $environment = [ 'XDEBUG_MODE' => 'off', ]; diff --git a/composer.json b/composer.json index 6b82ae93..e5688d9f 100644 --- a/composer.json +++ b/composer.json @@ -46,9 +46,8 @@ } }, "require": { - "php": ">=8.3", + "php": ">=8.2", "ext-json": "*", - "ext-mbstring": "*", "ext-openssl": "*", "brick/math": "^0.12", "psr/clock": "^1.0", diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 2c2287f1..d4d2779d 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1225,6 +1225,11 @@ parameters: count: 1 path: src/Library/Core/JWKSet.php + - + message: "#^Parameter \\#2 \\$mode of function count expects 0\\|1, int given\\.$#" + count: 1 + path: src/Library/Core/JWKSet.php + - message: "#^Property Jose\\\\Component\\\\Core\\\\JWKSet\\:\\:\\$keys type has no value type specified in iterable type array\\.$#" count: 1 @@ -1346,12 +1351,12 @@ parameters: path: src/Library/Encryption/Algorithm/ContentEncryption/AESCBCHS.php - - message: "#^Parameter \\#3 \\$length of function mb_substr expects int\\|null, float\\|int\\<1, max\\> given\\.$#" + message: "#^Parameter \\#3 \\$length of function substr expects int\\|null, float\\|int\\<1, max\\> given\\.$#" count: 1 path: src/Library/Encryption/Algorithm/ContentEncryption/AESCBCHS.php - - message: "#^Parameter \\#3 \\$length of function mb_substr expects int\\|null, float\\|int\\ given\\.$#" + message: "#^Parameter \\#3 \\$length of function substr expects int\\|null, float\\|int\\ given\\.$#" count: 1 path: src/Library/Encryption/Algorithm/KeyEncryption/AbstractECDH.php @@ -1761,7 +1766,7 @@ parameters: path: src/Library/KeyManagement/JWKFactory.php - - message: "#^Parameter \\#3 \\$length of function mb_substr expects int\\|null, float\\|int\\ given\\.$#" + message: "#^Parameter \\#3 \\$length of function substr expects int\\|null, float\\|int\\ given\\.$#" count: 1 path: src/Library/KeyManagement/JWKFactory.php diff --git a/rector.php b/rector.php index c6bc2810..9ce41deb 100644 --- a/rector.php +++ b/rector.php @@ -13,7 +13,7 @@ return static function (RectorConfig $config): void { $config->import(SetList::DEAD_CODE); - $config->import(LevelSetList::UP_TO_PHP_83); + $config->import(LevelSetList::UP_TO_PHP_82); $config->import(SymfonySetList::SYMFONY_64); $config->import(SymfonySetList::SYMFONY_50_TYPES); $config->import(SymfonySetList::SYMFONY_52_VALIDATOR_ATTRIBUTES); @@ -38,7 +38,7 @@ __DIR__ . '/src/Bundle/JoseFramework/DependencyInjection/Source/KeyManagement/JWKSource.php', __DIR__ . '/src/Bundle/JoseFramework/DependencyInjection/Source/KeyManagement/JWKSetSource.php', ]); - $config->phpVersion(PhpVersion::PHP_83); + $config->phpVersion(PhpVersion::PHP_82); $config->parallel(); $config->importNames(); $config->importShortClasses(); diff --git a/src/Bundle/Helper/ConfigurationHelper.php b/src/Bundle/Helper/ConfigurationHelper.php index 1cc488ac..8d5e8b55 100644 --- a/src/Bundle/Helper/ConfigurationHelper.php +++ b/src/Bundle/Helper/ConfigurationHelper.php @@ -9,7 +9,7 @@ final readonly class ConfigurationHelper { - final public const string BUNDLE_ALIAS = 'jose'; + final public const BUNDLE_ALIAS = 'jose'; /** * @param string[] $signatureAlgorithms diff --git a/src/Bundle/Serializer/JWEEncoder.php b/src/Bundle/Serializer/JWEEncoder.php index e18e5f7c..145ae64f 100644 --- a/src/Bundle/Serializer/JWEEncoder.php +++ b/src/Bundle/Serializer/JWEEncoder.php @@ -17,7 +17,6 @@ use Throwable; use function in_array; use function is_int; -use function mb_strtolower; final readonly class JWEEncoder implements EncoderInterface, DecoderInterface, NormalizationAwareInterface { @@ -54,7 +53,7 @@ public function encode(mixed $data, string $format, array $context = []): string try { return $this->serializerManager->serialize( - mb_strtolower($format), + strtolower($format), $data, $this->getRecipientIndex($context) ); @@ -91,6 +90,6 @@ private function getRecipientIndex(array $context): int private function formatSupported(?string $format): bool { return $format !== null - && in_array(mb_strtolower($format), $this->serializerManager->names(), true); + && in_array(strtolower($format), $this->serializerManager->names(), true); } } diff --git a/src/Bundle/Serializer/JWESerializer.php b/src/Bundle/Serializer/JWESerializer.php index 2703ef09..f9001d51 100644 --- a/src/Bundle/Serializer/JWESerializer.php +++ b/src/Bundle/Serializer/JWESerializer.php @@ -11,11 +11,10 @@ use Override; use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; use function in_array; -use function mb_strtolower; final readonly class JWESerializer implements DenormalizerInterface { - private readonly JWESerializerManager $serializerManager; + private JWESerializerManager $serializerManager; public function __construct( JWESerializerManagerFactory $serializerManagerFactory, @@ -63,6 +62,6 @@ public function denormalize(mixed $data, string $type, ?string $format = null, a private function formatSupported(?string $format): bool { return $format !== null - && in_array(mb_strtolower($format), $this->serializerManager->names(), true); + && in_array(strtolower($format), $this->serializerManager->names(), true); } } diff --git a/src/Bundle/Serializer/JWSEncoder.php b/src/Bundle/Serializer/JWSEncoder.php index bf97c412..554fafa4 100644 --- a/src/Bundle/Serializer/JWSEncoder.php +++ b/src/Bundle/Serializer/JWSEncoder.php @@ -16,7 +16,6 @@ use Symfony\Component\Serializer\Exception\NotEncodableValueException; use function in_array; use function is_int; -use function mb_strtolower; final readonly class JWSEncoder implements EncoderInterface, DecoderInterface, NormalizationAwareInterface { @@ -53,7 +52,7 @@ public function encode($data, $format, array $context = []): string try { return $this->serializerManager->serialize( - mb_strtolower($format), + strtolower($format), $data, $this->getSignatureIndex($context) ); @@ -90,6 +89,6 @@ private function getSignatureIndex(array $context): int private function formatSupported(?string $format): bool { return $format !== null - && in_array(mb_strtolower($format), $this->serializerManager->list(), true); + && in_array(strtolower($format), $this->serializerManager->list(), true); } } diff --git a/src/Bundle/Serializer/JWSSerializer.php b/src/Bundle/Serializer/JWSSerializer.php index 904c1910..a14e67f7 100644 --- a/src/Bundle/Serializer/JWSSerializer.php +++ b/src/Bundle/Serializer/JWSSerializer.php @@ -11,7 +11,6 @@ use Override; use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; use function in_array; -use function mb_strtolower; final readonly class JWSSerializer implements DenormalizerInterface { @@ -63,6 +62,6 @@ public function denormalize(mixed $data, string $type, ?string $format = null, a private function formatSupported(?string $format): bool { return $format !== null - && in_array(mb_strtolower($format), $this->serializerManager->list(), true); + && in_array(strtolower($format), $this->serializerManager->list(), true); } } diff --git a/src/Bundle/composer.json b/src/Bundle/composer.json index a30570cb..171895be 100644 --- a/src/Bundle/composer.json +++ b/src/Bundle/composer.json @@ -38,7 +38,7 @@ } }, "require": { - "php": ">=8.3", + "php": ">=8.2", "psr/event-dispatcher": "^1.0", "symfony/config": "^7.0", "symfony/console": "^7.0", diff --git a/src/Experimental/KeyEncryption/Chacha20Poly1305.php b/src/Experimental/KeyEncryption/Chacha20Poly1305.php index b52cfa21..5e9126a3 100644 --- a/src/Experimental/KeyEncryption/Chacha20Poly1305.php +++ b/src/Experimental/KeyEncryption/Chacha20Poly1305.php @@ -13,6 +13,7 @@ use RuntimeException; use function in_array; use function is_string; +use function strlen; use const OPENSSL_RAW_DATA; final readonly class Chacha20Poly1305 implements KeyEncryption @@ -68,7 +69,7 @@ public function decryptKey(JWK $key, string $encrypted_cek, array $header): stri isset($header['nonce']) || throw new InvalidArgumentException('The header parameter "nonce" is missing.'); is_string($header['nonce']) || throw new InvalidArgumentException('The header parameter "nonce" is not valid.'); $nonce = Base64UrlSafe::decodeNoPadding($header['nonce']); - if (mb_strlen($nonce, '8bit') !== 12) { + if (strlen($nonce) !== 12) { throw new InvalidArgumentException('The header parameter "nonce" is not valid.'); } diff --git a/src/Experimental/Signature/Blake2b.php b/src/Experimental/Signature/Blake2b.php index 6dfba333..c086db63 100644 --- a/src/Experimental/Signature/Blake2b.php +++ b/src/Experimental/Signature/Blake2b.php @@ -13,13 +13,14 @@ use function extension_loaded; use function in_array; use function is_string; +use function strlen; /** * @see \Jose\Tests\Component\Signature\Algorithm\Blake2bTest */ final readonly class Blake2b implements MacAlgorithm { - private const int MINIMUM_KEY_LENGTH = 32; + private const MINIMUM_KEY_LENGTH = 32; public function __construct() { @@ -67,7 +68,7 @@ private function getKey(JWK $key): string throw new InvalidArgumentException('The key parameter "k" is invalid.'); } $key = Base64UrlSafe::decodeNoPadding($k); - if (mb_strlen($key, '8bit') < self::MINIMUM_KEY_LENGTH) { + if (strlen($key) < self::MINIMUM_KEY_LENGTH) { throw new InvalidArgumentException('Key provided is shorter than 256 bits.'); } diff --git a/src/Experimental/Signature/HS256_64.php b/src/Experimental/Signature/HS256_64.php index 41ac8ee7..570ab36d 100644 --- a/src/Experimental/Signature/HS256_64.php +++ b/src/Experimental/Signature/HS256_64.php @@ -15,7 +15,7 @@ public function hash(JWK $key, string $input): string { $signature = parent::hash($key, $input); - return mb_substr($signature, 0, 8, '8bit'); + return substr($signature, 0, 8); } #[Override] diff --git a/src/Experimental/composer.json b/src/Experimental/composer.json index 13763211..62cd433e 100644 --- a/src/Experimental/composer.json +++ b/src/Experimental/composer.json @@ -38,7 +38,7 @@ } }, "require": { - "php": ">=8.3", + "php": ">=8.2", "ext-openssl": "*", "web-token/jwt-library": "^4.0" } diff --git a/src/Library/Checker/AlgorithmChecker.php b/src/Library/Checker/AlgorithmChecker.php index 23cb606a..33aa58cc 100644 --- a/src/Library/Checker/AlgorithmChecker.php +++ b/src/Library/Checker/AlgorithmChecker.php @@ -15,7 +15,7 @@ */ final readonly class AlgorithmChecker implements HeaderChecker { - private const string HEADER_NAME = 'alg'; + private const HEADER_NAME = 'alg'; /** * @param string[] $supportedAlgorithms diff --git a/src/Library/Checker/AudienceChecker.php b/src/Library/Checker/AudienceChecker.php index e7396a56..b23d2e75 100644 --- a/src/Library/Checker/AudienceChecker.php +++ b/src/Library/Checker/AudienceChecker.php @@ -14,7 +14,7 @@ */ final readonly class AudienceChecker implements ClaimChecker, HeaderChecker { - private const string CLAIM_NAME = 'aud'; + private const CLAIM_NAME = 'aud'; public function __construct( private string $audience, diff --git a/src/Library/Checker/ExpirationTimeChecker.php b/src/Library/Checker/ExpirationTimeChecker.php index 9eeaede7..3a131969 100644 --- a/src/Library/Checker/ExpirationTimeChecker.php +++ b/src/Library/Checker/ExpirationTimeChecker.php @@ -16,7 +16,7 @@ */ final readonly class ExpirationTimeChecker implements ClaimChecker, HeaderChecker { - private const string NAME = 'exp'; + private const NAME = 'exp'; public function __construct( private ClockInterface $clock, diff --git a/src/Library/Checker/IssuedAtChecker.php b/src/Library/Checker/IssuedAtChecker.php index 281c791a..10fd6f6a 100644 --- a/src/Library/Checker/IssuedAtChecker.php +++ b/src/Library/Checker/IssuedAtChecker.php @@ -14,7 +14,7 @@ */ final readonly class IssuedAtChecker implements ClaimChecker, HeaderChecker { - private const string NAME = 'iat'; + private const NAME = 'iat'; public function __construct( private ClockInterface $clock, diff --git a/src/Library/Checker/IssuerChecker.php b/src/Library/Checker/IssuerChecker.php index b5db0b98..ae5c86d9 100644 --- a/src/Library/Checker/IssuerChecker.php +++ b/src/Library/Checker/IssuerChecker.php @@ -15,7 +15,7 @@ */ final readonly class IssuerChecker implements ClaimChecker, HeaderChecker { - private const string CLAIM_NAME = 'iss'; + private const CLAIM_NAME = 'iss'; public function __construct( private array $issuers, diff --git a/src/Library/Checker/NotBeforeChecker.php b/src/Library/Checker/NotBeforeChecker.php index cf9daa06..a5536ac3 100644 --- a/src/Library/Checker/NotBeforeChecker.php +++ b/src/Library/Checker/NotBeforeChecker.php @@ -14,7 +14,7 @@ */ final readonly class NotBeforeChecker implements ClaimChecker, HeaderChecker { - private const string NAME = 'nbf'; + private const NAME = 'nbf'; public function __construct( private ClockInterface $clock, diff --git a/src/Library/Checker/UnencodedPayloadChecker.php b/src/Library/Checker/UnencodedPayloadChecker.php index b74429e2..6d4e4226 100644 --- a/src/Library/Checker/UnencodedPayloadChecker.php +++ b/src/Library/Checker/UnencodedPayloadChecker.php @@ -14,7 +14,7 @@ */ final class UnencodedPayloadChecker implements HeaderChecker { - private const string HEADER_NAME = 'b64'; + private const HEADER_NAME = 'b64'; #[Override] public function checkHeader(mixed $value): void diff --git a/src/Library/Core/Util/Base64UrlSafe.php b/src/Library/Core/Util/Base64UrlSafe.php index c3f44d65..91746255 100644 --- a/src/Library/Core/Util/Base64UrlSafe.php +++ b/src/Library/Core/Util/Base64UrlSafe.php @@ -4,6 +4,8 @@ namespace Jose\Component\Core\Util; +use function strlen; + /** * Copyright (c) 2016 - 2022 Paragon Initiative Enterprises. * Copyright (c) 2014 Steve "Sc00bz" Thomas (steve at tobtu dot com) @@ -202,7 +204,7 @@ private static function encode6Bits(int $src): string private static function safeStrlen(string $str): int { - return mb_strlen($str, '8bit'); + return strlen($str); } private static function safeSubstr(string $str, int $start = 0, $length = null): string @@ -210,6 +212,6 @@ private static function safeSubstr(string $str, int $start = 0, $length = null): if ($length === 0) { return ''; } - return mb_substr($str, $start, $length, '8bit'); + return substr($str, $start, $length); } } diff --git a/src/Library/Core/Util/BigInteger.php b/src/Library/Core/Util/BigInteger.php index 3735155e..b147ad83 100644 --- a/src/Library/Core/Util/BigInteger.php +++ b/src/Library/Core/Util/BigInteger.php @@ -7,6 +7,7 @@ use Brick\Math\BigInteger as BrickBigInteger; use InvalidArgumentException; use function chr; +use function strlen; /** * @internal @@ -49,7 +50,7 @@ public function toBytes(): string } $temp = $this->value->toBase(16); - $temp = 0 !== (mb_strlen($temp, '8bit') & 1) ? '0' . $temp : $temp; + $temp = 0 !== (strlen($temp) & 1) ? '0' . $temp : $temp; $temp = hex2bin($temp); if ($temp === false) { throw new InvalidArgumentException('Unable to convert the value into bytes'); diff --git a/src/Library/Core/Util/ECKey.php b/src/Library/Core/Util/ECKey.php index 38ecf545..319c7986 100644 --- a/src/Library/Core/Util/ECKey.php +++ b/src/Library/Core/Util/ECKey.php @@ -113,13 +113,13 @@ private static function createECKeyUsingOpenSSL(string $curve): array 'kty' => 'EC', 'crv' => $curve, 'd' => Base64UrlSafe::encodeUnpadded( - mb_str_pad((string) $details['ec']['d'], (int) ceil($nistCurveSize / 8), "\0", STR_PAD_LEFT, '8bit') + str_pad((string) $details['ec']['d'], (int) ceil($nistCurveSize / 8), "\0", STR_PAD_LEFT) ), 'x' => Base64UrlSafe::encodeUnpadded( - mb_str_pad((string) $details['ec']['x'], (int) ceil($nistCurveSize / 8), "\0", STR_PAD_LEFT, '8bit') + str_pad((string) $details['ec']['x'], (int) ceil($nistCurveSize / 8), "\0", STR_PAD_LEFT) ), 'y' => Base64UrlSafe::encodeUnpadded( - mb_str_pad((string) $details['ec']['y'], (int) ceil($nistCurveSize / 8), "\0", STR_PAD_LEFT, '8bit') + str_pad((string) $details['ec']['y'], (int) ceil($nistCurveSize / 8), "\0", STR_PAD_LEFT) ), ]; } @@ -201,7 +201,7 @@ private static function p256PrivateKey(JWK $jwk): string if (! is_string($d)) { throw new InvalidArgumentException('Unable to get the private key'); } - $d = unpack('H*', mb_str_pad(Base64UrlSafe::decodeNoPadding($d), 32, "\0", STR_PAD_LEFT, '8bit')); + $d = unpack('H*', str_pad(Base64UrlSafe::decodeNoPadding($d), 32, "\0", STR_PAD_LEFT)); if (! is_array($d) || ! isset($d[1])) { throw new InvalidArgumentException('Unable to get the private key'); } @@ -227,7 +227,7 @@ private static function p256KPrivateKey(JWK $jwk): string if (! is_string($d)) { throw new InvalidArgumentException('Unable to get the private key'); } - $d = unpack('H*', mb_str_pad(Base64UrlSafe::decodeNoPadding($d), 32, "\0", STR_PAD_LEFT, '8bit')); + $d = unpack('H*', str_pad(Base64UrlSafe::decodeNoPadding($d), 32, "\0", STR_PAD_LEFT)); if (! is_array($d) || ! isset($d[1])) { throw new InvalidArgumentException('Unable to get the private key'); } @@ -253,7 +253,7 @@ private static function p384PrivateKey(JWK $jwk): string if (! is_string($d)) { throw new InvalidArgumentException('Unable to get the private key'); } - $d = unpack('H*', mb_str_pad(Base64UrlSafe::decodeNoPadding($d), 48, "\0", STR_PAD_LEFT, '8bit')); + $d = unpack('H*', str_pad(Base64UrlSafe::decodeNoPadding($d), 48, "\0", STR_PAD_LEFT)); if (! is_array($d) || ! isset($d[1])) { throw new InvalidArgumentException('Unable to get the private key'); } @@ -279,7 +279,7 @@ private static function p521PrivateKey(JWK $jwk): string if (! is_string($d)) { throw new InvalidArgumentException('Unable to get the private key'); } - $d = unpack('H*', mb_str_pad(Base64UrlSafe::decodeNoPadding($d), 66, "\0", STR_PAD_LEFT, '8bit')); + $d = unpack('H*', str_pad(Base64UrlSafe::decodeNoPadding($d), 66, "\0", STR_PAD_LEFT)); if (! is_array($d) || ! isset($d[1])) { throw new InvalidArgumentException('Unable to get the private key'); } @@ -319,8 +319,8 @@ private static function getKey(JWK $jwk): string $binY = ltrim(Base64UrlSafe::decodeNoPadding($y), "\0"); return "\04" - . mb_str_pad($binX, $length, "\0", STR_PAD_LEFT, '8bit') - . mb_str_pad($binY, $length, "\0", STR_PAD_LEFT, '8bit') + . str_pad($binX, $length, "\0", STR_PAD_LEFT) + . str_pad($binY, $length, "\0", STR_PAD_LEFT) ; } } diff --git a/src/Library/Core/Util/ECSignature.php b/src/Library/Core/Util/ECSignature.php index 29dc907d..a598efc2 100644 --- a/src/Library/Core/Util/ECSignature.php +++ b/src/Library/Core/Util/ECSignature.php @@ -6,6 +6,7 @@ use InvalidArgumentException; use function is_string; +use function strlen; use const STR_PAD_LEFT; /** @@ -13,19 +14,19 @@ */ final readonly class ECSignature { - private const string ASN1_SEQUENCE = '30'; + private const ASN1_SEQUENCE = '30'; - private const string ASN1_INTEGER = '02'; + private const ASN1_INTEGER = '02'; - private const int ASN1_MAX_SINGLE_BYTE = 128; + private const ASN1_MAX_SINGLE_BYTE = 128; - private const string ASN1_LENGTH_2BYTES = '81'; + private const ASN1_LENGTH_2BYTES = '81'; - private const string ASN1_BIG_INTEGER_LIMIT = '7f'; + private const ASN1_BIG_INTEGER_LIMIT = '7f'; - private const string ASN1_NEGATIVE_INTEGER = '00'; + private const ASN1_NEGATIVE_INTEGER = '00'; - private const int BYTE_SIZE = 2; + private const BYTE_SIZE = 2; public static function toAsn1(string $signature, int $length): string { @@ -35,8 +36,8 @@ public static function toAsn1(string $signature, int $length): string throw new InvalidArgumentException('Invalid signature length.'); } - $pointR = self::preparePositiveInteger(mb_substr($signature, 0, $length, '8bit')); - $pointS = self::preparePositiveInteger(mb_substr($signature, $length, null, '8bit')); + $pointR = self::preparePositiveInteger(substr($signature, 0, $length)); + $pointS = self::preparePositiveInteger(substr($signature, $length)); $lengthR = self::octetLength($pointR); $lengthS = self::octetLength($pointS); @@ -74,13 +75,7 @@ public static function fromAsn1(string $signature, int $length): string $pointS = self::retrievePositiveInteger(self::readAsn1Integer($message, $position)); $bin = hex2bin( - mb_str_pad($pointR, $length, '0', STR_PAD_LEFT, '8bit') . mb_str_pad( - $pointS, - $length, - '0', - STR_PAD_LEFT, - '8bit' - ) + str_pad($pointR, $length, '0', STR_PAD_LEFT) . str_pad($pointS, $length, '0', STR_PAD_LEFT) ); if (! is_string($bin)) { throw new InvalidArgumentException('Unable to parse the data'); @@ -91,18 +86,18 @@ public static function fromAsn1(string $signature, int $length): string private static function octetLength(string $data): int { - return (int) (mb_strlen($data, '8bit') / self::BYTE_SIZE); + return (int) (strlen($data) / self::BYTE_SIZE); } private static function preparePositiveInteger(string $data): string { - if (mb_substr($data, 0, self::BYTE_SIZE, '8bit') > self::ASN1_BIG_INTEGER_LIMIT) { + if (substr($data, 0, self::BYTE_SIZE) > self::ASN1_BIG_INTEGER_LIMIT) { return self::ASN1_NEGATIVE_INTEGER . $data; } - while (mb_strpos($data, self::ASN1_NEGATIVE_INTEGER, 0, '8bit') === 0 - && mb_substr($data, 2, self::BYTE_SIZE, '8bit') <= self::ASN1_BIG_INTEGER_LIMIT) { - $data = mb_substr($data, 2, null, '8bit'); + while (str_starts_with($data, self::ASN1_NEGATIVE_INTEGER) + && substr($data, 2, self::BYTE_SIZE) <= self::ASN1_BIG_INTEGER_LIMIT) { + $data = substr($data, 2, null); } return $data; @@ -110,7 +105,7 @@ private static function preparePositiveInteger(string $data): string private static function readAsn1Content(string $message, int &$position, int $length): string { - $content = mb_substr($message, $position, $length, '8bit'); + $content = substr($message, $position, $length); $position += $length; return $content; @@ -129,9 +124,9 @@ private static function readAsn1Integer(string $message, int &$position): string private static function retrievePositiveInteger(string $data): string { - while (mb_strpos($data, self::ASN1_NEGATIVE_INTEGER, 0, '8bit') === 0 - && mb_substr($data, 2, self::BYTE_SIZE, '8bit') > self::ASN1_BIG_INTEGER_LIMIT) { - $data = mb_substr($data, 2, null, '8bit'); + while (str_starts_with($data, self::ASN1_NEGATIVE_INTEGER) + && substr($data, 2, self::BYTE_SIZE) > self::ASN1_BIG_INTEGER_LIMIT) { + $data = substr($data, 2); } return $data; diff --git a/src/Library/Core/Util/Ecc/Curve.php b/src/Library/Core/Util/Ecc/Curve.php index 2674d7da..0fd1e399 100644 --- a/src/Library/Core/Util/Ecc/Curve.php +++ b/src/Library/Core/Util/Ecc/Curve.php @@ -153,7 +153,7 @@ public function mul(Point $one, BigInteger $n): Point $r = [Point::infinity(), clone $one]; $k = $this->getSize(); - $n1 = mb_str_pad(Math::baseConvert(Math::toString($n), 10, 2), $k, '0', STR_PAD_LEFT, '8bit'); + $n1 = str_pad(Math::baseConvert(Math::toString($n), 10, 2), $k, '0', STR_PAD_LEFT); for ($i = 0; $i < $k; ++$i) { $j = $n1[$i]; diff --git a/src/Library/Core/Util/Ecc/Point.php b/src/Library/Core/Util/Ecc/Point.php index a5bdd05e..cb10f4a9 100644 --- a/src/Library/Core/Util/Ecc/Point.php +++ b/src/Library/Core/Util/Ecc/Point.php @@ -5,6 +5,7 @@ namespace Jose\Component\Core\Util\Ecc; use Brick\Math\BigInteger; +use function strlen; use const STR_PAD_LEFT; /** @@ -90,9 +91,9 @@ private static function cswapBoolean(bool &$a, bool &$b, int $cond): void private static function cswapBigInteger(BigInteger &$sa, BigInteger &$sb, int $cond): void { - $size = max(mb_strlen($sa->toBase(2), '8bit'), mb_strlen($sb->toBase(2), '8bit')); + $size = max(strlen($sa->toBase(2)), strlen($sb->toBase(2))); $mask = (string) (1 - $cond); - $mask = mb_str_pad('', $size, $mask, STR_PAD_LEFT, '8bit'); + $mask = str_pad('', $size, $mask, STR_PAD_LEFT); $mask = BigInteger::fromBase($mask, 2); $taA = $sa->and($mask); $taB = $sb->and($mask); diff --git a/src/Library/Core/Util/RSAKey.php b/src/Library/Core/Util/RSAKey.php index 39c45e1a..0032f6e2 100644 --- a/src/Library/Core/Util/RSAKey.php +++ b/src/Library/Core/Util/RSAKey.php @@ -18,6 +18,7 @@ use function array_key_exists; use function count; use function is_array; +use function strlen; /** * @internal @@ -201,7 +202,7 @@ public static function exponentiate(self $key, BigInteger $c): BigInteger private function populateBigIntegers(): void { $this->modulus = $this->convertBase64StringToBigInteger($this->values['n']); - $this->modulusLength = mb_strlen($this->getModulus()->toBytes(), '8bit'); + $this->modulusLength = strlen($this->getModulus()->toBytes()); $this->publicExponent = $this->convertBase64StringToBigInteger($this->values['e']); if (! $this->isPublic()) { diff --git a/src/Library/Encryption/Algorithm/ContentEncryption/AESCBCHS.php b/src/Library/Encryption/Algorithm/ContentEncryption/AESCBCHS.php index 82458ccc..f1630d64 100644 --- a/src/Library/Encryption/Algorithm/ContentEncryption/AESCBCHS.php +++ b/src/Library/Encryption/Algorithm/ContentEncryption/AESCBCHS.php @@ -9,6 +9,7 @@ use Override; use RuntimeException; use function extension_loaded; +use function strlen; use const OPENSSL_RAW_DATA; abstract readonly class AESCBCHS implements ContentEncryptionAlgorithm @@ -35,7 +36,7 @@ public function encryptContent( string $encoded_protected_header, ?string &$tag = null ): string { - $k = mb_substr($cek, $this->getCEKSize() / 16, null, '8bit'); + $k = substr($cek, $this->getCEKSize() / 16); $result = openssl_encrypt($data, $this->getMode(), $k, OPENSSL_RAW_DATA, $iv); if ($result === false) { throw new RuntimeException('Unable to encrypt the content'); @@ -58,7 +59,7 @@ public function decryptContent( if (! $this->isTagValid($data, $cek, $iv, $aad, $encoded_protected_header, $tag)) { throw new RuntimeException('Unable to decrypt or to verify the tag.'); } - $k = mb_substr($cek, $this->getCEKSize() / 16, null, '8bit'); + $k = substr($cek, $this->getCEKSize() / 16); $result = openssl_decrypt($data, $this->getMode(), $k, OPENSSL_RAW_DATA, $iv); if ($result === false) { @@ -85,8 +86,8 @@ protected function calculateAuthenticationTag( if ($aad !== null) { $calculated_aad .= '.' . Base64UrlSafe::encodeUnpadded($aad); } - $mac_key = mb_substr($cek, 0, $this->getCEKSize() / 16, '8bit'); - $auth_data_length = mb_strlen($encoded_header, '8bit'); + $mac_key = substr($cek, 0, $this->getCEKSize() / 16); + $auth_data_length = strlen($encoded_header); $secured_input = implode('', [ $calculated_aad, @@ -96,7 +97,7 @@ protected function calculateAuthenticationTag( ]); $hash = hash_hmac($this->getHashAlgorithm(), $secured_input, $mac_key, true); - return mb_substr($hash, 0, mb_strlen($hash, '8bit') / 2, '8bit'); + return substr($hash, 0, strlen($hash) / 2); } protected function isTagValid( diff --git a/src/Library/Encryption/Algorithm/KeyEncryption/AbstractECDH.php b/src/Library/Encryption/Algorithm/KeyEncryption/AbstractECDH.php index b705b362..bb2bcdea 100644 --- a/src/Library/Encryption/Algorithm/KeyEncryption/AbstractECDH.php +++ b/src/Library/Encryption/Algorithm/KeyEncryption/AbstractECDH.php @@ -23,6 +23,7 @@ use function in_array; use function is_array; use function is_string; +use function strlen; abstract readonly class AbstractECDH implements KeyAgreement { @@ -263,7 +264,7 @@ private function convertDecToBin(BigInteger $dec): string } $hex = $dec->toBase(16); - if (mb_strlen($hex, '8bit') % 2 !== 0) { + if (strlen($hex) % 2 !== 0) { $hex = '0' . $hex; } @@ -293,8 +294,8 @@ private function createOKPKey(string $curve): JWK case 'Ed25519': $keyPair = sodium_crypto_sign_keypair(); $secret = sodium_crypto_sign_secretkey($keyPair); - $secretLength = mb_strlen($secret, '8bit'); - $d = mb_substr($secret, 0, -$secretLength / 2, '8bit'); + $secretLength = strlen($secret); + $d = substr($secret, 0, -$secretLength / 2); $x = sodium_crypto_sign_publickey($keyPair); break; diff --git a/src/Library/Encryption/Algorithm/KeyEncryption/Util/ConcatKDF.php b/src/Library/Encryption/Algorithm/KeyEncryption/Util/ConcatKDF.php index 92c9d264..ec5a9f1a 100644 --- a/src/Library/Encryption/Algorithm/KeyEncryption/Util/ConcatKDF.php +++ b/src/Library/Encryption/Algorithm/KeyEncryption/Util/ConcatKDF.php @@ -6,6 +6,7 @@ use InvalidArgumentException; use Jose\Component\Core\Util\Base64UrlSafe; +use function strlen; use const STR_PAD_LEFT; /** @@ -36,9 +37,9 @@ public static function generate( $encryption_segments = [ self::toInt32Bits(1), // Round number 1 $Z, // Z (shared secret) - self::toInt32Bits(mb_strlen($algorithm, '8bit')) . $algorithm, // Size of algorithm's name and algorithm - self::toInt32Bits(mb_strlen($apu, '8bit')) . $apu, // PartyUInfo - self::toInt32Bits(mb_strlen($apv, '8bit')) . $apv, // PartyVInfo + self::toInt32Bits(strlen($algorithm)) . $algorithm, // Size of algorithm's name and algorithm + self::toInt32Bits(strlen($apu)) . $apu, // PartyUInfo + self::toInt32Bits(strlen($apv)) . $apv, // PartyVInfo self::toInt32Bits($encryption_key_size), // SuppPubInfo (the encryption key size) '', // SuppPrivInfo ]; @@ -46,7 +47,7 @@ public static function generate( $input = implode('', $encryption_segments); $hash = hash('sha256', $input, true); - return mb_substr($hash, 0, $encryption_key_size / 8, '8bit'); + return substr($hash, 0, $encryption_key_size / 8); } /** @@ -56,7 +57,7 @@ public static function generate( */ private static function toInt32Bits(int $value): string { - $result = hex2bin(mb_str_pad(dechex($value), 8, '0', STR_PAD_LEFT, '8bit')); + $result = hex2bin(str_pad(dechex($value), 8, '0', STR_PAD_LEFT)); if ($result === false) { throw new InvalidArgumentException('Invalid result'); } diff --git a/src/Library/Encryption/Algorithm/KeyEncryption/Util/RSACrypt.php b/src/Library/Encryption/Algorithm/KeyEncryption/Util/RSACrypt.php index ac035318..e2881ff9 100644 --- a/src/Library/Encryption/Algorithm/KeyEncryption/Util/RSACrypt.php +++ b/src/Library/Encryption/Algorithm/KeyEncryption/Util/RSACrypt.php @@ -13,6 +13,7 @@ use function chr; use function count; use function ord; +use function strlen; use const STR_PAD_LEFT; /** @@ -23,12 +24,12 @@ /** * Optimal Asymmetric Encryption Padding (OAEP). */ - public const int ENCRYPTION_OAEP = 1; + public const ENCRYPTION_OAEP = 1; /** * Use PKCS#1 padding. */ - public const int ENCRYPTION_PKCS1 = 2; + public const ENCRYPTION_PKCS1 = 2; public static function encrypt(RSAKey $key, string $data, int $mode, ?string $hash = null): string { @@ -64,15 +65,15 @@ public static function decrypt(RSAKey $key, string $plaintext, int $mode, ?strin public static function encryptWithRSA15(RSAKey $key, string $data): string { - $mLen = mb_strlen($data, '8bit'); + $mLen = strlen($data); if ($mLen > $key->getModulusLength() - 11) { throw new InvalidArgumentException('Message too long'); } $psLen = $key->getModulusLength() - $mLen - 3; $ps = ''; - while (mb_strlen($ps, '8bit') !== $psLen) { - $temp = random_bytes($psLen - mb_strlen($ps, '8bit')); + while (strlen($ps) !== $psLen) { + $temp = random_bytes($psLen - strlen($ps)); $temp = str_replace("\x00", '', $temp); $ps .= $temp; } @@ -87,7 +88,7 @@ public static function encryptWithRSA15(RSAKey $key, string $data): string public static function decryptWithRSA15(RSAKey $key, string $c): string { - if (mb_strlen($c, '8bit') !== $key->getModulusLength()) { + if (strlen($c) !== $key->getModulusLength()) { throw new InvalidArgumentException('Unable to decrypt'); } $c = BigInteger::createFromBinaryString($c); @@ -96,9 +97,9 @@ public static function decryptWithRSA15(RSAKey $key, string $c): string if (ord($em[0]) !== 0 || ord($em[1]) > 2) { throw new InvalidArgumentException('Unable to decrypt'); } - $ps = mb_substr($em, 2, (int) mb_strpos($em, chr(0), 2, '8bit') - 2, '8bit'); - $m = mb_substr($em, mb_strlen($ps, '8bit') + 3, null, '8bit'); - if (mb_strlen($ps, '8bit') < 8) { + $ps = substr($em, 2, (int) strpos($em, chr(0), 2) - 2); + $m = substr($em, strlen($ps) + 3, null); + if (strlen($ps) < 8) { throw new InvalidArgumentException('Unable to decrypt'); } @@ -116,7 +117,7 @@ public static function encryptWithRSAOAEP(RSAKey $key, string $plaintext, string if ($length <= 0) { throw new RuntimeException(); } - $splitPlaintext = mb_str_split($plaintext, $length, '8bit'); + $splitPlaintext = str_split($plaintext, $length); $ciphertext = ''; foreach ($splitPlaintext as $m) { $ciphertext .= self::encryptRSAESOAEP($key, $m, $hash); @@ -134,13 +135,12 @@ public static function decryptWithRSAOAEP(RSAKey $key, string $ciphertext, strin throw new RuntimeException('Invalid modulus length'); } $hash = Hash::$hash_algorithm(); - $splitCiphertext = mb_str_split($ciphertext, $key->getModulusLength(), '8bit'); - $splitCiphertext[count($splitCiphertext) - 1] = mb_str_pad( + $splitCiphertext = str_split($ciphertext, $key->getModulusLength()); + $splitCiphertext[count($splitCiphertext) - 1] = str_pad( $splitCiphertext[count($splitCiphertext) - 1], $key->getModulusLength(), chr(0), - STR_PAD_LEFT, - '8bit' + STR_PAD_LEFT ); $plaintext = ''; foreach ($splitCiphertext as $c) { @@ -154,11 +154,11 @@ public static function decryptWithRSAOAEP(RSAKey $key, string $ciphertext, strin private static function convertIntegerToOctetString(BigInteger $x, int $xLen): string { $x = $x->toBytes(); - if (mb_strlen($x, '8bit') > $xLen) { + if (strlen($x) > $xLen) { throw new RuntimeException('Invalid length.'); } - return mb_str_pad($x, $xLen, chr(0), STR_PAD_LEFT, '8bit'); + return str_pad($x, $xLen, chr(0), STR_PAD_LEFT); } /** @@ -205,7 +205,7 @@ private static function getMGF1(string $mgfSeed, int $maskLen, Hash $mgfHash): s $t .= $mgfHash->hash($mgfSeed . $c); } - return mb_substr($t, 0, $maskLen, '8bit'); + return substr($t, 0, $maskLen); } /** @@ -213,7 +213,7 @@ private static function getMGF1(string $mgfSeed, int $maskLen, Hash $mgfHash): s */ private static function encryptRSAESOAEP(RSAKey $key, string $m, Hash $hash): string { - $mLen = mb_strlen($m, '8bit'); + $mLen = strlen($m); $lHash = $hash->hash(''); $ps = str_repeat(chr(0), $key->getModulusLength() - $mLen - 2 * $hash->getLength() - 2); $db = $lHash . $ps . chr(1) . $m; @@ -239,14 +239,14 @@ private static function getRSAESOAEP(RSAKey $key, string $c, Hash $hash): string $m = self::getRSADP($key, $c); $em = self::convertIntegerToOctetString($m, $key->getModulusLength()); $lHash = $hash->hash(''); - $maskedSeed = mb_substr($em, 1, $hash->getLength(), '8bit'); - $maskedDB = mb_substr($em, $hash->getLength() + 1, null, '8bit'); + $maskedSeed = substr($em, 1, $hash->getLength()); + $maskedDB = substr($em, $hash->getLength() + 1); $seedMask = self::getMGF1($maskedDB, $hash->getLength(), $hash/*MGF*/); $seed = $maskedSeed ^ $seedMask; $dbMask = self::getMGF1($seed, $key->getModulusLength() - $hash->getLength() - 1, $hash/*MGF*/); $db = $maskedDB ^ $dbMask; - $lHash2 = mb_substr($db, 0, $hash->getLength(), '8bit'); - $m = mb_substr($db, $hash->getLength(), null, '8bit'); + $lHash2 = substr($db, 0, $hash->getLength()); + $m = substr($db, $hash->getLength()); if (! hash_equals($lHash, $lHash2)) { throw new RuntimeException(); } @@ -255,6 +255,6 @@ private static function getRSAESOAEP(RSAKey $key, string $c, Hash $hash): string throw new RuntimeException(); } - return mb_substr($m, 1, null, '8bit'); + return substr($m, 1); } } diff --git a/src/Library/Encryption/Algorithm/KeyEncryptionAlgorithm.php b/src/Library/Encryption/Algorithm/KeyEncryptionAlgorithm.php index c3ae1d11..9012a202 100644 --- a/src/Library/Encryption/Algorithm/KeyEncryptionAlgorithm.php +++ b/src/Library/Encryption/Algorithm/KeyEncryptionAlgorithm.php @@ -8,13 +8,13 @@ interface KeyEncryptionAlgorithm extends Algorithm { - public const string MODE_DIRECT = 'dir'; + public const MODE_DIRECT = 'dir'; - public const string MODE_ENCRYPT = 'enc'; + public const MODE_ENCRYPT = 'enc'; - public const string MODE_WRAP = 'wrap'; + public const MODE_WRAP = 'wrap'; - public const string MODE_AGREEMENT = 'agree'; + public const MODE_AGREEMENT = 'agree'; /** * Returns the key management mode used by the key encryption algorithm. diff --git a/src/Library/Encryption/JWEDecrypter.php b/src/Library/Encryption/JWEDecrypter.php index a711b0f0..5e35043d 100644 --- a/src/Library/Encryption/JWEDecrypter.php +++ b/src/Library/Encryption/JWEDecrypter.php @@ -19,6 +19,7 @@ use Jose\Component\Encryption\Algorithm\KeyEncryptionAlgorithm; use Throwable; use function is_string; +use function strlen; class JWEDecrypter { @@ -166,7 +167,7 @@ private function checkCekSize( if ($keyEncryptionAlgorithm instanceof DirectEncryption || $keyEncryptionAlgorithm instanceof KeyAgreement) { return; } - if (mb_strlen($cek, '8bit') * 8 !== $algorithm->getCEKSize()) { + if (strlen($cek) * 8 !== $algorithm->getCEKSize()) { throw new InvalidArgumentException('Invalid CEK size'); } } @@ -176,7 +177,7 @@ private function checkIvSize(?string $iv, int $requiredIvSize): void if ($iv === null && $requiredIvSize !== 0) { throw new InvalidArgumentException('Invalid IV size'); } - if (is_string($iv) && mb_strlen($iv, '8bit') !== $requiredIvSize / 8) { + if (is_string($iv) && strlen($iv) !== $requiredIvSize / 8) { throw new InvalidArgumentException('Invalid IV size'); } } diff --git a/src/Library/Encryption/Serializer/CompactSerializer.php b/src/Library/Encryption/Serializer/CompactSerializer.php index cfbc6b4b..3436dd20 100644 --- a/src/Library/Encryption/Serializer/CompactSerializer.php +++ b/src/Library/Encryption/Serializer/CompactSerializer.php @@ -17,7 +17,7 @@ final readonly class CompactSerializer implements JWESerializer { - public const string NAME = 'jwe_compact'; + public const NAME = 'jwe_compact'; #[Override] public function displayName(): string diff --git a/src/Library/Encryption/Serializer/JSONFlattenedSerializer.php b/src/Library/Encryption/Serializer/JSONFlattenedSerializer.php index 52c2936e..b0a7392d 100644 --- a/src/Library/Encryption/Serializer/JSONFlattenedSerializer.php +++ b/src/Library/Encryption/Serializer/JSONFlattenedSerializer.php @@ -16,7 +16,7 @@ final readonly class JSONFlattenedSerializer implements JWESerializer { - public const string NAME = 'jwe_json_flattened'; + public const NAME = 'jwe_json_flattened'; #[Override] public function displayName(): string diff --git a/src/Library/Encryption/Serializer/JSONGeneralSerializer.php b/src/Library/Encryption/Serializer/JSONGeneralSerializer.php index 768fb17c..f114f9bb 100644 --- a/src/Library/Encryption/Serializer/JSONGeneralSerializer.php +++ b/src/Library/Encryption/Serializer/JSONGeneralSerializer.php @@ -17,7 +17,7 @@ final readonly class JSONGeneralSerializer implements JWESerializer { - public const string NAME = 'jwe_json_general'; + public const NAME = 'jwe_json_general'; #[Override] public function displayName(): string diff --git a/src/Library/KeyManagement/Analyzer/ESKeyAnalyzer.php b/src/Library/KeyManagement/Analyzer/ESKeyAnalyzer.php index 1720047c..2c37d90d 100644 --- a/src/Library/KeyManagement/Analyzer/ESKeyAnalyzer.php +++ b/src/Library/KeyManagement/Analyzer/ESKeyAnalyzer.php @@ -10,6 +10,7 @@ use Jose\Component\Core\Util\Ecc\Curve; use Override; use function is_string; +use function strlen; abstract readonly class ESKeyAnalyzer implements KeyAnalyzer { @@ -34,7 +35,7 @@ public function analyze(JWK $jwk, MessageBag $bag): void return; } $x = Base64UrlSafe::decodeNoPadding($x); - $xLength = 8 * mb_strlen($x, '8bit'); + $xLength = 8 * strlen($x); $y = $jwk->get('y'); if (! is_string($y)) { $bag->add(Message::high('Invalid key. The components "y" shall be a string.')); @@ -42,7 +43,7 @@ public function analyze(JWK $jwk, MessageBag $bag): void return; } $y = Base64UrlSafe::decodeNoPadding($y); - $yLength = 8 * mb_strlen($y, '8bit'); + $yLength = 8 * strlen($y); if ($yLength !== $xLength || $yLength !== $this->getKeySize()) { $bag->add( Message::high(sprintf( diff --git a/src/Library/KeyManagement/Analyzer/HSKeyAnalyzer.php b/src/Library/KeyManagement/Analyzer/HSKeyAnalyzer.php index 004a9f16..9d62be8c 100644 --- a/src/Library/KeyManagement/Analyzer/HSKeyAnalyzer.php +++ b/src/Library/KeyManagement/Analyzer/HSKeyAnalyzer.php @@ -8,6 +8,7 @@ use Jose\Component\Core\Util\Base64UrlSafe; use Override; use function is_string; +use function strlen; abstract readonly class HSKeyAnalyzer implements KeyAnalyzer { @@ -27,7 +28,7 @@ public function analyze(JWK $jwk, MessageBag $bag): void return; } $k = Base64UrlSafe::decodeNoPadding($k); - $kLength = 8 * mb_strlen($k, '8bit'); + $kLength = 8 * strlen($k); if ($kLength < $this->getMinimumKeySize()) { $bag->add( Message::high(sprintf( diff --git a/src/Library/KeyManagement/Analyzer/Message.php b/src/Library/KeyManagement/Analyzer/Message.php index 2c800b16..f3ce4cfb 100644 --- a/src/Library/KeyManagement/Analyzer/Message.php +++ b/src/Library/KeyManagement/Analyzer/Message.php @@ -9,11 +9,11 @@ final readonly class Message implements JsonSerializable { - final public const string SEVERITY_LOW = 'low'; + final public const SEVERITY_LOW = 'low'; - final public const string SEVERITY_MEDIUM = 'medium'; + final public const SEVERITY_MEDIUM = 'medium'; - final public const string SEVERITY_HIGH = 'high'; + final public const SEVERITY_HIGH = 'high'; private function __construct( private string $message, diff --git a/src/Library/KeyManagement/Analyzer/OctAnalyzer.php b/src/Library/KeyManagement/Analyzer/OctAnalyzer.php index fe603f5f..3a8864df 100644 --- a/src/Library/KeyManagement/Analyzer/OctAnalyzer.php +++ b/src/Library/KeyManagement/Analyzer/OctAnalyzer.php @@ -8,6 +8,7 @@ use Jose\Component\Core\Util\Base64UrlSafe; use Override; use function is_string; +use function strlen; final readonly class OctAnalyzer implements KeyAnalyzer { @@ -24,7 +25,7 @@ public function analyze(JWK $jwk, MessageBag $bag): void return; } $k = Base64UrlSafe::decodeNoPadding($k); - $kLength = 8 * mb_strlen($k, '8bit'); + $kLength = 8 * strlen($k); if ($kLength < 128) { $bag->add(Message::high('The key length is less than 128 bits.')); } diff --git a/src/Library/KeyManagement/Analyzer/RsaAnalyzer.php b/src/Library/KeyManagement/Analyzer/RsaAnalyzer.php index c4ca05cc..5a76a5fa 100644 --- a/src/Library/KeyManagement/Analyzer/RsaAnalyzer.php +++ b/src/Library/KeyManagement/Analyzer/RsaAnalyzer.php @@ -10,6 +10,7 @@ use Override; use function is_array; use function is_string; +use function strlen; use const STR_PAD_RIGHT; final readonly class RsaAnalyzer implements KeyAnalyzer @@ -33,7 +34,7 @@ private function checkExponent(JWK $jwk, MessageBag $bag): void return; } - $exponent = unpack('l', mb_str_pad(Base64UrlSafe::decodeNoPadding($e), 4, "\0", STR_PAD_RIGHT, '8bit')); + $exponent = unpack('l', str_pad(Base64UrlSafe::decodeNoPadding($e), 4, "\0", STR_PAD_RIGHT)); if (! is_array($exponent) || ! isset($exponent[1])) { throw new InvalidArgumentException('Unable to get the private key'); } @@ -50,7 +51,7 @@ private function checkModulus(JWK $jwk, MessageBag $bag): void return; } - $n = 8 * mb_strlen(Base64UrlSafe::decodeNoPadding($n), '8bit'); + $n = 8 * strlen(Base64UrlSafe::decodeNoPadding($n)); if ($n < 2048) { $bag->add(Message::high('The key length is less than 2048 bits.')); } diff --git a/src/Library/KeyManagement/Analyzer/ZxcvbnKeyAnalyzer.php b/src/Library/KeyManagement/Analyzer/ZxcvbnKeyAnalyzer.php index 3bc36613..6c861438 100644 --- a/src/Library/KeyManagement/Analyzer/ZxcvbnKeyAnalyzer.php +++ b/src/Library/KeyManagement/Analyzer/ZxcvbnKeyAnalyzer.php @@ -10,19 +10,19 @@ use SensitiveParameter; use function count; use function is_string; -use function mb_strlen; +use function strlen; final readonly class ZxcvbnKeyAnalyzer implements KeyAnalyzer { - public const int STRENGTH_VERY_WEAK = 0; + public const STRENGTH_VERY_WEAK = 0; - public const int STRENGTH_WEAK = 1; + public const STRENGTH_WEAK = 1; - public const int STRENGTH_MEDIUM = 2; + public const STRENGTH_MEDIUM = 2; - public const int STRENGTH_STRONG = 3; + public const STRENGTH_STRONG = 3; - public const int STRENGTH_VERY_STRONG = 4; + public const STRENGTH_VERY_STRONG = 4; #[Override] public function analyze(JWK $jwk, MessageBag $bag): void @@ -67,7 +67,7 @@ public function analyze(JWK $jwk, MessageBag $bag): void */ private static function estimateStrength(#[SensitiveParameter] string $password): int { - if (! $length = mb_strlen($password)) { + if (! $length = strlen($password)) { return self::STRENGTH_VERY_WEAK; } $password = count_chars($password, 1); diff --git a/src/Library/KeyManagement/JWKFactory.php b/src/Library/KeyManagement/JWKFactory.php index 1bf4ac45..21de651c 100644 --- a/src/Library/KeyManagement/JWKFactory.php +++ b/src/Library/KeyManagement/JWKFactory.php @@ -18,6 +18,7 @@ use function extension_loaded; use function is_array; use function is_string; +use function strlen; use const JSON_THROW_ON_ERROR; use const OPENSSL_KEYTYPE_RSA; @@ -110,8 +111,8 @@ public static function createOKPKey(string $curve, array $values = []): JWK case 'Ed25519': $keyPair = sodium_crypto_sign_keypair(); $secret = sodium_crypto_sign_secretkey($keyPair); - $secretLength = mb_strlen($secret, '8bit'); - $d = mb_substr($secret, 0, -$secretLength / 2, '8bit'); + $secretLength = strlen($secret); + $d = substr($secret, 0, -$secretLength / 2); $x = sodium_crypto_sign_publickey($keyPair); break; diff --git a/src/Library/KeyManagement/KeyConverter/KeyConverter.php b/src/Library/KeyManagement/KeyConverter/KeyConverter.php index 55d8305e..0680463a 100644 --- a/src/Library/KeyManagement/KeyConverter/KeyConverter.php +++ b/src/Library/KeyManagement/KeyConverter/KeyConverter.php @@ -417,7 +417,7 @@ private static function decodePem(string $pem, array $matches, ?string $password } $iv = pack('H*', trim($matches[2])); - $iv_sub = mb_substr($iv, 0, 8, '8bit'); + $iv_sub = substr($iv, 0, 8); $symkey = pack('H*', md5($password . $iv_sub)); $symkey .= pack('H*', md5($symkey . $password . $iv_sub)); $key = preg_replace('#^(?:Proc-Type|DEK-Info): .*#m', '', $pem); @@ -426,7 +426,7 @@ private static function decodePem(string $pem, array $matches, ?string $password throw new InvalidArgumentException('Unable to encode the data.'); } - $decoded = openssl_decrypt($ciphertext, mb_strtolower($matches[1]), $symkey, OPENSSL_RAW_DATA, $iv); + $decoded = openssl_decrypt($ciphertext, strtolower($matches[1]), $symkey, OPENSSL_RAW_DATA, $iv); if ($decoded === false) { throw new RuntimeException('Unable to decrypt the key'); } diff --git a/src/Library/KeyManagement/X5UFactory.php b/src/Library/KeyManagement/X5UFactory.php index 74831cd7..0b6c9f8e 100644 --- a/src/Library/KeyManagement/X5UFactory.php +++ b/src/Library/KeyManagement/X5UFactory.php @@ -31,7 +31,7 @@ public function loadFromUrl(string $url, array $header = []): JWKSet $keys = []; foreach ($data as $kid => $cert) { assert(is_string($cert), 'Invalid content.'); - if (mb_strpos($cert, '-----BEGIN CERTIFICATE-----') === false) { + if (! str_contains($cert, '-----BEGIN CERTIFICATE-----')) { $cert = '-----BEGIN CERTIFICATE-----' . "\n" . $cert . "\n" . '-----END CERTIFICATE-----'; } $jwk = KeyConverter::loadKeyFromCertificate($cert); diff --git a/src/Library/Signature/Algorithm/HS256.php b/src/Library/Signature/Algorithm/HS256.php index ba1dc83c..75f384c9 100644 --- a/src/Library/Signature/Algorithm/HS256.php +++ b/src/Library/Signature/Algorithm/HS256.php @@ -7,6 +7,7 @@ use InvalidArgumentException; use Jose\Component\Core\JWK; use Override; +use function strlen; final readonly class HS256 extends HMAC { @@ -26,7 +27,7 @@ protected function getHashAlgorithm(): string protected function getKey(JWK $key): string { $k = parent::getKey($key); - if (mb_strlen($k, '8bit') < 32) { + if (strlen($k) < 32) { throw new InvalidArgumentException('Invalid key length.'); } diff --git a/src/Library/Signature/Algorithm/HS384.php b/src/Library/Signature/Algorithm/HS384.php index 7dd18b32..ba4c1d6d 100644 --- a/src/Library/Signature/Algorithm/HS384.php +++ b/src/Library/Signature/Algorithm/HS384.php @@ -7,6 +7,7 @@ use InvalidArgumentException; use Jose\Component\Core\JWK; use Override; +use function strlen; final readonly class HS384 extends HMAC { @@ -26,7 +27,7 @@ protected function getHashAlgorithm(): string protected function getKey(JWK $key): string { $k = parent::getKey($key); - if (mb_strlen($k, '8bit') < 48) { + if (strlen($k) < 48) { throw new InvalidArgumentException('Invalid key length.'); } diff --git a/src/Library/Signature/Algorithm/HS512.php b/src/Library/Signature/Algorithm/HS512.php index 7db4b176..cdc82f01 100644 --- a/src/Library/Signature/Algorithm/HS512.php +++ b/src/Library/Signature/Algorithm/HS512.php @@ -7,6 +7,7 @@ use InvalidArgumentException; use Jose\Component\Core\JWK; use Override; +use function strlen; final readonly class HS512 extends HMAC { @@ -26,7 +27,7 @@ protected function getHashAlgorithm(): string protected function getKey(JWK $key): string { $k = parent::getKey($key); - if (mb_strlen($k, '8bit') < 64) { + if (strlen($k) < 64) { throw new InvalidArgumentException('Invalid key length.'); } diff --git a/src/Library/Signature/Algorithm/Util/RSA.php b/src/Library/Signature/Algorithm/Util/RSA.php index 9f6d015d..c46a2942 100644 --- a/src/Library/Signature/Algorithm/Util/RSA.php +++ b/src/Library/Signature/Algorithm/Util/RSA.php @@ -12,6 +12,7 @@ use function chr; use function extension_loaded; use function ord; +use function strlen; use const STR_PAD_LEFT; /** @@ -22,12 +23,12 @@ /** * Probabilistic Signature Scheme. */ - public const int SIGNATURE_PSS = 1; + public const SIGNATURE_PSS = 1; /** * Use the PKCS#1. */ - public const int SIGNATURE_PKCS1 = 2; + public const SIGNATURE_PKCS1 = 2; /** * @return non-empty-string @@ -92,7 +93,7 @@ public static function verify(RSAKey $key, string $message, string $signature, s */ public static function verifyWithPSS(RSAKey $key, string $message, string $signature, string $hash): bool { - if (mb_strlen($signature, '8bit') !== $key->getModulusLength()) { + if (strlen($signature) !== $key->getModulusLength()) { throw new RuntimeException(); } $s2 = BigInteger::createFromBinaryString($signature); @@ -106,11 +107,11 @@ public static function verifyWithPSS(RSAKey $key, string $message, string $signa private static function convertIntegerToOctetString(BigInteger $x, int $xLen): string { $x = $x->toBytes(); - if (mb_strlen($x, '8bit') > $xLen) { + if (strlen($x) > $xLen) { throw new RuntimeException(); } - return mb_str_pad($x, $xLen, chr(0), STR_PAD_LEFT, '8bit'); + return str_pad($x, $xLen, chr(0), STR_PAD_LEFT); } /** @@ -125,7 +126,7 @@ private static function getMGF1(string $mgfSeed, int $maskLen, Hash $mgfHash): s $t .= $mgfHash->hash($mgfSeed . $c); } - return mb_substr($t, 0, $maskLen, '8bit'); + return substr($t, 0, $maskLen); } /** @@ -162,11 +163,11 @@ private static function verifyEMSAPSS(string $m, string $em, int $emBits, Hash $ if ($emLen < $hash->getLength() + $sLen + 2) { throw new InvalidArgumentException(); } - if ($em[mb_strlen($em, '8bit') - 1] !== chr(0xBC)) { + if ($em[strlen($em) - 1] !== chr(0xBC)) { throw new InvalidArgumentException(); } - $maskedDB = mb_substr($em, 0, -$hash->getLength() - 1, '8bit'); - $h = mb_substr($em, -$hash->getLength() - 1, $hash->getLength(), '8bit'); + $maskedDB = substr($em, 0, -$hash->getLength() - 1); + $h = substr($em, -$hash->getLength() - 1, $hash->getLength()); $temp = chr(0xFF << ($emBits & 7)); if ((~$maskedDB[0] & $temp) !== $temp) { throw new InvalidArgumentException(); @@ -175,13 +176,13 @@ private static function verifyEMSAPSS(string $m, string $em, int $emBits, Hash $ $db = $maskedDB ^ $dbMask; $db[0] = ~chr(0xFF << ($emBits & 7)) & $db[0]; $temp = $emLen - $hash->getLength() - $sLen - 2; - if (mb_substr($db, 0, $temp, '8bit') !== str_repeat(chr(0), $temp)) { + if (substr($db, 0, $temp) !== str_repeat(chr(0), $temp)) { throw new InvalidArgumentException(); } if (ord($db[$temp]) !== 1) { throw new InvalidArgumentException(); } - $salt = mb_substr($db, $temp + 1, null, '8bit'); // should be $sLen long + $salt = substr($db, $temp + 1, null); // should be $sLen long $m2 = "\0\0\0\0\0\0\0\0" . $mHash . $salt; $h2 = $hash->hash($m2); diff --git a/src/Library/Signature/Serializer/CompactSerializer.php b/src/Library/Signature/Serializer/CompactSerializer.php index 191973c3..f1121201 100644 --- a/src/Library/Signature/Serializer/CompactSerializer.php +++ b/src/Library/Signature/Serializer/CompactSerializer.php @@ -16,7 +16,7 @@ final readonly class CompactSerializer extends Serializer { - public const string NAME = 'jws_compact'; + public const NAME = 'jws_compact'; #[Override] public function displayName(): string diff --git a/src/Library/Signature/Serializer/JSONFlattenedSerializer.php b/src/Library/Signature/Serializer/JSONFlattenedSerializer.php index aa94d51e..f6c898c3 100644 --- a/src/Library/Signature/Serializer/JSONFlattenedSerializer.php +++ b/src/Library/Signature/Serializer/JSONFlattenedSerializer.php @@ -14,7 +14,7 @@ final readonly class JSONFlattenedSerializer extends Serializer { - public const string NAME = 'jws_json_flattened'; + public const NAME = 'jws_json_flattened'; #[Override] public function displayName(): string diff --git a/src/Library/Signature/Serializer/JSONGeneralSerializer.php b/src/Library/Signature/Serializer/JSONGeneralSerializer.php index 4f7d8866..bc235186 100644 --- a/src/Library/Signature/Serializer/JSONGeneralSerializer.php +++ b/src/Library/Signature/Serializer/JSONGeneralSerializer.php @@ -17,7 +17,7 @@ final readonly class JSONGeneralSerializer extends Serializer { - public const string NAME = 'jws_json_general'; + public const NAME = 'jws_json_general'; #[Override] public function displayName(): string diff --git a/src/Library/composer.json b/src/Library/composer.json index bb83871e..1e3a08e9 100644 --- a/src/Library/composer.json +++ b/src/Library/composer.json @@ -38,9 +38,8 @@ } }, "require": { - "php": ">=8.3", + "php": ">=8.2", "ext-json": "*", - "ext-mbstring": "*", "brick/math": "^0.12", "psr/clock": "^1.0", "spomky-labs/pki-framework": "^1.2.1" diff --git a/tests/Component/Encryption/RSAKeyEncryptionTest.php b/tests/Component/Encryption/RSAKeyEncryptionTest.php index 83bb1b7c..910e5cf6 100644 --- a/tests/Component/Encryption/RSAKeyEncryptionTest.php +++ b/tests/Component/Encryption/RSAKeyEncryptionTest.php @@ -94,7 +94,7 @@ public function rSA15EncryptionAndDecryption(): void 207, ]; foreach ($cek as $key => $value) { - $cek[$key] = mb_str_pad(dechex($value), 2, '0', STR_PAD_LEFT); + $cek[$key] = str_pad(dechex($value), 2, '0', STR_PAD_LEFT); } $cek = hex2bin(implode('', $cek)); @@ -164,7 +164,7 @@ public function rSAOAEPEncryptionAndDecryption(): void 252, ]; foreach ($cek as $key => $value) { - $cek[$key] = mb_str_pad(dechex($value), 2, '0', STR_PAD_LEFT); + $cek[$key] = str_pad(dechex($value), 2, '0', STR_PAD_LEFT); } $cek = hex2bin(implode('', $cek)); @@ -234,7 +234,7 @@ public function rSAOAEP256EncryptionAndDecryption(): void 252, ]; foreach ($cek as $key => $value) { - $cek[$key] = mb_str_pad(dechex($value), 2, '0', STR_PAD_LEFT); + $cek[$key] = str_pad(dechex($value), 2, '0', STR_PAD_LEFT); } $cek = hex2bin(implode('', $cek)); diff --git a/tests/Component/KeyManagement/JWKTest.php b/tests/Component/KeyManagement/JWKTest.php index 2d37dbf4..4b6e3f37 100644 --- a/tests/Component/KeyManagement/JWKTest.php +++ b/tests/Component/KeyManagement/JWKTest.php @@ -210,7 +210,7 @@ public function loadCertificateChain(): void static::assertSame( '178f7e93a74ed73d88c29042220b9ae6e4b371cd', - mb_strtolower(bin2hex(Base64UrlSafe::decode($key->get('x5t')))) + strtolower(bin2hex(Base64UrlSafe::decode($key->get('x5t')))) ); static::assertEqualsCanonicalizing([ 'kty' => 'RSA', diff --git a/tests/ComposerJsonTest.php b/tests/ComposerJsonTest.php index c6661941..de4a287c 100644 --- a/tests/ComposerJsonTest.php +++ b/tests/ComposerJsonTest.php @@ -18,7 +18,7 @@ */ final class ComposerJsonTest extends TestCase { - private const string SRC_DIR = __DIR__ . '/../src'; + private const SRC_DIR = __DIR__ . '/../src'; #[Test] public function packageDependenciesEqualRootDependencies(): void diff --git a/tests/EncryptionAlgorithm/ContentEncryption/AESCBC/AESCBC_HSContentEncryptionTest.php b/tests/EncryptionAlgorithm/ContentEncryption/AESCBC/AESCBC_HSContentEncryptionTest.php index 2f3bad20..3eab015c 100644 --- a/tests/EncryptionAlgorithm/ContentEncryption/AESCBC/AESCBC_HSContentEncryptionTest.php +++ b/tests/EncryptionAlgorithm/ContentEncryption/AESCBC/AESCBC_HSContentEncryptionTest.php @@ -329,7 +329,7 @@ protected static function getMethod(string $class, string $name): ReflectionMeth private function convertArrayToBinString(array $data): string { foreach ($data as $key => $value) { - $data[$key] = mb_str_pad(dechex($value), 2, '0', STR_PAD_LEFT); + $data[$key] = str_pad(dechex($value), 2, '0', STR_PAD_LEFT); } return hex2bin(implode('', $data)); diff --git a/tests/EncryptionAlgorithm/ContentEncryption/AESGCM/AESGCMContentEncryptionTest.php b/tests/EncryptionAlgorithm/ContentEncryption/AESGCM/AESGCMContentEncryptionTest.php index 11a15e1b..41c8bbd7 100644 --- a/tests/EncryptionAlgorithm/ContentEncryption/AESGCM/AESGCMContentEncryptionTest.php +++ b/tests/EncryptionAlgorithm/ContentEncryption/AESGCM/AESGCMContentEncryptionTest.php @@ -211,7 +211,7 @@ public function a256GCMDecryptTestVector(): void private function convertArrayToBinString(array $data): string { foreach ($data as $key => $value) { - $data[$key] = mb_str_pad(dechex($value), 2, '0', STR_PAD_LEFT); + $data[$key] = str_pad(dechex($value), 2, '0', STR_PAD_LEFT); } return hex2bin(implode('', $data)); diff --git a/tests/EncryptionAlgorithm/KeyEncryption/ECDHES/ECDHESKeyAgreementTest.php b/tests/EncryptionAlgorithm/KeyEncryption/ECDHES/ECDHESKeyAgreementTest.php index 79bf42a7..b9f8fff8 100644 --- a/tests/EncryptionAlgorithm/KeyEncryption/ECDHES/ECDHESKeyAgreementTest.php +++ b/tests/EncryptionAlgorithm/KeyEncryption/ECDHES/ECDHESKeyAgreementTest.php @@ -104,7 +104,7 @@ public function getAgreementKeyWithA128KeyWrapAndWithOctetKeyPairKey(): void 207, ]; foreach ($cek as $key => $value) { - $cek[$key] = mb_str_pad(dechex($value), 2, '0', STR_PAD_LEFT); + $cek[$key] = str_pad(dechex($value), 2, '0', STR_PAD_LEFT); } $cek = hex2bin(implode('', $cek)); @@ -171,7 +171,7 @@ public function getAgreementKeyWithA128KeyWrap(): void 207, ]; foreach ($cek as $key => $value) { - $cek[$key] = mb_str_pad(dechex($value), 2, '0', STR_PAD_LEFT); + $cek[$key] = str_pad(dechex($value), 2, '0', STR_PAD_LEFT); } $cek = hex2bin(implode('', $cek)); @@ -238,7 +238,7 @@ public function getAgreementKeyWithA192KeyWrap(): void 207, ]; foreach ($cek as $key => $value) { - $cek[$key] = mb_str_pad(dechex($value), 2, '0', STR_PAD_LEFT); + $cek[$key] = str_pad(dechex($value), 2, '0', STR_PAD_LEFT); } $cek = hex2bin(implode('', $cek)); @@ -311,7 +311,7 @@ public function getAgreementKeyWithA256KeyWrap(): void 207, ]; foreach ($cek as $key => $value) { - $cek[$key] = mb_str_pad(dechex($value), 2, '0', STR_PAD_LEFT); + $cek[$key] = str_pad(dechex($value), 2, '0', STR_PAD_LEFT); } $cek = hex2bin(implode('', $cek)); diff --git a/tests/EncryptionAlgorithm/KeyEncryption/ECDHSS/ECDHSSKeyAgreementTest.php b/tests/EncryptionAlgorithm/KeyEncryption/ECDHSS/ECDHSSKeyAgreementTest.php index 5a93909d..aa7108e0 100644 --- a/tests/EncryptionAlgorithm/KeyEncryption/ECDHSS/ECDHSSKeyAgreementTest.php +++ b/tests/EncryptionAlgorithm/KeyEncryption/ECDHSS/ECDHSSKeyAgreementTest.php @@ -106,7 +106,7 @@ public function getAgreementKeyWithA128KeyWrapAndOctetKeyPairKey(): void 207, ]; foreach ($cek as $key => $value) { - $cek[$key] = mb_str_pad(dechex($value), 2, '0', STR_PAD_LEFT); + $cek[$key] = str_pad(dechex($value), 2, '0', STR_PAD_LEFT); } $cek = hex2bin(implode('', $cek)); @@ -182,7 +182,7 @@ public function getAgreementKeyWithA128KeyWrap(): void 207, ]; foreach ($cek as $key => $value) { - $cek[$key] = mb_str_pad(dechex($value), 2, '0', STR_PAD_LEFT); + $cek[$key] = str_pad(dechex($value), 2, '0', STR_PAD_LEFT); } $cek = hex2bin(implode('', $cek)); @@ -259,7 +259,7 @@ public function getAgreementKeyWithA192KeyWrap(): void 207, ]; foreach ($cek as $key => $value) { - $cek[$key] = mb_str_pad(dechex($value), 2, '0', STR_PAD_LEFT); + $cek[$key] = str_pad(dechex($value), 2, '0', STR_PAD_LEFT); } $cek = hex2bin(implode('', $cek)); @@ -336,7 +336,7 @@ public function getAgreementKeyWithA256KeyWrap(): void 207, ]; foreach ($cek as $key => $value) { - $cek[$key] = mb_str_pad(dechex($value), 2, '0', STR_PAD_LEFT); + $cek[$key] = str_pad(dechex($value), 2, '0', STR_PAD_LEFT); } $cek = hex2bin(implode('', $cek)); diff --git a/tests/EncryptionAlgorithm/KeyEncryption/PBES2/PBES2_HS_AESKWKeyEncryptionTest.php b/tests/EncryptionAlgorithm/KeyEncryption/PBES2/PBES2_HS_AESKWKeyEncryptionTest.php index 07b61db2..f60e21c1 100644 --- a/tests/EncryptionAlgorithm/KeyEncryption/PBES2/PBES2_HS_AESKWKeyEncryptionTest.php +++ b/tests/EncryptionAlgorithm/KeyEncryption/PBES2/PBES2_HS_AESKWKeyEncryptionTest.php @@ -914,7 +914,7 @@ public function p2SParameterIsMissing(): void private function convertArrayToBinString(array $data) { foreach ($data as $key => $value) { - $data[$key] = mb_str_pad(dechex($value), 2, '0', STR_PAD_LEFT); + $data[$key] = str_pad(dechex($value), 2, '0', STR_PAD_LEFT); } return hex2bin(implode('', $data)); diff --git a/tests/SignatureAlgorithm/Experimental/Blake2bTest.php b/tests/SignatureAlgorithm/Experimental/Blake2bTest.php index 6ad2ba59..a8d5183d 100644 --- a/tests/SignatureAlgorithm/Experimental/Blake2bTest.php +++ b/tests/SignatureAlgorithm/Experimental/Blake2bTest.php @@ -17,15 +17,15 @@ */ final class Blake2bTest extends TestCase { - private const string KEY_ONE = 'GOu4rLyVCBxmxP-sbniU68ojAja5PkRdvv7vNvBCqDQ'; + private const KEY_ONE = 'GOu4rLyVCBxmxP-sbniU68ojAja5PkRdvv7vNvBCqDQ'; - private const string KEY_TWO = 'Pu7gywseH-R5HLIWnMll4rEg1ltjUPq_P9WwEzAsAb8'; + private const KEY_TWO = 'Pu7gywseH-R5HLIWnMll4rEg1ltjUPq_P9WwEzAsAb8'; - private const string CONTENTS = 'test'; + private const CONTENTS = 'test'; - private const string EXPECTED_HASH_WITH_KEY_ONE = '_TG5kmkav_YGl3I9uQiv4cm1VN6Q0zPCom4G7-p74JU'; + private const EXPECTED_HASH_WITH_KEY_ONE = '_TG5kmkav_YGl3I9uQiv4cm1VN6Q0zPCom4G7-p74JU'; - private const string SHORT_KEY = 'PIBQuM5PopdMxtmTWmyvNA'; + private const SHORT_KEY = 'PIBQuM5PopdMxtmTWmyvNA'; private JWK $keyOne;