예제 #1
0
        private void ArrayHash(byte[] array, int offset, int count)
        {
            byte[] result;

            using (HashAlgorithm hash = new Length32Hash())
            {
                result = hash.ComputeHash(array, offset, count);
            }

            AssertCorrectAnswer((uint)count, result);
        }
예제 #2
0
        public void HashFullArrayInvalidArguments()
        {
            using (HashAlgorithm hash = new Length32Hash())
            {
                Assert.Throws <ArgumentNullException>(() => hash.ComputeHash((byte[])null));

                hash.Dispose();

                Assert.Throws <ObjectDisposedException>(() => hash.ComputeHash(s_tenBytes));
            }
        }
예제 #3
0
        private void StreamHashHelper(int byteCount)
        {
            byte[] result;

            using (var stream = new PositionValueStream(byteCount))
                using (HashAlgorithm hash = new Length32Hash())
                {
                    result = hash.ComputeHash(stream);
                }

            AssertCorrectAnswer((uint)byteCount, result);
        }
예제 #4
0
        public void ClearIsDispose()
        {
            using (var stream = new PositionValueStream(0))
                using (HashAlgorithm hash = new Length32Hash())
                {
                    Assert.Throws <NullReferenceException>(() => hash.ComputeHash((Stream)null));

                    hash.Clear();

                    Assert.Throws <ObjectDisposedException>(() => hash.ComputeHash(stream));
                }
        }
예제 #5
0
        private void ArrayHash(byte[] array)
        {
            // Do not call ArrayHash(byte[], int, int).
            // Here we're verifying ComputeHash(byte[]).
            byte[] result;

            using (HashAlgorithm hash = new Length32Hash())
            {
                result = hash.ComputeHash(array);
            }

            AssertCorrectAnswer((uint)array.Length, result);
        }
예제 #6
0
        public void HashPartialArrayInvalidArguments()
        {
            using (HashAlgorithm hash = new Length32Hash())
            {
                Assert.Throws <ArgumentNullException>(() => hash.ComputeHash((byte[])null, 0, 0));
                Assert.Throws <ArgumentOutOfRangeException>(() => hash.ComputeHash(s_tenBytes, -1, 0));
                AssertExtensions.Throws <ArgumentException>(null, () => hash.ComputeHash(s_tenBytes, 0, -1));
                AssertExtensions.Throws <ArgumentException>(null, () => hash.ComputeHash(s_tenBytes, 0, 11));
                AssertExtensions.Throws <ArgumentException>(null, () => hash.ComputeHash(s_tenBytes, 9, 2));

                hash.Dispose();

                Assert.Throws <ObjectDisposedException>(() => hash.ComputeHash(s_tenBytes, 0, 10));
            }
        }