Unify code for AttributeAsn and X501AttributeAsn
authorFilip Navara <filip.navara@gmail.com>
Thu, 13 Sep 2018 15:09:26 +0000 (17:09 +0200)
committerJeremy Barton <jbarton@microsoft.com>
Thu, 13 Sep 2018 15:09:26 +0000 (08:09 -0700)
* Declare AttributeAsn.AttrValues as SetOf instead of encoding it manually.
* Replace X501AttributeAsn with AttributeAsn.

Commit migrated from https://github.com/dotnet/corefx/commit/35320e086b5f159d74737558f4e3806c53dfaf8c

13 files changed:
src/libraries/Common/src/System/Security/Cryptography/Asn1/AttributeAsn.manual.cs [moved from src/libraries/System.Security.Cryptography.X509Certificates/src/System/Security/Cryptography/X509Certificates/Asn1/X501AttributeAsn.manual.cs with 64% similarity]
src/libraries/Common/src/System/Security/Cryptography/Asn1/AttributeAsn.xml
src/libraries/Common/src/System/Security/Cryptography/Asn1/AttributeAsn.xml.cs
src/libraries/System.Security.Cryptography.Pkcs/src/System.Security.Cryptography.Pkcs.csproj
src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/CmsSigner.cs
src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/Pkcs12SafeBag.cs
src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/SignerInfo.cs
src/libraries/System.Security.Cryptography.X509Certificates/src/System.Security.Cryptography.X509Certificates.csproj
src/libraries/System.Security.Cryptography.X509Certificates/src/System/Security/Cryptography/X509Certificates/Asn1/CertificationRequestInfoAsn.xml
src/libraries/System.Security.Cryptography.X509Certificates/src/System/Security/Cryptography/X509Certificates/Asn1/CertificationRequestInfoAsn.xml.cs
src/libraries/System.Security.Cryptography.X509Certificates/src/System/Security/Cryptography/X509Certificates/Asn1/X501AttributeAsn.xml [deleted file]
src/libraries/System.Security.Cryptography.X509Certificates/src/System/Security/Cryptography/X509Certificates/Asn1/X501AttributeAsn.xml.cs [deleted file]
src/libraries/System.Security.Cryptography.X509Certificates/src/System/Security/Cryptography/X509Certificates/Pkcs10CertificationRequestInfo.cs

@@ -2,20 +2,18 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
 
-using System.Security.Cryptography.X509Certificates;
-
-namespace System.Security.Cryptography.X509Certificates.Asn1
+namespace System.Security.Cryptography.Asn1
 {
-    internal partial struct X501AttributeAsn
+    internal partial struct AttributeAsn
     {
-        public X501AttributeAsn(X501Attribute attribute)
+        public AttributeAsn(AsnEncodedData attribute)
         {
             if (attribute == null)
             {
                 throw new ArgumentNullException(nameof(attribute));
             }
 
-            AttrId = attribute.Oid;
+            AttrType = new Oid(attribute.Oid);
             AttrValues = new[] { new ReadOnlyMemory<byte>(attribute.RawData) };
         }
     }
index 62204d1..9aa30a1 100644 (file)
@@ -15,5 +15,7 @@
     AttributeValue ::= ANY
   -->
   <asn:ObjectIdentifier name="AttrType" />
-  <asn:AnyValue name="AttrValues" />
+  <asn:SetOf name="AttrValues">
+         <asn:AnyValue />
+  </asn:SetOf>
 </asn:Sequence>
\ No newline at end of file
index 5a27a82..6b170ed 100644 (file)
@@ -1,4 +1,5 @@
 using System;
+using System.Collections.Generic;
 using System.Runtime.InteropServices;
 using System.Security.Cryptography;
 using System.Security.Cryptography.Asn1;
@@ -9,7 +10,7 @@ namespace System.Security.Cryptography.Asn1
     internal partial struct AttributeAsn
     {
         internal Oid AttrType;
-        internal ReadOnlyMemory<byte> AttrValues;
+        internal ReadOnlyMemory<byte>[] AttrValues;
       
         internal void Encode(AsnWriter writer)
         {
@@ -21,7 +22,14 @@ namespace System.Security.Cryptography.Asn1
             writer.PushSequence(tag);
             
             writer.WriteObjectIdentifier(AttrType);
-            writer.WriteEncodedValue(AttrValues);
+
+            writer.PushSetOf();
+            for (int i = 0; i < AttrValues.Length; i++)
+            {
+                writer.WriteEncodedValue(AttrValues[i]); 
+            }
+            writer.PopSetOf();
+
             writer.PopSequence(tag);
         }
 
@@ -54,9 +62,25 @@ namespace System.Security.Cryptography.Asn1
 
             decoded = default;
             AsnReader sequenceReader = reader.ReadSequence(expectedTag);
+            AsnReader collectionReader;
             
             decoded.AttrType = sequenceReader.ReadObjectIdentifier();
-            decoded.AttrValues = sequenceReader.GetEncodedValue();
+
+            // Decode SEQUENCE OF for AttrValues
+            {
+                collectionReader = sequenceReader.ReadSetOf();
+                var tmpList = new List<ReadOnlyMemory<byte>>();
+                ReadOnlyMemory<byte> tmpItem;
+
+                while (collectionReader.HasData)
+                {
+                    tmpItem = collectionReader.GetEncodedValue(); 
+                    tmpList.Add(tmpItem);
+                }
+
+                decoded.AttrValues = tmpList.ToArray();
+            }
+
 
             sequenceReader.ThrowIfNotEmpty();
         }
index bfcd96a..236b7cb 100644 (file)
       <Link>Common\System\Security\Cryptography\Asn1\AttributeAsn.xml.cs</Link>
       <DependentUpon>Common\System\Security\Cryptography\Asn1\AttributeAsn.xml</DependentUpon>
     </Compile>
+    <Compile Include="$(CommonPath)\System\Security\Cryptography\Asn1\AttributeAsn.manual.cs">
+      <Link>Common\System\Security\Cryptography\Asn1\AttributeAsn.manual.cs</Link>
+      <DependentUpon>Common\System\Security\Cryptography\Asn1\AttributeAsn.xml</DependentUpon>
+    </Compile>
     <AsnXml Include="$(CommonPath)\System\Security\Cryptography\Asn1\EncryptedPrivateKeyInfoAsn.xml">
       <Link>Common\System\Security\Cryptography\Asn1\EncryptedPrivateKeyInfoAsn.xml</Link>
     </AsnXml>
index 1111cd0..f44b167 100644 (file)
@@ -139,15 +139,12 @@ namespace System.Security.Cryptography.Pkcs
 
                 using (var writer = new AsnWriter(AsnEncodingRules.DER))
                 {
-                    writer.PushSetOf();
                     writer.WriteOctetString(dataHash);
-                    writer.PopSetOf();
-
                     signedAttrs.Add(
                         new AttributeAsn
                         {
                             AttrType = new Oid(Oids.MessageDigest, Oids.MessageDigest),
-                            AttrValues = writer.Encode(),
+                            AttrValues = new[] { new ReadOnlyMemory<byte>(writer.Encode()) },
                         });
                 }
 
@@ -155,15 +152,12 @@ namespace System.Security.Cryptography.Pkcs
                 {
                     using (var writer = new AsnWriter(AsnEncodingRules.DER))
                     {
-                        writer.PushSetOf();
                         writer.WriteObjectIdentifier(contentTypeOid);
-                        writer.PopSetOf();
-
                         signedAttrs.Add(
                             new AttributeAsn
                             {
                                 AttrType = new Oid(Oids.ContentType, Oids.ContentType),
-                                AttrValues = writer.Encode(),
+                                AttrValues = new[] { new ReadOnlyMemory<byte>(writer.Encode()) },
                             });
                     }
                 }
@@ -321,25 +315,18 @@ namespace System.Security.Cryptography.Pkcs
 
             foreach (CryptographicAttributeObject attributeObject in attributes)
             {
-                using (var writer = new AsnWriter(AsnEncodingRules.DER))
+                AttributeAsn newAttr = new AttributeAsn
                 {
-                    writer.PushSetOf();
-
-                    foreach (AsnEncodedData objectValue in attributeObject.Values)
-                    {
-                        writer.WriteEncodedValue(objectValue.RawData);
-                    }
+                    AttrType = attributeObject.Oid,
+                    AttrValues = new ReadOnlyMemory<byte>[attributeObject.Values.Count],
+                };
 
-                    writer.PopSetOf();
-
-                    AttributeAsn newAttr = new AttributeAsn
-                    {
-                        AttrType = attributeObject.Oid,
-                        AttrValues = writer.Encode(),
-                    };
-
-                    signedAttrs.Add(newAttr);
+                for (int i = 0; i < attributeObject.Values.Count; i++)
+                {
+                    newAttr.AttrValues[i] = attributeObject.Values[i].RawData;
                 }
+
+                signedAttrs.Add(newAttr);
             }
 
             return signedAttrs;
index 81e1c3f..786447c 100644 (file)
@@ -104,10 +104,7 @@ namespace System.Security.Cryptography.Pkcs
 
                 foreach (AttributeAsn attr in attrs)
                 {
-                    writer.PushSequence();
-                    writer.WriteObjectIdentifier(attr.AttrType);
-                    writer.WriteEncodedValue(attr.AttrValues);
-                    writer.PopSequence();
+                    attr.Encode(writer);
                 }
 
                 writer.PopSetOf();
index 7d3338c..b12b82f 100644 (file)
@@ -137,20 +137,7 @@ namespace System.Security.Cryptography.Pkcs
             if (existingAttribute == -1)
             {
                 // create a new attribute
-                AttributeAsn newUnsignedAttr;
-                using (AsnWriter writer = new AsnWriter(AsnEncodingRules.BER))
-                {
-                    writer.PushSetOf();
-                    writer.WriteEncodedValue(unsignedAttribute.RawData);
-                    writer.PopSetOf();
-
-                    newUnsignedAttr = new AttributeAsn
-                    {
-                        AttrType = new Oid(unsignedAttribute.Oid),
-                        AttrValues = writer.Encode(),
-                    };
-                }
-
+                AttributeAsn newUnsignedAttr = new AttributeAsn(unsignedAttribute);
                 int newAttributeIdx;
 
                 if (mySigner.UnsignedAttributes == null)
@@ -170,27 +157,9 @@ namespace System.Security.Cryptography.Pkcs
             {
                 // merge with existing attribute
                 ref AttributeAsn modifiedAttr = ref mySigner.UnsignedAttributes[existingAttribute];
-
-                using (AsnWriter writer = new AsnWriter(AsnEncodingRules.BER))
-                {
-                    writer.PushSetOf();
-
-                    AsnReader reader = new AsnReader(modifiedAttr.AttrValues, AsnEncodingRules.BER);
-                    AsnReader collReader = reader.ReadSetOf();
-
-                    reader.ThrowIfNotEmpty();
-
-                    // re-add old values
-                    while (collReader.HasData)
-                    {
-                        writer.WriteEncodedValue(collReader.GetEncodedValue());
-                    }
-
-                    writer.WriteEncodedValue(unsignedAttribute.RawData);
-
-                    writer.PopSetOf();
-                    modifiedAttr.AttrValues = writer.Encode();
-                }
+                int newIndex = modifiedAttr.AttrValues.Length;
+                Array.Resize(ref modifiedAttr.AttrValues, newIndex + 1);
+                modifiedAttr.AttrValues[newIndex] = unsignedAttribute.RawData;
             }
 
             // Re-normalize the document
@@ -222,7 +191,7 @@ namespace System.Security.Cryptography.Pkcs
             }
             else
             {
-                RemoveAttributeValueWithoutIndexChecking(ref mySigner.UnsignedAttributes[outerIndex], innerIndex);
+                PkcsHelpers.RemoveAt(ref mySigner.UnsignedAttributes[outerIndex].AttrValues, innerIndex);
             }
 
             // Re-normalize the document
@@ -239,14 +208,9 @@ namespace System.Security.Cryptography.Pkcs
             {
                 if (attributeAsn.AttrType.Value == Oids.CounterSigner)
                 {
-                    AsnReader reader = new AsnReader(attributeAsn.AttrValues, AsnEncodingRules.BER);
-                    AsnReader collReader = reader.ReadSetOf();
-
-                    reader.ThrowIfNotEmpty();
-
-                    while (collReader.HasData)
+                    foreach (ReadOnlyMemory<byte> attrValue in attributeAsn.AttrValues)
                     {
-                        SignerInfoAsn.Decode(collReader, out SignerInfoAsn parsedData);
+                        SignerInfoAsn parsedData = SignerInfoAsn.Decode(attrValue, AsnEncodingRules.BER);
 
                         SignerInfo signerInfo = new SignerInfo(ref parsedData, _document)
                         {
@@ -291,14 +255,12 @@ namespace System.Security.Cryptography.Pkcs
 
             using (AsnWriter writer = new AsnWriter(AsnEncodingRules.DER))
             {
-                writer.PushSetOf();
                 newSignerInfo.Encode(writer);
-                writer.PopSetOf();
 
                 newUnsignedAttr = new AttributeAsn
                 {
                     AttrType = new Oid(Oids.CounterSigner, Oids.CounterSigner),
-                    AttrValues = writer.Encode(),
+                    AttrValues = new[] { new ReadOnlyMemory<byte>(writer.Encode()) },
                 };
             }
 
@@ -367,36 +329,18 @@ namespace System.Security.Cryptography.Pkcs
 
                 if (attributeAsn.AttrType.Value == Oids.CounterSigner)
                 {
-                    AsnReader reader = new AsnReader(attributeAsn.AttrValues, AsnEncodingRules.BER);
-                    AsnReader collReader = reader.ReadSetOf();
-
-                    reader.ThrowIfNotEmpty();
-
-                    int j = 0;
-
-                    while (collReader.HasData)
+                    if (index < csIndex + attributeAsn.AttrValues.Length)
                     {
-                        collReader.GetEncodedValue();
-
-                        if (csIndex == index)
+                        removeAttrIdx = i;
+                        removeValueIndex = index - csIndex;
+                        if (removeValueIndex == 0 && attributeAsn.AttrValues.Length == 1)
                         {
-                            removeAttrIdx = i;
-                            removeValueIndex = j;
+                            removeWholeAttr = true;
                         }
-
-                        csIndex++;
-                        j++;
-                    }
-
-                    if (removeValueIndex == 0 && j == 1)
-                    {
-                        removeWholeAttr = true;
-                    }
-
-                    if (removeAttrIdx >= 0)
-                    {
                         break;
                     }
+
+                    csIndex += attributeAsn.AttrValues.Length;
                 }
             }
 
@@ -420,7 +364,7 @@ namespace System.Security.Cryptography.Pkcs
             }
             else
             {
-                RemoveAttributeValueWithoutIndexChecking(ref unsignedAttrs[removeAttrIdx], removeValueIndex);
+                PkcsHelpers.RemoveAt(ref unsignedAttrs[removeAttrIdx].AttrValues, removeValueIndex);
             }
         }
 
@@ -811,20 +755,11 @@ namespace System.Security.Cryptography.Pkcs
         private static CryptographicAttributeObject MakeAttribute(AttributeAsn attribute)
         {
             Oid type = new Oid(attribute.AttrType);
-
-            ReadOnlyMemory<byte> attrSetBytes = attribute.AttrValues;
-
-            AsnReader reader = new AsnReader(attrSetBytes, AsnEncodingRules.BER);
-            AsnReader collReader = reader.ReadSetOf();
-
-            reader.ThrowIfNotEmpty();
-
             AsnEncodedDataCollection valueColl = new AsnEncodedDataCollection();
 
-            while (collReader.HasData)
+            foreach (ReadOnlyMemory<byte> attrValue in attribute.AttrValues)
             {
-                byte[] attrBytes = collReader.GetEncodedValue().ToArray();
-                valueColl.Add(PkcsHelpers.CreateBestPkcs9AttributeObjectAvailable(type, attrBytes));
+                valueColl.Add(PkcsHelpers.CreateBestPkcs9AttributeObjectAvailable(type, attrValue.ToArray()));
             }
 
             return new CryptographicAttributeObject(type, valueColl);
@@ -843,19 +778,14 @@ namespace System.Security.Cryptography.Pkcs
             return -1;
         }
 
-        private static int FindAttributeValueIndexByEncodedData(ReadOnlyMemory<byte> attributeValues, ReadOnlySpan<byte> asnEncodedData, out bool isOnlyValue)
+        private static int FindAttributeValueIndexByEncodedData(ReadOnlyMemory<byte>[] attributeValues, ReadOnlySpan<byte> asnEncodedData, out bool isOnlyValue)
         {
-            AsnReader reader = new AsnReader(attributeValues, AsnEncodingRules.BER);
-            AsnReader collReader = reader.ReadSetOf();
-
-            reader.ThrowIfNotEmpty();
-
-            for (int i = 0; collReader.HasData; i++)
+            for (int i = 0; i < attributeValues.Length; i++)
             {
-                ReadOnlySpan<byte> data = collReader.GetEncodedValue().Span;
+                ReadOnlySpan<byte> data = attributeValues[i].Span;
                 if (data.SequenceEqual(asnEncodedData))
                 {
-                    isOnlyValue = i == 0 && !collReader.HasData;
+                    isOnlyValue = attributeValues.Length == 1;
                     return i;
                 }
             }
@@ -885,36 +815,5 @@ namespace System.Security.Cryptography.Pkcs
             isOnlyValue = false;
             return (-1, -1);
         }
-
-        private static void RemoveAttributeValueWithoutIndexChecking(ref AttributeAsn modifiedAttr, int removeValueIndex)
-        {
-            // Using BER rules to avoid resorting
-            using (AsnWriter writer = new AsnWriter(AsnEncodingRules.BER))
-            {
-                writer.PushSetOf();
-
-                AsnReader reader = new AsnReader(modifiedAttr.AttrValues, writer.RuleSet);
-                AsnReader collReader = reader.ReadSetOf();
-
-                reader.ThrowIfNotEmpty();
-
-                int i = 0;
-
-                while (collReader.HasData)
-                {
-                    ReadOnlyMemory<byte> encodedValue = collReader.GetEncodedValue();
-
-                    if (i != removeValueIndex)
-                    {
-                        writer.WriteEncodedValue(encodedValue);
-                    }
-
-                    i++;
-                }
-
-                writer.PopSetOf();
-                modifiedAttr.AttrValues = writer.Encode();
-            }
-        }
     }
 }
index 15b9243..b1f8454 100644 (file)
       <Link>Common\System\Security\Cryptography\Asn1\AlgorithmIdentifierAsn.manual.cs</Link>
       <DependentUpon>Common\System\Security\Cryptography\Asn1\AlgorithmIdentifierAsn.xml</DependentUpon>
     </Compile>
+    <AsnXml Include="$(CommonPath)\System\Security\Cryptography\Asn1\AttributeAsn.xml">
+      <Link>Common\System\Security\Cryptography\Asn1\AttributeAsn.xml</Link>
+    </AsnXml>
+    <Compile Include="$(CommonPath)\System\Security\Cryptography\Asn1\AttributeAsn.xml.cs">
+      <Link>Common\System\Security\Cryptography\Asn1\AttributeAsn.xml.cs</Link>
+      <DependentUpon>Common\System\Security\Cryptography\Asn1\AttributeAsn.xml</DependentUpon>
+    </Compile>
+    <Compile Include="$(CommonPath)\System\Security\Cryptography\Asn1\AttributeAsn.manual.cs">
+      <Link>Common\System\Security\Cryptography\Asn1\AttributeAsn.manual.cs</Link>
+      <DependentUpon>Common\System\Security\Cryptography\Asn1\AttributeAsn.xml</DependentUpon>
+    </Compile>
     <AsnXml Include="$(CommonPath)\System\Security\Cryptography\Asn1\DirectoryStringAsn.xml">
       <Link>Common\System\Security\Cryptography\Asn1\DirectoryStringAsn.xml</Link>
     </AsnXml>
       <DependentUpon>System\Security\Cryptography\X509Certificates\Asn1\ValidityAsn.xml</DependentUpon>
     </Compile>
     <Compile Include="System\Security\Cryptography\X509Certificates\Asn1\ValidityAsn.manual.cs" />
-    <AsnXml Include="System\Security\Cryptography\X509Certificates\Asn1\X501AttributeAsn.xml" />
-    <Compile Include="System\Security\Cryptography\X509Certificates\Asn1\X501AttributeAsn.xml.cs">
-      <DependentUpon>System\Security\Cryptography\X509Certificates\Asn1\X501AttributeAsn.xml</DependentUpon>
-    </Compile>
-    <Compile Include="System\Security\Cryptography\X509Certificates\Asn1\X501AttributeAsn.manual.cs" />
     <AsnXml Include="System\Security\Cryptography\X509Certificates\Asn1\AccessDescriptionAsn.xml" />
     <Compile Include="System\Security\Cryptography\X509Certificates\Asn1\AccessDescriptionAsn.xml.cs">
       <DependentUpon>System\Security\Cryptography\X509Certificates\Asn1\AccessDescriptionAsn.xml</DependentUpon>
     <Compile Include="$(CommonPath)\System\Security\Cryptography\SecKeyPair.cs">
       <Link>Common\System\Security\Cryptography\SecKeyPair.cs</Link>
     </Compile>
-    <AsnXml Include="$(CommonPath)\System\Security\Cryptography\Asn1\AttributeAsn.xml">
-      <Link>Common\System\Security\Cryptography\Asn1\AttributeAsn.xml</Link>
-    </AsnXml>
-    <Compile Include="$(CommonPath)\System\Security\Cryptography\Asn1\AttributeAsn.xml.cs">
-      <Link>Common\System\Security\Cryptography\Asn1\AttributeAsn.xml.cs</Link>
-      <DependentUpon>Common\System\Security\Cryptography\Asn1\AttributeAsn.xml</DependentUpon>
-    </Compile>
     <AsnXml Include="$(CommonPath)\System\Security\Cryptography\Asn1\CurveAsn.xml">
       <Link>Common\System\Security\Cryptography\Asn1\CurveAsn.xml</Link>
     </AsnXml>
index c31a1b0..41cd357 100644 (file)
@@ -18,6 +18,6 @@
   <asn:AnyValue name="Subject" universalTagNumber="16" />
   <asn:AsnType name="SubjectPublicKeyInfo" typeName="System.Security.Cryptography.Asn1.SubjectPublicKeyInfoAsn" />
   <asn:SetOf name="Attributes" implicitTag="0">
-         <asn:AsnType typeName="System.Security.Cryptography.X509Certificates.Asn1.X501AttributeAsn" />
+    <asn:AsnType typeName="System.Security.Cryptography.Asn1.AttributeAsn" />
   </asn:SetOf>
 </asn:Sequence>
\ No newline at end of file
index 84a887f..a6c7263 100644 (file)
@@ -12,7 +12,7 @@ namespace System.Security.Cryptography.X509Certificates.Asn1
         internal System.Numerics.BigInteger Version;
         internal ReadOnlyMemory<byte> Subject;
         internal System.Security.Cryptography.Asn1.SubjectPublicKeyInfoAsn SubjectPublicKeyInfo;
-        internal System.Security.Cryptography.X509Certificates.Asn1.X501AttributeAsn[] Attributes;
+        internal System.Security.Cryptography.Asn1.AttributeAsn[] Attributes;
       
         internal void Encode(AsnWriter writer)
         {
@@ -89,12 +89,12 @@ namespace System.Security.Cryptography.X509Certificates.Asn1
             // Decode SEQUENCE OF for Attributes
             {
                 collectionReader = sequenceReader.ReadSetOf(new Asn1Tag(TagClass.ContextSpecific, 0));
-                var tmpList = new List<System.Security.Cryptography.X509Certificates.Asn1.X501AttributeAsn>();
-                System.Security.Cryptography.X509Certificates.Asn1.X501AttributeAsn tmpItem;
+                var tmpList = new List<System.Security.Cryptography.Asn1.AttributeAsn>();
+                System.Security.Cryptography.Asn1.AttributeAsn tmpItem;
 
                 while (collectionReader.HasData)
                 {
-                    System.Security.Cryptography.X509Certificates.Asn1.X501AttributeAsn.Decode(collectionReader, out tmpItem); 
+                    System.Security.Cryptography.Asn1.AttributeAsn.Decode(collectionReader, out tmpItem); 
                     tmpList.Add(tmpItem);
                 }
 
diff --git a/src/libraries/System.Security.Cryptography.X509Certificates/src/System/Security/Cryptography/X509Certificates/Asn1/X501AttributeAsn.xml b/src/libraries/System.Security.Cryptography.X509Certificates/src/System/Security/Cryptography/X509Certificates/Asn1/X501AttributeAsn.xml
deleted file mode 100644 (file)
index 8c375a9..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<asn:Sequence
-  xmlns:asn="http://schemas.dot.net/asnxml/201808/"
-  name="X501AttributeAsn"
-  namespace="System.Security.Cryptography.X509Certificates.Asn1">
-
-  <!--
-    https://tools.ietf.org/html/rfc2986#section-4.1
-
-    Attribute { ATTRIBUTE:IOSet } ::= SEQUENCE {
-        type   ATTRIBUTE.&id({IOSet}),
-        values SET SIZE(1..MAX) OF ATTRIBUTE.&Type({IOSet}{@type})
-    }
-  -->
-  <asn:ObjectIdentifier name="AttrId" />
-  <asn:SetOf name="AttrValues">
-         <asn:AnyValue />
-  </asn:SetOf>
-</asn:Sequence>
\ No newline at end of file
diff --git a/src/libraries/System.Security.Cryptography.X509Certificates/src/System/Security/Cryptography/X509Certificates/Asn1/X501AttributeAsn.xml.cs b/src/libraries/System.Security.Cryptography.X509Certificates/src/System/Security/Cryptography/X509Certificates/Asn1/X501AttributeAsn.xml.cs
deleted file mode 100644 (file)
index 4112455..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Runtime.InteropServices;
-using System.Security.Cryptography;
-using System.Security.Cryptography.Asn1;
-
-namespace System.Security.Cryptography.X509Certificates.Asn1
-{
-    [StructLayout(LayoutKind.Sequential)]
-    internal partial struct X501AttributeAsn
-    {
-        internal Oid AttrId;
-        internal ReadOnlyMemory<byte>[] AttrValues;
-      
-        internal void Encode(AsnWriter writer)
-        {
-            Encode(writer, Asn1Tag.Sequence);
-        }
-    
-        internal void Encode(AsnWriter writer, Asn1Tag tag)
-        {
-            writer.PushSequence(tag);
-            
-            writer.WriteObjectIdentifier(AttrId);
-
-            writer.PushSetOf();
-            for (int i = 0; i < AttrValues.Length; i++)
-            {
-                writer.WriteEncodedValue(AttrValues[i]); 
-            }
-            writer.PopSetOf();
-
-            writer.PopSequence(tag);
-        }
-
-        internal static X501AttributeAsn Decode(ReadOnlyMemory<byte> encoded, AsnEncodingRules ruleSet)
-        {
-            return Decode(Asn1Tag.Sequence, encoded, ruleSet);
-        }
-        
-        internal static X501AttributeAsn Decode(Asn1Tag expectedTag, ReadOnlyMemory<byte> encoded, AsnEncodingRules ruleSet)
-        {
-            AsnReader reader = new AsnReader(encoded, ruleSet);
-            
-            Decode(reader, expectedTag, out X501AttributeAsn decoded);
-            reader.ThrowIfNotEmpty();
-            return decoded;
-        }
-
-        internal static void Decode(AsnReader reader, out X501AttributeAsn decoded)
-        {
-            if (reader == null)
-                throw new ArgumentNullException(nameof(reader));
-
-            Decode(reader, Asn1Tag.Sequence, out decoded);
-        }
-
-        internal static void Decode(AsnReader reader, Asn1Tag expectedTag, out X501AttributeAsn decoded)
-        {
-            if (reader == null)
-                throw new ArgumentNullException(nameof(reader));
-
-            decoded = default;
-            AsnReader sequenceReader = reader.ReadSequence(expectedTag);
-            AsnReader collectionReader;
-            
-            decoded.AttrId = sequenceReader.ReadObjectIdentifier();
-
-            // Decode SEQUENCE OF for AttrValues
-            {
-                collectionReader = sequenceReader.ReadSetOf();
-                var tmpList = new List<ReadOnlyMemory<byte>>();
-                ReadOnlyMemory<byte> tmpItem;
-
-                while (collectionReader.HasData)
-                {
-                    tmpItem = collectionReader.GetEncodedValue(); 
-                    tmpList.Add(tmpItem);
-                }
-
-                decoded.AttrValues = tmpList.ToArray();
-            }
-
-
-            sequenceReader.ThrowIfNotEmpty();
-        }
-    }
-}
index a36c138..47c6139 100644 (file)
@@ -63,7 +63,7 @@ namespace System.Security.Cryptography.X509Certificates
                 Version = 0,
                 Subject = this.Subject.RawData,
                 SubjectPublicKeyInfo = spki,
-                Attributes = Attributes.Select(a => new X501AttributeAsn(a)).ToArray(),
+                Attributes = Attributes.Select(a => new AttributeAsn(a)).ToArray(),
             };
 
             using (AsnWriter writer = new AsnWriter(AsnEncodingRules.DER))