Cleanup unused locals in more places (dotnet/corefx#41964)
authorKevin Jones <kevin@vcsjones.com>
Tue, 22 Oct 2019 14:16:21 +0000 (10:16 -0400)
committerJeremy Barton <jbarton@microsoft.com>
Tue, 22 Oct 2019 14:16:21 +0000 (07:16 -0700)
* Removed unused locals from AsnReader.

The return value of the method is not needed however the out values
are.

* Remove key local from ECDiffieHellmanCng.

The return value is not needed however the key still needs to be
generated.

* Remove key local from ECDsaCng.

The return value is not needed however the key still needs to be
generated.

* Remove unused local.

The return value is not needed from the method however the out
parameters are.

* Discard result from `CryptAcquireContext`.

The result is discarded rather than entirely omitted to clearly express
the intent that the return value is not used.

Commit migrated from https://github.com/dotnet/corefx/commit/3d4511a79cbdbe85832c2af2ec18e165b696adc9

src/libraries/Common/src/System/Security/Cryptography/Asn1Reader/AsnReader.cs
src/libraries/System.Security.Cryptography.Cng/src/System/Security/Cryptography/ECDiffieHellmanCng.Key.cs
src/libraries/System.Security.Cryptography.Cng/src/System/Security/Cryptography/ECDsaCng.Key.cs
src/libraries/System.Security.Cryptography.Pkcs/src/Internal/Cryptography/Pal/Windows/PkcsPalWindows.Encrypt.cs
src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Windows/Native/SafeHandles.cs

index cd8d614..d733fbf 100644 (file)
@@ -102,7 +102,7 @@ namespace System.Security.Cryptography.Asn1
         /// <seealso cref="ReadEncodedValue"/>
         public ReadOnlyMemory<byte> PeekEncodedValue()
         {
-            Asn1Tag tag = ReadTagAndLength(out int? length, out int bytesRead);
+            ReadTagAndLength(out int? length, out int bytesRead);
 
             if (length == null)
             {
@@ -127,7 +127,7 @@ namespace System.Security.Cryptography.Asn1
         /// <seealso cref="PeekEncodedValue"/>
         public ReadOnlyMemory<byte> PeekContentBytes()
         {
-            Asn1Tag tag = ReadTagAndLength(out int? length, out int bytesRead);
+            ReadTagAndLength(out int? length, out int bytesRead);
 
             if (length == null)
             {
index f7ba762..166e87c 100644 (file)
@@ -82,7 +82,7 @@ namespace System.Security.Cryptography
                         Debug.Fail($"Unknown algorithm {alg}");
                         throw new ArgumentException(SR.Cryptography_InvalidKeySize);
                     }
-                    CngKey key = _core.GetOrGenerateKey(keySize, alg);
+                    _core.GetOrGenerateKey(keySize, alg);
                     ForceSetKeySize(keySize);
                 }
             }
index 783e807..a4ca9ac 100644 (file)
@@ -71,7 +71,7 @@ namespace System.Security.Cryptography
                         Debug.Fail($"Unknown algorithm {alg}");
                         throw new ArgumentException(SR.Cryptography_InvalidKeySize);
                     }
-                    CngKey key = _core.GetOrGenerateKey(keySize, alg);
+                    _core.GetOrGenerateKey(keySize, alg);
                     ForceSetKeySize(keySize);
                 }
             }
index 8120d76..96de5e2 100644 (file)
@@ -70,7 +70,7 @@ namespace Internal.Cryptography.Pal.Windows
         private static void ReencodeIfUsingIndefiniteLengthEncodingOnOuterStructure(ref byte[] encodedContent)
         {
             AsnReader reader = new AsnReader(encodedContent, AsnEncodingRules.BER);
-            Asn1Tag tag = reader.ReadTagAndLength(out int? contentsLength, out int _);
+            reader.ReadTagAndLength(out int? contentsLength, out int _);
 
             if (contentsLength != null)
             {
index b164fb0..4878f3c 100644 (file)
@@ -185,7 +185,7 @@ namespace Internal.Cryptography.Pal.Native
                     {
                         CryptAcquireContextFlags flags = (pProvInfo->dwFlags & CryptAcquireContextFlags.CRYPT_MACHINE_KEYSET) | CryptAcquireContextFlags.CRYPT_DELETEKEYSET;
                         IntPtr hProv;
-                        bool success = Interop.cryptoapi.CryptAcquireContext(out hProv, pProvInfo->pwszContainerName, pProvInfo->pwszProvName, pProvInfo->dwProvType, flags);
+                        _ = Interop.cryptoapi.CryptAcquireContext(out hProv, pProvInfo->pwszContainerName, pProvInfo->pwszProvName, pProvInfo->dwProvType, flags);
 
                         // Called CryptAcquireContext solely for the side effect of deleting the key containers. When called with these flags, no actual
                         // hProv is returned (so there's nothing to clean up.)