Пример #1
0
        public static void DecodeInvalidBlock()
        {
            var base64  = Encoding.UTF8.GetBytes("AB");
            var decoder = new Base64Decoder();

            using var writer = new PooledArrayBufferWriter <byte>();
            decoder.Decode(base64, writer);
            True(decoder.NeedMoreData);
            Equal(0, writer.WrittenCount);
        }
Пример #2
0
        public static void DecodeBase64CharsToByteBuffer(int chunkSize, int size)
        {
            var expected = RandomBytes(size);
            var base64   = ToReadOnlySequence <char>(Convert.ToBase64String(expected).AsMemory(), chunkSize);
            var actual   = new ArrayBufferWriter <byte>();
            var decoder  = new Base64Decoder();

            decoder.Decode(base64, actual);
            False(decoder.NeedMoreData);

            Equal(expected, actual.WrittenSpan.ToArray());
        }
Пример #3
0
        public static void DecodeBase64CharsToCallback(int chunkSize, int size)
        {
            var expected = RandomBytes(size);
            var base64   = ToReadOnlySequence <char>(Convert.ToBase64String(expected).AsMemory(), chunkSize);
            var actual   = new ArrayBufferWriter <byte>();
            var decoder  = new Base64Decoder();

            foreach (var segment in base64)
            {
                decoder.Decode(segment.Span, static (input, output) => output.Write(input), actual);
            }
            False(decoder.NeedMoreData);

            Equal(expected, actual.WrittenSpan.ToArray());
        }