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)"); }
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); }
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"); }