Beispiel #1
0
        public void EncodeAndDecodeBlock_GetOriginBlock()
        {
            // Arrange
            Random random = new Random();
            int    key    = random.Next();

            var buffer = new byte[3];

            byte[] data   = { 1, 2, 3 };
            var    result = new byte[3];

            IOutputStream encodingOutputStream = new EncodingOutputStream(new MemoryOutputStream(buffer), key);
            IInputStream  decodingInputStream  = new DecodingInputStream(new MemoryInputStream(buffer), key);

            // Act
            encodingOutputStream.WriteBlock(data, ( uint )data.Length);
            encodingOutputStream.Dispose();
            int readSize = decodingInputStream.ReadBlock(result, ( uint )result.Length);

            decodingInputStream.Dispose();

            // Assert
            Assert.Equal(result.Length, readSize);
            Assert.True(result.SequenceEqual(data));
        }
Beispiel #2
0
        public void DecorateByArgumentOptions(List <ArgumentOption> argumentOptions, ref IInputStream inputStream, ref IOutputStream outputStream)
        {
            if (argumentOptions.Count == 0)
            {
                return;
            }

            foreach (ArgumentOption argumentOption in argumentOptions)
            {
                switch (argumentOption.FirstArgument)
                {
                case "--encrypt":
                    outputStream = new EncodingOutputStream(outputStream, argumentOption.SecondArgument.Value);
                    break;

                case "--decrypt":
                    inputStream = new DecodingInputStream(inputStream, argumentOption.SecondArgument.Value);
                    break;

                case "--compress":
                    outputStream = new CompressionOutputStream(outputStream);
                    break;

                case "--decompress":
                    inputStream = new DecompressionInputStream(inputStream);
                    break;

                default:
                    break;
                }
            }
        }
Beispiel #3
0
        public void EncodeAndDecodeByte_GetOriginByte()
        {
            // Arrange
            Random random = new Random();
            int    key    = random.Next();

            var  buffer = new byte[1];
            byte data   = 1;

            IOutputStream encodingOutputStream = new EncodingOutputStream(new MemoryOutputStream(buffer), key);
            IInputStream  decodingInputStream  = new DecodingInputStream(new MemoryInputStream(buffer), key);

            // Act
            encodingOutputStream.WriteByte(data);
            encodingOutputStream.Dispose();
            int result = decodingInputStream.ReadByte();

            decodingInputStream.Dispose();

            // Assert
            Assert.Equal(data, result);
        }