示例#1
0
        public static void OverriddenGetHashAndReset_TooBig_Succeeds()
        {
            Span <byte> buf  = stackalloc byte[16];
            var         hash = new FlexibleAlgorithmOverride(buf.Length / 2);
            int         i    = 0;

            while (buf.Length > hash.HashLengthInBytes)
            {
                Assert.Equal(0, hash.GetCurrentHashCoreCallCount);
                Assert.Equal(i, hash.GetHashAndResetCoreCallCount);

                hash.Append(buf);
                Assert.False(hash.IsReset);

                Assert.True(hash.TryGetHashAndReset(buf, out int written));
                Assert.Equal(hash.HashLengthInBytes, written);
                Assert.True(hash.IsReset);

                buf = buf.Slice(1);
                i++;
            }

            Assert.Equal(0, hash.GetCurrentHashCoreCallCount);
            Assert.Equal(i, hash.GetHashAndResetCoreCallCount);
            Assert.True(hash.IsReset);
        }
示例#2
0
        public static void OverriddenTryGetHashAndReset_TooSmall()
        {
            Span <byte> buf  = stackalloc byte[7];
            var         hash = new FlexibleAlgorithmOverride(buf.Length + 1);

            Assert.True(hash.IsReset);
            hash.Append(buf);
            Assert.False(hash.IsReset);

            while (true)
            {
                Assert.False(hash.TryGetHashAndReset(buf, out int written));
                Assert.Equal(0, written);

                if (buf.IsEmpty)
                {
                    break;
                }

                buf = buf.Slice(1);
            }

            Assert.Equal(0, hash.GetCurrentHashCoreCallCount);
            Assert.Equal(0, hash.GetHashAndResetCoreCallCount);
            Assert.False(hash.IsReset);
        }
示例#3
0
        public static void OverriddenAllocatingGetHashAndReset_CorrectSize()
        {
            var hash = new FlexibleAlgorithmOverride(12);

            byte[] ret = hash.GetHashAndReset();
            Assert.Equal(hash.HashLengthInBytes, ret.Length);
            Assert.Equal(0, hash.GetCurrentHashCoreCallCount);
            Assert.Equal(1, hash.GetHashAndResetCoreCallCount);
        }
示例#4
0
        public static void OverriddenGetHashAndReset_TooSmall()
        {
            byte[] buf  = new byte[7];
            var    hash = new FlexibleAlgorithmOverride(buf.Length + 1);

            Assert.True(hash.IsReset);
            hash.Append(buf);
            Assert.False(hash.IsReset);

            for (int i = 0; i <= buf.Length; i++)
            {
                AssertExtensions.Throws <ArgumentException>(
                    "destination",
                    () => hash.GetHashAndReset(buf.AsSpan(i)));
            }

            Assert.Equal(0, hash.GetCurrentHashCoreCallCount);
            Assert.Equal(0, hash.GetHashAndResetCoreCallCount);
            Assert.False(hash.IsReset);
        }