From dfce237a4069960c582878421f570434eb77ea0b Mon Sep 17 00:00:00 2001 From: Florent Morselli Date: Thu, 21 Oct 2021 17:57:49 +0200 Subject: [PATCH] Update LengthCalculator.php --- src/LengthCalculator.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/LengthCalculator.php b/src/LengthCalculator.php index e00b292..f49bc07 100644 --- a/src/LengthCalculator.php +++ b/src/LengthCalculator.php @@ -48,16 +48,16 @@ public static function getLengthOfArray(array $data): array private static function computeLength(int $length): array { switch (true) { - case $length < 24: + case $length <= 23: return [$length, null]; - case $length < 0xFF: + case $length <= 0xFF: return [24, chr($length)]; - case $length < 0xFFFF: - return [25, self::hex2bin(dechex($length))]; - case $length < 0xFFFFFFFF: - return [26, self::hex2bin(dechex($length))]; - case BigInteger::of($length)->isLessThan(BigInteger::fromBase('FFFFFFFFFFFFFFFF', 16)): - return [27, self::hex2bin(dechex($length))]; + case $length <= 0xFFFF: + return [25, self::hex2bin(static::fixHexLength(Utils::intToHex($length)))]; + case $length <= 0xFFFFFFFF: + return [26, self::hex2bin(static::fixHexLength(Utils::intToHex($length)))]; + case BigInteger::of($length)->isLessThanOrEqualTo(BigInteger::fromBase('FFFFFFFFFFFFFFFF', 16)): + return [27, self::hex2bin(static::fixHexLength(Utils::intToHex($length)))]; default: return [31, null]; }