예제 #1
0
        public void TestAnotherChunkedDataIncrementalHash()
        {
            var hashInstanceClone = HashInstance.Clone();

            for (var idx = 0; idx < ChunkSizes.Length / sizeof(int); idx++)
            {
                var size = ChunkSizes[idx];
                HashInstance.Initialize();
                var    jdx = size;
                byte[] temp;
                while (jdx < ChunkedDataBytes.Length)
                {
                    temp = new byte[size];
                    Array.Copy(ChunkedDataBytes, jdx - size, temp, 0, temp.Length);
                    HashInstance.TransformBytes(temp);

                    jdx += size;
                }

                temp = new byte[ChunkedDataBytes.Length - (jdx - size)];
                Array.Copy(ChunkedDataBytes, jdx - size, temp, 0, temp.Length);

                HashInstance.TransformBytes(temp);

                ExpectedString = hashInstanceClone.ComputeBytes(ChunkedDataBytes).ToString();
                ActualString   = HashInstance.TransformFinal().ToString();
                AssertAreEqual(ExpectedString, ActualString);
            }
        }
예제 #2
0
        public void TestSplits()
        {
            var input = ZeroToNineteenBytes;

            for (var i = 0; i < input.Length; i++)
            {
                HashInstance.Initialize();
                HashInstance.TransformBytes(input, 0, i);
                ExpectedString = HashInstance.TransformFinal().ToString();

                for (var j = 0; j <= i; j++)
                {
                    for (var k = j; k <= i; k++)
                    {
                        HashInstance.Initialize();
                        HashInstance.TransformBytes(input, 0, j);
                        HashInstance.TransformBytes(input, j, k - j);
                        HashInstance.TransformBytes(input, k, i - k);
                        ActualString = HashInstance.TransformFinal().ToString();

                        AssertAreEqual(ExpectedString, ActualString);
                    }
                }
            }
        }
예제 #3
0
 public void TestHashingNullDataIncrementalThrowsCorrectException() =>
 Assert.Throws <ArgumentNullException>(() =>
 {
     HashInstance.Initialize();
     HashInstance.TransformBytes(NullBytes, 0, 0);
     HashInstance.TransformFinal();
 });
예제 #4
0
        public void TestStreamAndArrayHashMatchTwo()
        {
            LargeMemoryStream.Position = 0;
            ActualString = HashInstance.ComputeStream(LargeMemoryStream, LargeMemoryStream.Length / 2).ToString();
            HashInstance.Initialize();
            HashInstance.TransformBytes(LargeMemoryStream.ToArray(), 0, (int)(LargeMemoryStream.Length / 2));
            ExpectedString = HashInstance.TransformFinal().ToString();

            AssertAreEqual(ExpectedString, ActualString);
        }
예제 #5
0
        public void TestInitializeWorks()
        {
            HashInstance.Initialize();
            HashInstance.TransformBytes(DefaultDataBytes);
            ExpectedString = HashInstance.TransformFinal().ToString();

            HashInstance.Initialize();
            HashInstance.TransformBytes(DefaultDataBytes);
            ActualString = HashInstance.TransformFinal().ToString();

            AssertAreEqual(ExpectedString, ActualString);
        }
예제 #6
0
        public void TestIncrementalHash()
        {
            ExpectedString = HashOfDefaultData;
            HashInstance.Initialize();
            foreach (var b in DefaultDataBytes)
            {
                HashInstance.TransformBytes(new[] { b });
            }

            ActualString = HashInstance.TransformFinal().ToString();
            AssertAreEqual(ExpectedString, ActualString);
        }
예제 #7
0
        public void TestHashCloneMatchesMainHash()
        {
            HashInstance.Initialize();

            foreach (var b in DefaultDataBytes)
            {
                HashInstance.TransformBytes(new[] { b });
            }

            var hashInstanceClone = HashInstance.Clone();

            ExpectedString = HashInstance.TransformFinal().ToString();
            ActualString   = hashInstanceClone.TransformFinal().ToString();

            AssertAreEqual(ExpectedString, ActualString);
        }
예제 #8
0
        public void TestIndexChunkedDataIncrementalHash()
        {
            var hashInstanceClone = HashInstance.Clone();

            for (var idx = 0; idx < ChunkedDataBytes.Length; idx++)
            {
                var count = ChunkedDataBytes.Length - idx;

                var temp = new byte[count];
                Array.Copy(ChunkedDataBytes, idx, temp, 0, count);

                HashInstance.Initialize();
                HashInstance.TransformBytes(ChunkedDataBytes, idx, count);

                ExpectedString = hashInstanceClone.ComputeBytes(temp).ToString();
                ActualString   = HashInstance.TransformFinal().ToString();
                AssertAreEqual(ExpectedString, ActualString);
            }
        }
예제 #9
0
        public void TestHashCloneIsCorrect()
        {
            var count  = DefaultDataBytes.Length - 3;
            var chunk1 = new byte[count];

            Array.Copy(DefaultDataBytes, 0, chunk1, 0, chunk1.Length);

            var chunk2 = new byte[DefaultDataBytes.Length - count];

            Array.Copy(DefaultDataBytes, count, chunk1, 0, chunk2.Length);

            HashInstance.Initialize();
            HashInstance.TransformBytes(chunk1);
            // Make Clone Of Current State
            var hashInstanceClone = HashInstance.Clone();

            HashInstance.TransformBytes(chunk2);
            ExpectedString = HashInstance.TransformFinal().ToString();

            hashInstanceClone.TransformBytes(chunk2);
            ActualString = hashInstanceClone.TransformFinal().ToString();

            AssertAreEqual(ExpectedString, ActualString);
        }