Enable more nullable reference types in asn.xslt.
authorKevin Jones <kevin@vcsjones.com>
Mon, 6 Apr 2020 17:31:58 +0000 (13:31 -0400)
committerGitHub <noreply@github.com>
Mon, 6 Apr 2020 17:31:58 +0000 (10:31 -0700)
string and Oid types on Choice can be null.
Reference types that are @optional can be null.

Also, remove #nullable enable, because all projects that include the ASN.1 generate files should already have nullable enable project-wide.

33 files changed:
src/libraries/Common/src/System/Security/Cryptography/Asn1/DirectoryStringAsn.xml.cs
src/libraries/Common/src/System/Security/Cryptography/Asn1/ECDomainParameters.xml.cs
src/libraries/Common/src/System/Security/Cryptography/Asn1/GeneralNameAsn.xml.cs
src/libraries/Common/src/System/Security/Cryptography/Asn1/Pbkdf2SaltChoice.xml.cs
src/libraries/Common/src/System/Security/Cryptography/Asn1/Pkcs12/SafeBagAsn.xml.cs
src/libraries/Common/src/System/Security/Cryptography/Asn1/Pkcs7/EncryptedDataAsn.xml.cs
src/libraries/Common/src/System/Security/Cryptography/Asn1/PrivateKeyInfoAsn.xml.cs
src/libraries/Common/src/System/Security/Cryptography/Asn1/SpecifiedECDomain.xml.cs
src/libraries/Common/src/System/Security/Cryptography/Asn1/asn.xslt
src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/Asn1/CertificateChoiceAsn.xml.cs
src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/Asn1/EnvelopedDataAsn.xml.cs
src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/Asn1/KeyAgreeRecipientIdentifierAsn.xml.cs
src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/Asn1/OriginatorIdentifierOrKeyAsn.xml.cs
src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/Asn1/OriginatorInfoAsn.xml.cs
src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/Asn1/PolicyInformation.xml.cs
src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/Asn1/RecipientIdentifierAsn.xml.cs
src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/Asn1/RecipientInfoAsn.xml.cs
src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/Asn1/Rfc3161TimeStampReq.xml.cs
src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/Asn1/Rfc3161TstInfo.xml.cs
src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/Asn1/SignedAttributesSet.xml.cs
src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/Asn1/SignedDataAsn.xml.cs
src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/Asn1/SignerIdentifierAsn.xml.cs
src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/Asn1/SigningCertificateAsn.xml.cs
src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/Asn1/SigningCertificateV2Asn.xml.cs
src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/Rfc3161TimestampRequest.cs
src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/Rfc3161TimestampTokenInfo.cs
src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/SignedCms.cs
src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Unix/UnixExportProvider.cs
src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Unix/UnixPkcs12Reader.cs
src/libraries/System.Security.Cryptography.X509Certificates/src/System/Security/Cryptography/X509Certificates/Asn1/DistributionPointAsn.xml.cs
src/libraries/System.Security.Cryptography.X509Certificates/src/System/Security/Cryptography/X509Certificates/Asn1/DistributionPointNameAsn.xml.cs
src/libraries/System.Security.Cryptography.X509Certificates/src/System/Security/Cryptography/X509Certificates/Asn1/TbsCertificateAsn.xml.cs
src/libraries/System.Security.Cryptography.X509Certificates/src/System/Security/Cryptography/X509Certificates/Asn1/TimeAsn.xml.cs

index 2f420f8..eda1cfd 100644 (file)
@@ -2,7 +2,6 @@
 // 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
 #pragma warning disable SA1028 // ignore whitespace warnings for generated code
 using System;
 using System.Runtime.InteropServices;
@@ -14,11 +13,11 @@ namespace System.Security.Cryptography.Asn1
     [StructLayout(LayoutKind.Sequential)]
     internal partial struct DirectoryStringAsn
     {
-        internal string TeletexString;
-        internal string PrintableString;
+        internal string? TeletexString;
+        internal string? PrintableString;
         internal ReadOnlyMemory<byte>? UniversalString;
-        internal string Utf8String;
-        internal string BmpString;
+        internal string? Utf8String;
+        internal string? BmpString;
 
 #if DEBUG
         static DirectoryStringAsn()
index 4c89970..727797d 100644 (file)
@@ -2,7 +2,6 @@
 // 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
 #pragma warning disable SA1028 // ignore whitespace warnings for generated code
 using System;
 using System.Runtime.InteropServices;
@@ -15,7 +14,7 @@ namespace System.Security.Cryptography.Asn1
     internal partial struct ECDomainParameters
     {
         internal System.Security.Cryptography.Asn1.SpecifiedECDomain? Specified;
-        internal Oid Named;
+        internal Oid? Named;
 
 #if DEBUG
         static ECDomainParameters()
index 79316b1..5525fc3 100644 (file)
@@ -2,7 +2,6 @@
 // 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
 #pragma warning disable SA1028 // ignore whitespace warnings for generated code
 using System;
 using System.Runtime.InteropServices;
@@ -15,14 +14,14 @@ namespace System.Security.Cryptography.Asn1
     internal partial struct GeneralNameAsn
     {
         internal System.Security.Cryptography.Asn1.OtherNameAsn? OtherName;
-        internal string Rfc822Name;
-        internal string DnsName;
+        internal string? Rfc822Name;
+        internal string? DnsName;
         internal ReadOnlyMemory<byte>? X400Address;
         internal ReadOnlyMemory<byte>? DirectoryName;
         internal System.Security.Cryptography.Asn1.EdiPartyNameAsn? EdiPartyName;
-        internal string Uri;
+        internal string? Uri;
         internal ReadOnlyMemory<byte>? IPAddress;
-        internal string RegisteredId;
+        internal string? RegisteredId;
 
 #if DEBUG
         static GeneralNameAsn()
index 0ff367a..9a1c275 100644 (file)
@@ -2,7 +2,6 @@
 // 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
 #pragma warning disable SA1028 // ignore whitespace warnings for generated code
 using System;
 using System.Runtime.InteropServices;
index e961640..c34015f 100644 (file)
@@ -16,7 +16,7 @@ namespace System.Security.Cryptography.Asn1.Pkcs12
     {
         internal string BagId;
         internal ReadOnlyMemory<byte> BagValue;
-        internal System.Security.Cryptography.Asn1.AttributeAsn[] BagAttributes;
+        internal System.Security.Cryptography.Asn1.AttributeAsn[]? BagAttributes;
 
         internal void Encode(AsnWriter writer)
         {
index 8938c54..fffd2c0 100644 (file)
@@ -16,7 +16,7 @@ namespace System.Security.Cryptography.Asn1.Pkcs7
     {
         internal int Version;
         internal System.Security.Cryptography.Asn1.Pkcs7.EncryptedContentInfoAsn EncryptedContentInfo;
-        internal System.Security.Cryptography.Asn1.AttributeAsn[] UnprotectedAttributes;
+        internal System.Security.Cryptography.Asn1.AttributeAsn[]? UnprotectedAttributes;
 
         internal void Encode(AsnWriter writer)
         {
index 12ba027..648489e 100644 (file)
@@ -17,7 +17,7 @@ namespace System.Security.Cryptography.Asn1
         internal byte Version;
         internal System.Security.Cryptography.Asn1.AlgorithmIdentifierAsn PrivateKeyAlgorithm;
         internal ReadOnlyMemory<byte> PrivateKey;
-        internal System.Security.Cryptography.Asn1.AttributeAsn[] Attributes;
+        internal System.Security.Cryptography.Asn1.AttributeAsn[]? Attributes;
 
         internal void Encode(AsnWriter writer)
         {
index f1f44d8..dbe070a 100644 (file)
@@ -19,7 +19,7 @@ namespace System.Security.Cryptography.Asn1
         internal ReadOnlyMemory<byte> Base;
         internal ReadOnlyMemory<byte> Order;
         internal ReadOnlyMemory<byte>? Cofactor;
-        internal Oid Hash;
+        internal Oid? Hash;
 
         internal void Encode(AsnWriter writer)
         {
index b686608..3433cd1 100644 (file)
@@ -127,7 +127,6 @@ namespace <xsl:value-of select="@namespace" />
 // 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
 #pragma warning disable SA1028 // ignore whitespace warnings for generated code
 using System;<xsl:if test="asn:SequenceOf | asn:SetOf">
 using System.Collections.Generic;</xsl:if>
@@ -690,9 +689,9 @@ namespace <xsl:value-of select="@namespace" />
   <xsl:template match="asn:OctetString" mode="DefaultTag">Asn1Tag.PrimitiveOctetString</xsl:template>
 
   <xsl:template match="asn:ObjectIdentifier[not(@backingType)] | asn:ObjectIdentifier[@backingType = 'Oid']" mode="FieldDef">
-        internal Oid <xsl:value-of select="@name" />;</xsl:template>
+        internal Oid<xsl:if test="@optional | parent::asn:Choice">?</xsl:if> <xsl:value-of select="@name" />;</xsl:template>
   <xsl:template match="asn:ObjectIdentifier[@backingType = 'string']" mode="FieldDef">
-        internal string <xsl:value-of select="@name" />;</xsl:template>
+        internal string<xsl:if test="@optional | parent::asn:Choice">?</xsl:if> <xsl:value-of select="@name" />;</xsl:template>
 
   <xsl:template match="asn:ObjectIdentifier[not(@backingType)] | asn:ObjectIdentifier[@backingType = 'Oid']" mode="CollectionElementType">Oid</xsl:template>
   <xsl:template match="asn:ObjectIdentifier[@backingType = 'string']" mode="CollectionElementType">string</xsl:template>
@@ -761,7 +760,7 @@ namespace <xsl:value-of select="@namespace" />
 
   <!-- All character string types -->
   <xsl:template match="asn:UTF8String | asn:PrintableString | asn:T61String | asn:IA5String | asn:VisibleString | asn:BMPString" mode="FieldDef">
-        internal string <xsl:value-of select="@name"/>;</xsl:template>
+        internal string<xsl:if test="@optional | parent::asn:Choice">?</xsl:if> <xsl:value-of select="@name"/>;</xsl:template>
 
   <xsl:template match="asn:UTF8String | asn:PrintableString | asn:T61String | asn:IA5String | asn:VisibleString | asn:BMPString" mode="CollectionElementType">string</xsl:template>
 
@@ -784,7 +783,7 @@ namespace <xsl:value-of select="@namespace" />
   <xsl:template match="asn:UTF8String | asn:PrintableString | asn:T61String | asn:IA5String | asn:VisibleString | asn:BMPString" mode="DefaultTag">new Asn1Tag(UniversalTagNumber.<xsl:value-of select="local-name()"/>)</xsl:template>
 
   <xsl:template match="asn:SequenceOf | asn:SetOf" mode="FieldDef">
-        internal <xsl:apply-templates mode="CollectionElementType"/>[] <xsl:value-of select="@name"/>;</xsl:template>
+        internal <xsl:apply-templates mode="CollectionElementType"/>[]<xsl:if test="@optional | parent::asn:Choice">?</xsl:if> <xsl:value-of select="@name"/>;</xsl:template>
 
   <xsl:template match="asn:SequenceOf | asn:SetOf" mode="EncodeSimpleValue" xml:space="default">
     <xsl:param name="writerName"/>
index f0efb33..073aac1 100644 (file)
@@ -2,7 +2,6 @@
 // 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
 #pragma warning disable SA1028 // ignore whitespace warnings for generated code
 using System;
 using System.Runtime.InteropServices;
index 005d78a..dfcaffa 100644 (file)
@@ -18,7 +18,7 @@ namespace System.Security.Cryptography.Pkcs.Asn1
         internal System.Security.Cryptography.Pkcs.Asn1.OriginatorInfoAsn? OriginatorInfo;
         internal System.Security.Cryptography.Pkcs.Asn1.RecipientInfoAsn[] RecipientInfos;
         internal System.Security.Cryptography.Asn1.Pkcs7.EncryptedContentInfoAsn EncryptedContentInfo;
-        internal System.Security.Cryptography.Asn1.AttributeAsn[] UnprotectedAttributes;
+        internal System.Security.Cryptography.Asn1.AttributeAsn[]? UnprotectedAttributes;
 
         internal void Encode(AsnWriter writer)
         {
index 8ccaea7..cc5df62 100644 (file)
@@ -2,7 +2,6 @@
 // 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
 #pragma warning disable SA1028 // ignore whitespace warnings for generated code
 using System;
 using System.Runtime.InteropServices;
index 82acb18..b9a72cc 100644 (file)
@@ -2,7 +2,6 @@
 // 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
 #pragma warning disable SA1028 // ignore whitespace warnings for generated code
 using System;
 using System.Runtime.InteropServices;
index 76af43c..009aef4 100644 (file)
@@ -14,8 +14,8 @@ namespace System.Security.Cryptography.Pkcs.Asn1
     [StructLayout(LayoutKind.Sequential)]
     internal partial struct OriginatorInfoAsn
     {
-        internal System.Security.Cryptography.Pkcs.Asn1.CertificateChoiceAsn[] CertificateSet;
-        internal ReadOnlyMemory<byte>[] RevocationInfoChoices;
+        internal System.Security.Cryptography.Pkcs.Asn1.CertificateChoiceAsn[]? CertificateSet;
+        internal ReadOnlyMemory<byte>[]? RevocationInfoChoices;
 
         internal void Encode(AsnWriter writer)
         {
index b70e9ae..2836c2a 100644 (file)
@@ -15,7 +15,7 @@ namespace System.Security.Cryptography.Pkcs.Asn1
     internal partial struct PolicyInformation
     {
         internal string PolicyIdentifier;
-        internal System.Security.Cryptography.Pkcs.Asn1.PolicyQualifierInfo[] PolicyQualifiers;
+        internal System.Security.Cryptography.Pkcs.Asn1.PolicyQualifierInfo[]? PolicyQualifiers;
 
         internal void Encode(AsnWriter writer)
         {
index b8e3f7c..2523671 100644 (file)
@@ -2,7 +2,6 @@
 // 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
 #pragma warning disable SA1028 // ignore whitespace warnings for generated code
 using System;
 using System.Runtime.InteropServices;
index 8f4a41a..4290612 100644 (file)
@@ -2,7 +2,6 @@
 // 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
 #pragma warning disable SA1028 // ignore whitespace warnings for generated code
 using System;
 using System.Runtime.InteropServices;
index f99b08c..704fcc6 100644 (file)
@@ -21,7 +21,7 @@ namespace System.Security.Cryptography.Pkcs.Asn1
         internal Oid? ReqPolicy;
         internal ReadOnlyMemory<byte>? Nonce;
         internal bool CertReq;
-        internal System.Security.Cryptography.Asn1.X509ExtensionAsn[] Extensions;
+        internal System.Security.Cryptography.Asn1.X509ExtensionAsn[]? Extensions;
 
 #if DEBUG
         static Rfc3161TimeStampReq()
index 8bf7ca2..49a96ec 100644 (file)
@@ -25,7 +25,7 @@ namespace System.Security.Cryptography.Pkcs.Asn1
         internal bool Ordering;
         internal ReadOnlyMemory<byte>? Nonce;
         internal System.Security.Cryptography.Asn1.GeneralNameAsn? Tsa;
-        internal System.Security.Cryptography.Asn1.X509ExtensionAsn[] Extensions;
+        internal System.Security.Cryptography.Asn1.X509ExtensionAsn[]? Extensions;
 
 #if DEBUG
         static Rfc3161TstInfo()
index 8b2e7a1..7c81d8c 100644 (file)
@@ -2,7 +2,6 @@
 // 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
 #pragma warning disable SA1028 // ignore whitespace warnings for generated code
 using System;
 using System.Collections.Generic;
@@ -15,7 +14,7 @@ namespace System.Security.Cryptography.Pkcs
     [StructLayout(LayoutKind.Sequential)]
     internal partial struct SignedAttributesSet
     {
-        internal System.Security.Cryptography.Asn1.AttributeAsn[] SignedAttributes;
+        internal System.Security.Cryptography.Asn1.AttributeAsn[]? SignedAttributes;
 
 #if DEBUG
         static SignedAttributesSet()
index 75fa98e..1af67b0 100644 (file)
@@ -17,8 +17,8 @@ namespace System.Security.Cryptography.Pkcs.Asn1
         internal int Version;
         internal System.Security.Cryptography.Asn1.AlgorithmIdentifierAsn[] DigestAlgorithms;
         internal System.Security.Cryptography.Pkcs.Asn1.EncapsulatedContentInfoAsn EncapContentInfo;
-        internal System.Security.Cryptography.Pkcs.Asn1.CertificateChoiceAsn[] CertificateSet;
-        internal ReadOnlyMemory<byte>[] Crls;
+        internal System.Security.Cryptography.Pkcs.Asn1.CertificateChoiceAsn[]? CertificateSet;
+        internal ReadOnlyMemory<byte>[]? Crls;
         internal System.Security.Cryptography.Pkcs.Asn1.SignerInfoAsn[] SignerInfos;
 
         internal void Encode(AsnWriter writer)
index 2a0a97b..5cb956e 100644 (file)
@@ -2,7 +2,6 @@
 // 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
 #pragma warning disable SA1028 // ignore whitespace warnings for generated code
 using System;
 using System.Runtime.InteropServices;
index ae7922f..52a06d9 100644 (file)
@@ -15,7 +15,7 @@ namespace System.Security.Cryptography.Pkcs.Asn1
     internal partial struct SigningCertificateAsn
     {
         internal System.Security.Cryptography.Pkcs.Asn1.EssCertId[] Certs;
-        internal System.Security.Cryptography.Pkcs.Asn1.PolicyInformation[] Policies;
+        internal System.Security.Cryptography.Pkcs.Asn1.PolicyInformation[]? Policies;
 
         internal void Encode(AsnWriter writer)
         {
index 01c8929..6556faf 100644 (file)
@@ -15,7 +15,7 @@ namespace System.Security.Cryptography.Pkcs.Asn1
     internal partial struct SigningCertificateV2Asn
     {
         internal System.Security.Cryptography.Pkcs.Asn1.EssCertIdV2[] Certs;
-        internal System.Security.Cryptography.Pkcs.Asn1.PolicyInformation[] Policies;
+        internal System.Security.Cryptography.Pkcs.Asn1.PolicyInformation[]? Policies;
 
         internal void Encode(AsnWriter writer)
         {
index 15e9076..b126b1a 100644 (file)
@@ -38,7 +38,7 @@ namespace System.Security.Cryptography.Pkcs
                 return coll;
             }
 
-            X509ExtensionAsn[] rawExtensions = _parsedData.Extensions;
+            X509ExtensionAsn[] rawExtensions = _parsedData.Extensions!;
 
             foreach (X509ExtensionAsn rawExtension in rawExtensions)
             {
index c2e1d89..a9ff1fe 100644 (file)
@@ -97,7 +97,7 @@ namespace System.Security.Cryptography.Pkcs
                 return coll;
             }
 
-            X509ExtensionAsn[] rawExtensions = _parsedData.Extensions;
+            X509ExtensionAsn[] rawExtensions = _parsedData.Extensions!;
 
             foreach (X509ExtensionAsn rawExtension in rawExtensions)
             {
index d7a5e8a..d45d274 100644 (file)
@@ -80,7 +80,7 @@ namespace System.Security.Cryptography.Pkcs
                     return coll;
                 }
 
-                CertificateChoiceAsn[] certChoices = _signedData.CertificateSet;
+                CertificateChoiceAsn[]? certChoices = _signedData.CertificateSet;
 
                 if (certChoices == null)
                 {
index b2bc76f..89c5e0c 100644 (file)
@@ -197,25 +197,23 @@ namespace Internal.Cryptography.Pal
                 attrBytes[1] = sizeof(int);
                 MemoryMarshal.Write(attrBytes.AsSpan(2), ref keyIdx);
 
+                AttributeAsn attribute = new AttributeAsn
+                {
+                    AttrType = new Oid(Oids.LocalKeyId, null),
+                    AttrValues = new ReadOnlyMemory<byte>[]
+                    {
+                        attrBytes,
+                    }
+                };
                 keyBags[keyIdx] = new SafeBagAsn
                 {
                     BagId = Oids.Pkcs12ShroudedKeyBag,
                     BagValue = ExportPkcs8(certPal, passwordSpan),
-                    BagAttributes = new[]
-                    {
-                        new AttributeAsn
-                        {
-                            AttrType = new Oid(Oids.LocalKeyId, null),
-                            AttrValues = new ReadOnlyMemory<byte>[]
-                            {
-                                attrBytes,
-                            }
-                        }
-                    }
+                    BagAttributes = new[] { attribute }
                 };
 
                 // Reuse the attribute between the cert and the key.
-                certAttrs[certIdx] = keyBags[keyIdx].BagAttributes[0];
+                certAttrs[certIdx] = attribute;
                 keyIdx++;
             }
 
index 808ff35..d1d4532 100644 (file)
@@ -248,7 +248,7 @@ namespace Internal.Cryptography.Pal
             // Nothing requires that there be fewer keys than certs,
             // but it's sort of nonsensical when loading this way.
             CertBagAsn[] certBags = ArrayPool<CertBagAsn>.Shared.Rent(10);
-            AttributeAsn[][] certBagAttrs = ArrayPool<AttributeAsn[]>.Shared.Rent(10);
+            AttributeAsn[]?[] certBagAttrs = ArrayPool<AttributeAsn[]?>.Shared.Rent(10);
             SafeBagAsn[] keyBags = ArrayPool<SafeBagAsn>.Shared.Rent(10);
             RentedSubjectPublicKeyInfo[]? publicKeyInfos = null;
             AsymmetricAlgorithm[]? keys = null;
@@ -326,7 +326,7 @@ namespace Internal.Cryptography.Pal
                 }
 
                 ArrayPool<CertBagAsn>.Shared.Return(certBags, clearArray: true);
-                ArrayPool<AttributeAsn[]>.Shared.Return(certBagAttrs, clearArray: true);
+                ArrayPool<AttributeAsn[]?>.Shared.Return(certBagAttrs, clearArray: true);
                 ArrayPool<SafeBagAsn>.Shared.Return(keyBags, clearArray: true);
             }
         }
@@ -356,7 +356,7 @@ namespace Internal.Cryptography.Pal
         private void DecryptAndProcessSafeContents(
             ReadOnlySpan<char> password,
             ref CertBagAsn[] certBags,
-            ref AttributeAsn[][] certBagAttrs,
+            ref AttributeAsn[]?[] certBagAttrs,
             ref int certBagIdx,
             ref SafeBagAsn[] keyBags,
             ref int keyBagIdx)
@@ -455,7 +455,7 @@ namespace Internal.Cryptography.Pal
 
         private void BuildCertsWithKeys(
             CertBagAsn[] certBags,
-            AttributeAsn[][] certBagAttrs,
+            AttributeAsn[]?[] certBagAttrs,
             CertAndKey[] certs,
             int certBagIdx,
             SafeBagAsn[] keyBags,
@@ -581,7 +581,7 @@ namespace Internal.Cryptography.Pal
         {
             for (int i = 0; i < keyBagCount; i++)
             {
-                foreach (AttributeAsn attr in keyBags[i].BagAttributes)
+                foreach (AttributeAsn attr in keyBags[i].BagAttributes ?? Array.Empty<AttributeAsn>())
                 {
                     if (attr.AttrType.Value == Oids.LocalKeyId && attr.AttrValues.Length > 0)
                     {
@@ -656,7 +656,7 @@ namespace Internal.Cryptography.Pal
         private static void ProcessSafeContents(
             in ContentInfoAsn safeContentsAsn,
             ref CertBagAsn[] certBags,
-            ref AttributeAsn[][] certBagAttrs,
+            ref AttributeAsn[]?[] certBagAttrs,
             ref int certBagIdx,
             ref SafeBagAsn[] keyBags,
             ref int keyBagIdx)
index 94adda8..23af630 100644 (file)
@@ -16,7 +16,7 @@ namespace System.Security.Cryptography.X509Certificates.Asn1
     {
         internal System.Security.Cryptography.X509Certificates.Asn1.DistributionPointNameAsn? DistributionPoint;
         internal System.Security.Cryptography.X509Certificates.Asn1.ReasonFlagsAsn? Reasons;
-        internal System.Security.Cryptography.Asn1.GeneralNameAsn[] CRLIssuer;
+        internal System.Security.Cryptography.Asn1.GeneralNameAsn[]? CRLIssuer;
 
         internal void Encode(AsnWriter writer)
         {
index 2a4d6d5..03164cd 100644 (file)
@@ -2,7 +2,6 @@
 // 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
 #pragma warning disable SA1028 // ignore whitespace warnings for generated code
 using System;
 using System.Collections.Generic;
@@ -15,7 +14,7 @@ namespace System.Security.Cryptography.X509Certificates.Asn1
     [StructLayout(LayoutKind.Sequential)]
     internal partial struct DistributionPointNameAsn
     {
-        internal System.Security.Cryptography.Asn1.GeneralNameAsn[] FullName;
+        internal System.Security.Cryptography.Asn1.GeneralNameAsn[]? FullName;
         internal ReadOnlyMemory<byte>? NameRelativeToCRLIssuer;
 
 #if DEBUG
index cdebe2a..c9ea25a 100644 (file)
@@ -25,7 +25,7 @@ namespace System.Security.Cryptography.X509Certificates.Asn1
         internal System.Security.Cryptography.Asn1.SubjectPublicKeyInfoAsn SubjectPublicKeyInfo;
         internal ReadOnlyMemory<byte>? IssuerUniqueId;
         internal ReadOnlyMemory<byte>? SubjectUniqueId;
-        internal System.Security.Cryptography.Asn1.X509ExtensionAsn[] Extensions;
+        internal System.Security.Cryptography.Asn1.X509ExtensionAsn[]? Extensions;
 
 #if DEBUG
         static TbsCertificateAsn()
index e382786..4b2f3ac 100644 (file)
@@ -2,7 +2,6 @@
 // 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
 #pragma warning disable SA1028 // ignore whitespace warnings for generated code
 using System;
 using System.Runtime.InteropServices;