From f9442edb9279563a2be156f485dfd109634e082a Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Wed, 20 Jul 2022 09:19:52 -0700 Subject: [PATCH 1/7] Annotating System.Formats.Asn1 library for Aot --- .../System.Formats.Asn1/ref/System.Formats.Asn1.cs | 8 ++++++++ .../System.Formats.Asn1/ref/System.Formats.Asn1.csproj | 4 ++++ .../System.Formats.Asn1/src/System.Formats.Asn1.csproj | 5 +++++ .../src/System/Formats/Asn1/AsnDecoder.Enumerated.cs | 5 +++++ .../src/System/Formats/Asn1/AsnDecoder.NamedBitList.cs | 5 +++++ 5 files changed, 27 insertions(+) diff --git a/src/libraries/System.Formats.Asn1/ref/System.Formats.Asn1.cs b/src/libraries/System.Formats.Asn1/ref/System.Formats.Asn1.cs index d649ad56879a8d..a0e66d5549fd6a 100644 --- a/src/libraries/System.Formats.Asn1/ref/System.Formats.Asn1.cs +++ b/src/libraries/System.Formats.Asn1/ref/System.Formats.Asn1.cs @@ -56,13 +56,17 @@ public static partial class AsnDecoder public static string ReadCharacterString(System.ReadOnlySpan source, System.Formats.Asn1.AsnEncodingRules ruleSet, System.Formats.Asn1.UniversalTagNumber encodingType, out int bytesConsumed, System.Formats.Asn1.Asn1Tag? expectedTag = default(System.Formats.Asn1.Asn1Tag?)) { throw null; } public static System.Formats.Asn1.Asn1Tag ReadEncodedValue(System.ReadOnlySpan source, System.Formats.Asn1.AsnEncodingRules ruleSet, out int contentOffset, out int contentLength, out int bytesConsumed) { throw null; } public static System.ReadOnlySpan ReadEnumeratedBytes(System.ReadOnlySpan source, System.Formats.Asn1.AsnEncodingRules ruleSet, out int bytesConsumed, System.Formats.Asn1.Asn1Tag? expectedTag = default(System.Formats.Asn1.Asn1Tag?)) { throw null; } + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("The enum type might not be available at runtime.")] public static System.Enum ReadEnumeratedValue(System.ReadOnlySpan source, System.Formats.Asn1.AsnEncodingRules ruleSet, System.Type enumType, out int bytesConsumed, System.Formats.Asn1.Asn1Tag? expectedTag = default(System.Formats.Asn1.Asn1Tag?)) { throw null; } + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("The enum type might not be available at runtime.")] public static TEnum ReadEnumeratedValue(System.ReadOnlySpan source, System.Formats.Asn1.AsnEncodingRules ruleSet, out int bytesConsumed, System.Formats.Asn1.Asn1Tag? expectedTag = default(System.Formats.Asn1.Asn1Tag?)) where TEnum : System.Enum { throw null; } public static System.DateTimeOffset ReadGeneralizedTime(System.ReadOnlySpan source, System.Formats.Asn1.AsnEncodingRules ruleSet, out int bytesConsumed, System.Formats.Asn1.Asn1Tag? expectedTag = default(System.Formats.Asn1.Asn1Tag?)) { throw null; } public static System.Numerics.BigInteger ReadInteger(System.ReadOnlySpan source, System.Formats.Asn1.AsnEncodingRules ruleSet, out int bytesConsumed, System.Formats.Asn1.Asn1Tag? expectedTag = default(System.Formats.Asn1.Asn1Tag?)) { throw null; } public static System.ReadOnlySpan ReadIntegerBytes(System.ReadOnlySpan source, System.Formats.Asn1.AsnEncodingRules ruleSet, out int bytesConsumed, System.Formats.Asn1.Asn1Tag? expectedTag = default(System.Formats.Asn1.Asn1Tag?)) { throw null; } public static System.Collections.BitArray ReadNamedBitList(System.ReadOnlySpan source, System.Formats.Asn1.AsnEncodingRules ruleSet, out int bytesConsumed, System.Formats.Asn1.Asn1Tag? expectedTag = default(System.Formats.Asn1.Asn1Tag?)) { throw null; } + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("The enum type might not be available at runtime.")] public static System.Enum ReadNamedBitListValue(System.ReadOnlySpan source, System.Formats.Asn1.AsnEncodingRules ruleSet, System.Type flagsEnumType, out int bytesConsumed, System.Formats.Asn1.Asn1Tag? expectedTag = default(System.Formats.Asn1.Asn1Tag?)) { throw null; } + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("The enum type might not be available at runtime.")] public static TFlagsEnum ReadNamedBitListValue(System.ReadOnlySpan source, System.Formats.Asn1.AsnEncodingRules ruleSet, out int bytesConsumed, System.Formats.Asn1.Asn1Tag? expectedTag = default(System.Formats.Asn1.Asn1Tag?)) where TFlagsEnum : System.Enum { throw null; } public static void ReadNull(System.ReadOnlySpan source, System.Formats.Asn1.AsnEncodingRules ruleSet, out int bytesConsumed, System.Formats.Asn1.Asn1Tag? expectedTag = default(System.Formats.Asn1.Asn1Tag?)) { throw null; } public static string ReadObjectIdentifier(System.ReadOnlySpan source, System.Formats.Asn1.AsnEncodingRules ruleSet, out int bytesConsumed, System.Formats.Asn1.Asn1Tag? expectedTag = default(System.Formats.Asn1.Asn1Tag?)) { throw null; } @@ -104,13 +108,17 @@ public partial class AsnReader public string ReadCharacterString(System.Formats.Asn1.UniversalTagNumber encodingType, System.Formats.Asn1.Asn1Tag? expectedTag = default(System.Formats.Asn1.Asn1Tag?)) { throw null; } public System.ReadOnlyMemory ReadEncodedValue() { throw null; } public System.ReadOnlyMemory ReadEnumeratedBytes(System.Formats.Asn1.Asn1Tag? expectedTag = default(System.Formats.Asn1.Asn1Tag?)) { throw null; } + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("The enum type might not be available at runtime.")] public System.Enum ReadEnumeratedValue(System.Type enumType, System.Formats.Asn1.Asn1Tag? expectedTag = default(System.Formats.Asn1.Asn1Tag?)) { throw null; } + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("The enum type might not be available at runtime.")] public TEnum ReadEnumeratedValue(System.Formats.Asn1.Asn1Tag? expectedTag = default(System.Formats.Asn1.Asn1Tag?)) where TEnum : System.Enum { throw null; } public System.DateTimeOffset ReadGeneralizedTime(System.Formats.Asn1.Asn1Tag? expectedTag = default(System.Formats.Asn1.Asn1Tag?)) { throw null; } public System.Numerics.BigInteger ReadInteger(System.Formats.Asn1.Asn1Tag? expectedTag = default(System.Formats.Asn1.Asn1Tag?)) { throw null; } public System.ReadOnlyMemory ReadIntegerBytes(System.Formats.Asn1.Asn1Tag? expectedTag = default(System.Formats.Asn1.Asn1Tag?)) { throw null; } public System.Collections.BitArray ReadNamedBitList(System.Formats.Asn1.Asn1Tag? expectedTag = default(System.Formats.Asn1.Asn1Tag?)) { throw null; } + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("The enum type might not be available at runtime.")] public System.Enum ReadNamedBitListValue(System.Type flagsEnumType, System.Formats.Asn1.Asn1Tag? expectedTag = default(System.Formats.Asn1.Asn1Tag?)) { throw null; } + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("The enum type might not be available at runtime.")] public TFlagsEnum ReadNamedBitListValue(System.Formats.Asn1.Asn1Tag? expectedTag = default(System.Formats.Asn1.Asn1Tag?)) where TFlagsEnum : System.Enum { throw null; } public void ReadNull(System.Formats.Asn1.Asn1Tag? expectedTag = default(System.Formats.Asn1.Asn1Tag?)) { } public string ReadObjectIdentifier(System.Formats.Asn1.Asn1Tag? expectedTag = default(System.Formats.Asn1.Asn1Tag?)) { throw null; } diff --git a/src/libraries/System.Formats.Asn1/ref/System.Formats.Asn1.csproj b/src/libraries/System.Formats.Asn1/ref/System.Formats.Asn1.csproj index d259de65660aa1..7122ad2d5b0545 100644 --- a/src/libraries/System.Formats.Asn1/ref/System.Formats.Asn1.csproj +++ b/src/libraries/System.Formats.Asn1/ref/System.Formats.Asn1.csproj @@ -13,6 +13,10 @@ + + + + diff --git a/src/libraries/System.Formats.Asn1/src/System.Formats.Asn1.csproj b/src/libraries/System.Formats.Asn1/src/System.Formats.Asn1.csproj index ba71d9c02375d7..5636e1fbed996c 100644 --- a/src/libraries/System.Formats.Asn1/src/System.Formats.Asn1.csproj +++ b/src/libraries/System.Formats.Asn1/src/System.Formats.Asn1.csproj @@ -4,6 +4,7 @@ true $(DefineConstants);CP_NO_ZEROMEMORY true + true Provides classes that can read and write the ASN.1 BER, CER, and DER data formats. Commonly Used Types: @@ -62,6 +63,10 @@ System.Formats.Asn1.AsnWriter + + + + diff --git a/src/libraries/System.Formats.Asn1/src/System/Formats/Asn1/AsnDecoder.Enumerated.cs b/src/libraries/System.Formats.Asn1/src/System/Formats/Asn1/AsnDecoder.Enumerated.cs index 4bf10cc8b231ff..5b9d2c2032ef31 100644 --- a/src/libraries/System.Formats.Asn1/src/System/Formats/Asn1/AsnDecoder.Enumerated.cs +++ b/src/libraries/System.Formats.Asn1/src/System/Formats/Asn1/AsnDecoder.Enumerated.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; namespace System.Formats.Asn1 @@ -113,6 +114,7 @@ public static ReadOnlySpan ReadEnumeratedBytes( /// . is not correct for /// the method. /// + [RequiresDynamicCode("The enum type might not be available at runtime.")] public static TEnum ReadEnumeratedValue( ReadOnlySpan source, AsnEncodingRules ruleSet, @@ -186,6 +188,7 @@ public static TEnum ReadEnumeratedValue( /// /// is . /// + [RequiresDynamicCode("The enum type might not be available at runtime.")] public static Enum ReadEnumeratedValue( ReadOnlySpan source, AsnEncodingRules ruleSet, @@ -347,6 +350,7 @@ public ReadOnlyMemory ReadEnumeratedBytes(Asn1Tag? expectedTag = null) /// . is not correct for /// the method. /// + [RequiresDynamicCode("The enum type might not be available at runtime.")] public TEnum ReadEnumeratedValue(Asn1Tag? expectedTag = null) where TEnum : Enum { TEnum ret = AsnDecoder.ReadEnumeratedValue(_data.Span, RuleSet, out int consumed, expectedTag); @@ -401,6 +405,7 @@ public TEnum ReadEnumeratedValue(Asn1Tag? expectedTag = null) where TEnum /// /// is . /// + [RequiresDynamicCode("The enum type might not be available at runtime.")] public Enum ReadEnumeratedValue(Type enumType, Asn1Tag? expectedTag = null) { Enum ret = AsnDecoder.ReadEnumeratedValue(_data.Span, RuleSet, enumType, out int consumed, expectedTag); diff --git a/src/libraries/System.Formats.Asn1/src/System/Formats/Asn1/AsnDecoder.NamedBitList.cs b/src/libraries/System.Formats.Asn1/src/System/Formats/Asn1/AsnDecoder.NamedBitList.cs index ec1da0d280765c..5055b2f0055686 100644 --- a/src/libraries/System.Formats.Asn1/src/System/Formats/Asn1/AsnDecoder.NamedBitList.cs +++ b/src/libraries/System.Formats.Asn1/src/System/Formats/Asn1/AsnDecoder.NamedBitList.cs @@ -3,6 +3,7 @@ using System.Collections; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; using System.Security.Cryptography; @@ -102,6 +103,7 @@ public static partial class AsnDecoder /// the example enum uses values thar are different from /// System.Security.Cryptography.X509Certificates.X509KeyUsageFlags. /// + [RequiresDynamicCode("The enum type might not be available at runtime.")] public static TFlagsEnum ReadNamedBitListValue( ReadOnlySpan source, AsnEncodingRules ruleSet, @@ -174,6 +176,7 @@ public static TFlagsEnum ReadNamedBitListValue( /// is /// /// + [RequiresDynamicCode("The enum type might not be available at runtime.")] public static Enum ReadNamedBitListValue( ReadOnlySpan source, AsnEncodingRules ruleSet, @@ -490,6 +493,7 @@ public partial class AsnReader /// the example enum uses values thar are different from /// System.Security.Cryptography.X509Certificates.X509KeyUsageFlags. /// + [RequiresDynamicCode("The enum type might not be available at runtime.")] public TFlagsEnum ReadNamedBitListValue(Asn1Tag? expectedTag = null) where TFlagsEnum : Enum { TFlagsEnum ret = AsnDecoder.ReadNamedBitListValue( @@ -544,6 +548,7 @@ public TFlagsEnum ReadNamedBitListValue(Asn1Tag? expectedTag = null) /// is /// /// + [RequiresDynamicCode("The enum type might not be available at runtime.")] public Enum ReadNamedBitListValue(Type flagsEnumType, Asn1Tag? expectedTag = null) { Enum ret = AsnDecoder.ReadNamedBitListValue( From 0badaa5744eb5c8d3daa699c257fce23ea56c1a9 Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Wed, 20 Jul 2022 11:11:36 -0700 Subject: [PATCH 2/7] FB --- .../System.Formats.Asn1/ref/System.Formats.Asn1.cs | 8 -------- .../ref/System.Formats.Asn1.csproj | 4 ---- .../src/System.Formats.Asn1.csproj | 4 ---- .../System/Formats/Asn1/AsnDecoder.Enumerated.cs | 7 +------ .../System/Formats/Asn1/AsnDecoder.NamedBitList.cs | 7 +------ .../src/System/Formats/Asn1/AsnDecoder.cs | 13 +++++++++++++ 6 files changed, 15 insertions(+), 28 deletions(-) diff --git a/src/libraries/System.Formats.Asn1/ref/System.Formats.Asn1.cs b/src/libraries/System.Formats.Asn1/ref/System.Formats.Asn1.cs index a0e66d5549fd6a..d649ad56879a8d 100644 --- a/src/libraries/System.Formats.Asn1/ref/System.Formats.Asn1.cs +++ b/src/libraries/System.Formats.Asn1/ref/System.Formats.Asn1.cs @@ -56,17 +56,13 @@ public static partial class AsnDecoder public static string ReadCharacterString(System.ReadOnlySpan source, System.Formats.Asn1.AsnEncodingRules ruleSet, System.Formats.Asn1.UniversalTagNumber encodingType, out int bytesConsumed, System.Formats.Asn1.Asn1Tag? expectedTag = default(System.Formats.Asn1.Asn1Tag?)) { throw null; } public static System.Formats.Asn1.Asn1Tag ReadEncodedValue(System.ReadOnlySpan source, System.Formats.Asn1.AsnEncodingRules ruleSet, out int contentOffset, out int contentLength, out int bytesConsumed) { throw null; } public static System.ReadOnlySpan ReadEnumeratedBytes(System.ReadOnlySpan source, System.Formats.Asn1.AsnEncodingRules ruleSet, out int bytesConsumed, System.Formats.Asn1.Asn1Tag? expectedTag = default(System.Formats.Asn1.Asn1Tag?)) { throw null; } - [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("The enum type might not be available at runtime.")] public static System.Enum ReadEnumeratedValue(System.ReadOnlySpan source, System.Formats.Asn1.AsnEncodingRules ruleSet, System.Type enumType, out int bytesConsumed, System.Formats.Asn1.Asn1Tag? expectedTag = default(System.Formats.Asn1.Asn1Tag?)) { throw null; } - [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("The enum type might not be available at runtime.")] public static TEnum ReadEnumeratedValue(System.ReadOnlySpan source, System.Formats.Asn1.AsnEncodingRules ruleSet, out int bytesConsumed, System.Formats.Asn1.Asn1Tag? expectedTag = default(System.Formats.Asn1.Asn1Tag?)) where TEnum : System.Enum { throw null; } public static System.DateTimeOffset ReadGeneralizedTime(System.ReadOnlySpan source, System.Formats.Asn1.AsnEncodingRules ruleSet, out int bytesConsumed, System.Formats.Asn1.Asn1Tag? expectedTag = default(System.Formats.Asn1.Asn1Tag?)) { throw null; } public static System.Numerics.BigInteger ReadInteger(System.ReadOnlySpan source, System.Formats.Asn1.AsnEncodingRules ruleSet, out int bytesConsumed, System.Formats.Asn1.Asn1Tag? expectedTag = default(System.Formats.Asn1.Asn1Tag?)) { throw null; } public static System.ReadOnlySpan ReadIntegerBytes(System.ReadOnlySpan source, System.Formats.Asn1.AsnEncodingRules ruleSet, out int bytesConsumed, System.Formats.Asn1.Asn1Tag? expectedTag = default(System.Formats.Asn1.Asn1Tag?)) { throw null; } public static System.Collections.BitArray ReadNamedBitList(System.ReadOnlySpan source, System.Formats.Asn1.AsnEncodingRules ruleSet, out int bytesConsumed, System.Formats.Asn1.Asn1Tag? expectedTag = default(System.Formats.Asn1.Asn1Tag?)) { throw null; } - [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("The enum type might not be available at runtime.")] public static System.Enum ReadNamedBitListValue(System.ReadOnlySpan source, System.Formats.Asn1.AsnEncodingRules ruleSet, System.Type flagsEnumType, out int bytesConsumed, System.Formats.Asn1.Asn1Tag? expectedTag = default(System.Formats.Asn1.Asn1Tag?)) { throw null; } - [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("The enum type might not be available at runtime.")] public static TFlagsEnum ReadNamedBitListValue(System.ReadOnlySpan source, System.Formats.Asn1.AsnEncodingRules ruleSet, out int bytesConsumed, System.Formats.Asn1.Asn1Tag? expectedTag = default(System.Formats.Asn1.Asn1Tag?)) where TFlagsEnum : System.Enum { throw null; } public static void ReadNull(System.ReadOnlySpan source, System.Formats.Asn1.AsnEncodingRules ruleSet, out int bytesConsumed, System.Formats.Asn1.Asn1Tag? expectedTag = default(System.Formats.Asn1.Asn1Tag?)) { throw null; } public static string ReadObjectIdentifier(System.ReadOnlySpan source, System.Formats.Asn1.AsnEncodingRules ruleSet, out int bytesConsumed, System.Formats.Asn1.Asn1Tag? expectedTag = default(System.Formats.Asn1.Asn1Tag?)) { throw null; } @@ -108,17 +104,13 @@ public partial class AsnReader public string ReadCharacterString(System.Formats.Asn1.UniversalTagNumber encodingType, System.Formats.Asn1.Asn1Tag? expectedTag = default(System.Formats.Asn1.Asn1Tag?)) { throw null; } public System.ReadOnlyMemory ReadEncodedValue() { throw null; } public System.ReadOnlyMemory ReadEnumeratedBytes(System.Formats.Asn1.Asn1Tag? expectedTag = default(System.Formats.Asn1.Asn1Tag?)) { throw null; } - [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("The enum type might not be available at runtime.")] public System.Enum ReadEnumeratedValue(System.Type enumType, System.Formats.Asn1.Asn1Tag? expectedTag = default(System.Formats.Asn1.Asn1Tag?)) { throw null; } - [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("The enum type might not be available at runtime.")] public TEnum ReadEnumeratedValue(System.Formats.Asn1.Asn1Tag? expectedTag = default(System.Formats.Asn1.Asn1Tag?)) where TEnum : System.Enum { throw null; } public System.DateTimeOffset ReadGeneralizedTime(System.Formats.Asn1.Asn1Tag? expectedTag = default(System.Formats.Asn1.Asn1Tag?)) { throw null; } public System.Numerics.BigInteger ReadInteger(System.Formats.Asn1.Asn1Tag? expectedTag = default(System.Formats.Asn1.Asn1Tag?)) { throw null; } public System.ReadOnlyMemory ReadIntegerBytes(System.Formats.Asn1.Asn1Tag? expectedTag = default(System.Formats.Asn1.Asn1Tag?)) { throw null; } public System.Collections.BitArray ReadNamedBitList(System.Formats.Asn1.Asn1Tag? expectedTag = default(System.Formats.Asn1.Asn1Tag?)) { throw null; } - [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("The enum type might not be available at runtime.")] public System.Enum ReadNamedBitListValue(System.Type flagsEnumType, System.Formats.Asn1.Asn1Tag? expectedTag = default(System.Formats.Asn1.Asn1Tag?)) { throw null; } - [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("The enum type might not be available at runtime.")] public TFlagsEnum ReadNamedBitListValue(System.Formats.Asn1.Asn1Tag? expectedTag = default(System.Formats.Asn1.Asn1Tag?)) where TFlagsEnum : System.Enum { throw null; } public void ReadNull(System.Formats.Asn1.Asn1Tag? expectedTag = default(System.Formats.Asn1.Asn1Tag?)) { } public string ReadObjectIdentifier(System.Formats.Asn1.Asn1Tag? expectedTag = default(System.Formats.Asn1.Asn1Tag?)) { throw null; } diff --git a/src/libraries/System.Formats.Asn1/ref/System.Formats.Asn1.csproj b/src/libraries/System.Formats.Asn1/ref/System.Formats.Asn1.csproj index 7122ad2d5b0545..d259de65660aa1 100644 --- a/src/libraries/System.Formats.Asn1/ref/System.Formats.Asn1.csproj +++ b/src/libraries/System.Formats.Asn1/ref/System.Formats.Asn1.csproj @@ -13,10 +13,6 @@ - - - - diff --git a/src/libraries/System.Formats.Asn1/src/System.Formats.Asn1.csproj b/src/libraries/System.Formats.Asn1/src/System.Formats.Asn1.csproj index 5636e1fbed996c..59eb334f328cd6 100644 --- a/src/libraries/System.Formats.Asn1/src/System.Formats.Asn1.csproj +++ b/src/libraries/System.Formats.Asn1/src/System.Formats.Asn1.csproj @@ -64,10 +64,6 @@ System.Formats.Asn1.AsnWriter - - - - diff --git a/src/libraries/System.Formats.Asn1/src/System/Formats/Asn1/AsnDecoder.Enumerated.cs b/src/libraries/System.Formats.Asn1/src/System/Formats/Asn1/AsnDecoder.Enumerated.cs index 5b9d2c2032ef31..04435e147aedf4 100644 --- a/src/libraries/System.Formats.Asn1/src/System/Formats/Asn1/AsnDecoder.Enumerated.cs +++ b/src/libraries/System.Formats.Asn1/src/System/Formats/Asn1/AsnDecoder.Enumerated.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; namespace System.Formats.Asn1 @@ -114,7 +113,6 @@ public static ReadOnlySpan ReadEnumeratedBytes( /// . is not correct for /// the method. /// - [RequiresDynamicCode("The enum type might not be available at runtime.")] public static TEnum ReadEnumeratedValue( ReadOnlySpan source, AsnEncodingRules ruleSet, @@ -188,7 +186,6 @@ public static TEnum ReadEnumeratedValue( /// /// is . /// - [RequiresDynamicCode("The enum type might not be available at runtime.")] public static Enum ReadEnumeratedValue( ReadOnlySpan source, AsnEncodingRules ruleSet, @@ -214,7 +211,7 @@ public static Enum ReadEnumeratedValue( } // T-REC-X.690-201508 sec 8.4 says the contents are the same as for integers. - int sizeLimit = Marshal.SizeOf(backingType); + int sizeLimit = GetPrimitiveIntegerSize(backingType); if (backingType == typeof(int) || backingType == typeof(long) || @@ -350,7 +347,6 @@ public ReadOnlyMemory ReadEnumeratedBytes(Asn1Tag? expectedTag = null) /// . is not correct for /// the method. /// - [RequiresDynamicCode("The enum type might not be available at runtime.")] public TEnum ReadEnumeratedValue(Asn1Tag? expectedTag = null) where TEnum : Enum { TEnum ret = AsnDecoder.ReadEnumeratedValue(_data.Span, RuleSet, out int consumed, expectedTag); @@ -405,7 +401,6 @@ public TEnum ReadEnumeratedValue(Asn1Tag? expectedTag = null) where TEnum /// /// is . /// - [RequiresDynamicCode("The enum type might not be available at runtime.")] public Enum ReadEnumeratedValue(Type enumType, Asn1Tag? expectedTag = null) { Enum ret = AsnDecoder.ReadEnumeratedValue(_data.Span, RuleSet, enumType, out int consumed, expectedTag); diff --git a/src/libraries/System.Formats.Asn1/src/System/Formats/Asn1/AsnDecoder.NamedBitList.cs b/src/libraries/System.Formats.Asn1/src/System/Formats/Asn1/AsnDecoder.NamedBitList.cs index 5055b2f0055686..260c5a43449f6f 100644 --- a/src/libraries/System.Formats.Asn1/src/System/Formats/Asn1/AsnDecoder.NamedBitList.cs +++ b/src/libraries/System.Formats.Asn1/src/System/Formats/Asn1/AsnDecoder.NamedBitList.cs @@ -3,7 +3,6 @@ using System.Collections; using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; using System.Security.Cryptography; @@ -103,7 +102,6 @@ public static partial class AsnDecoder /// the example enum uses values thar are different from /// System.Security.Cryptography.X509Certificates.X509KeyUsageFlags. /// - [RequiresDynamicCode("The enum type might not be available at runtime.")] public static TFlagsEnum ReadNamedBitListValue( ReadOnlySpan source, AsnEncodingRules ruleSet, @@ -176,7 +174,6 @@ public static TFlagsEnum ReadNamedBitListValue( /// is /// /// - [RequiresDynamicCode("The enum type might not be available at runtime.")] public static Enum ReadNamedBitListValue( ReadOnlySpan source, AsnEncodingRules ruleSet, @@ -199,7 +196,7 @@ public static Enum ReadNamedBitListValue( } Span stackSpan = stackalloc byte[sizeof(ulong)]; - int sizeLimit = Marshal.SizeOf(backingType); + int sizeLimit = GetPrimitiveIntegerSize(backingType); stackSpan = stackSpan.Slice(0, sizeLimit); bool read = TryReadBitString( @@ -493,7 +490,6 @@ public partial class AsnReader /// the example enum uses values thar are different from /// System.Security.Cryptography.X509Certificates.X509KeyUsageFlags. /// - [RequiresDynamicCode("The enum type might not be available at runtime.")] public TFlagsEnum ReadNamedBitListValue(Asn1Tag? expectedTag = null) where TFlagsEnum : Enum { TFlagsEnum ret = AsnDecoder.ReadNamedBitListValue( @@ -548,7 +544,6 @@ public TFlagsEnum ReadNamedBitListValue(Asn1Tag? expectedTag = null) /// is /// /// - [RequiresDynamicCode("The enum type might not be available at runtime.")] public Enum ReadNamedBitListValue(Type flagsEnumType, Asn1Tag? expectedTag = null) { Enum ret = AsnDecoder.ReadNamedBitListValue( diff --git a/src/libraries/System.Formats.Asn1/src/System/Formats/Asn1/AsnDecoder.cs b/src/libraries/System.Formats.Asn1/src/System/Formats/Asn1/AsnDecoder.cs index d6f70cacab1960..aa05e57928c13f 100644 --- a/src/libraries/System.Formats.Asn1/src/System/Formats/Asn1/AsnDecoder.cs +++ b/src/libraries/System.Formats.Asn1/src/System/Formats/Asn1/AsnDecoder.cs @@ -466,6 +466,19 @@ private static AsnContentException GetValidityException(LengthValidity validity) } } + private static int GetPrimitiveIntegerSize(Type primitiveType) + { + if (primitiveType == typeof(byte) || primitiveType == typeof(sbyte)) + return 1; + if (primitiveType == typeof(short) || primitiveType == typeof(ushort)) + return 2; + if (primitiveType == typeof(int) || primitiveType == typeof(uint)) + return 4; + if (primitiveType == typeof(long) || primitiveType == typeof(ulong)) + return 8; + return 0; + } + /// /// Get the number of bytes between the start of and /// the End-of-Contents marker From 9da435c20ed67eb50f0b876aeec71d3aee2b6a28 Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Wed, 20 Jul 2022 11:27:29 -0700 Subject: [PATCH 3/7] Update src/libraries/System.Formats.Asn1/src/System.Formats.Asn1.csproj --- src/libraries/System.Formats.Asn1/src/System.Formats.Asn1.csproj | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libraries/System.Formats.Asn1/src/System.Formats.Asn1.csproj b/src/libraries/System.Formats.Asn1/src/System.Formats.Asn1.csproj index 59eb334f328cd6..8881596b6bf280 100644 --- a/src/libraries/System.Formats.Asn1/src/System.Formats.Asn1.csproj +++ b/src/libraries/System.Formats.Asn1/src/System.Formats.Asn1.csproj @@ -63,7 +63,6 @@ System.Formats.Asn1.AsnWriter - From a44401e0999356fdfdfcbd5cc128b20c74e5a97f Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Wed, 20 Jul 2022 11:28:48 -0700 Subject: [PATCH 4/7] Update src/libraries/System.Formats.Asn1/src/System.Formats.Asn1.csproj --- src/libraries/System.Formats.Asn1/src/System.Formats.Asn1.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libraries/System.Formats.Asn1/src/System.Formats.Asn1.csproj b/src/libraries/System.Formats.Asn1/src/System.Formats.Asn1.csproj index 8881596b6bf280..fe14e8c27a8708 100644 --- a/src/libraries/System.Formats.Asn1/src/System.Formats.Asn1.csproj +++ b/src/libraries/System.Formats.Asn1/src/System.Formats.Asn1.csproj @@ -63,6 +63,7 @@ System.Formats.Asn1.AsnWriter + From 64f3d0c41ece176f57311e7c45654a27462e9639 Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Wed, 20 Jul 2022 12:04:49 -0700 Subject: [PATCH 5/7] enabling the tests by exluding not supported scenarios --- .../tests/TestUtilities/System/PlatformDetection.cs | 2 ++ .../System.Formats.Asn1/tests/Reader/ReadLength.cs | 12 ++++++------ src/libraries/tests.proj | 1 - 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs b/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs index 682166af146cbf..ed0ffd5b514a4a 100644 --- a/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs +++ b/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs @@ -141,6 +141,8 @@ private static bool GetLinqExpressionsBuiltWithIsInterpretingOnly() public static bool IsMetadataUpdateSupported => !IsNativeAot; + public static bool IsBoxedByRefLikeValuesSupported => !IsNativeAot; + // System.Security.Cryptography.Xml.XmlDsigXsltTransform.GetOutput() relies on XslCompiledTransform which relies // heavily on Reflection.Emit public static bool IsXmlDsigXsltTransformSupported => !PlatformDetection.IsInAppContainer && IsReflectionEmitSupported; diff --git a/src/libraries/System.Formats.Asn1/tests/Reader/ReadLength.cs b/src/libraries/System.Formats.Asn1/tests/Reader/ReadLength.cs index e2238ce7c687b8..ff41c11bd2df70 100644 --- a/src/libraries/System.Formats.Asn1/tests/Reader/ReadLength.cs +++ b/src/libraries/System.Formats.Asn1/tests/Reader/ReadLength.cs @@ -19,7 +19,7 @@ private delegate Asn1Tag ReadTagAndLengthDelegate( typeof(AsnDecoder).GetMethod("ReadTagAndLength", BindingFlags.Static | BindingFlags.NonPublic) .CreateDelegate(typeof(ReadTagAndLengthDelegate)); - [Theory] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBoxedByRefLikeValuesSupported))] [InlineData(4, 0, "0400")] [InlineData(1, 1, "0101")] [InlineData(4, 127, "047F")] @@ -53,7 +53,7 @@ public static void ReadWithUnknownRuleSet(int invalidRuleSetValue) () => new AsnReader(data, (AsnEncodingRules)invalidRuleSetValue)); } - [Theory] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBoxedByRefLikeValuesSupported))] [InlineData("")] [InlineData("05")] [InlineData("0481")] @@ -68,7 +68,7 @@ public static void ReadWithInsufficientData(string inputHex) () => ReadTagAndLength(inputData, AsnEncodingRules.DER, out _, out _)); } - [Theory] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBoxedByRefLikeValuesSupported))] [InlineData("DER indefinite constructed", AsnEncodingRules.DER, "3080" + "0500" + "0000")] [InlineData("0xFF-BER", AsnEncodingRules.BER, "04FF")] [InlineData("0xFF-CER", AsnEncodingRules.CER, "04FF")] @@ -108,7 +108,7 @@ public static void InvalidLengths( () => ReadTagAndLength(inputData, rules, out _, out _)); } - [Theory] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBoxedByRefLikeValuesSupported))] [InlineData(AsnEncodingRules.BER)] [InlineData(AsnEncodingRules.CER)] public static void IndefiniteLength(AsnEncodingRules ruleSet) @@ -131,7 +131,7 @@ public static void IndefiniteLength(AsnEncodingRules ruleSet) Assert.True(tag.IsConstructed, "tag.IsConstructed"); } - [Theory] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBoxedByRefLikeValuesSupported))] [InlineData(0, "0483000000")] [InlineData(1, "048A00000000000000000001")] [InlineData(128, "049000000000000000000000000000000080")] @@ -152,7 +152,7 @@ public static void BerNonMinimalLength(int expectedLength, string inputHex) Assert.True(reader.HasData, "reader.HasData"); } - [Theory] + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBoxedByRefLikeValuesSupported))] [InlineData(AsnEncodingRules.BER, 4, 0, 5, "0483000000" + "0500")] [InlineData(AsnEncodingRules.DER, 1, 1, 2, "0101" + "FF")] [InlineData(AsnEncodingRules.CER, 0x10, null, 2, "3080" + "0500" + "0000")] diff --git a/src/libraries/tests.proj b/src/libraries/tests.proj index ce9fbccd13aa1c..d2c10fdb1f47f2 100644 --- a/src/libraries/tests.proj +++ b/src/libraries/tests.proj @@ -511,7 +511,6 @@ - From 5a4acd168f00bd2e9d70f1b477e72aa2f8fad741 Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Wed, 20 Jul 2022 14:06:01 -0700 Subject: [PATCH 6/7] changed the failing tests to be disabled under an active bug --- .../TestUtilities/System/PlatformDetection.cs | 2 -- .../tests/Reader/ReadLength.cs | 18 ++++++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs b/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs index ed0ffd5b514a4a..682166af146cbf 100644 --- a/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs +++ b/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs @@ -141,8 +141,6 @@ private static bool GetLinqExpressionsBuiltWithIsInterpretingOnly() public static bool IsMetadataUpdateSupported => !IsNativeAot; - public static bool IsBoxedByRefLikeValuesSupported => !IsNativeAot; - // System.Security.Cryptography.Xml.XmlDsigXsltTransform.GetOutput() relies on XslCompiledTransform which relies // heavily on Reflection.Emit public static bool IsXmlDsigXsltTransformSupported => !PlatformDetection.IsInAppContainer && IsReflectionEmitSupported; diff --git a/src/libraries/System.Formats.Asn1/tests/Reader/ReadLength.cs b/src/libraries/System.Formats.Asn1/tests/Reader/ReadLength.cs index ff41c11bd2df70..b765f345321cca 100644 --- a/src/libraries/System.Formats.Asn1/tests/Reader/ReadLength.cs +++ b/src/libraries/System.Formats.Asn1/tests/Reader/ReadLength.cs @@ -19,7 +19,7 @@ private delegate Asn1Tag ReadTagAndLengthDelegate( typeof(AsnDecoder).GetMethod("ReadTagAndLength", BindingFlags.Static | BindingFlags.NonPublic) .CreateDelegate(typeof(ReadTagAndLengthDelegate)); - [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBoxedByRefLikeValuesSupported))] + [Theory] [InlineData(4, 0, "0400")] [InlineData(1, 1, "0101")] [InlineData(4, 127, "047F")] @@ -27,6 +27,7 @@ private delegate Asn1Tag ReadTagAndLengthDelegate( [InlineData(4, 255, "0481FF")] [InlineData(2, 256, "02820100")] [InlineData(4, int.MaxValue, "04847FFFFFFF")] + [ActiveIssue("https://github.com/dotnet/runtime/issues/72547", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))] public static void MinimalPrimitiveLength(int tagValue, int length, string inputHex) { byte[] inputBytes = inputHex.HexToByteArray(); @@ -53,13 +54,14 @@ public static void ReadWithUnknownRuleSet(int invalidRuleSetValue) () => new AsnReader(data, (AsnEncodingRules)invalidRuleSetValue)); } - [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBoxedByRefLikeValuesSupported))] + [Theory] [InlineData("")] [InlineData("05")] [InlineData("0481")] [InlineData("048201")] [InlineData("04830102")] [InlineData("0484010203")] + [ActiveIssue("https://github.com/dotnet/runtime/issues/72547", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))] public static void ReadWithInsufficientData(string inputHex) { byte[] inputData = inputHex.HexToByteArray(); @@ -68,7 +70,7 @@ public static void ReadWithInsufficientData(string inputHex) () => ReadTagAndLength(inputData, AsnEncodingRules.DER, out _, out _)); } - [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBoxedByRefLikeValuesSupported))] + [Theory] [InlineData("DER indefinite constructed", AsnEncodingRules.DER, "3080" + "0500" + "0000")] [InlineData("0xFF-BER", AsnEncodingRules.BER, "04FF")] [InlineData("0xFF-CER", AsnEncodingRules.CER, "04FF")] @@ -95,6 +97,7 @@ public static void ReadWithInsufficientData(string inputHex) [InlineData("CER 5 byte spread", AsnEncodingRules.CER, "04850100000000")] [InlineData("DER 5 byte spread", AsnEncodingRules.DER, "04850100000000")] [InlineData("BER padded 5 byte spread", AsnEncodingRules.BER, "0486000100000000")] + [ActiveIssue("https://github.com/dotnet/runtime/issues/72547", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))] public static void InvalidLengths( string description, AsnEncodingRules rules, @@ -108,9 +111,10 @@ public static void InvalidLengths( () => ReadTagAndLength(inputData, rules, out _, out _)); } - [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBoxedByRefLikeValuesSupported))] + [Theory] [InlineData(AsnEncodingRules.BER)] [InlineData(AsnEncodingRules.CER)] + [ActiveIssue("https://github.com/dotnet/runtime/issues/72547", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))] public static void IndefiniteLength(AsnEncodingRules ruleSet) { // SEQUENCE (indefinite) @@ -131,10 +135,11 @@ public static void IndefiniteLength(AsnEncodingRules ruleSet) Assert.True(tag.IsConstructed, "tag.IsConstructed"); } - [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBoxedByRefLikeValuesSupported))] + [Theory] [InlineData(0, "0483000000")] [InlineData(1, "048A00000000000000000001")] [InlineData(128, "049000000000000000000000000000000080")] + [ActiveIssue("https://github.com/dotnet/runtime/issues/72547", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))] public static void BerNonMinimalLength(int expectedLength, string inputHex) { byte[] inputData = inputHex.HexToByteArray(); @@ -152,10 +157,11 @@ public static void BerNonMinimalLength(int expectedLength, string inputHex) Assert.True(reader.HasData, "reader.HasData"); } - [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBoxedByRefLikeValuesSupported))] + [Theory] [InlineData(AsnEncodingRules.BER, 4, 0, 5, "0483000000" + "0500")] [InlineData(AsnEncodingRules.DER, 1, 1, 2, "0101" + "FF")] [InlineData(AsnEncodingRules.CER, 0x10, null, 2, "3080" + "0500" + "0000")] + [ActiveIssue("https://github.com/dotnet/runtime/issues/72547", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))] public static void ReadWithDataRemaining( AsnEncodingRules ruleSet, int tagValue, From 6426c5817ae60da0ddeb51a47e8bb90f6df9962f Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Thu, 21 Jul 2022 04:02:51 -0700 Subject: [PATCH 7/7] update the bug number --- .../System.Formats.Asn1/tests/Reader/ReadLength.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/libraries/System.Formats.Asn1/tests/Reader/ReadLength.cs b/src/libraries/System.Formats.Asn1/tests/Reader/ReadLength.cs index b765f345321cca..98c3a87ae75d10 100644 --- a/src/libraries/System.Formats.Asn1/tests/Reader/ReadLength.cs +++ b/src/libraries/System.Formats.Asn1/tests/Reader/ReadLength.cs @@ -27,7 +27,7 @@ private delegate Asn1Tag ReadTagAndLengthDelegate( [InlineData(4, 255, "0481FF")] [InlineData(2, 256, "02820100")] [InlineData(4, int.MaxValue, "04847FFFFFFF")] - [ActiveIssue("https://github.com/dotnet/runtime/issues/72547", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))] + [ActiveIssue("https://github.com/dotnet/runtime/issues/72548", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))] public static void MinimalPrimitiveLength(int tagValue, int length, string inputHex) { byte[] inputBytes = inputHex.HexToByteArray(); @@ -61,7 +61,7 @@ public static void ReadWithUnknownRuleSet(int invalidRuleSetValue) [InlineData("048201")] [InlineData("04830102")] [InlineData("0484010203")] - [ActiveIssue("https://github.com/dotnet/runtime/issues/72547", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))] + [ActiveIssue("https://github.com/dotnet/runtime/issues/72548", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))] public static void ReadWithInsufficientData(string inputHex) { byte[] inputData = inputHex.HexToByteArray(); @@ -97,7 +97,7 @@ public static void ReadWithInsufficientData(string inputHex) [InlineData("CER 5 byte spread", AsnEncodingRules.CER, "04850100000000")] [InlineData("DER 5 byte spread", AsnEncodingRules.DER, "04850100000000")] [InlineData("BER padded 5 byte spread", AsnEncodingRules.BER, "0486000100000000")] - [ActiveIssue("https://github.com/dotnet/runtime/issues/72547", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))] + [ActiveIssue("https://github.com/dotnet/runtime/issues/72548", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))] public static void InvalidLengths( string description, AsnEncodingRules rules, @@ -114,7 +114,7 @@ public static void InvalidLengths( [Theory] [InlineData(AsnEncodingRules.BER)] [InlineData(AsnEncodingRules.CER)] - [ActiveIssue("https://github.com/dotnet/runtime/issues/72547", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))] + [ActiveIssue("https://github.com/dotnet/runtime/issues/72548", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))] public static void IndefiniteLength(AsnEncodingRules ruleSet) { // SEQUENCE (indefinite) @@ -139,7 +139,7 @@ public static void IndefiniteLength(AsnEncodingRules ruleSet) [InlineData(0, "0483000000")] [InlineData(1, "048A00000000000000000001")] [InlineData(128, "049000000000000000000000000000000080")] - [ActiveIssue("https://github.com/dotnet/runtime/issues/72547", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))] + [ActiveIssue("https://github.com/dotnet/runtime/issues/72548", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))] public static void BerNonMinimalLength(int expectedLength, string inputHex) { byte[] inputData = inputHex.HexToByteArray(); @@ -161,7 +161,7 @@ public static void BerNonMinimalLength(int expectedLength, string inputHex) [InlineData(AsnEncodingRules.BER, 4, 0, 5, "0483000000" + "0500")] [InlineData(AsnEncodingRules.DER, 1, 1, 2, "0101" + "FF")] [InlineData(AsnEncodingRules.CER, 0x10, null, 2, "3080" + "0500" + "0000")] - [ActiveIssue("https://github.com/dotnet/runtime/issues/72547", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))] + [ActiveIssue("https://github.com/dotnet/runtime/issues/72548", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))] public static void ReadWithDataRemaining( AsnEncodingRules ruleSet, int tagValue,