Use ReadOnlySpan<byte> for defaultDerInit (#33828)
authorKevin Jones <kevin@vcsjones.com>
Fri, 20 Mar 2020 02:35:42 +0000 (22:35 -0400)
committerGitHub <noreply@github.com>
Fri, 20 Mar 2020 02:35:42 +0000 (02:35 +0000)
* Use ReadOnlySpan for defaultDerInit.

This removes an array allocation for each type initializer.

* Regenerate files.

src/libraries/Common/src/System/Security/Cryptography/Asn1/OaepParamsAsn.xml.cs
src/libraries/Common/src/System/Security/Cryptography/Asn1/Pbkdf2Params.xml.cs
src/libraries/Common/src/System/Security/Cryptography/Asn1/Pkcs12/MacData.xml.cs
src/libraries/Common/src/System/Security/Cryptography/Asn1/PssParamsAsn.xml.cs
src/libraries/Common/src/System/Security/Cryptography/Asn1/X509ExtensionAsn.xml.cs
src/libraries/Common/src/System/Security/Cryptography/Asn1/asn.xslt
src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/Asn1/EssCertIdV2.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.X509Certificates/src/System/Security/Cryptography/X509Certificates/Asn1/BasicConstraintsAsn.xml.cs
src/libraries/System.Security.Cryptography.X509Certificates/src/System/Security/Cryptography/X509Certificates/Asn1/TbsCertificateAsn.xml.cs

index e1bc57c..06fb623 100644 (file)
@@ -13,11 +13,11 @@ namespace System.Security.Cryptography.Asn1
     [StructLayout(LayoutKind.Sequential)]
     internal partial struct OaepParamsAsn
     {
-        private static readonly byte[] s_defaultHashFunc = { 0x30, 0x09, 0x06, 0x05, 0x2B, 0x0E, 0x03, 0x02, 0x1A, 0x05, 0x00 };
+        private static ReadOnlySpan<byte> DefaultHashFunc => new byte[] { 0x30, 0x09, 0x06, 0x05, 0x2B, 0x0E, 0x03, 0x02, 0x1A, 0x05, 0x00 };
 
-        private static readonly byte[] s_defaultMaskGenFunc = { 0x30, 0x16, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x08, 0x30, 0x09, 0x06, 0x05, 0x2B, 0x0E, 0x03, 0x02, 0x1A, 0x05, 0x00 };
+        private static ReadOnlySpan<byte> DefaultMaskGenFunc => new byte[] { 0x30, 0x16, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x08, 0x30, 0x09, 0x06, 0x05, 0x2B, 0x0E, 0x03, 0x02, 0x1A, 0x05, 0x00 };
 
-        private static readonly byte[] s_defaultPSourceFunc = { 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x09, 0x04, 0x00 };
+        private static ReadOnlySpan<byte> DefaultPSourceFunc => new byte[] { 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x09, 0x04, 0x00 };
 
         internal System.Security.Cryptography.Asn1.AlgorithmIdentifierAsn HashFunc;
         internal System.Security.Cryptography.Asn1.AlgorithmIdentifierAsn MaskGenFunc;
@@ -30,15 +30,15 @@ namespace System.Security.Cryptography.Asn1
             ReadOnlyMemory<byte> rebind = default;
             AsnValueReader reader;
 
-            reader = new AsnValueReader(s_defaultHashFunc, AsnEncodingRules.DER);
+            reader = new AsnValueReader(DefaultHashFunc, AsnEncodingRules.DER);
             System.Security.Cryptography.Asn1.AlgorithmIdentifierAsn.Decode(ref reader, rebind, out decoded.HashFunc);
             reader.ThrowIfNotEmpty();
 
-            reader = new AsnValueReader(s_defaultMaskGenFunc, AsnEncodingRules.DER);
+            reader = new AsnValueReader(DefaultMaskGenFunc, AsnEncodingRules.DER);
             System.Security.Cryptography.Asn1.AlgorithmIdentifierAsn.Decode(ref reader, rebind, out decoded.MaskGenFunc);
             reader.ThrowIfNotEmpty();
 
-            reader = new AsnValueReader(s_defaultPSourceFunc, AsnEncodingRules.DER);
+            reader = new AsnValueReader(DefaultPSourceFunc, AsnEncodingRules.DER);
             System.Security.Cryptography.Asn1.AlgorithmIdentifierAsn.Decode(ref reader, rebind, out decoded.PSourceFunc);
             reader.ThrowIfNotEmpty();
         }
@@ -61,7 +61,7 @@ namespace System.Security.Cryptography.Asn1
                     HashFunc.Encode(tmp);
                     ReadOnlySpan<byte> encoded = tmp.EncodeAsSpan();
 
-                    if (!encoded.SequenceEqual(s_defaultHashFunc))
+                    if (!encoded.SequenceEqual(DefaultHashFunc))
                     {
                         writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 0));
                         writer.WriteEncodedValue(encoded);
@@ -78,7 +78,7 @@ namespace System.Security.Cryptography.Asn1
                     MaskGenFunc.Encode(tmp);
                     ReadOnlySpan<byte> encoded = tmp.EncodeAsSpan();
 
-                    if (!encoded.SequenceEqual(s_defaultMaskGenFunc))
+                    if (!encoded.SequenceEqual(DefaultMaskGenFunc))
                     {
                         writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 1));
                         writer.WriteEncodedValue(encoded);
@@ -95,7 +95,7 @@ namespace System.Security.Cryptography.Asn1
                     PSourceFunc.Encode(tmp);
                     ReadOnlySpan<byte> encoded = tmp.EncodeAsSpan();
 
-                    if (!encoded.SequenceEqual(s_defaultPSourceFunc))
+                    if (!encoded.SequenceEqual(DefaultPSourceFunc))
                     {
                         writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 2));
                         writer.WriteEncodedValue(encoded);
@@ -142,7 +142,7 @@ namespace System.Security.Cryptography.Asn1
             }
             else
             {
-                defaultReader = new AsnValueReader(s_defaultHashFunc, AsnEncodingRules.DER);
+                defaultReader = new AsnValueReader(DefaultHashFunc, AsnEncodingRules.DER);
                 System.Security.Cryptography.Asn1.AlgorithmIdentifierAsn.Decode(ref defaultReader, rebind, out decoded.HashFunc);
             }
 
@@ -155,7 +155,7 @@ namespace System.Security.Cryptography.Asn1
             }
             else
             {
-                defaultReader = new AsnValueReader(s_defaultMaskGenFunc, AsnEncodingRules.DER);
+                defaultReader = new AsnValueReader(DefaultMaskGenFunc, AsnEncodingRules.DER);
                 System.Security.Cryptography.Asn1.AlgorithmIdentifierAsn.Decode(ref defaultReader, rebind, out decoded.MaskGenFunc);
             }
 
@@ -168,7 +168,7 @@ namespace System.Security.Cryptography.Asn1
             }
             else
             {
-                defaultReader = new AsnValueReader(s_defaultPSourceFunc, AsnEncodingRules.DER);
+                defaultReader = new AsnValueReader(DefaultPSourceFunc, AsnEncodingRules.DER);
                 System.Security.Cryptography.Asn1.AlgorithmIdentifierAsn.Decode(ref defaultReader, rebind, out decoded.PSourceFunc);
             }
 
index 67c2cec..7873090 100644 (file)
@@ -13,7 +13,7 @@ namespace System.Security.Cryptography.Asn1
     [StructLayout(LayoutKind.Sequential)]
     internal partial struct Pbkdf2Params
     {
-        private static readonly byte[] s_defaultPrf = { 0x30, 0x0C, 0x06, 0x08, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x07, 0x05, 0x00 };
+        private static ReadOnlySpan<byte> DefaultPrf => new byte[] { 0x30, 0x0C, 0x06, 0x08, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x07, 0x05, 0x00 };
 
         internal System.Security.Cryptography.Asn1.Pbkdf2SaltChoice Salt;
         internal int IterationCount;
@@ -27,7 +27,7 @@ namespace System.Security.Cryptography.Asn1
             ReadOnlyMemory<byte> rebind = default;
             AsnValueReader reader;
 
-            reader = new AsnValueReader(s_defaultPrf, AsnEncodingRules.DER);
+            reader = new AsnValueReader(DefaultPrf, AsnEncodingRules.DER);
             System.Security.Cryptography.Asn1.AlgorithmIdentifierAsn.Decode(ref reader, rebind, out decoded.Prf);
             reader.ThrowIfNotEmpty();
         }
@@ -58,7 +58,7 @@ namespace System.Security.Cryptography.Asn1
                     Prf.Encode(tmp);
                     ReadOnlySpan<byte> encoded = tmp.EncodeAsSpan();
 
-                    if (!encoded.SequenceEqual(s_defaultPrf))
+                    if (!encoded.SequenceEqual(DefaultPrf))
                     {
                         writer.WriteEncodedValue(encoded);
                     }
@@ -122,7 +122,7 @@ namespace System.Security.Cryptography.Asn1
             }
             else
             {
-                defaultReader = new AsnValueReader(s_defaultPrf, AsnEncodingRules.DER);
+                defaultReader = new AsnValueReader(DefaultPrf, AsnEncodingRules.DER);
                 System.Security.Cryptography.Asn1.AlgorithmIdentifierAsn.Decode(ref defaultReader, rebind, out decoded.Prf);
             }
 
index cf059b7..da40456 100644 (file)
@@ -13,7 +13,7 @@ namespace System.Security.Cryptography.Asn1.Pkcs12
     [StructLayout(LayoutKind.Sequential)]
     internal partial struct MacData
     {
-        private static readonly byte[] s_defaultIterationCount = { 0x02, 0x01, 0x01 };
+        private static ReadOnlySpan<byte> DefaultIterationCount => new byte[] { 0x02, 0x01, 0x01 };
 
         internal System.Security.Cryptography.Asn1.DigestInfoAsn Mac;
         internal ReadOnlyMemory<byte> MacSalt;
@@ -25,7 +25,7 @@ namespace System.Security.Cryptography.Asn1.Pkcs12
             MacData decoded = default;
             AsnValueReader reader;
 
-            reader = new AsnValueReader(s_defaultIterationCount, AsnEncodingRules.DER);
+            reader = new AsnValueReader(DefaultIterationCount, AsnEncodingRules.DER);
 
             if (!reader.TryReadInt32(out decoded.IterationCount))
             {
@@ -55,7 +55,7 @@ namespace System.Security.Cryptography.Asn1.Pkcs12
                     tmp.WriteInteger(IterationCount);
                     ReadOnlySpan<byte> encoded = tmp.EncodeAsSpan();
 
-                    if (!encoded.SequenceEqual(s_defaultIterationCount))
+                    if (!encoded.SequenceEqual(DefaultIterationCount))
                     {
                         writer.WriteEncodedValue(encoded);
                     }
@@ -116,7 +116,7 @@ namespace System.Security.Cryptography.Asn1.Pkcs12
             }
             else
             {
-                defaultReader = new AsnValueReader(s_defaultIterationCount, AsnEncodingRules.DER);
+                defaultReader = new AsnValueReader(DefaultIterationCount, AsnEncodingRules.DER);
 
                 if (!defaultReader.TryReadInt32(out decoded.IterationCount))
                 {
index 78985e2..6c42acd 100644 (file)
@@ -13,13 +13,13 @@ namespace System.Security.Cryptography.Asn1
     [StructLayout(LayoutKind.Sequential)]
     internal partial struct PssParamsAsn
     {
-        private static readonly byte[] s_defaultHashAlgorithm = { 0x30, 0x09, 0x06, 0x05, 0x2B, 0x0E, 0x03, 0x02, 0x1A, 0x05, 0x00 };
+        private static ReadOnlySpan<byte> DefaultHashAlgorithm => new byte[] { 0x30, 0x09, 0x06, 0x05, 0x2B, 0x0E, 0x03, 0x02, 0x1A, 0x05, 0x00 };
 
-        private static readonly byte[] s_defaultMaskGenAlgorithm = { 0x30, 0x16, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x08, 0x30, 0x09, 0x06, 0x05, 0x2B, 0x0E, 0x03, 0x02, 0x1A, 0x05, 0x00 };
+        private static ReadOnlySpan<byte> DefaultMaskGenAlgorithm => new byte[] { 0x30, 0x16, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x08, 0x30, 0x09, 0x06, 0x05, 0x2B, 0x0E, 0x03, 0x02, 0x1A, 0x05, 0x00 };
 
-        private static readonly byte[] s_defaultSaltLength = { 0x02, 0x01, 0x14 };
+        private static ReadOnlySpan<byte> DefaultSaltLength => new byte[] { 0x02, 0x01, 0x14 };
 
-        private static readonly byte[] s_defaultTrailerField = { 0x02, 0x01, 0x01 };
+        private static ReadOnlySpan<byte> DefaultTrailerField => new byte[] { 0x02, 0x01, 0x01 };
 
         internal System.Security.Cryptography.Asn1.AlgorithmIdentifierAsn HashAlgorithm;
         internal System.Security.Cryptography.Asn1.AlgorithmIdentifierAsn MaskGenAlgorithm;
@@ -33,15 +33,15 @@ namespace System.Security.Cryptography.Asn1
             ReadOnlyMemory<byte> rebind = default;
             AsnValueReader reader;
 
-            reader = new AsnValueReader(s_defaultHashAlgorithm, AsnEncodingRules.DER);
+            reader = new AsnValueReader(DefaultHashAlgorithm, AsnEncodingRules.DER);
             System.Security.Cryptography.Asn1.AlgorithmIdentifierAsn.Decode(ref reader, rebind, out decoded.HashAlgorithm);
             reader.ThrowIfNotEmpty();
 
-            reader = new AsnValueReader(s_defaultMaskGenAlgorithm, AsnEncodingRules.DER);
+            reader = new AsnValueReader(DefaultMaskGenAlgorithm, AsnEncodingRules.DER);
             System.Security.Cryptography.Asn1.AlgorithmIdentifierAsn.Decode(ref reader, rebind, out decoded.MaskGenAlgorithm);
             reader.ThrowIfNotEmpty();
 
-            reader = new AsnValueReader(s_defaultSaltLength, AsnEncodingRules.DER);
+            reader = new AsnValueReader(DefaultSaltLength, AsnEncodingRules.DER);
 
             if (!reader.TryReadInt32(out decoded.SaltLength))
             {
@@ -50,7 +50,7 @@ namespace System.Security.Cryptography.Asn1
 
             reader.ThrowIfNotEmpty();
 
-            reader = new AsnValueReader(s_defaultTrailerField, AsnEncodingRules.DER);
+            reader = new AsnValueReader(DefaultTrailerField, AsnEncodingRules.DER);
 
             if (!reader.TryReadInt32(out decoded.TrailerField))
             {
@@ -78,7 +78,7 @@ namespace System.Security.Cryptography.Asn1
                     HashAlgorithm.Encode(tmp);
                     ReadOnlySpan<byte> encoded = tmp.EncodeAsSpan();
 
-                    if (!encoded.SequenceEqual(s_defaultHashAlgorithm))
+                    if (!encoded.SequenceEqual(DefaultHashAlgorithm))
                     {
                         writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 0));
                         writer.WriteEncodedValue(encoded);
@@ -95,7 +95,7 @@ namespace System.Security.Cryptography.Asn1
                     MaskGenAlgorithm.Encode(tmp);
                     ReadOnlySpan<byte> encoded = tmp.EncodeAsSpan();
 
-                    if (!encoded.SequenceEqual(s_defaultMaskGenAlgorithm))
+                    if (!encoded.SequenceEqual(DefaultMaskGenAlgorithm))
                     {
                         writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 1));
                         writer.WriteEncodedValue(encoded);
@@ -112,7 +112,7 @@ namespace System.Security.Cryptography.Asn1
                     tmp.WriteInteger(SaltLength);
                     ReadOnlySpan<byte> encoded = tmp.EncodeAsSpan();
 
-                    if (!encoded.SequenceEqual(s_defaultSaltLength))
+                    if (!encoded.SequenceEqual(DefaultSaltLength))
                     {
                         writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 2));
                         writer.WriteEncodedValue(encoded);
@@ -129,7 +129,7 @@ namespace System.Security.Cryptography.Asn1
                     tmp.WriteInteger(TrailerField);
                     ReadOnlySpan<byte> encoded = tmp.EncodeAsSpan();
 
-                    if (!encoded.SequenceEqual(s_defaultTrailerField))
+                    if (!encoded.SequenceEqual(DefaultTrailerField))
                     {
                         writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 3));
                         writer.WriteEncodedValue(encoded);
@@ -176,7 +176,7 @@ namespace System.Security.Cryptography.Asn1
             }
             else
             {
-                defaultReader = new AsnValueReader(s_defaultHashAlgorithm, AsnEncodingRules.DER);
+                defaultReader = new AsnValueReader(DefaultHashAlgorithm, AsnEncodingRules.DER);
                 System.Security.Cryptography.Asn1.AlgorithmIdentifierAsn.Decode(ref defaultReader, rebind, out decoded.HashAlgorithm);
             }
 
@@ -189,7 +189,7 @@ namespace System.Security.Cryptography.Asn1
             }
             else
             {
-                defaultReader = new AsnValueReader(s_defaultMaskGenAlgorithm, AsnEncodingRules.DER);
+                defaultReader = new AsnValueReader(DefaultMaskGenAlgorithm, AsnEncodingRules.DER);
                 System.Security.Cryptography.Asn1.AlgorithmIdentifierAsn.Decode(ref defaultReader, rebind, out decoded.MaskGenAlgorithm);
             }
 
@@ -207,7 +207,7 @@ namespace System.Security.Cryptography.Asn1
             }
             else
             {
-                defaultReader = new AsnValueReader(s_defaultSaltLength, AsnEncodingRules.DER);
+                defaultReader = new AsnValueReader(DefaultSaltLength, AsnEncodingRules.DER);
 
                 if (!defaultReader.TryReadInt32(out decoded.SaltLength))
                 {
@@ -230,7 +230,7 @@ namespace System.Security.Cryptography.Asn1
             }
             else
             {
-                defaultReader = new AsnValueReader(s_defaultTrailerField, AsnEncodingRules.DER);
+                defaultReader = new AsnValueReader(DefaultTrailerField, AsnEncodingRules.DER);
 
                 if (!defaultReader.TryReadInt32(out decoded.TrailerField))
                 {
index 0c447e9..45ead32 100644 (file)
@@ -13,7 +13,7 @@ namespace System.Security.Cryptography.Asn1
     [StructLayout(LayoutKind.Sequential)]
     internal partial struct X509ExtensionAsn
     {
-        private static readonly byte[] s_defaultCritical = { 0x01, 0x01, 0x00 };
+        private static ReadOnlySpan<byte> DefaultCritical => new byte[] { 0x01, 0x01, 0x00 };
 
         internal Oid ExtnId;
         internal bool Critical;
@@ -25,7 +25,7 @@ namespace System.Security.Cryptography.Asn1
             X509ExtensionAsn decoded = default;
             AsnValueReader reader;
 
-            reader = new AsnValueReader(s_defaultCritical, AsnEncodingRules.DER);
+            reader = new AsnValueReader(DefaultCritical, AsnEncodingRules.DER);
             decoded.Critical = reader.ReadBoolean();
             reader.ThrowIfNotEmpty();
         }
@@ -49,7 +49,7 @@ namespace System.Security.Cryptography.Asn1
                     tmp.WriteBoolean(Critical);
                     ReadOnlySpan<byte> encoded = tmp.EncodeAsSpan();
 
-                    if (!encoded.SequenceEqual(s_defaultCritical))
+                    if (!encoded.SequenceEqual(DefaultCritical))
                     {
                         writer.WriteEncodedValue(encoded);
                     }
@@ -96,7 +96,7 @@ namespace System.Security.Cryptography.Asn1
             }
             else
             {
-                defaultReader = new AsnValueReader(s_defaultCritical, AsnEncodingRules.DER);
+                defaultReader = new AsnValueReader(DefaultCritical, AsnEncodingRules.DER);
                 decoded.Critical = defaultReader.ReadBoolean();
             }
 
index a182bd6..b686608 100644 (file)
@@ -213,7 +213,7 @@ namespace <xsl:value-of select="@namespace" />
   </xsl:template>
 
   <xsl:template match="*[@defaultDerInit]" mode="DefaultFieldDef">
-        private static readonly byte[] <xsl:call-template name="DefaultValueField"/> = { <xsl:value-of select="@defaultDerInit"/> };
+        private static ReadOnlySpan&lt;byte&gt; <xsl:call-template name="DefaultValueField"/> =&gt; new byte[] { <xsl:value-of select="@defaultDerInit"/> };
 </xsl:template>
 
   <xsl:template match="*[@defaultDerInit]" mode="DefaultFieldVerify">
@@ -909,7 +909,7 @@ namespace <xsl:value-of select="@namespace" />
 
   <xsl:template name="ContextTag">new Asn1Tag(TagClass.ContextSpecific, <xsl:value-of select="@implicitTag | @explicitTag"/>)</xsl:template>
 
-  <xsl:template name="DefaultValueField">s_default<xsl:value-of select="@name"/></xsl:template>
+  <xsl:template name="DefaultValueField">Default<xsl:value-of select="@name"/></xsl:template>
 
   <xsl:template name="DefaultValueDecoder"><xsl:if test="@defaultDerInit">
             else
index cfff6e4..df54bc6 100644 (file)
@@ -13,7 +13,7 @@ namespace System.Security.Cryptography.Pkcs.Asn1
     [StructLayout(LayoutKind.Sequential)]
     internal partial struct EssCertIdV2
     {
-        private static readonly byte[] s_defaultHashAlgorithm = { 0x30, 0x0B, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01 };
+        private static ReadOnlySpan<byte> DefaultHashAlgorithm => new byte[] { 0x30, 0x0B, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01 };
 
         internal System.Security.Cryptography.Asn1.AlgorithmIdentifierAsn HashAlgorithm;
         internal ReadOnlyMemory<byte> Hash;
@@ -26,7 +26,7 @@ namespace System.Security.Cryptography.Pkcs.Asn1
             ReadOnlyMemory<byte> rebind = default;
             AsnValueReader reader;
 
-            reader = new AsnValueReader(s_defaultHashAlgorithm, AsnEncodingRules.DER);
+            reader = new AsnValueReader(DefaultHashAlgorithm, AsnEncodingRules.DER);
             System.Security.Cryptography.Asn1.AlgorithmIdentifierAsn.Decode(ref reader, rebind, out decoded.HashAlgorithm);
             reader.ThrowIfNotEmpty();
         }
@@ -49,7 +49,7 @@ namespace System.Security.Cryptography.Pkcs.Asn1
                     HashAlgorithm.Encode(tmp);
                     ReadOnlySpan<byte> encoded = tmp.EncodeAsSpan();
 
-                    if (!encoded.SequenceEqual(s_defaultHashAlgorithm))
+                    if (!encoded.SequenceEqual(DefaultHashAlgorithm))
                     {
                         writer.WriteEncodedValue(encoded);
                     }
@@ -101,7 +101,7 @@ namespace System.Security.Cryptography.Pkcs.Asn1
             }
             else
             {
-                defaultReader = new AsnValueReader(s_defaultHashAlgorithm, AsnEncodingRules.DER);
+                defaultReader = new AsnValueReader(DefaultHashAlgorithm, AsnEncodingRules.DER);
                 System.Security.Cryptography.Asn1.AlgorithmIdentifierAsn.Decode(ref defaultReader, rebind, out decoded.HashAlgorithm);
             }
 
index d31c8fc..f99b08c 100644 (file)
@@ -14,7 +14,7 @@ namespace System.Security.Cryptography.Pkcs.Asn1
     [StructLayout(LayoutKind.Sequential)]
     internal partial struct Rfc3161TimeStampReq
     {
-        private static readonly byte[] s_defaultCertReq = { 0x01, 0x01, 0x00 };
+        private static ReadOnlySpan<byte> DefaultCertReq => new byte[] { 0x01, 0x01, 0x00 };
 
         internal int Version;
         internal System.Security.Cryptography.Pkcs.Asn1.MessageImprint MessageImprint;
@@ -29,7 +29,7 @@ namespace System.Security.Cryptography.Pkcs.Asn1
             Rfc3161TimeStampReq decoded = default;
             AsnValueReader reader;
 
-            reader = new AsnValueReader(s_defaultCertReq, AsnEncodingRules.DER);
+            reader = new AsnValueReader(DefaultCertReq, AsnEncodingRules.DER);
             decoded.CertReq = reader.ReadBoolean();
             reader.ThrowIfNotEmpty();
         }
@@ -66,7 +66,7 @@ namespace System.Security.Cryptography.Pkcs.Asn1
                     tmp.WriteBoolean(CertReq);
                     ReadOnlySpan<byte> encoded = tmp.EncodeAsSpan();
 
-                    if (!encoded.SequenceEqual(s_defaultCertReq))
+                    if (!encoded.SequenceEqual(DefaultCertReq))
                     {
                         writer.WriteEncodedValue(encoded);
                     }
@@ -145,7 +145,7 @@ namespace System.Security.Cryptography.Pkcs.Asn1
             }
             else
             {
-                defaultReader = new AsnValueReader(s_defaultCertReq, AsnEncodingRules.DER);
+                defaultReader = new AsnValueReader(DefaultCertReq, AsnEncodingRules.DER);
                 decoded.CertReq = defaultReader.ReadBoolean();
             }
 
index ff0a95b..8bf7ca2 100644 (file)
@@ -14,7 +14,7 @@ namespace System.Security.Cryptography.Pkcs.Asn1
     [StructLayout(LayoutKind.Sequential)]
     internal partial struct Rfc3161TstInfo
     {
-        private static readonly byte[] s_defaultOrdering = { 0x01, 0x01, 0x00 };
+        private static ReadOnlySpan<byte> DefaultOrdering => new byte[] { 0x01, 0x01, 0x00 };
 
         internal int Version;
         internal Oid Policy;
@@ -33,7 +33,7 @@ namespace System.Security.Cryptography.Pkcs.Asn1
             Rfc3161TstInfo decoded = default;
             AsnValueReader reader;
 
-            reader = new AsnValueReader(s_defaultOrdering, AsnEncodingRules.DER);
+            reader = new AsnValueReader(DefaultOrdering, AsnEncodingRules.DER);
             decoded.Ordering = reader.ReadBoolean();
             reader.ThrowIfNotEmpty();
         }
@@ -67,7 +67,7 @@ namespace System.Security.Cryptography.Pkcs.Asn1
                     tmp.WriteBoolean(Ordering);
                     ReadOnlySpan<byte> encoded = tmp.EncodeAsSpan();
 
-                    if (!encoded.SequenceEqual(s_defaultOrdering))
+                    if (!encoded.SequenceEqual(DefaultOrdering))
                     {
                         writer.WriteEncodedValue(encoded);
                     }
@@ -161,7 +161,7 @@ namespace System.Security.Cryptography.Pkcs.Asn1
             }
             else
             {
-                defaultReader = new AsnValueReader(s_defaultOrdering, AsnEncodingRules.DER);
+                defaultReader = new AsnValueReader(DefaultOrdering, AsnEncodingRules.DER);
                 decoded.Ordering = defaultReader.ReadBoolean();
             }
 
index abd2507..400b063 100644 (file)
@@ -13,7 +13,7 @@ namespace System.Security.Cryptography.X509Certificates.Asn1
     [StructLayout(LayoutKind.Sequential)]
     internal partial struct BasicConstraintsAsn
     {
-        private static readonly byte[] s_defaultCA = { 0x01, 0x01, 0x00 };
+        private static ReadOnlySpan<byte> DefaultCA => new byte[] { 0x01, 0x01, 0x00 };
 
         internal bool CA;
         internal int? PathLengthConstraint;
@@ -24,7 +24,7 @@ namespace System.Security.Cryptography.X509Certificates.Asn1
             BasicConstraintsAsn decoded = default;
             AsnValueReader reader;
 
-            reader = new AsnValueReader(s_defaultCA, AsnEncodingRules.DER);
+            reader = new AsnValueReader(DefaultCA, AsnEncodingRules.DER);
             decoded.CA = reader.ReadBoolean();
             reader.ThrowIfNotEmpty();
         }
@@ -47,7 +47,7 @@ namespace System.Security.Cryptography.X509Certificates.Asn1
                     tmp.WriteBoolean(CA);
                     ReadOnlySpan<byte> encoded = tmp.EncodeAsSpan();
 
-                    if (!encoded.SequenceEqual(s_defaultCA))
+                    if (!encoded.SequenceEqual(DefaultCA))
                     {
                         writer.WriteEncodedValue(encoded);
                     }
@@ -95,7 +95,7 @@ namespace System.Security.Cryptography.X509Certificates.Asn1
             }
             else
             {
-                defaultReader = new AsnValueReader(s_defaultCA, AsnEncodingRules.DER);
+                defaultReader = new AsnValueReader(DefaultCA, AsnEncodingRules.DER);
                 decoded.CA = defaultReader.ReadBoolean();
             }
 
index 241ba95..cdebe2a 100644 (file)
@@ -14,7 +14,7 @@ namespace System.Security.Cryptography.X509Certificates.Asn1
     [StructLayout(LayoutKind.Sequential)]
     internal partial struct TbsCertificateAsn
     {
-        private static readonly byte[] s_defaultVersion = { 0x02, 0x01, 0x00 };
+        private static ReadOnlySpan<byte> DefaultVersion => new byte[] { 0x02, 0x01, 0x00 };
 
         internal int Version;
         internal ReadOnlyMemory<byte> SerialNumber;
@@ -33,7 +33,7 @@ namespace System.Security.Cryptography.X509Certificates.Asn1
             TbsCertificateAsn decoded = default;
             AsnValueReader reader;
 
-            reader = new AsnValueReader(s_defaultVersion, AsnEncodingRules.DER);
+            reader = new AsnValueReader(DefaultVersion, AsnEncodingRules.DER);
 
             if (!reader.TryReadInt32(out decoded.Version))
             {
@@ -61,7 +61,7 @@ namespace System.Security.Cryptography.X509Certificates.Asn1
                     tmp.WriteInteger(Version);
                     ReadOnlySpan<byte> encoded = tmp.EncodeAsSpan();
 
-                    if (!encoded.SequenceEqual(s_defaultVersion))
+                    if (!encoded.SequenceEqual(DefaultVersion))
                     {
                         writer.PushSequence(new Asn1Tag(TagClass.ContextSpecific, 0));
                         writer.WriteEncodedValue(encoded);
@@ -168,7 +168,7 @@ namespace System.Security.Cryptography.X509Certificates.Asn1
             }
             else
             {
-                defaultReader = new AsnValueReader(s_defaultVersion, AsnEncodingRules.DER);
+                defaultReader = new AsnValueReader(DefaultVersion, AsnEncodingRules.DER);
 
                 if (!defaultReader.TryReadInt32(out decoded.Version))
                 {