private static function _decodeLongFormLength(int $length, string $data,
        int &$offset): string
    {
        // first octet must not be 0xff (spec 8.1.3.5c)
        if ($length == 127) {
            throw new DecodeException("Invalid number of length octets.");
        }
        $num = gmp_init(0, 10);
        while (--$length >= 0) {
            $byte = ord($data[$offset++]);
            $num <<= 8;
            $num |= $byte;
        }
        return gmp_strval($num);
    }