CoreFiles by mySites.guru
Utils.php66 lines, 1,522 bytes, from Joomla_6.2.0-beta3-Beta-Full_Package.zip
Raw History Compare with 6.2.0-beta2
md5
c6c36dd99caf1ea856fce3d63c331d35
sha1
94dcdb0a6bc9797e1da2602270423a651496ab20
sha256
ea9488aacb1c1174e61dd095818d80cc05452c89e728e82c381415a66c06c3ad
<?php

declare(strict_types=1);

namespace CBOR;

use function assert;
use Brick\Math\BigInteger;
use InvalidArgumentException;
use function is_string;

/**
 * @internal
 */
abstract class Utils
{
    public static function binToInt(string $value): int
    {
        return self::binToBigInteger($value)->toInt();
    }

    public static function binToBigInteger(string $value): BigInteger
    {
        return self::hexToBigInteger(bin2hex($value));
    }

    public static function hexToInt(string $value): int
    {
        return self::hexToBigInteger($value)->toInt();
    }

    public static function hexToBigInteger(string $value): BigInteger
    {
        assert($value !== '', 'Value must not be empty');

        return BigInteger::fromBase($value, 16);
    }

    public static function hexToString(string $value): string
    {
        $hex = bin2hex($value);
        assert($hex !== '', 'Value must not be empty');

        return BigInteger::fromBase($hex, 16)->toBase(10);
    }

    public static function decode(string $data): string
    {
        $decoded = base64_decode(strtr($data, '-_', '+/'), true);
        if ($decoded === false) {
            throw new InvalidArgumentException('Invalid data provided');
        }

        return $decoded;
    }

    /**
     * @param mixed|null $data
     */
    public static function assertString($data, ?string $message = null): void
    {
        if (! is_string($data)) {
            throw new InvalidArgumentException($message ?? '');
        }
    }
}

The same content is in 11 releases, Joomla 6.2.0-alpha2 to 6.3.0-alpha1. See them all, or every version of this file.