Skip to content

Commit

Permalink
Avoid infinite recursion in RSAEncryptionPadding equality check
Browse files Browse the repository at this point in the history
  • Loading branch information
cshung authored Nov 22, 2019
2 parents 241f0c7 + cf096b0 commit 1b44133
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public override bool Equals(object obj)

public bool Equals(RSAEncryptionPadding other)
{
return other != null
return !object.ReferenceEquals(other, null)
&& _mode == other._mode
&& _oaepHashAlgorithm == other._oaepHashAlgorithm;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ public void VerifyDataStream_UsesHashDataAndVerifyHash()
Assert.True(rsa.VerifyData(new MemoryStream(new byte[] { 42 }), new byte[1] { 24 }, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1));
}

[Fact]
public void RSAEncryptionPadding_Equals()
{
Assert.Equal(RSAEncryptionPadding.Pkcs1, RSAEncryptionPadding.Pkcs1);
}

private sealed class EmptyRSA : RSA
{
public override RSAParameters ExportParameters(bool includePrivateParameters) => throw new NotImplementedException();
Expand Down

0 comments on commit 1b44133

Please sign in to comment.