Have consistent Dispose behaviors for AsymmetricAlgorithm objects
authorJeremy Barton <jbarton@microsoft.com>
Tue, 18 Jun 2019 01:25:56 +0000 (18:25 -0700)
committerGitHub <noreply@github.com>
Tue, 18 Jun 2019 01:25:56 +0000 (18:25 -0700)
commit8e1eaebc582c0a2e42643a55fb51a3b0d868f7c3
tree99e12a3af7483d20cec431029e9d8869acff4307
parentc111f40f0ae24c697ff627d3f74bd1d83be364e2
Have consistent Dispose behaviors for AsymmetricAlgorithm objects

The AsymmetricAlgorithm types weren't consistent in how they handled Dispose. There were four predominant behaviors on use-after-Dispose

* NullReferenceException (mainly from the OpenSsl implementations)
* Generate a new key, like the object was fresh (the public Cng implementations)
* Not notice that anything was Disposed, keep on keepin' on (the private Cng implementations in Algorithms)
* Indirect ObjectDisposedExceptions 95% of the time (the Windows CSP types)

This change makes all of the types consistently go into (and stay in) a Disposed state, throwing ObjectDisposedExceptions when asked to do work in that state.

Commit migrated from https://github.com/dotnet/corefx/commit/fb81332b9643ecf8c0bb34d7938da97aa5e13e03
51 files changed:
src/libraries/Common/src/System/Security/Cryptography/DSACng.ImportExport.cs
src/libraries/Common/src/System/Security/Cryptography/DSAOpenSsl.cs
src/libraries/Common/src/System/Security/Cryptography/DSASecurityTransforms.cs
src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanCng.ImportExport.cs
src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanOpenSsl.Derive.cs
src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanOpenSsl.cs
src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanOpenSslPublicKey.cs
src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanSecurityTransforms.cs
src/libraries/Common/src/System/Security/Cryptography/ECDsaCng.ImportExport.cs
src/libraries/Common/src/System/Security/Cryptography/ECDsaOpenSsl.cs
src/libraries/Common/src/System/Security/Cryptography/ECDsaSecurityTransforms.cs
src/libraries/Common/src/System/Security/Cryptography/EccSecurityTransforms.cs
src/libraries/Common/src/System/Security/Cryptography/RSACng.ImportExport.cs
src/libraries/Common/src/System/Security/Cryptography/RSAOpenSsl.cs
src/libraries/Common/src/System/Security/Cryptography/RSASecurityTransforms.cs
src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/DSA/DSAImportExport.cs
src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/DSA/DSAKeyFileTests.cs
src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/DSA/DSASignVerify.cs
src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/EC/ECKeyFileTests.cs
src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/EC/EccTestData.cs
src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/ECDiffieHellman/ECDiffieHellmanTests.cs
src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/ECDsa/ECDsaTests.cs
src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/ECDsa/ECDsaTests.netcoreapp.cs
src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/RSA/EncryptDecrypt.cs
src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/RSA/ImportExport.cs
src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/RSA/RSAKeyFileTests.cs
src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/RSA/SignVerify.cs
src/libraries/System.Security.Cryptography.Algorithms/ref/System.Security.Cryptography.Algorithms.cs
src/libraries/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/DSACng.cs
src/libraries/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/ECCngKey.cs
src/libraries/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/ECDiffieHellmanCng.Key.cs
src/libraries/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/ECDiffieHellmanCng.cs
src/libraries/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/ECDiffieHellmanCngPublicKey.cs
src/libraries/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/ECDsaCng.Key.cs
src/libraries/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/ECDsaCng.cs
src/libraries/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/RSACng.cs
src/libraries/System.Security.Cryptography.Cng/src/Internal/Cryptography/CngAlgorithmCore.cs
src/libraries/System.Security.Cryptography.Cng/src/System/Security/Cryptography/DSACng.cs
src/libraries/System.Security.Cryptography.Cng/src/System/Security/Cryptography/ECDiffieHellmanCng.cs
src/libraries/System.Security.Cryptography.Cng/src/System/Security/Cryptography/ECDiffieHellmanCngPublicKey.cs
src/libraries/System.Security.Cryptography.Cng/src/System/Security/Cryptography/ECDsaCng.cs
src/libraries/System.Security.Cryptography.Cng/src/System/Security/Cryptography/RSACng.cs
src/libraries/System.Security.Cryptography.Cng/tests/Configurations.props
src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/DSACryptoServiceProvider.Unix.cs
src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/DSACryptoServiceProvider.Windows.cs
src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/RSACryptoServiceProvider.Unix.cs
src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/RSACryptoServiceProvider.Windows.cs
src/libraries/System.Security.Cryptography.OpenSsl/src/System/Security/Cryptography/DSAOpenSsl.cs
src/libraries/System.Security.Cryptography.OpenSsl/src/System/Security/Cryptography/RSAOpenSsl.cs
src/libraries/System.Security.Cryptography.OpenSsl/tests/DsaOpenSslTests.cs
src/libraries/System.Security.Cryptography.OpenSsl/tests/RsaOpenSslTests.cs