Skip to content

Commit

Permalink
Improve test coverage for RSAEncryptionPadding comparsion (dotnet#230)
Browse files Browse the repository at this point in the history
* Improve test coverage for RSAEncryptionPadding comparsion

* Simplify RSASignaturePadding comparison logic
  • Loading branch information
cshung authored and stephentoub committed Nov 26, 2019
1 parent a71a324 commit 6fe9120
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public override bool Equals(object obj)

public bool Equals(RSASignaturePadding other)
{
return other != null && _mode == other._mode;
return !object.ReferenceEquals(other, null) && _mode == other._mode;
}

public static bool operator ==(RSASignaturePadding left, RSASignaturePadding right)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,41 @@ public void VerifyDataStream_UsesHashDataAndVerifyHash()
}

[Fact]
public void RSAEncryptionPadding_Equals()
public void RSAEncryptionPadding_Equality()
{
Assert.Equal(RSAEncryptionPadding.Pkcs1, RSAEncryptionPadding.Pkcs1);
Assert.True(RSAEncryptionPadding.Pkcs1.Equals(RSAEncryptionPadding.Pkcs1));
Assert.True(RSAEncryptionPadding.Pkcs1.Equals((object)RSAEncryptionPadding.Pkcs1));
Assert.True(RSAEncryptionPadding.Pkcs1 == RSAEncryptionPadding.Pkcs1);
Assert.False(RSAEncryptionPadding.Pkcs1 != RSAEncryptionPadding.Pkcs1);

Assert.False(RSAEncryptionPadding.Pkcs1.Equals(RSAEncryptionPadding.OaepSHA1));
Assert.False(RSAEncryptionPadding.Pkcs1.Equals((object)RSAEncryptionPadding.OaepSHA1));
Assert.False(RSAEncryptionPadding.Pkcs1 == RSAEncryptionPadding.OaepSHA1);
Assert.True(RSAEncryptionPadding.Pkcs1 != RSAEncryptionPadding.OaepSHA1);

Assert.False(RSAEncryptionPadding.Pkcs1.Equals(null));
Assert.False(RSAEncryptionPadding.Pkcs1.Equals((object)null));
Assert.False(RSAEncryptionPadding.Pkcs1 == null);
Assert.True(RSAEncryptionPadding.Pkcs1 != null);
}

[Fact]
public void RSASignaturePadding_Equality()
{
Assert.True(RSASignaturePadding.Pkcs1.Equals(RSASignaturePadding.Pkcs1));
Assert.True(RSASignaturePadding.Pkcs1.Equals((object)RSASignaturePadding.Pkcs1));
Assert.True(RSASignaturePadding.Pkcs1 == RSASignaturePadding.Pkcs1);
Assert.False(RSASignaturePadding.Pkcs1 != RSASignaturePadding.Pkcs1);

Assert.False(RSASignaturePadding.Pkcs1.Equals(RSASignaturePadding.Pss));
Assert.False(RSASignaturePadding.Pkcs1.Equals((object)RSASignaturePadding.Pss));
Assert.False(RSASignaturePadding.Pkcs1 == RSASignaturePadding.Pss);
Assert.True(RSASignaturePadding.Pkcs1 != RSASignaturePadding.Pss);

Assert.False(RSASignaturePadding.Pkcs1.Equals(null));
Assert.False(RSASignaturePadding.Pkcs1.Equals((object)null));
Assert.False(RSASignaturePadding.Pkcs1 == null);
Assert.True(RSASignaturePadding.Pkcs1 != null);
}

private sealed class EmptyRSA : RSA
Expand Down

0 comments on commit 6fe9120

Please sign in to comment.