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.
// 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;
[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()
// 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;
internal partial struct ECDomainParameters
{
internal System.Security.Cryptography.Asn1.SpecifiedECDomain? Specified;
- internal Oid Named;
+ internal Oid? Named;
#if DEBUG
static ECDomainParameters()
// 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;
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()
// 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;
{
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)
{
{
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)
{
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)
{
internal ReadOnlyMemory<byte> Base;
internal ReadOnlyMemory<byte> Order;
internal ReadOnlyMemory<byte>? Cofactor;
- internal Oid Hash;
+ internal Oid? Hash;
internal void Encode(AsnWriter writer)
{
// 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>
<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>
<!-- 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>
<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"/>
// 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;
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)
{
// 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;
// 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;
[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)
{
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)
{
// 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;
// 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;
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()
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()
// 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;
[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()
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)
// 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;
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)
{
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)
{
return coll;
}
- X509ExtensionAsn[] rawExtensions = _parsedData.Extensions;
+ X509ExtensionAsn[] rawExtensions = _parsedData.Extensions!;
foreach (X509ExtensionAsn rawExtension in rawExtensions)
{
return coll;
}
- X509ExtensionAsn[] rawExtensions = _parsedData.Extensions;
+ X509ExtensionAsn[] rawExtensions = _parsedData.Extensions!;
foreach (X509ExtensionAsn rawExtension in rawExtensions)
{
return coll;
}
- CertificateChoiceAsn[] certChoices = _signedData.CertificateSet;
+ CertificateChoiceAsn[]? certChoices = _signedData.CertificateSet;
if (certChoices == null)
{
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++;
}
// 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;
}
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);
}
}
private void DecryptAndProcessSafeContents(
ReadOnlySpan<char> password,
ref CertBagAsn[] certBags,
- ref AttributeAsn[][] certBagAttrs,
+ ref AttributeAsn[]?[] certBagAttrs,
ref int certBagIdx,
ref SafeBagAsn[] keyBags,
ref int keyBagIdx)
private void BuildCertsWithKeys(
CertBagAsn[] certBags,
- AttributeAsn[][] certBagAttrs,
+ AttributeAsn[]?[] certBagAttrs,
CertAndKey[] certs,
int certBagIdx,
SafeBagAsn[] keyBags,
{
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)
{
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)
{
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)
{
// 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;
[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
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()
// 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;