Ejemplo n.º 1
0
        public static void EmptyReturnTrue()
        {
            int byteLength = 0;

            byte[] rented = ArrayPool <byte> .Shared.Rent(byteLength);

            Span <byte> testSpan = new Span <byte>(rented, 0, byteLength);

            Fill(rented, 0, byteLength);

            ReadOnlySpan <byte> emptySpan = ReadOnlySpan <byte> .Empty;

            bool isEqualA = CryptographicOperations.FixedTimeEquals(testSpan, emptySpan);
            bool isEqualB = CryptographicOperations.FixedTimeEquals(emptySpan, testSpan);

            ArrayPool <byte> .Shared.Return(rented);

            Assert.True(isEqualA, "FixedTimeEquals(testSpan, emptySpan)");
            Assert.True(isEqualB, "FixedTimeEquals(emptySpan, testSpan)");
        }
Ejemplo n.º 2
0
        public static void EqualReturnsTrue(int byteLength)
        {
            byte[] rented = ArrayPool <byte> .Shared.Rent(byteLength);

            Span <byte> testSpan = new Span <byte>(rented, 0, byteLength);

            Fill(rented, 0, byteLength);

            byte[] rented2 = ArrayPool <byte> .Shared.Rent(byteLength);

            Span <byte> testSpan2 = new Span <byte>(rented2, 0, byteLength);

            testSpan.CopyTo(testSpan2);

            bool isEqual = CryptographicOperations.FixedTimeEquals(testSpan, testSpan2);

            ArrayPool <byte> .Shared.Return(rented);

            ArrayPool <byte> .Shared.Return(rented2);

            Assert.True(isEqual);
        }
Ejemplo n.º 3
0
        public static void DifferentLengthsReturnFalse(int byteLength)
        {
            byte[] rented = ArrayPool <byte> .Shared.Rent(byteLength);

            Span <byte> testSpan = new Span <byte>(rented, 0, byteLength);

            Fill(rented, 0, byteLength);

            byte[] rented2 = ArrayPool <byte> .Shared.Rent(byteLength);

            Span <byte> testSpan2 = new Span <byte>(rented2, 0, byteLength);

            testSpan.CopyTo(testSpan2);

            bool isEqualA = CryptographicOperations.FixedTimeEquals(testSpan, testSpan2.Slice(0, byteLength - 1));
            bool isEqualB = CryptographicOperations.FixedTimeEquals(testSpan.Slice(0, byteLength - 1), testSpan2);

            ArrayPool <byte> .Shared.Return(rented);

            ArrayPool <byte> .Shared.Return(rented2);

            Assert.False(isEqualA, "value, value missing last byte");
            Assert.False(isEqualB, "value missing last byte, value");
        }