Exemplo n.º 1
0
        public void CheckParseBase64_Fixed()
        {
            string[] str_list = new string[]
            {
                "ABCDEFG",
                "abcdefg",
                "ABCDEF",
                "abcdef",
            };

            var bytes_native   = new NativeList <byte>(Allocator.Persistent);
            var encoded_native = new NativeList <Char16>(Allocator.Persistent);
            var bytes_decoded  = new NativeList <byte>(Allocator.Persistent);

            var b64_encoder = new NativeBase64Encoder(Allocator.Persistent);
            var b64_decoder = new NativeBase64Decoder(Allocator.Persistent);

            foreach (var str_ref in str_list)
            {
                byte[] bytes_ref   = Encoding.UTF8.GetBytes(str_ref);
                string encoded_ref = Convert.ToBase64String(bytes_ref);

                bytes_native.Clear();
                encoded_native.Clear();
                bytes_decoded.Clear();

                foreach (var b in bytes_ref)
                {
                    bytes_native.Add(b);
                }

                b64_encoder.Clear();
                b64_encoder.GetChars(encoded_native, bytes_native);

                CheckBase64EncodedStr(encoded_native, encoded_ref, true);

                b64_decoder.Clear();
                b64_decoder.GetBytes(bytes_decoded, encoded_native);

                CheckBase64DecodedBytes(bytes_decoded, bytes_ref, true);
            }

            bytes_native.Dispose();
            encoded_native.Dispose();
            bytes_decoded.Dispose();

            b64_encoder.Dispose();
            b64_decoder.Dispose();
        }
Exemplo n.º 2
0
        public void Dispose()
        {
            if (_allocated)
            {
                Data.Dispose();
                IndexSeq.Dispose();

                _name.Dispose();

                _str_list.Dispose();
                _tmp_name.Dispose();
                _mark_list.Dispose();

                _b64_decoder.Dispose();
                _b64_decoded_bytes.Dispose();

                _allocated = false;
            }
        }
Exemplo n.º 3
0
        public void CheckParseBase64_Random(int n)
        {
            Assert.IsTrue(n > 0);
            const int Base64InLine = 76;

            var bytes_native   = new NativeList <byte>(Allocator.Persistent);
            var encoded_native = new NativeList <Char16>(Allocator.Persistent);
            var bytes_decoded  = new NativeList <byte>(Allocator.Persistent);

            var b64_encoder = new NativeBase64Encoder(Allocator.Persistent);
            var b64_decoder = new NativeBase64Decoder(Allocator.Persistent);

            long total_bytes = 0;

            for (int i = 0; i < n; i++)
            {
                int byte_len = random.Next(16, 256);
                total_bytes += byte_len;

                byte[] bytes_ref = new byte[byte_len];
                bytes_native.Clear();
                for (int j = 0; j < byte_len; j++)
                {
                    byte b = (byte)random.Next(0, 255);
                    bytes_ref[j] = b;
                    bytes_native.Add(b);
                }

                string encoded_ref = Convert.ToBase64String(bytes_ref);

                var sb        = new StringBuilder();
                int charcount = 0;
                foreach (char c in encoded_ref)
                {
                    if (charcount == Base64InLine)
                    {
                        sb.Append("\r\n");
                        charcount = 0;
                    }

                    sb.Append(c);
                    charcount++;
                }
                string encoded_ref_withLF = sb.ToString();

                // test for encoded str with CRLF
                encoded_native.Clear();
                bytes_decoded.Clear();

                b64_encoder.Clear();
                b64_encoder.GetChars(encoded_native, bytes_native);

                CheckBase64EncodedStr(encoded_native, encoded_ref_withLF);

                b64_decoder.Clear();
                b64_decoder.GetBytes(bytes_decoded, encoded_native);

                CheckBase64DecodedBytes(bytes_decoded, bytes_ref);

                // test for encoded str without CRLF
                encoded_native.Clear();
                bytes_decoded.Clear();

                b64_encoder.Clear();
                b64_encoder.InsertLineBrakes = false;  // default: encode with "CRLF".
                b64_encoder.GetChars(encoded_native, bytes_native);
                b64_encoder.InsertLineBrakes = true;

                CheckBase64EncodedStr(encoded_native, encoded_ref);

                b64_decoder.Clear();
                b64_decoder.GetBytes(bytes_decoded, encoded_native);

                CheckBase64DecodedBytes(bytes_decoded, bytes_ref);
            }

            Debug.Log("total test bytes: " + total_bytes.ToString() + " B\n");

            bytes_native.Dispose();
            encoded_native.Dispose();
            bytes_decoded.Dispose();

            b64_encoder.Dispose();
            b64_decoder.Dispose();
        }