From: buyaa-n Date: Fri, 14 Feb 2020 21:52:33 +0000 (-0800) Subject: Annotate System.Security.Cryptography.Csp for nullable (#32140) X-Git-Tag: submit/tizen/20210909.063632~9746 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=89f16be922f8fcc50b96eb91b6d0e3f7ca9e84c0;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Annotate System.Security.Cryptography.Csp for nullable (#32140) * Annotate System.Security.Cryptography for nullable --- diff --git a/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.CryptAcquireContext.cs b/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.CryptAcquireContext.cs index 78c7d0d..0b512e2 100644 --- a/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.CryptAcquireContext.cs +++ b/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.CryptAcquireContext.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable using System; using System.Runtime.InteropServices; using System.Security.Cryptography; @@ -24,8 +25,8 @@ internal partial class Interop [DllImport(Libraries.Advapi32, SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "CryptAcquireContextW")] public static extern bool CryptAcquireContext( out SafeProvHandle phProv, - string szContainer, - string szProvider, + string? szContainer, + string? szProvider, int dwProvType, uint dwFlags); } diff --git a/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.CryptEncrypt.cs b/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.CryptEncrypt.cs index 2f41049..bd46df1 100644 --- a/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.CryptEncrypt.cs +++ b/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.CryptEncrypt.cs @@ -15,7 +15,7 @@ internal partial class Interop SafeHashHandle hHash, bool Final, int dwFlags, - byte[] pbData, + byte[]? pbData, ref int pdwDataLen, int dwBufLen); } diff --git a/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.CryptExportKey.cs b/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.CryptExportKey.cs index 79d85b9..e6e3985 100644 --- a/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.CryptExportKey.cs +++ b/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.CryptExportKey.cs @@ -15,7 +15,7 @@ internal partial class Interop SafeKeyHandle hExpKey, int dwBlobType, int dwFlags, - [In, Out] byte[] pbData, + [In, Out] byte[]? pbData, ref int dwDataLen); } } diff --git a/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.CryptGetDefaultProvider.cs b/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.CryptGetDefaultProvider.cs index 89d44b1..c09bc90 100644 --- a/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.CryptGetDefaultProvider.cs +++ b/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.CryptGetDefaultProvider.cs @@ -21,7 +21,7 @@ internal partial class Interop int dwProvType, IntPtr pdwReserved, GetDefaultProviderFlags dwFlags, - StringBuilder pszProvName, + StringBuilder? pszProvName, ref int pcbProvName); } } diff --git a/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.CryptGetKeyParam.cs b/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.CryptGetKeyParam.cs index 1e7c975..13fefca 100644 --- a/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.CryptGetKeyParam.cs +++ b/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.CryptGetKeyParam.cs @@ -22,7 +22,7 @@ internal partial class Interop public static extern bool CryptGetKeyParam( SafeKeyHandle hKey, CryptGetKeyParamFlags dwParam, - byte[] pbData, + byte[]? pbData, ref int pdwDataLen, int dwFlags); } diff --git a/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.CryptSignHash.cs b/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.CryptSignHash.cs index 01f92bf..46533d0 100644 --- a/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.CryptSignHash.cs +++ b/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.CryptSignHash.cs @@ -29,9 +29,9 @@ internal partial class Interop public static extern bool CryptSignHash( SafeHashHandle hHash, KeySpec dwKeySpec, - string szDescription, + string? szDescription, CryptSignAndVerifyHashFlags dwFlags, - [Out] byte[] pbSignature, + [Out] byte[]? pbSignature, [In, Out] ref int pdwSigLen); [DllImport(Libraries.Advapi32, CharSet = CharSet.Unicode, SetLastError = true, EntryPoint = "CryptVerifySignatureW")] @@ -40,7 +40,7 @@ internal partial class Interop byte[] pbSignature, int dwSigLen, SafeKeyHandle hPubKey, - string szDescription, + string? szDescription, CryptSignAndVerifyHashFlags dwFlags); } } diff --git a/src/libraries/Common/src/Interop/Windows/Advapi32/SafeHashHandle.cs b/src/libraries/Common/src/Interop/Windows/Advapi32/SafeHashHandle.cs index 6335af3..cc79223 100644 --- a/src/libraries/Common/src/Interop/Windows/Advapi32/SafeHashHandle.cs +++ b/src/libraries/Common/src/Interop/Windows/Advapi32/SafeHashHandle.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable using System.Diagnostics; using Microsoft.Win32.SafeHandles; @@ -12,7 +13,7 @@ namespace System.Security.Cryptography /// internal sealed class SafeHashHandle : SafeHandleZeroOrMinusOneIsInvalid { - private SafeProvHandle _parent; + private SafeProvHandle? _parent; private SafeHashHandle() : base(true) { @@ -54,7 +55,7 @@ namespace System.Security.Cryptography bool successfullyFreed = Interop.Advapi32.CryptDestroyHash(handle); Debug.Assert(successfullyFreed); - SafeProvHandle parent = _parent; + SafeProvHandle? parent = _parent; _parent = null; parent?.DangerousRelease(); diff --git a/src/libraries/Common/src/Interop/Windows/Advapi32/SafeKeyHandle.cs b/src/libraries/Common/src/Interop/Windows/Advapi32/SafeKeyHandle.cs index cbde16b..261cd11 100644 --- a/src/libraries/Common/src/Interop/Windows/Advapi32/SafeKeyHandle.cs +++ b/src/libraries/Common/src/Interop/Windows/Advapi32/SafeKeyHandle.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable using System.Diagnostics; using Microsoft.Win32.SafeHandles; @@ -21,7 +22,7 @@ namespace System.Security.Cryptography { private int _keySpec; private bool _fPublicOnly; - private SafeProvHandle _parent; + private SafeProvHandle? _parent; private SafeKeyHandle() : base(true) { @@ -89,7 +90,7 @@ namespace System.Security.Cryptography bool successfullyFreed = Interop.Advapi32.CryptDestroyKey(handle); Debug.Assert(successfullyFreed); - SafeProvHandle parent = _parent; + SafeProvHandle? parent = _parent; _parent = null; parent?.DangerousRelease(); diff --git a/src/libraries/Common/src/Interop/Windows/Advapi32/SafeProvHandle.cs b/src/libraries/Common/src/Interop/Windows/Advapi32/SafeProvHandle.cs index f8c116a..e4e16ee 100644 --- a/src/libraries/Common/src/Interop/Windows/Advapi32/SafeProvHandle.cs +++ b/src/libraries/Common/src/Interop/Windows/Advapi32/SafeProvHandle.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable using System.Diagnostics; using Microsoft.Win32.SafeHandles; @@ -12,8 +13,8 @@ namespace System.Security.Cryptography /// internal sealed class SafeProvHandle : SafeHandleZeroOrMinusOneIsInvalid { - private string _containerName; - private string _providerName; + private string? _containerName; + private string? _providerName; private int _type; private uint _flags; private bool _fPersistKeyInCsp; @@ -28,7 +29,7 @@ namespace System.Security.Cryptography _fPersistKeyInCsp = true; } - internal string ContainerName + internal string? ContainerName { get { @@ -40,7 +41,7 @@ namespace System.Security.Cryptography } } - internal string ProviderName + internal string? ProviderName { get { diff --git a/src/libraries/System.Security.Cryptography.Algorithms/ref/System.Security.Cryptography.Algorithms.cs b/src/libraries/System.Security.Cryptography.Algorithms/ref/System.Security.Cryptography.Algorithms.cs index 78b04de..f32c828 100644 --- a/src/libraries/System.Security.Cryptography.Algorithms/ref/System.Security.Cryptography.Algorithms.cs +++ b/src/libraries/System.Security.Cryptography.Algorithms/ref/System.Security.Cryptography.Algorithms.cs @@ -508,7 +508,7 @@ namespace System.Security.Cryptography public abstract partial class RSA : System.Security.Cryptography.AsymmetricAlgorithm { protected RSA() { } - public override string KeyExchangeAlgorithm { get { throw null; } } + public override string? KeyExchangeAlgorithm { get { throw null; } } public override string SignatureAlgorithm { get { throw null; } } public static new System.Security.Cryptography.RSA Create() { throw null; } public static System.Security.Cryptography.RSA Create(int keySizeInBits) { throw null; } diff --git a/src/libraries/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/RSA.cs b/src/libraries/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/RSA.cs index 31e89e5..0d7a6c6 100644 --- a/src/libraries/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/RSA.cs +++ b/src/libraries/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/RSA.cs @@ -635,7 +635,7 @@ namespace System.Security.Cryptography CryptographicOperations.ZeroMemory(rsaParameters.InverseQ); } - public override string KeyExchangeAlgorithm => "RSA"; + public override string? KeyExchangeAlgorithm => "RSA"; public override string SignatureAlgorithm => "RSA"; private static Exception HashAlgorithmNameNullOrEmpty() => diff --git a/src/libraries/System.Security.Cryptography.Csp/ref/System.Security.Cryptography.Csp.cs b/src/libraries/System.Security.Cryptography.Csp/ref/System.Security.Cryptography.Csp.cs index e5d3ceb..1b65565 100644 --- a/src/libraries/System.Security.Cryptography.Csp/ref/System.Security.Cryptography.Csp.cs +++ b/src/libraries/System.Security.Cryptography.Csp/ref/System.Security.Cryptography.Csp.cs @@ -21,9 +21,9 @@ namespace System.Security.Cryptography public override System.Security.Cryptography.CipherMode Mode { get { throw null; } set { } } public override System.Security.Cryptography.PaddingMode Padding { get { throw null; } set { } } public override System.Security.Cryptography.ICryptoTransform CreateDecryptor() { throw null; } - public override System.Security.Cryptography.ICryptoTransform CreateDecryptor(byte[] rgbKey, byte[] rgbIV) { throw null; } + public override System.Security.Cryptography.ICryptoTransform CreateDecryptor(byte[] rgbKey, byte[]? rgbIV) { throw null; } public override System.Security.Cryptography.ICryptoTransform CreateEncryptor() { throw null; } - public override System.Security.Cryptography.ICryptoTransform CreateEncryptor(byte[] rgbKey, byte[] rgbIV) { throw null; } + public override System.Security.Cryptography.ICryptoTransform CreateEncryptor(byte[] rgbKey, byte[]? rgbIV) { throw null; } protected override void Dispose(bool disposing) { } public override void GenerateIV() { } public override void GenerateKey() { } @@ -34,11 +34,11 @@ namespace System.Security.Cryptography public bool Accessible { get { throw null; } } public bool Exportable { get { throw null; } } public bool HardwareDevice { get { throw null; } } - public string KeyContainerName { get { throw null; } } + public string? KeyContainerName { get { throw null; } } public System.Security.Cryptography.KeyNumber KeyNumber { get { throw null; } } public bool MachineKeyStore { get { throw null; } } public bool Protected { get { throw null; } } - public string ProviderName { get { throw null; } } + public string? ProviderName { get { throw null; } } public int ProviderType { get { throw null; } } public bool RandomlyGenerated { get { throw null; } } public bool Removable { get { throw null; } } @@ -46,17 +46,17 @@ namespace System.Security.Cryptography } public sealed partial class CspParameters { - public string KeyContainerName; + public string? KeyContainerName; public int KeyNumber; - public string ProviderName; + public string? ProviderName; public int ProviderType; public CspParameters() { } public CspParameters(int dwTypeIn) { } - public CspParameters(int dwTypeIn, string strProviderNameIn) { } - public CspParameters(int dwTypeIn, string strProviderNameIn, string strContainerNameIn) { } + public CspParameters(int dwTypeIn, string? strProviderNameIn) { } + public CspParameters(int dwTypeIn, string? strProviderNameIn, string? strContainerNameIn) { } public System.Security.Cryptography.CspProviderFlags Flags { get { throw null; } set { } } [System.CLSCompliantAttribute(false)] - public System.Security.SecureString KeyPassword { get { throw null; } set { } } + public System.Security.SecureString? KeyPassword { get { throw null; } set { } } public System.IntPtr ParentWindowHandle { get { throw null; } set { } } } [System.FlagsAttribute] @@ -77,9 +77,9 @@ namespace System.Security.Cryptography { public DESCryptoServiceProvider() { } public override System.Security.Cryptography.ICryptoTransform CreateDecryptor() { throw null; } - public override System.Security.Cryptography.ICryptoTransform CreateDecryptor(byte[] rgbKey, byte[] rgbIV) { throw null; } + public override System.Security.Cryptography.ICryptoTransform CreateDecryptor(byte[] rgbKey, byte[]? rgbIV) { throw null; } public override System.Security.Cryptography.ICryptoTransform CreateEncryptor() { throw null; } - public override System.Security.Cryptography.ICryptoTransform CreateEncryptor(byte[] rgbKey, byte[] rgbIV) { throw null; } + public override System.Security.Cryptography.ICryptoTransform CreateEncryptor(byte[] rgbKey, byte[]? rgbIV) { throw null; } public override void GenerateIV() { } public override void GenerateKey() { } } @@ -87,10 +87,10 @@ namespace System.Security.Cryptography { public DSACryptoServiceProvider() { } public DSACryptoServiceProvider(int dwKeySize) { } - public DSACryptoServiceProvider(int dwKeySize, System.Security.Cryptography.CspParameters parameters) { } - public DSACryptoServiceProvider(System.Security.Cryptography.CspParameters parameters) { } + public DSACryptoServiceProvider(int dwKeySize, System.Security.Cryptography.CspParameters? parameters) { } + public DSACryptoServiceProvider(System.Security.Cryptography.CspParameters? parameters) { } public System.Security.Cryptography.CspKeyContainerInfo CspKeyContainerInfo { get { throw null; } } - public override string KeyExchangeAlgorithm { get { throw null; } } + public override string? KeyExchangeAlgorithm { get { throw null; } } public override int KeySize { get { throw null; } } public override System.Security.Cryptography.KeySizes[] LegalKeySizes { get { throw null; } } public bool PersistKeyInCsp { get { throw null; } set { } } @@ -108,9 +108,9 @@ namespace System.Security.Cryptography public byte[] SignData(byte[] buffer) { throw null; } public byte[] SignData(byte[] buffer, int offset, int count) { throw null; } public byte[] SignData(System.IO.Stream inputStream) { throw null; } - public byte[] SignHash(byte[] rgbHash, string str) { throw null; } + public byte[] SignHash(byte[] rgbHash, string? str) { throw null; } public bool VerifyData(byte[] rgbData, byte[] rgbSignature) { throw null; } - public bool VerifyHash(byte[] rgbHash, string str, byte[] rgbSignature) { throw null; } + public bool VerifyHash(byte[] rgbHash, string? str, byte[] rgbSignature) { throw null; } public override bool VerifySignature(byte[] rgbHash, byte[] rgbSignature) { throw null; } } public partial interface ICspAsymmetricAlgorithm @@ -138,18 +138,18 @@ namespace System.Security.Cryptography [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public partial class PasswordDeriveBytes : System.Security.Cryptography.DeriveBytes { - public PasswordDeriveBytes(byte[] password, byte[] salt) { } - public PasswordDeriveBytes(byte[] password, byte[] salt, System.Security.Cryptography.CspParameters cspParams) { } - public PasswordDeriveBytes(byte[] password, byte[] salt, string hashName, int iterations) { } - public PasswordDeriveBytes(byte[] password, byte[] salt, string hashName, int iterations, System.Security.Cryptography.CspParameters cspParams) { } - public PasswordDeriveBytes(string strPassword, byte[] rgbSalt) { } - public PasswordDeriveBytes(string strPassword, byte[] rgbSalt, System.Security.Cryptography.CspParameters cspParams) { } - public PasswordDeriveBytes(string strPassword, byte[] rgbSalt, string strHashName, int iterations) { } - public PasswordDeriveBytes(string strPassword, byte[] rgbSalt, string strHashName, int iterations, System.Security.Cryptography.CspParameters cspParams) { } + public PasswordDeriveBytes(byte[] password, byte[]? salt) { } + public PasswordDeriveBytes(byte[] password, byte[]? salt, System.Security.Cryptography.CspParameters? cspParams) { } + public PasswordDeriveBytes(byte[] password, byte[]? salt, string hashName, int iterations) { } + public PasswordDeriveBytes(byte[] password, byte[]? salt, string hashName, int iterations, System.Security.Cryptography.CspParameters? cspParams) { } + public PasswordDeriveBytes(string strPassword, byte[]? rgbSalt) { } + public PasswordDeriveBytes(string strPassword, byte[]? rgbSalt, System.Security.Cryptography.CspParameters? cspParams) { } + public PasswordDeriveBytes(string strPassword, byte[]? rgbSalt, string strHashName, int iterations) { } + public PasswordDeriveBytes(string strPassword, byte[]? rgbSalt, string strHashName, int iterations, System.Security.Cryptography.CspParameters? cspParams) { } public string HashName { get { throw null; } set { } } public int IterationCount { get { throw null; } set { } } - public byte[] Salt { get { throw null; } set { } } - public byte[] CryptDeriveKey(string algname, string alghashname, int keySize, byte[] rgbIV) { throw null; } + public byte[]? Salt { get { throw null; } set { } } + public byte[] CryptDeriveKey(string? algname, string? alghashname, int keySize, byte[] rgbIV) { throw null; } protected override void Dispose(bool disposing) { } #pragma warning disable 0809 [System.ObsoleteAttribute("Rfc2898DeriveBytes replaces PasswordDeriveBytes for deriving key material from a password and is preferred in new applications.")] @@ -163,8 +163,8 @@ namespace System.Security.Cryptography public RC2CryptoServiceProvider() { } public override int EffectiveKeySize { get { throw null; } set { } } public bool UseSalt { get { throw null; } set { } } - public override System.Security.Cryptography.ICryptoTransform CreateDecryptor(byte[] rgbKey, byte[] rgbIV) { throw null; } - public override System.Security.Cryptography.ICryptoTransform CreateEncryptor(byte[] rgbKey, byte[] rgbIV) { throw null; } + public override System.Security.Cryptography.ICryptoTransform CreateDecryptor(byte[] rgbKey, byte[]? rgbIV) { throw null; } + public override System.Security.Cryptography.ICryptoTransform CreateEncryptor(byte[] rgbKey, byte[]? rgbIV) { throw null; } public override void GenerateIV() { } public override void GenerateKey() { } } @@ -186,10 +186,10 @@ namespace System.Security.Cryptography { public RSACryptoServiceProvider() { } public RSACryptoServiceProvider(int dwKeySize) { } - public RSACryptoServiceProvider(int dwKeySize, System.Security.Cryptography.CspParameters parameters) { } - public RSACryptoServiceProvider(System.Security.Cryptography.CspParameters parameters) { } + public RSACryptoServiceProvider(int dwKeySize, System.Security.Cryptography.CspParameters? parameters) { } + public RSACryptoServiceProvider(System.Security.Cryptography.CspParameters? parameters) { } public System.Security.Cryptography.CspKeyContainerInfo CspKeyContainerInfo { get { throw null; } } - public override string KeyExchangeAlgorithm { get { throw null; } } + public override string? KeyExchangeAlgorithm { get { throw null; } } public override int KeySize { get { throw null; } } public override System.Security.Cryptography.KeySizes[] LegalKeySizes { get { throw null; } } public bool PersistKeyInCsp { get { throw null; } set { } } @@ -213,7 +213,7 @@ namespace System.Security.Cryptography public byte[] SignData(byte[] buffer, object halg) { throw null; } public byte[] SignData(System.IO.Stream inputStream, object halg) { throw null; } public override byte[] SignHash(byte[] hash, System.Security.Cryptography.HashAlgorithmName hashAlgorithm, System.Security.Cryptography.RSASignaturePadding padding) { throw null; } - public byte[] SignHash(byte[] rgbHash, string str) { throw null; } + public byte[] SignHash(byte[] rgbHash, string? str) { throw null; } public bool VerifyData(byte[] buffer, object halg, byte[] signature) { throw null; } public override bool VerifyHash(byte[] hash, byte[] signature, System.Security.Cryptography.HashAlgorithmName hashAlgorithm, System.Security.Cryptography.RSASignaturePadding padding) { throw null; } public bool VerifyHash(byte[] rgbHash, string str, byte[] rgbSignature) { throw null; } @@ -276,9 +276,9 @@ namespace System.Security.Cryptography public override System.Security.Cryptography.CipherMode Mode { get { throw null; } set { } } public override System.Security.Cryptography.PaddingMode Padding { get { throw null; } set { } } public override System.Security.Cryptography.ICryptoTransform CreateDecryptor() { throw null; } - public override System.Security.Cryptography.ICryptoTransform CreateDecryptor(byte[] rgbKey, byte[] rgbIV) { throw null; } + public override System.Security.Cryptography.ICryptoTransform CreateDecryptor(byte[] rgbKey, byte[]? rgbIV) { throw null; } public override System.Security.Cryptography.ICryptoTransform CreateEncryptor() { throw null; } - public override System.Security.Cryptography.ICryptoTransform CreateEncryptor(byte[] rgbKey, byte[] rgbIV) { throw null; } + public override System.Security.Cryptography.ICryptoTransform CreateEncryptor(byte[] rgbKey, byte[]? rgbIV) { throw null; } protected override void Dispose(bool disposing) { } public override void GenerateIV() { } public override void GenerateKey() { } diff --git a/src/libraries/System.Security.Cryptography.Csp/ref/System.Security.Cryptography.Csp.csproj b/src/libraries/System.Security.Cryptography.Csp/ref/System.Security.Cryptography.Csp.csproj index a2d1d13..c12467a 100644 --- a/src/libraries/System.Security.Cryptography.Csp/ref/System.Security.Cryptography.Csp.csproj +++ b/src/libraries/System.Security.Cryptography.Csp/ref/System.Security.Cryptography.Csp.csproj @@ -1,6 +1,7 @@ $(NetCoreAppCurrent) + enable diff --git a/src/libraries/System.Security.Cryptography.Csp/src/Internal/Cryptography/BasicSymmetricCipherCsp.cs b/src/libraries/System.Security.Cryptography.Csp/src/Internal/Cryptography/BasicSymmetricCipherCsp.cs index ada0f5f..d801544 100644 --- a/src/libraries/System.Security.Cryptography.Csp/src/Internal/Cryptography/BasicSymmetricCipherCsp.cs +++ b/src/libraries/System.Security.Cryptography.Csp/src/Internal/Cryptography/BasicSymmetricCipherCsp.cs @@ -17,7 +17,7 @@ namespace Internal.Cryptography private SafeProvHandle _hProvider; private SafeKeyHandle _hKey; - public BasicSymmetricCipherCsp(int algId, CipherMode cipherMode, int blockSizeInBytes, byte[] key, int effectiveKeyLength, bool addNoSaltFlag, byte[] iv, bool encrypting) + public BasicSymmetricCipherCsp(int algId, CipherMode cipherMode, int blockSizeInBytes, byte[] key, int effectiveKeyLength, bool addNoSaltFlag, byte[]? iv, bool encrypting) : base(cipherMode.GetCipherIv(iv), blockSizeInBytes) { _encrypting = encrypting; @@ -27,7 +27,7 @@ namespace Internal.Cryptography SetKeyParameter(_hKey, CryptGetKeyParamQueryType.KP_MODE, (int)cipherMode); - byte[] currentIv = cipherMode.GetCipherIv(iv); + byte[]? currentIv = cipherMode.GetCipherIv(iv); if (currentIv != null) { SetKeyParameter(_hKey, CryptGetKeyParamQueryType.KP_IV, currentIv); @@ -44,14 +44,14 @@ namespace Internal.Cryptography if (disposing) { SafeKeyHandle hKey = _hKey; - _hKey = null; + _hKey = null!; if (hKey != null) { hKey.Dispose(); } SafeProvHandle hProvider = _hProvider; - _hProvider = null; + _hProvider = null!; if (hProvider != null) { hProvider.Dispose(); @@ -127,7 +127,7 @@ namespace Internal.Cryptography private static SafeProvHandle AcquireSafeProviderHandle() { - SafeProvHandle safeProvHandle = null; + SafeProvHandle safeProvHandle; var cspParams = new CspParameters((int)ProviderType.PROV_RSA_FULL); CapiHelper.AcquireCsp(cspParams, out safeProvHandle); return safeProvHandle; diff --git a/src/libraries/System.Security.Cryptography.Csp/src/Internal/Cryptography/Helpers.cs b/src/libraries/System.Security.Cryptography.Csp/src/Internal/Cryptography/Helpers.cs index 7d5f93d..2ae8098 100644 --- a/src/libraries/System.Security.Cryptography.Csp/src/Internal/Cryptography/Helpers.cs +++ b/src/libraries/System.Security.Cryptography.Csp/src/Internal/Cryptography/Helpers.cs @@ -14,7 +14,7 @@ namespace Internal.Cryptography return cipherMode != CipherMode.ECB; } - public static byte[] GetCipherIv(this CipherMode cipherMode, byte[] iv) + public static byte[]? GetCipherIv(this CipherMode cipherMode, byte[]? iv) { if (cipherMode.UsesIv()) { @@ -29,7 +29,7 @@ namespace Internal.Cryptography return null; } - public static byte[] TrimLargeIV(byte[] currentIV, int blockSizeInBits) + public static byte[]? TrimLargeIV(byte[]? currentIV, int blockSizeInBits) { int blockSizeBytes = checked((blockSizeInBits + 7) / 8); diff --git a/src/libraries/System.Security.Cryptography.Csp/src/Internal/Cryptography/Unix/HashAlgorithmNames.cs b/src/libraries/System.Security.Cryptography.Csp/src/Internal/Cryptography/Unix/HashAlgorithmNames.cs index 14167a3..7d34baa 100644 --- a/src/libraries/System.Security.Cryptography.Csp/src/Internal/Cryptography/Unix/HashAlgorithmNames.cs +++ b/src/libraries/System.Security.Cryptography.Csp/src/Internal/Cryptography/Unix/HashAlgorithmNames.cs @@ -61,7 +61,7 @@ namespace Internal.Cryptography } else { - string oidValue = CryptoConfig.MapNameToOID(nameOrOid); + string? oidValue = CryptoConfig.MapNameToOID(nameOrOid); if (oidValue == null) oidValue = nameOrOid; // we were probably passed an OID value directly diff --git a/src/libraries/System.Security.Cryptography.Csp/src/System.Security.Cryptography.Csp.csproj b/src/libraries/System.Security.Cryptography.Csp/src/System.Security.Cryptography.Csp.csproj index b6889fa..85f5b05 100644 --- a/src/libraries/System.Security.Cryptography.Csp/src/System.Security.Cryptography.Csp.csproj +++ b/src/libraries/System.Security.Cryptography.Csp/src/System.Security.Cryptography.Csp.csproj @@ -5,6 +5,7 @@ $(NoWarn);CA5373 $(NoWarn);CS0809 $(NetCoreAppCurrent)-Windows_NT;$(NetCoreAppCurrent)-Unix + enable diff --git a/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/AesCryptoServiceProvider.cs b/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/AesCryptoServiceProvider.cs index 0054440..a7c6f08 100644 --- a/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/AesCryptoServiceProvider.cs +++ b/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/AesCryptoServiceProvider.cs @@ -63,9 +63,9 @@ namespace System.Security.Cryptography public override KeySizes[] LegalBlockSizes => _impl.LegalBlockSizes; public override KeySizes[] LegalKeySizes => _impl.LegalKeySizes; public override ICryptoTransform CreateEncryptor() => _impl.CreateEncryptor(); - public override ICryptoTransform CreateEncryptor(byte[] rgbKey, byte[] rgbIV) => _impl.CreateEncryptor(rgbKey, rgbIV); + public override ICryptoTransform CreateEncryptor(byte[] rgbKey, byte[]? rgbIV) => _impl.CreateEncryptor(rgbKey, rgbIV); public override ICryptoTransform CreateDecryptor() => _impl.CreateDecryptor(); - public override ICryptoTransform CreateDecryptor(byte[] rgbKey, byte[] rgbIV) => _impl.CreateDecryptor(rgbKey, rgbIV); + public override ICryptoTransform CreateDecryptor(byte[] rgbKey, byte[]? rgbIV) => _impl.CreateDecryptor(rgbKey, rgbIV); public override void GenerateIV() => _impl.GenerateIV(); public override void GenerateKey() => _impl.GenerateKey(); diff --git a/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/CapiHelper.DSA.Shared.cs b/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/CapiHelper.DSA.Shared.cs index 2c5a781..11f43a8 100644 --- a/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/CapiHelper.DSA.Shared.cs +++ b/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/CapiHelper.DSA.Shared.cs @@ -48,7 +48,7 @@ namespace Internal.NativeCrypto bool isPrivate = (dsaParameters.X != null && dsaParameters.X.Length > 0); // The private key should be the same length as Q - if (isPrivate && dsaParameters.X.Length != DSS_Q_LEN) + if (isPrivate && dsaParameters.X!.Length != DSS_Q_LEN) throw GetBadDataException(); uint bitLenP = (uint)dsaParameters.P.Length * 8; @@ -86,7 +86,7 @@ namespace Internal.NativeCrypto if (isPrivate) { - bw.Write((uint)dsaParameters.X.Length * 8); + bw.Write((uint)dsaParameters.X!.Length * 8); } WriteDSSSeed(dsaParameters, bw); @@ -97,14 +97,14 @@ namespace Internal.NativeCrypto if (bitLenJ != 0) { - bw.WriteReversed(dsaParameters.J); + bw.WriteReversed(dsaParameters.J!); } - bw.WriteReversed(dsaParameters.Y); + bw.WriteReversed(dsaParameters.Y!); if (isPrivate) { - bw.WriteReversed(dsaParameters.X); + bw.WriteReversed(dsaParameters.X!); } } else @@ -128,10 +128,11 @@ namespace Internal.NativeCrypto if (isPrivate) { - bw.WriteReversed(dsaParameters.X); + bw.WriteReversed(dsaParameters.X!); } else { + Debug.Assert(dsaParameters.Y != null); bw.WriteReversed(dsaParameters.Y); } @@ -147,7 +148,7 @@ namespace Internal.NativeCrypto /// /// Helper for DSACryptoServiceProvider.ExportParameters() /// - internal static DSAParameters ToDSAParameters(this byte[] cspBlob, bool includePrivateParameters, byte[] cspPublicBlob) + internal static DSAParameters ToDSAParameters(this byte[] cspBlob, bool includePrivateParameters, byte[]? cspPublicBlob) { try { diff --git a/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/CapiHelper.DSA.Windows.cs b/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/CapiHelper.DSA.Windows.cs index f334a98..94e8dc4 100644 --- a/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/CapiHelper.DSA.Windows.cs +++ b/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/CapiHelper.DSA.Windows.cs @@ -25,9 +25,9 @@ namespace Internal.NativeCrypto /// provider type /// provider name /// Returns upgrade CSP name - public static string UpgradeDSS(int dwProvType, string wszProvider) + public static string? UpgradeDSS(int dwProvType, string wszProvider) { - string wszUpgrade = null; + string? wszUpgrade = null; if (string.Equals(wszProvider, MS_DEF_DSS_DH_PROV, StringComparison.Ordinal)) { SafeProvHandle safeProvHandle; diff --git a/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/CapiHelper.Shared.cs b/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/CapiHelper.Shared.cs index 8fb0ca3..3e99e02 100644 --- a/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/CapiHelper.Shared.cs +++ b/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/CapiHelper.Shared.cs @@ -130,12 +130,12 @@ namespace Internal.NativeCrypto if (isPrivate) { - bw.WriteReversed(rsaParameters.P); - bw.WriteReversed(rsaParameters.Q); - bw.WriteReversed(rsaParameters.DP); - bw.WriteReversed(rsaParameters.DQ); - bw.WriteReversed(rsaParameters.InverseQ); - bw.WriteReversed(rsaParameters.D); + bw.WriteReversed(rsaParameters.P!); + bw.WriteReversed(rsaParameters.Q!); + bw.WriteReversed(rsaParameters.DP!); + bw.WriteReversed(rsaParameters.DQ!); + bw.WriteReversed(rsaParameters.InverseQ!); + bw.WriteReversed(rsaParameters.D!); } bw.Flush(); diff --git a/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/CapiHelper.Windows.cs b/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/CapiHelper.Windows.cs index 193b036..d4ca167 100644 --- a/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/CapiHelper.Windows.cs +++ b/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/CapiHelper.Windows.cs @@ -4,6 +4,7 @@ using System; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; using System.Security.Cryptography; using System.Text; @@ -47,11 +48,11 @@ namespace Internal.NativeCrypto /// Provider type /// Provider name /// Returns upgrade CSP name - public static string UpgradeRSA(int dwProvType, string wszProvider) + public static string? UpgradeRSA(int dwProvType, string wszProvider) { bool requestedEnhanced = string.Equals(wszProvider, MS_ENHANCED_PROV, StringComparison.Ordinal); bool requestedBase = string.Equals(wszProvider, MS_DEF_PROV, StringComparison.Ordinal); - string wszUpgrade = null; + string? wszUpgrade = null; if (requestedBase || requestedEnhanced) { SafeProvHandle safeProvHandle; @@ -100,7 +101,7 @@ namespace Internal.NativeCrypto // check to see if there are upgrades available for the requested CSP string providerNameString = providerName.ToString(); - string wszUpgrade = null; + string? wszUpgrade = null; if (dwType == (int)ProviderType.PROV_RSA_FULL) { wszUpgrade = UpgradeRSA(dwType, providerNameString); @@ -140,7 +141,7 @@ namespace Internal.NativeCrypto /// Acquire a handle to a crypto service provider and optionally a key container /// This function implements the WszCryptAcquireContext_SO_TOLERANT /// - private static int AcquireCryptContext(out SafeProvHandle safeProvHandle, string keyContainer, + private static int AcquireCryptContext(out SafeProvHandle safeProvHandle, string? keyContainer, string providerName, int providerType, uint flags) { const uint VerifyContextFlag = (uint)Interop.Advapi32.CryptAcquireContextFlags.CRYPT_VERIFYCONTEXT; @@ -197,8 +198,8 @@ namespace Internal.NativeCrypto /// public static int OpenCSP(CspParameters cspParameters, uint flags, out SafeProvHandle safeProvHandle) { - string providerName = null; - string containerName = null; + string providerName; + string? containerName = null; if (null == cspParameters) { throw new ArgumentException(SR.Format(SR.CspParameter_invalid, nameof(cspParameters))); @@ -341,7 +342,7 @@ namespace Internal.NativeCrypto /// /// This method helps reduce the duplicate code in the GetProviderParameter method /// - internal static int GetProviderParameterWorker(SafeProvHandle safeProvHandle, byte[] impType, ref int cb, CryptProvParam flags) + internal static int GetProviderParameterWorker(SafeProvHandle safeProvHandle, byte[]? impType, ref int cb, CryptProvParam flags) { int impTypeReturn = 0; if (!Interop.Advapi32.CryptGetProvParam(safeProvHandle, flags, impType, ref cb)) @@ -368,7 +369,7 @@ namespace Internal.NativeCrypto int impTypeReturn = 0; int returnType = 0; //using 0 for bool and 1 for string return types bool retVal = false; - string retStr = null; + string? retStr = null; try { @@ -384,7 +385,7 @@ namespace Internal.NativeCrypto { throw GetErrorCode().ToCryptographicException(); } - byte[] permissions = null; + byte[]? permissions = null; int permissionsReturn = 0; permissions = new byte[Constants.SIZE_OF_DWORD]; cb = sizeof(byte) * Constants.SIZE_OF_DWORD; @@ -424,7 +425,7 @@ namespace Internal.NativeCrypto case Constants.CLR_UNIQUE_CONTAINER: { returnType = 1; - byte[] pb = null; + byte[]? pb = null; impTypeReturn = GetProviderParameterWorker(safeProvHandle, pb, ref cb, CryptProvParam.PP_UNIQUE_CONTAINER); pb = new byte[cb]; impTypeReturn = GetProviderParameterWorker(safeProvHandle, pb, ref cb, CryptProvParam.PP_UNIQUE_CONTAINER); @@ -447,7 +448,7 @@ namespace Internal.NativeCrypto } Debug.Assert(returnType == 0 || returnType == 1); - return returnType == 0 ? (object)retVal : retStr; + return returnType == 0 ? (object)retVal : retStr!; } /// @@ -552,7 +553,7 @@ namespace Internal.NativeCrypto /// Returns the key property internal static byte[] GetKeyParameter(SafeKeyHandle safeKeyHandle, int keyParam) { - byte[] pb = null; + byte[]? pb = null; int cb = 0; VerifyValidHandle(safeKeyHandle); //This will throw if handle is invalid @@ -658,7 +659,7 @@ namespace Internal.NativeCrypto /// internal static CspParameters SaveCspParameters( CspAlgorithmType keyType, - CspParameters userParameters, + CspParameters? userParameters, CspProviderFlags defaultFlags, out bool randomKeyContainer) { @@ -871,7 +872,7 @@ namespace Internal.NativeCrypto // The returned value in ohRetEncryptedKey is byte-reversed from the version CAPI gives us. This is for // compatibility with previous releases of the CLR and other RSA implementations. // - internal static void EncryptKey(SafeKeyHandle safeKeyHandle, byte[] pbKey, int cbKey, bool foep, ref byte[] pbEncryptedKey) + internal static void EncryptKey(SafeKeyHandle safeKeyHandle, byte[] pbKey, int cbKey, bool foep, [NotNull] ref byte[]? pbEncryptedKey) { VerifyValidHandle(safeKeyHandle); Debug.Assert(pbKey != null, "pbKey is null"); @@ -1043,7 +1044,7 @@ namespace Internal.NativeCrypto { VerifyValidHandle(safeKeyHandle); - byte[] pbRawData = null; + byte[] pbRawData; int cbRawData = 0; int dwBlobType = includePrivateParameters ? PRIVATEKEYBLOB : PUBLICKEYBLOB; @@ -1063,13 +1064,13 @@ namespace Internal.NativeCrypto /// /// Helper for signing and verifications that accept a string to specify a hashing algorithm. /// - public static int NameOrOidToHashAlgId(string nameOrOid, OidGroup oidGroup) + public static int NameOrOidToHashAlgId(string? nameOrOid, OidGroup oidGroup) { // Default Algorithm Id is CALG_SHA1 if (nameOrOid == null) return CapiHelper.CALG_SHA1; - string oidValue = CryptoConfig.MapNameToOID(nameOrOid); + string? oidValue = CryptoConfig.MapNameToOID(nameOrOid); if (oidValue == null) oidValue = nameOrOid; // we were probably passed an OID value directly @@ -1088,7 +1089,7 @@ namespace Internal.NativeCrypto if (hashAlg == null) throw new ArgumentNullException(nameof(hashAlg)); - string hashAlgString = hashAlg as string; + string? hashAlgString = hashAlg as string; if (hashAlgString != null) { int algId = NameOrOidToHashAlgId(hashAlgString, OidGroup.HashAlgorithm); @@ -1113,8 +1114,8 @@ namespace Internal.NativeCrypto } else { - Type hashAlgType = hashAlg as Type; - if ((object)hashAlgType != null) + Type? hashAlgType = hashAlg as Type; + if ((object?)hashAlgType != null) { if (typeof(MD5).IsAssignableFrom(hashAlgType)) return CapiHelper.CALG_MD5; @@ -1254,12 +1255,12 @@ namespace Internal.NativeCrypto int dwFlags, byte[] IV_Out, int cbIV_In, - ref byte[] pbKey) + [NotNull] ref byte[]? pbKey) { VerifyValidHandle(hProv); - SafeHashHandle hHash = null; - SafeKeyHandle hKey = null; + SafeHashHandle? hHash = null; + SafeKeyHandle? hKey = null; try { if (!CryptCreateHash(hProv, algidHash, SafeKeyHandle.InvalidHandle, Interop.Advapi32.CryptCreateHashFlags.None, out hHash)) @@ -1283,7 +1284,7 @@ namespace Internal.NativeCrypto } // Get the key contents - byte[] rgbKey = null; + byte[]? rgbKey = null; int cbKey = 0; UnloadKey(hProv, hKey, ref rgbKey, ref cbKey); @@ -1323,9 +1324,9 @@ namespace Internal.NativeCrypto // Helper method used by DeriveKey (above) to return the key contents. // WARNING: This function side-effects its first argument (hProv) - private static void UnloadKey(SafeProvHandle hProv, SafeKeyHandle hKey, ref byte[] key_out, ref int cb_out) + private static void UnloadKey(SafeProvHandle hProv, SafeKeyHandle hKey, [NotNull] ref byte[]? key_out, ref int cb_out) { - SafeKeyHandle hPubKey = null; + SafeKeyHandle? hPubKey = null; try { // Import the public key @@ -1391,7 +1392,7 @@ namespace Internal.NativeCrypto /// private static SafeHashHandle CreateHashHandle(this SafeProvHandle hProv, byte[] hash, int calgHash) { - SafeHashHandle hHash; + SafeHashHandle? hHash; if (!CryptCreateHash(hProv, calgHash, SafeKeyHandle.InvalidHandle, Interop.Advapi32.CryptCreateHashFlags.None, out hHash)) { int hr = Marshal.GetHRForLastWin32Error(); diff --git a/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/CspKeyContainerInfo.Windows.cs b/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/CspKeyContainerInfo.Windows.cs index 1fa90d5..cffe089 100644 --- a/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/CspKeyContainerInfo.Windows.cs +++ b/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/CspKeyContainerInfo.Windows.cs @@ -48,7 +48,7 @@ namespace System.Security.Cryptography { get { - object retVal = ReadKeyParameterSilent(Constants.CLR_ACCESSIBLE, throwOnNotFound: false); + object? retVal = ReadKeyParameterSilent(Constants.CLR_ACCESSIBLE, throwOnNotFound: false); if (retVal == null) { @@ -73,7 +73,7 @@ namespace System.Security.Cryptography return false; } - return (bool)ReadKeyParameterSilent(Constants.CLR_EXPORTABLE); + return (bool)ReadKeyParameterSilent(Constants.CLR_EXPORTABLE)!; } } @@ -91,7 +91,7 @@ namespace System.Security.Cryptography /// /// Get Key container Name /// - public string KeyContainerName + public string? KeyContainerName { get { @@ -134,14 +134,14 @@ namespace System.Security.Cryptography return true; } - return (bool)ReadKeyParameterSilent(Constants.CLR_PROTECTED); + return (bool)ReadKeyParameterSilent(Constants.CLR_PROTECTED)!; } } /// /// Gets the provider name /// - public string ProviderName + public string? ProviderName { get { @@ -189,14 +189,14 @@ namespace System.Security.Cryptography { get { - return (string)ReadKeyParameterSilent(Constants.CLR_UNIQUE_CONTAINER); + return (string)ReadKeyParameterSilent(Constants.CLR_UNIQUE_CONTAINER)!; } } /// /// Read a parameter from the current key using CRYPT_SILENT, to avoid any potential UI prompts. /// - private object ReadKeyParameterSilent(int keyParam, bool throwOnNotFound = true) + private object? ReadKeyParameterSilent(int keyParam, bool throwOnNotFound = true) { const uint SilentFlags = (uint)Interop.Advapi32.CryptAcquireContextFlags.CRYPT_SILENT; diff --git a/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/CspParameters.cs b/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/CspParameters.cs index 04253a1..01beaef 100644 --- a/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/CspParameters.cs +++ b/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/CspParameters.cs @@ -12,8 +12,8 @@ namespace System.Security.Cryptography public sealed class CspParameters { public int ProviderType; - public string ProviderName; - public string KeyContainerName; + public string? ProviderName; + public string? KeyContainerName; public int KeyNumber; private int _flags; private IntPtr _parentWindowHandle; @@ -49,18 +49,18 @@ namespace System.Security.Cryptography } [CLSCompliantAttribute(false)] - public SecureString KeyPassword { get; set; } + public SecureString? KeyPassword { get; set; } public CspParameters() : this(CapiHelper.DefaultRsaProviderType, null, null) { } public CspParameters(int dwTypeIn) : this(dwTypeIn, null, null) { } - public CspParameters(int dwTypeIn, string strProviderNameIn) : this(dwTypeIn, strProviderNameIn, null) { } - public CspParameters(int dwTypeIn, string strProviderNameIn, string strContainerNameIn) : + public CspParameters(int dwTypeIn, string? strProviderNameIn) : this(dwTypeIn, strProviderNameIn, null) { } + public CspParameters(int dwTypeIn, string? strProviderNameIn, string? strContainerNameIn) : this(dwTypeIn, strProviderNameIn, strContainerNameIn, CspProviderFlags.NoFlags) { } - internal CspParameters(int providerType, string providerName, string keyContainerName, CspProviderFlags flags) + internal CspParameters(int providerType, string? providerName, string? keyContainerName, CspProviderFlags flags) { ProviderType = providerType; ProviderName = providerName; diff --git a/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/DESCryptoServiceProvider.Unix.cs b/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/DESCryptoServiceProvider.Unix.cs index 46a345b..1423d56 100644 --- a/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/DESCryptoServiceProvider.Unix.cs +++ b/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/DESCryptoServiceProvider.Unix.cs @@ -29,10 +29,10 @@ namespace System.Security.Cryptography public override ICryptoTransform CreateDecryptor() => _impl.CreateDecryptor(); public override ICryptoTransform CreateEncryptor() => _impl.CreateEncryptor(); - public override ICryptoTransform CreateEncryptor(byte[] rgbKey, byte[] rgbIV) => + public override ICryptoTransform CreateEncryptor(byte[] rgbKey, byte[]? rgbIV) => _impl.CreateEncryptor(rgbKey, Helpers.TrimLargeIV(rgbIV, BlockSize)); - public override ICryptoTransform CreateDecryptor(byte[] rgbKey, byte[] rgbIV) => + public override ICryptoTransform CreateDecryptor(byte[] rgbKey, byte[]? rgbIV) => _impl.CreateDecryptor(rgbKey, Helpers.TrimLargeIV(rgbIV, BlockSize)); protected override void Dispose(bool disposing) diff --git a/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/DESCryptoServiceProvider.Windows.cs b/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/DESCryptoServiceProvider.Windows.cs index 3310cce..f64c087 100644 --- a/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/DESCryptoServiceProvider.Windows.cs +++ b/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/DESCryptoServiceProvider.Windows.cs @@ -45,7 +45,7 @@ namespace System.Security.Cryptography } [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA5351", Justification = "This is the implementation of DES")] - public override ICryptoTransform CreateDecryptor(byte[] rgbKey, byte[] rgbIV) + public override ICryptoTransform CreateDecryptor(byte[] rgbKey, byte[]? rgbIV) { return CreateTransform(rgbKey, rgbIV == null ? null : rgbIV.CloneByteArray(), encrypting: false); } @@ -57,13 +57,13 @@ namespace System.Security.Cryptography } [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA5351", Justification = "This is the implementation of DES")] - public override ICryptoTransform CreateEncryptor(byte[] rgbKey, byte[] rgbIV) + public override ICryptoTransform CreateEncryptor(byte[] rgbKey, byte[]? rgbIV) { return CreateTransform(rgbKey, rgbIV == null ? null : rgbIV.CloneByteArray(), encrypting: true); } [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA5351", Justification = "This is the implementation of DES")] - private ICryptoTransform CreateTransform(byte[] rgbKey, byte[] rgbIV, bool encrypting) + private ICryptoTransform CreateTransform(byte[] rgbKey, byte[]? rgbIV, bool encrypting) { // note: rgbIV is guaranteed to be cloned before this method, so no need to clone it again diff --git a/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/DSACryptoServiceProvider.Unix.cs b/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/DSACryptoServiceProvider.Unix.cs index 6132541..76777a0 100644 --- a/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/DSACryptoServiceProvider.Unix.cs +++ b/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/DSACryptoServiceProvider.Unix.cs @@ -135,7 +135,7 @@ namespace System.Security.Cryptography _impl.ImportEncryptedPkcs8PrivateKey(password, source, out bytesRead); } - public override string KeyExchangeAlgorithm => _impl.KeyExchangeAlgorithm; + public override string? KeyExchangeAlgorithm => _impl.KeyExchangeAlgorithm; public override int KeySize { diff --git a/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/DSACryptoServiceProvider.Windows.cs b/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/DSACryptoServiceProvider.Windows.cs index 39d3cdb..ed51902 100644 --- a/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/DSACryptoServiceProvider.Windows.cs +++ b/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/DSACryptoServiceProvider.Windows.cs @@ -13,8 +13,8 @@ namespace System.Security.Cryptography private int _keySize; private readonly CspParameters _parameters; private readonly bool _randomKeyContainer; - private SafeKeyHandle _safeKeyHandle; - private SafeProvHandle _safeProvHandle; + private SafeKeyHandle? _safeKeyHandle; + private SafeProvHandle? _safeProvHandle; private readonly SHA1 _sha1; private static volatile CspProviderFlags s_useMachineKeyStore = 0; private bool _disposed; @@ -49,7 +49,7 @@ namespace System.Security.Cryptography /// for the cryptographic service provider (CSP). /// /// The parameters for the CSP. - public DSACryptoServiceProvider(CspParameters parameters) + public DSACryptoServiceProvider(CspParameters? parameters) : this(0, parameters) { } @@ -61,7 +61,7 @@ namespace System.Security.Cryptography /// The size of the key for the cryptographic algorithm in bits. /// The parameters for the CSP. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA5350", Justification = "SHA1 is required by the FIPS 186-2 DSA spec.")] - public DSACryptoServiceProvider(int dwKeySize, CspParameters parameters) + public DSACryptoServiceProvider(int dwKeySize, CspParameters? parameters) { if (dwKeySize < 0) throw new ArgumentOutOfRangeException(nameof(dwKeySize), SR.ArgumentOutOfRange_NeedNonNegNum); @@ -114,7 +114,7 @@ namespace System.Security.Cryptography { lock (_parameters) { - SafeProvHandle current = _safeProvHandle; + SafeProvHandle? current = _safeProvHandle; if (ReferenceEquals(value, current)) { @@ -123,7 +123,7 @@ namespace System.Security.Cryptography if (current != null) { - SafeKeyHandle keyHandle = _safeKeyHandle; + SafeKeyHandle? keyHandle = _safeKeyHandle; _safeKeyHandle = null; keyHandle?.Dispose(); current.Dispose(); @@ -166,7 +166,7 @@ namespace System.Security.Cryptography { lock (_parameters) { - SafeKeyHandle current = _safeKeyHandle; + SafeKeyHandle? current = _safeKeyHandle; if (ReferenceEquals(value, current)) { @@ -263,7 +263,7 @@ namespace System.Security.Cryptography } } - public override string KeyExchangeAlgorithm => null; + public override string? KeyExchangeAlgorithm => null; public override string SignatureAlgorithm => "http://www.w3.org/2000/09/xmldsig#dsa-sha1"; protected override void Dispose(bool disposing) @@ -297,7 +297,7 @@ namespace System.Security.Cryptography public override DSAParameters ExportParameters(bool includePrivateParameters) { byte[] cspBlob = ExportCspBlob(includePrivateParameters); - byte[] cspPublicBlob = null; + byte[]? cspPublicBlob = null; if (includePrivateParameters) { @@ -473,7 +473,7 @@ namespace System.Security.Cryptography /// The hash value of the data to be signed. /// The name of the hash algorithm used to create the hash value of the data. /// The DSA signature for the specified hash value. - public byte[] SignHash(byte[] rgbHash, string str) + public byte[] SignHash(byte[] rgbHash, string? str) { if (rgbHash == null) throw new ArgumentNullException(nameof(rgbHash)); @@ -501,7 +501,7 @@ namespace System.Security.Cryptography /// The name of the hash algorithm used to create the hash value of the data. /// The signature data to be verified. /// true if the signature verifies as valid; otherwise, false. - public bool VerifyHash(byte[] rgbHash, string str, byte[] rgbSignature) + public bool VerifyHash(byte[] rgbHash, string? str, byte[] rgbSignature) { if (rgbHash == null) throw new ArgumentNullException(nameof(rgbHash)); diff --git a/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/PasswordDeriveBytes.Unix.cs b/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/PasswordDeriveBytes.Unix.cs index b5eb556..9196b3c 100644 --- a/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/PasswordDeriveBytes.Unix.cs +++ b/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/PasswordDeriveBytes.Unix.cs @@ -6,7 +6,7 @@ namespace System.Security.Cryptography { public partial class PasswordDeriveBytes : DeriveBytes { - public byte[] CryptDeriveKey(string algname, string alghashname, int keySize, byte[] rgbIV) + public byte[] CryptDeriveKey(string? algname, string? alghashname, int keySize, byte[] rgbIV) { throw new PlatformNotSupportedException(SR.Format(SR.Cryptography_CAPI_Required, nameof(CryptDeriveKey))); } diff --git a/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/PasswordDeriveBytes.Windows.cs b/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/PasswordDeriveBytes.Windows.cs index 276c499..003a3a6 100644 --- a/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/PasswordDeriveBytes.Windows.cs +++ b/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/PasswordDeriveBytes.Windows.cs @@ -9,9 +9,9 @@ namespace System.Security.Cryptography { public partial class PasswordDeriveBytes : DeriveBytes { - private SafeProvHandle _safeProvHandle = null; + private SafeProvHandle? _safeProvHandle = null; - public byte[] CryptDeriveKey(string algname, string alghashname, int keySize, byte[] rgbIV) + public byte[] CryptDeriveKey(string? algname, string? alghashname, int keySize, byte[] rgbIV) { if (keySize < 0) throw new CryptographicException(SR.Cryptography_InvalidKeySize); @@ -27,7 +27,7 @@ namespace System.Security.Cryptography if (rgbIV == null) throw new CryptographicException(SR.Cryptography_PasswordDerivedBytes_InvalidIV); - byte[] key = null; + byte[]? key = null; CapiHelper.DeriveKey(ProvHandle, algid, algidhash, _password, _password.Length, keySize << 16, rgbIV, rgbIV.Length, ref key); return key; } @@ -52,15 +52,14 @@ namespace System.Security.Cryptography } } - private static SafeProvHandle AcquireSafeProviderHandle(CspParameters cspParams) + private static SafeProvHandle AcquireSafeProviderHandle(CspParameters? cspParams) { if (cspParams == null) { cspParams = new CspParameters(CapiHelper.DefaultRsaProviderType); } - SafeProvHandle safeProvHandle = null; - CapiHelper.AcquireCsp(cspParams, out safeProvHandle); + CapiHelper.AcquireCsp(cspParams, out SafeProvHandle safeProvHandle); return safeProvHandle; } } diff --git a/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/PasswordDeriveBytes.cs b/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/PasswordDeriveBytes.cs index 03be8eb..fb7d16b 100644 --- a/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/PasswordDeriveBytes.cs +++ b/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/PasswordDeriveBytes.cs @@ -3,6 +3,8 @@ // See the LICENSE file in the project root for more information. using System.ComponentModel; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.IO; using System.Text; @@ -14,34 +16,34 @@ namespace System.Security.Cryptography private int _extraCount; private int _prefix; private int _iterations; - private byte[] _baseValue; - private byte[] _extra; - private byte[] _salt; + private byte[]? _baseValue; + private byte[]? _extra; + private byte[]? _salt; private readonly byte[] _password; - private string _hashName; - private HashAlgorithm _hash; - private readonly CspParameters _cspParams; + private string? _hashName; + private HashAlgorithm? _hash; + private readonly CspParameters? _cspParams; - public PasswordDeriveBytes(string strPassword, byte[] rgbSalt) : this(strPassword, rgbSalt, new CspParameters()) { } + public PasswordDeriveBytes(string strPassword, byte[]? rgbSalt) : this(strPassword, rgbSalt, new CspParameters()) { } - public PasswordDeriveBytes(byte[] password, byte[] salt) : this(password, salt, new CspParameters()) { } + public PasswordDeriveBytes(byte[] password, byte[]? salt) : this(password, salt, new CspParameters()) { } - public PasswordDeriveBytes(string strPassword, byte[] rgbSalt, string strHashName, int iterations) : + public PasswordDeriveBytes(string strPassword, byte[]? rgbSalt, string strHashName, int iterations) : this(strPassword, rgbSalt, strHashName, iterations, new CspParameters()) { } - public PasswordDeriveBytes(byte[] password, byte[] salt, string hashName, int iterations) : + public PasswordDeriveBytes(byte[] password, byte[]? salt, string hashName, int iterations) : this(password, salt, hashName, iterations, new CspParameters()) { } - public PasswordDeriveBytes(string strPassword, byte[] rgbSalt, CspParameters cspParams) : + public PasswordDeriveBytes(string strPassword, byte[]? rgbSalt, CspParameters? cspParams) : this(strPassword, rgbSalt, "SHA1", 100, cspParams) { } - public PasswordDeriveBytes(byte[] password, byte[] salt, CspParameters cspParams) : + public PasswordDeriveBytes(byte[] password, byte[]? salt, CspParameters? cspParams) : this(password, salt, "SHA1", 100, cspParams) { } - public PasswordDeriveBytes(string strPassword, byte[] rgbSalt, string strHashName, int iterations, CspParameters cspParams) : + public PasswordDeriveBytes(string strPassword, byte[]? rgbSalt, string strHashName, int iterations, CspParameters? cspParams) : this((new UTF8Encoding(false)).GetBytes(strPassword), rgbSalt, strHashName, iterations, cspParams) { } - public PasswordDeriveBytes(byte[] password, byte[] salt, string hashName, int iterations, CspParameters cspParams) + public PasswordDeriveBytes(byte[] password, byte[]? salt, string hashName, int iterations, CspParameters? cspParams) { IterationCount = iterations; Salt = salt; @@ -52,14 +54,14 @@ namespace System.Security.Cryptography public string HashName { - get { return _hashName; } + get { return _hashName!; } set { if (_baseValue != null) throw new CryptographicException(SR.Cryptography_PasswordDerivedBytes_ValuesFixed, nameof(HashName)); _hashName = value; - _hash = (HashAlgorithm)CryptoConfig.CreateFromName(_hashName); + _hash = (HashAlgorithm?)CryptoConfig.CreateFromName(_hashName); } } @@ -77,18 +79,18 @@ namespace System.Security.Cryptography } } - public byte[] Salt + public byte[]? Salt { get { - return (byte[])_salt?.Clone(); + return (byte[]?)_salt?.Clone(); } set { if (_baseValue != null) throw new CryptographicException(SR.Cryptography_PasswordDerivedBytes_ValuesFixed, nameof(Salt)); - _salt = (byte[])value?.Clone(); + _salt = (byte[]?)value?.Clone(); } } @@ -181,6 +183,7 @@ namespace System.Security.Cryptography private byte[] ComputeBaseValue() { + Debug.Assert(_hash != null); _hash.Initialize(); _hash.TransformBlock(_password, 0, _password.Length, _password, 0); @@ -195,11 +198,11 @@ namespace System.Security.Cryptography for (int i = 1; i < (_iterations - 1); i++) { - _hash.ComputeHash(_baseValue); + _hash.ComputeHash(_baseValue!); _baseValue = _hash.Hash; } - return _baseValue; + return _baseValue!; } private byte[] ComputeBytes(int cb) @@ -208,18 +211,18 @@ namespace System.Security.Cryptography int ib = 0; byte[] rgb; - _hash.Initialize(); + _hash!.Initialize(); cbHash = _hash.HashSize / 8; rgb = new byte[((cb + cbHash - 1) / cbHash) * cbHash]; using (CryptoStream cs = new CryptoStream(Stream.Null, _hash, CryptoStreamMode.Write)) { HashPrefix(cs); - cs.Write(_baseValue, 0, _baseValue.Length); + cs.Write(_baseValue!, 0, _baseValue!.Length); cs.Close(); } - Buffer.BlockCopy(_hash.Hash, 0, rgb, ib, cbHash); + Buffer.BlockCopy(_hash.Hash!, 0, rgb, ib, cbHash); ib += cbHash; while (cb > ib) @@ -232,7 +235,7 @@ namespace System.Security.Cryptography cs.Close(); } - Buffer.BlockCopy(_hash.Hash, 0, rgb, ib, cbHash); + Buffer.BlockCopy(_hash.Hash!, 0, rgb, ib, cbHash); ib += cbHash; } diff --git a/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/RC2CryptoServiceProvider.Unix.cs b/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/RC2CryptoServiceProvider.Unix.cs index 4b9deaf..2179c9a 100644 --- a/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/RC2CryptoServiceProvider.Unix.cs +++ b/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/RC2CryptoServiceProvider.Unix.cs @@ -31,10 +31,10 @@ namespace System.Security.Cryptography public override ICryptoTransform CreateDecryptor() => _impl.CreateDecryptor(); public override ICryptoTransform CreateEncryptor() => _impl.CreateEncryptor(); - public override ICryptoTransform CreateEncryptor(byte[] rgbKey, byte[] rgbIV) => + public override ICryptoTransform CreateEncryptor(byte[] rgbKey, byte[]? rgbIV) => _impl.CreateEncryptor(rgbKey, Helpers.TrimLargeIV(rgbIV, BlockSize)); - public override ICryptoTransform CreateDecryptor(byte[] rgbKey, byte[] rgbIV) => + public override ICryptoTransform CreateDecryptor(byte[] rgbKey, byte[]? rgbIV) => _impl.CreateDecryptor(rgbKey, Helpers.TrimLargeIV(rgbIV, BlockSize)); protected override void Dispose(bool disposing) diff --git a/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/RC2CryptoServiceProvider.Windows.cs b/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/RC2CryptoServiceProvider.Windows.cs index d154ddc..28071c2 100644 --- a/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/RC2CryptoServiceProvider.Windows.cs +++ b/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/RC2CryptoServiceProvider.Windows.cs @@ -51,13 +51,13 @@ namespace System.Security.Cryptography } [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA5351", Justification = "This is the implementation of RC2")] - public override ICryptoTransform CreateEncryptor(byte[] rgbKey, byte[] rgbIV) + public override ICryptoTransform CreateEncryptor(byte[] rgbKey, byte[]? rgbIV) { return CreateTransform(rgbKey, rgbIV == null ? null : rgbIV.CloneByteArray(), encrypting: true); } [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA5351", Justification = "This is the implementation of RC2")] - public override ICryptoTransform CreateDecryptor(byte[] rgbKey, byte[] rgbIV) + public override ICryptoTransform CreateDecryptor(byte[] rgbKey, byte[]? rgbIV) { return CreateTransform(rgbKey, rgbIV == null ? null : rgbIV.CloneByteArray(), encrypting: false); } @@ -78,7 +78,7 @@ namespace System.Security.Cryptography } [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA5351", Justification = "This is the implementation of RC2")] - private ICryptoTransform CreateTransform(byte[] rgbKey, byte[] rgbIV, bool encrypting) + private ICryptoTransform CreateTransform(byte[] rgbKey, byte[]? rgbIV, bool encrypting) { // note: rgbIV is guaranteed to be cloned before this method, so no need to clone it again diff --git a/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/RNGCryptoServiceProvider.cs b/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/RNGCryptoServiceProvider.cs index d8af32d..ffa7b49 100644 --- a/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/RNGCryptoServiceProvider.cs +++ b/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/RNGCryptoServiceProvider.cs @@ -11,11 +11,11 @@ namespace System.Security.Cryptography { private readonly RandomNumberGenerator _impl; - public RNGCryptoServiceProvider() : this((CspParameters)null) { } - public RNGCryptoServiceProvider(string str) : this((CspParameters)null) { } - public RNGCryptoServiceProvider(byte[] rgb) : this((CspParameters)null) { } + public RNGCryptoServiceProvider() : this((CspParameters?)null) { } + public RNGCryptoServiceProvider(string str) : this((CspParameters?)null) { } + public RNGCryptoServiceProvider(byte[] rgb) : this((CspParameters?)null) { } - public RNGCryptoServiceProvider(CspParameters cspParams) + public RNGCryptoServiceProvider(CspParameters? cspParams) { if (cspParams != null) throw new PlatformNotSupportedException(); diff --git a/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/RSACryptoServiceProvider.Unix.cs b/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/RSACryptoServiceProvider.Unix.cs index 43c8790..8487275 100644 --- a/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/RSACryptoServiceProvider.Unix.cs +++ b/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/RSACryptoServiceProvider.Unix.cs @@ -167,7 +167,7 @@ namespace System.Security.Cryptography _impl.ImportEncryptedPkcs8PrivateKey(password, source, out bytesRead); } - public override string KeyExchangeAlgorithm => _impl.KeyExchangeAlgorithm; + public override string? KeyExchangeAlgorithm => _impl.KeyExchangeAlgorithm; public override int KeySize { diff --git a/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/RSACryptoServiceProvider.Windows.cs b/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/RSACryptoServiceProvider.Windows.cs index 1040191..2b272dc 100644 --- a/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/RSACryptoServiceProvider.Windows.cs +++ b/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/RSACryptoServiceProvider.Windows.cs @@ -16,8 +16,8 @@ namespace System.Security.Cryptography private int _keySize; private readonly CspParameters _parameters; private readonly bool _randomKeyContainer; - private SafeKeyHandle _safeKeyHandle; - private SafeProvHandle _safeProvHandle; + private SafeKeyHandle? _safeKeyHandle; + private SafeProvHandle? _safeProvHandle; private static volatile CspProviderFlags s_useMachineKeyStore = 0; private bool _disposed; @@ -39,17 +39,17 @@ namespace System.Security.Cryptography { } - public RSACryptoServiceProvider(int dwKeySize, CspParameters parameters) + public RSACryptoServiceProvider(int dwKeySize, CspParameters? parameters) : this(dwKeySize, parameters, false) { } - public RSACryptoServiceProvider(CspParameters parameters) + public RSACryptoServiceProvider(CspParameters? parameters) : this(0, parameters, true) { } - private RSACryptoServiceProvider(int keySize, CspParameters parameters, bool useDefaultKeySize) + private RSACryptoServiceProvider(int keySize, CspParameters? parameters, bool useDefaultKeySize) { if (keySize < 0) { @@ -103,7 +103,7 @@ namespace System.Security.Cryptography { lock (_parameters) { - SafeProvHandle current = _safeProvHandle; + SafeProvHandle? current = _safeProvHandle; if (ReferenceEquals(value, current)) { @@ -112,7 +112,7 @@ namespace System.Security.Cryptography if (current != null) { - SafeKeyHandle keyHandle = _safeKeyHandle; + SafeKeyHandle? keyHandle = _safeKeyHandle; _safeKeyHandle = null; keyHandle?.Dispose(); current.Dispose(); @@ -155,7 +155,7 @@ namespace System.Security.Cryptography { lock (_parameters) { - SafeKeyHandle current = _safeKeyHandle; + SafeKeyHandle? current = _safeKeyHandle; if (ReferenceEquals(value, current)) { @@ -336,7 +336,7 @@ namespace System.Security.Cryptography } } - byte[] encryptedKey = null; + byte[]? encryptedKey = null; CapiHelper.EncryptKey(SafeKeyHandle, rgb, rgb.Length, fOAEP, ref encryptedKey); return encryptedKey; } @@ -481,7 +481,7 @@ namespace System.Security.Cryptography /// The input data for which to compute the hash /// The hash algorithm to use to create the hash value. /// The RSA signature for the specified data. - public byte[] SignHash(byte[] rgbHash, string str) + public byte[] SignHash(byte[] rgbHash, string? str) { if (rgbHash == null) throw new ArgumentNullException(nameof(rgbHash)); @@ -706,7 +706,7 @@ namespace System.Security.Cryptography return VerifyHash(hash, GetAlgorithmId(hashAlgorithm), signature); } - public override string KeyExchangeAlgorithm + public override string? KeyExchangeAlgorithm { get { diff --git a/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/TripleDESCryptoServiceProvider.cs b/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/TripleDESCryptoServiceProvider.cs index 07b1864..2569f01 100644 --- a/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/TripleDESCryptoServiceProvider.cs +++ b/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/TripleDESCryptoServiceProvider.cs @@ -68,10 +68,10 @@ namespace System.Security.Cryptography public override void GenerateIV() => _impl.GenerateIV(); public override void GenerateKey() => _impl.GenerateKey(); - public override ICryptoTransform CreateEncryptor(byte[] rgbKey, byte[] rgbIV) => + public override ICryptoTransform CreateEncryptor(byte[] rgbKey, byte[]? rgbIV) => _impl.CreateEncryptor(rgbKey, Helpers.TrimLargeIV(rgbIV, BlockSize)); - public override ICryptoTransform CreateDecryptor(byte[] rgbKey, byte[] rgbIV) => + public override ICryptoTransform CreateDecryptor(byte[] rgbKey, byte[]? rgbIV) => _impl.CreateDecryptor(rgbKey, Helpers.TrimLargeIV(rgbIV, BlockSize)); protected override void Dispose(bool disposing)