Skip to content

Commit d6adddf

Browse files
bartonjsjkotas
andauthored
Limit the use of a pointer to the lexical scope of the target
Co-authored-by: Jan Kotas <[email protected]>
1 parent caf8cf3 commit d6adddf

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/StorePal.Windows.Export.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,20 +109,20 @@ private unsafe byte[] ExportPkcs12Core(Pkcs12ExportPbeParameters? exportParamete
109109
Interop.Crypt32.PKCS12_PBES2_EXPORT_PARAMS* exportParams = null;
110110
PbeParameters? reEncodeParameters = null;
111111

112+
char* PKCS12_PBES2_ALG_AES256_SHA256 = stackalloc char[] { 'A', 'E', 'S', '2', '5', '6', '-', 'S', 'H', 'A', '2', '5', '6', '\0' };
113+
Interop.Crypt32.PKCS12_PBES2_EXPORT_PARAMS specifiedParams = new()
114+
{
115+
dwSize = (uint)sizeof(Interop.Crypt32.PKCS12_PBES2_EXPORT_PARAMS),
116+
hNcryptDescriptor = 0,
117+
pwszPbes2Alg = PKCS12_PBES2_ALG_AES256_SHA256,
118+
};
119+
112120
if (exportParameters is Pkcs12ExportPbeParameters.Pbes2Aes256Sha256 or Pkcs12ExportPbeParameters.Default)
113121
{
114122
if (s_supportsAes256Sha256)
115123
{
116124
flags |= Interop.Crypt32.PFXExportFlags.PKCS12_EXPORT_PBES2_PARAMS;
117-
// PKCS12_PBES2_ALG_AES256_SHA256
118-
char* algStr = stackalloc char[] { 'A', 'E', 'S', '2', '5', '6', '-', 'S', 'H', 'A', '2', '5', '6', '\0' };
119-
Interop.Crypt32.PKCS12_PBES2_EXPORT_PARAMS p = new()
120-
{
121-
dwSize = (uint)Marshal.SizeOf<Interop.Crypt32.PKCS12_PBES2_EXPORT_PARAMS>(),
122-
hNcryptDescriptor = 0,
123-
pwszPbes2Alg = algStr,
124-
};
125-
exportParams = &p;
125+
exportParams = &specifiedParams;
126126
}
127127
else
128128
{

0 commit comments

Comments
 (0)