示例#1
0
        private static uint Checksum(Stream file)
        {
            var hash   = new XXH32();
            var buffer = new byte[0x10000];

            while (true)
            {
                var read = file.Read(buffer, 0, buffer.Length);
                if (read == 0)
                {
                    break;
                }

                hash.Update(buffer, 0, read);
            }

            return(hash.Digest());
        }
        public void EveryCallToDigestReturnsSameHash(int seed, int length)
        {
            var random = new Random(seed);
            var bytes  = new byte[length];

            random.NextBytes(bytes);

            var expected = XXH32.DigestOf(bytes, 0, bytes.Length);

            var transform = new XXH32();

            transform.Update(bytes, 0, length);

            for (var i = 0; i < 100; i++)
            {
                Assert.Equal(expected, transform.Digest());
            }
        }
        public void RestartableHashReturnsSameResultsAsSingleBlock(int seed, int length, int chunk)
        {
            var random = new Random(seed);
            var bytes  = new byte[length];

            random.NextBytes(bytes);

            var expected = XXH32.DigestOf(bytes, 0, bytes.Length);

            var transform = new XXH32();
            var index     = 0;

            while (index < length)
            {
                var l = Math.Min(chunk, length - index);
                transform.Update(bytes, index, l);
                index += l;
            }

            var actual = transform.Digest();

            Assert.Equal(expected, actual);
        }