From ada03d7f4aaabb956331353b298b6e4739ec78f5 Mon Sep 17 00:00:00 2001 From: Kevin Jones Date: Thu, 19 Mar 2020 22:35:42 -0400 Subject: [PATCH] Use ReadOnlySpan for defaultDerInit (#33828) * Use ReadOnlySpan for defaultDerInit. This removes an array allocation for each type initializer. * Regenerate files. --- .../Cryptography/Asn1/OaepParamsAsn.xml.cs | 24 +++++++------- .../Cryptography/Asn1/Pbkdf2Params.xml.cs | 8 ++--- .../Cryptography/Asn1/Pkcs12/MacData.xml.cs | 8 ++--- .../Cryptography/Asn1/PssParamsAsn.xml.cs | 32 +++++++++---------- .../Cryptography/Asn1/X509ExtensionAsn.xml.cs | 8 ++--- .../Security/Cryptography/Asn1/asn.xslt | 4 +-- .../Cryptography/Pkcs/Asn1/EssCertIdV2.xml.cs | 8 ++--- .../Pkcs/Asn1/Rfc3161TimeStampReq.xml.cs | 8 ++--- .../Pkcs/Asn1/Rfc3161TstInfo.xml.cs | 8 ++--- .../Asn1/BasicConstraintsAsn.xml.cs | 8 ++--- .../Asn1/TbsCertificateAsn.xml.cs | 8 ++--- 11 files changed, 62 insertions(+), 62 deletions(-) diff --git a/src/libraries/Common/src/System/Security/Cryptography/Asn1/OaepParamsAsn.xml.cs b/src/libraries/Common/src/System/Security/Cryptography/Asn1/OaepParamsAsn.xml.cs index e1bc57cb95f94..06fb623cc81c5 100644 --- a/src/libraries/Common/src/System/Security/Cryptography/Asn1/OaepParamsAsn.xml.cs +++ b/src/libraries/Common/src/System/Security/Cryptography/Asn1/OaepParamsAsn.xml.cs @@ -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 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 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 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 @@ static OaepParamsAsn() ReadOnlyMemory 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 @@ internal void Encode(AsnWriter writer, Asn1Tag tag) HashFunc.Encode(tmp); ReadOnlySpan 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 @@ internal void Encode(AsnWriter writer, Asn1Tag tag) MaskGenFunc.Encode(tmp); ReadOnlySpan 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 @@ internal void Encode(AsnWriter writer, Asn1Tag tag) PSourceFunc.Encode(tmp); ReadOnlySpan 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 @@ internal static void Decode(ref AsnValueReader reader, Asn1Tag expectedTag, Read } 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 @@ internal static void Decode(ref AsnValueReader reader, Asn1Tag expectedTag, Read } 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 @@ internal static void Decode(ref AsnValueReader reader, Asn1Tag expectedTag, Read } 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); } diff --git a/src/libraries/Common/src/System/Security/Cryptography/Asn1/Pbkdf2Params.xml.cs b/src/libraries/Common/src/System/Security/Cryptography/Asn1/Pbkdf2Params.xml.cs index 67c2cecd73b77..78730906951dd 100644 --- a/src/libraries/Common/src/System/Security/Cryptography/Asn1/Pbkdf2Params.xml.cs +++ b/src/libraries/Common/src/System/Security/Cryptography/Asn1/Pbkdf2Params.xml.cs @@ -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 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 @@ static Pbkdf2Params() ReadOnlyMemory 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 @@ internal void Encode(AsnWriter writer, Asn1Tag tag) Prf.Encode(tmp); ReadOnlySpan encoded = tmp.EncodeAsSpan(); - if (!encoded.SequenceEqual(s_defaultPrf)) + if (!encoded.SequenceEqual(DefaultPrf)) { writer.WriteEncodedValue(encoded); } @@ -122,7 +122,7 @@ internal static void Decode(ref AsnValueReader reader, Asn1Tag expectedTag, Read } 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); } diff --git a/src/libraries/Common/src/System/Security/Cryptography/Asn1/Pkcs12/MacData.xml.cs b/src/libraries/Common/src/System/Security/Cryptography/Asn1/Pkcs12/MacData.xml.cs index cf059b72be739..da404561afb87 100644 --- a/src/libraries/Common/src/System/Security/Cryptography/Asn1/Pkcs12/MacData.xml.cs +++ b/src/libraries/Common/src/System/Security/Cryptography/Asn1/Pkcs12/MacData.xml.cs @@ -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 DefaultIterationCount => new byte[] { 0x02, 0x01, 0x01 }; internal System.Security.Cryptography.Asn1.DigestInfoAsn Mac; internal ReadOnlyMemory MacSalt; @@ -25,7 +25,7 @@ static MacData() 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 @@ internal void Encode(AsnWriter writer, Asn1Tag tag) tmp.WriteInteger(IterationCount); ReadOnlySpan encoded = tmp.EncodeAsSpan(); - if (!encoded.SequenceEqual(s_defaultIterationCount)) + if (!encoded.SequenceEqual(DefaultIterationCount)) { writer.WriteEncodedValue(encoded); } @@ -116,7 +116,7 @@ internal static void Decode(ref AsnValueReader reader, Asn1Tag expectedTag, Read } else { - defaultReader = new AsnValueReader(s_defaultIterationCount, AsnEncodingRules.DER); + defaultReader = new AsnValueReader(DefaultIterationCount, AsnEncodingRules.DER); if (!defaultReader.TryReadInt32(out decoded.IterationCount)) { diff --git a/src/libraries/Common/src/System/Security/Cryptography/Asn1/PssParamsAsn.xml.cs b/src/libraries/Common/src/System/Security/Cryptography/Asn1/PssParamsAsn.xml.cs index 78985e2b8ca77..6c42acd09a1cc 100644 --- a/src/libraries/Common/src/System/Security/Cryptography/Asn1/PssParamsAsn.xml.cs +++ b/src/libraries/Common/src/System/Security/Cryptography/Asn1/PssParamsAsn.xml.cs @@ -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 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 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 DefaultSaltLength => new byte[] { 0x02, 0x01, 0x14 }; - private static readonly byte[] s_defaultTrailerField = { 0x02, 0x01, 0x01 }; + private static ReadOnlySpan DefaultTrailerField => new byte[] { 0x02, 0x01, 0x01 }; internal System.Security.Cryptography.Asn1.AlgorithmIdentifierAsn HashAlgorithm; internal System.Security.Cryptography.Asn1.AlgorithmIdentifierAsn MaskGenAlgorithm; @@ -33,15 +33,15 @@ static PssParamsAsn() ReadOnlyMemory 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 @@ static PssParamsAsn() 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 @@ internal void Encode(AsnWriter writer, Asn1Tag tag) HashAlgorithm.Encode(tmp); ReadOnlySpan 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 @@ internal void Encode(AsnWriter writer, Asn1Tag tag) MaskGenAlgorithm.Encode(tmp); ReadOnlySpan 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 @@ internal void Encode(AsnWriter writer, Asn1Tag tag) tmp.WriteInteger(SaltLength); ReadOnlySpan 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 @@ internal void Encode(AsnWriter writer, Asn1Tag tag) tmp.WriteInteger(TrailerField); ReadOnlySpan 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 @@ internal static void Decode(ref AsnValueReader reader, Asn1Tag expectedTag, Read } 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 @@ internal static void Decode(ref AsnValueReader reader, Asn1Tag expectedTag, Read } 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 @@ internal static void Decode(ref AsnValueReader reader, Asn1Tag expectedTag, Read } else { - defaultReader = new AsnValueReader(s_defaultSaltLength, AsnEncodingRules.DER); + defaultReader = new AsnValueReader(DefaultSaltLength, AsnEncodingRules.DER); if (!defaultReader.TryReadInt32(out decoded.SaltLength)) { @@ -230,7 +230,7 @@ internal static void Decode(ref AsnValueReader reader, Asn1Tag expectedTag, Read } else { - defaultReader = new AsnValueReader(s_defaultTrailerField, AsnEncodingRules.DER); + defaultReader = new AsnValueReader(DefaultTrailerField, AsnEncodingRules.DER); if (!defaultReader.TryReadInt32(out decoded.TrailerField)) { diff --git a/src/libraries/Common/src/System/Security/Cryptography/Asn1/X509ExtensionAsn.xml.cs b/src/libraries/Common/src/System/Security/Cryptography/Asn1/X509ExtensionAsn.xml.cs index 0c447e9bf6bf3..45ead32bef0c2 100644 --- a/src/libraries/Common/src/System/Security/Cryptography/Asn1/X509ExtensionAsn.xml.cs +++ b/src/libraries/Common/src/System/Security/Cryptography/Asn1/X509ExtensionAsn.xml.cs @@ -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 DefaultCritical => new byte[] { 0x01, 0x01, 0x00 }; internal Oid ExtnId; internal bool Critical; @@ -25,7 +25,7 @@ static X509ExtensionAsn() 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 @@ internal void Encode(AsnWriter writer, Asn1Tag tag) tmp.WriteBoolean(Critical); ReadOnlySpan encoded = tmp.EncodeAsSpan(); - if (!encoded.SequenceEqual(s_defaultCritical)) + if (!encoded.SequenceEqual(DefaultCritical)) { writer.WriteEncodedValue(encoded); } @@ -96,7 +96,7 @@ internal static void Decode(ref AsnValueReader reader, Asn1Tag expectedTag, Read } else { - defaultReader = new AsnValueReader(s_defaultCritical, AsnEncodingRules.DER); + defaultReader = new AsnValueReader(DefaultCritical, AsnEncodingRules.DER); decoded.Critical = defaultReader.ReadBoolean(); } diff --git a/src/libraries/Common/src/System/Security/Cryptography/Asn1/asn.xslt b/src/libraries/Common/src/System/Security/Cryptography/Asn1/asn.xslt index a182bd6ba865b..b6866081ab6d4 100644 --- a/src/libraries/Common/src/System/Security/Cryptography/Asn1/asn.xslt +++ b/src/libraries/Common/src/System/Security/Cryptography/Asn1/asn.xslt @@ -213,7 +213,7 @@ namespace - private static readonly byte[] = { }; + private static ReadOnlySpan<byte> => new byte[] { }; @@ -909,7 +909,7 @@ namespace new Asn1Tag(TagClass.ContextSpecific, ) - s_default + Default else diff --git a/src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/Asn1/EssCertIdV2.xml.cs b/src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/Asn1/EssCertIdV2.xml.cs index cfff6e464007b..df54bc64b5efe 100644 --- a/src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/Asn1/EssCertIdV2.xml.cs +++ b/src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/Asn1/EssCertIdV2.xml.cs @@ -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 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 Hash; @@ -26,7 +26,7 @@ static EssCertIdV2() ReadOnlyMemory 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 @@ internal void Encode(AsnWriter writer, Asn1Tag tag) HashAlgorithm.Encode(tmp); ReadOnlySpan encoded = tmp.EncodeAsSpan(); - if (!encoded.SequenceEqual(s_defaultHashAlgorithm)) + if (!encoded.SequenceEqual(DefaultHashAlgorithm)) { writer.WriteEncodedValue(encoded); } @@ -101,7 +101,7 @@ internal static void Decode(ref AsnValueReader reader, Asn1Tag expectedTag, Read } 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); } diff --git a/src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/Asn1/Rfc3161TimeStampReq.xml.cs b/src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/Asn1/Rfc3161TimeStampReq.xml.cs index d31c8fc023661..f99b08c3121c5 100644 --- a/src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/Asn1/Rfc3161TimeStampReq.xml.cs +++ b/src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/Asn1/Rfc3161TimeStampReq.xml.cs @@ -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 DefaultCertReq => new byte[] { 0x01, 0x01, 0x00 }; internal int Version; internal System.Security.Cryptography.Pkcs.Asn1.MessageImprint MessageImprint; @@ -29,7 +29,7 @@ static Rfc3161TimeStampReq() 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 @@ internal void Encode(AsnWriter writer, Asn1Tag tag) tmp.WriteBoolean(CertReq); ReadOnlySpan encoded = tmp.EncodeAsSpan(); - if (!encoded.SequenceEqual(s_defaultCertReq)) + if (!encoded.SequenceEqual(DefaultCertReq)) { writer.WriteEncodedValue(encoded); } @@ -145,7 +145,7 @@ internal static void Decode(ref AsnValueReader reader, Asn1Tag expectedTag, Read } else { - defaultReader = new AsnValueReader(s_defaultCertReq, AsnEncodingRules.DER); + defaultReader = new AsnValueReader(DefaultCertReq, AsnEncodingRules.DER); decoded.CertReq = defaultReader.ReadBoolean(); } diff --git a/src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/Asn1/Rfc3161TstInfo.xml.cs b/src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/Asn1/Rfc3161TstInfo.xml.cs index ff0a95b202a62..8bf7ca2a8a65f 100644 --- a/src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/Asn1/Rfc3161TstInfo.xml.cs +++ b/src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/Asn1/Rfc3161TstInfo.xml.cs @@ -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 DefaultOrdering => new byte[] { 0x01, 0x01, 0x00 }; internal int Version; internal Oid Policy; @@ -33,7 +33,7 @@ static Rfc3161TstInfo() 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 @@ internal void Encode(AsnWriter writer, Asn1Tag tag) tmp.WriteBoolean(Ordering); ReadOnlySpan encoded = tmp.EncodeAsSpan(); - if (!encoded.SequenceEqual(s_defaultOrdering)) + if (!encoded.SequenceEqual(DefaultOrdering)) { writer.WriteEncodedValue(encoded); } @@ -161,7 +161,7 @@ internal static void Decode(ref AsnValueReader reader, Asn1Tag expectedTag, Read } else { - defaultReader = new AsnValueReader(s_defaultOrdering, AsnEncodingRules.DER); + defaultReader = new AsnValueReader(DefaultOrdering, AsnEncodingRules.DER); decoded.Ordering = defaultReader.ReadBoolean(); } diff --git a/src/libraries/System.Security.Cryptography.X509Certificates/src/System/Security/Cryptography/X509Certificates/Asn1/BasicConstraintsAsn.xml.cs b/src/libraries/System.Security.Cryptography.X509Certificates/src/System/Security/Cryptography/X509Certificates/Asn1/BasicConstraintsAsn.xml.cs index abd25078a0c36..400b063f8c739 100644 --- a/src/libraries/System.Security.Cryptography.X509Certificates/src/System/Security/Cryptography/X509Certificates/Asn1/BasicConstraintsAsn.xml.cs +++ b/src/libraries/System.Security.Cryptography.X509Certificates/src/System/Security/Cryptography/X509Certificates/Asn1/BasicConstraintsAsn.xml.cs @@ -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 DefaultCA => new byte[] { 0x01, 0x01, 0x00 }; internal bool CA; internal int? PathLengthConstraint; @@ -24,7 +24,7 @@ static BasicConstraintsAsn() 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 @@ internal void Encode(AsnWriter writer, Asn1Tag tag) tmp.WriteBoolean(CA); ReadOnlySpan encoded = tmp.EncodeAsSpan(); - if (!encoded.SequenceEqual(s_defaultCA)) + if (!encoded.SequenceEqual(DefaultCA)) { writer.WriteEncodedValue(encoded); } @@ -95,7 +95,7 @@ internal static void Decode(ref AsnValueReader reader, Asn1Tag expectedTag, Read } else { - defaultReader = new AsnValueReader(s_defaultCA, AsnEncodingRules.DER); + defaultReader = new AsnValueReader(DefaultCA, AsnEncodingRules.DER); decoded.CA = defaultReader.ReadBoolean(); } diff --git a/src/libraries/System.Security.Cryptography.X509Certificates/src/System/Security/Cryptography/X509Certificates/Asn1/TbsCertificateAsn.xml.cs b/src/libraries/System.Security.Cryptography.X509Certificates/src/System/Security/Cryptography/X509Certificates/Asn1/TbsCertificateAsn.xml.cs index 241ba953bb774..cdebe2a89be97 100644 --- a/src/libraries/System.Security.Cryptography.X509Certificates/src/System/Security/Cryptography/X509Certificates/Asn1/TbsCertificateAsn.xml.cs +++ b/src/libraries/System.Security.Cryptography.X509Certificates/src/System/Security/Cryptography/X509Certificates/Asn1/TbsCertificateAsn.xml.cs @@ -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 DefaultVersion => new byte[] { 0x02, 0x01, 0x00 }; internal int Version; internal ReadOnlyMemory SerialNumber; @@ -33,7 +33,7 @@ static TbsCertificateAsn() 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 @@ internal void Encode(AsnWriter writer, Asn1Tag tag) tmp.WriteInteger(Version); ReadOnlySpan 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 @@ internal static void Decode(ref AsnValueReader reader, Asn1Tag expectedTag, Read } else { - defaultReader = new AsnValueReader(s_defaultVersion, AsnEncodingRules.DER); + defaultReader = new AsnValueReader(DefaultVersion, AsnEncodingRules.DER); if (!defaultReader.TryReadInt32(out decoded.Version)) {