Exemplo n.º 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);
            }
        }
Exemplo n.º 2
0
        public void TestHashCloneIsUnique()
        {
            HashInstance.Initialize();
            HashInstance.BufferSize = 64 * 1024; // 64Kb
            ExpectedString          = HashInstance.BufferSize.ToString();
            // Make Clone Of Current State
            var hashInstanceClone = HashInstance.Clone();

            hashInstanceClone.BufferSize = 128 * 1024; // 128Kb
            ActualString = hashInstanceClone.BufferSize.ToString();
            AssertAreNotEqual(ExpectedString, ActualString);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
            }
        }
Exemplo n.º 5
0
        public void TestMultiThreadingAndCloneWorks()
        {
            const int iterations = 20;

            var h1 = HashInstance.Clone();
            var h2 = HashInstance.Clone();
            var h3 = HashInstance.Clone();
            var h4 = HashInstance.Clone();

            var a = Clone(DefaultDataBytes);
            var b = Clone(DefaultDataBytes);
            var c = Clone(DefaultDataBytes);
            var d = Clone(DefaultDataBytes);

            var t1 = Task.Factory.StartNew(() => HashComputation(ref a, h1, iterations));
            var t2 = Task.Factory.StartNew(() => HashComputation(ref b, h2, iterations));
            var t3 = Task.Factory.StartNew(() => HashComputation(ref c, h3, iterations));
            var t4 = Task.Factory.StartNew(() => HashComputation(ref d, h4, iterations));

            Task.WaitAll(t1, t2, t3, t4);

            Assert.IsTrue(AreEqual(a, b) == AreEqual(c, d),
                          $"MultiThreading and Clone test failed for '{HashInstance.Name}'");
        }
Exemplo n.º 6
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);
        }