コード例 #1
0
        public void CapacityExistingItemsTest()
        {
            // arrange
            ByteCircularBuffer target;
            int expectedCapacity;

            byte[] expectedItems;
            int    expectedSize;

            expectedCapacity = 10;
            expectedSize     = 2;
            expectedItems    = new byte[]
            {
                1,
                2
            };

            target = new ByteCircularBuffer(3);
            target.Put(1);
            target.Put(2);

            // act
            target.Capacity = expectedCapacity;

            // assert
            target.Capacity.Should().
            Be(expectedCapacity);
            target.Size.Should().
            Be(expectedSize);
            target.ToArray().
            Should().
            Equal(expectedItems);
        }
コード例 #2
0
        public void ToArrayTest()
        {
            // arrange
            ByteCircularBuffer target;

            byte[] actual;
            byte[] expected;

            target = new ByteCircularBuffer(10);
            target.Put(1);
            target.Put(2);
            target.Put(3);
            target.Put(4);

            expected = new byte[]
            {
                1,
                2,
                3,
                4
            };

            // act
            actual = target.ToArray();

            // assert
            actual.Should().
            Equal(expected);
        }
コード例 #3
0
        public void PutArrayTest()
        {
            // arrange

            byte[] expected = this.GenerateRandomData(100);

            ByteCircularBuffer target = new ByteCircularBuffer(expected.Length);

            // act
            target.Put(expected);

            // assert
            target.ToArray().
            Should().
            Equal(expected);
        }
コード例 #4
0
 public override void Decrypt(byte[] buf, int length, byte[] outbuf, out int outlength)
 {
     Debug.Assert(_decCircularBuffer != null, "_circularBuffer != null");
     _decCircularBuffer.Put(buf, 0, length);
     if (!_decryptIVReceived)
     {
         if (_decCircularBuffer.Size <= ivLen)
         {
             // we need more data
             outlength = 0;
             return;
         }
         // start decryption
         _decryptIVReceived = true;
         byte[] iv = _decCircularBuffer.Get(ivLen);
         initCipher(iv, false);
     }
     byte[] cipher = _decCircularBuffer.ToArray();
     cipherUpdate(false, cipher.Length, cipher, outbuf);
     _decCircularBuffer.Clear();
     outlength = cipher.Length;
     // done the decryption
 }
        public override void Decrypt(byte[] buf, int length, byte[] outbuf, out int outlength)
        {
            _decCircularBuffer.Put(buf, 0, length);
            if (!_decryptIVReceived)
            {
                if (_decCircularBuffer.Size <= ivLen)
                {
                    // we need more data
                    outlength = 0;
                    return;
                }
                // start decryption
                _decryptIVReceived = true;
                var iv = ivLen == 0 ? new byte[0] : _decCircularBuffer.Get(ivLen); //none rc4
                InitCipher(iv, false);
            }
            var cipher = _decCircularBuffer.ToArray();

            CipherUpdate(false, cipher.Length, cipher, outbuf);
            // move pointer only
            _decCircularBuffer.Skip(_decCircularBuffer.Size);
            outlength = cipher.Length;
            // done the decryption
        }