Skip to content

Commit cf0f14c

Browse files
LakshanFjkotas
andauthored
Annotating System.Formats.Asn1 library for Aot (#72533)
* Annotating System.Formats.Asn1 library for Aot * FB * Update src/libraries/System.Formats.Asn1/src/System.Formats.Asn1.csproj * Update src/libraries/System.Formats.Asn1/src/System.Formats.Asn1.csproj * enabling the tests by exluding not supported scenarios * changed the failing tests to be disabled under an active bug * update the bug number Co-authored-by: Jan Kotas <[email protected]>
1 parent 57469b2 commit cf0f14c

File tree

6 files changed

+22
-3
lines changed

6 files changed

+22
-3
lines changed

src/libraries/System.Formats.Asn1/src/System.Formats.Asn1.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
55
<DefineConstants>$(DefineConstants);CP_NO_ZEROMEMORY</DefineConstants>
66
<IsPackable>true</IsPackable>
7+
<EnableAOTAnalyzer>true</EnableAOTAnalyzer>
78
<PackageDescription>Provides classes that can read and write the ASN.1 BER, CER, and DER data formats.
89

910
Commonly Used Types:

src/libraries/System.Formats.Asn1/src/System/Formats/Asn1/AsnDecoder.Enumerated.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ public static Enum ReadEnumeratedValue(
211211
}
212212

213213
// T-REC-X.690-201508 sec 8.4 says the contents are the same as for integers.
214-
int sizeLimit = Marshal.SizeOf(backingType);
214+
int sizeLimit = GetPrimitiveIntegerSize(backingType);
215215

216216
if (backingType == typeof(int) ||
217217
backingType == typeof(long) ||

src/libraries/System.Formats.Asn1/src/System/Formats/Asn1/AsnDecoder.NamedBitList.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ public static Enum ReadNamedBitListValue(
196196
}
197197

198198
Span<byte> stackSpan = stackalloc byte[sizeof(ulong)];
199-
int sizeLimit = Marshal.SizeOf(backingType);
199+
int sizeLimit = GetPrimitiveIntegerSize(backingType);
200200
stackSpan = stackSpan.Slice(0, sizeLimit);
201201

202202
bool read = TryReadBitString(

src/libraries/System.Formats.Asn1/src/System/Formats/Asn1/AsnDecoder.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,19 @@ private static AsnContentException GetValidityException(LengthValidity validity)
466466
}
467467
}
468468

469+
private static int GetPrimitiveIntegerSize(Type primitiveType)
470+
{
471+
if (primitiveType == typeof(byte) || primitiveType == typeof(sbyte))
472+
return 1;
473+
if (primitiveType == typeof(short) || primitiveType == typeof(ushort))
474+
return 2;
475+
if (primitiveType == typeof(int) || primitiveType == typeof(uint))
476+
return 4;
477+
if (primitiveType == typeof(long) || primitiveType == typeof(ulong))
478+
return 8;
479+
return 0;
480+
}
481+
469482
/// <summary>
470483
/// Get the number of bytes between the start of <paramref name="source" /> and
471484
/// the End-of-Contents marker

src/libraries/System.Formats.Asn1/tests/Reader/ReadLength.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ private delegate Asn1Tag ReadTagAndLengthDelegate(
2727
[InlineData(4, 255, "0481FF")]
2828
[InlineData(2, 256, "02820100")]
2929
[InlineData(4, int.MaxValue, "04847FFFFFFF")]
30+
[ActiveIssue("https://github.com/dotnet/runtime/issues/72548", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))]
3031
public static void MinimalPrimitiveLength(int tagValue, int length, string inputHex)
3132
{
3233
byte[] inputBytes = inputHex.HexToByteArray();
@@ -60,6 +61,7 @@ public static void ReadWithUnknownRuleSet(int invalidRuleSetValue)
6061
[InlineData("048201")]
6162
[InlineData("04830102")]
6263
[InlineData("0484010203")]
64+
[ActiveIssue("https://github.com/dotnet/runtime/issues/72548", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))]
6365
public static void ReadWithInsufficientData(string inputHex)
6466
{
6567
byte[] inputData = inputHex.HexToByteArray();
@@ -95,6 +97,7 @@ public static void ReadWithInsufficientData(string inputHex)
9597
[InlineData("CER 5 byte spread", AsnEncodingRules.CER, "04850100000000")]
9698
[InlineData("DER 5 byte spread", AsnEncodingRules.DER, "04850100000000")]
9799
[InlineData("BER padded 5 byte spread", AsnEncodingRules.BER, "0486000100000000")]
100+
[ActiveIssue("https://github.com/dotnet/runtime/issues/72548", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))]
98101
public static void InvalidLengths(
99102
string description,
100103
AsnEncodingRules rules,
@@ -111,6 +114,7 @@ public static void InvalidLengths(
111114
[Theory]
112115
[InlineData(AsnEncodingRules.BER)]
113116
[InlineData(AsnEncodingRules.CER)]
117+
[ActiveIssue("https://github.com/dotnet/runtime/issues/72548", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))]
114118
public static void IndefiniteLength(AsnEncodingRules ruleSet)
115119
{
116120
// SEQUENCE (indefinite)
@@ -135,6 +139,7 @@ public static void IndefiniteLength(AsnEncodingRules ruleSet)
135139
[InlineData(0, "0483000000")]
136140
[InlineData(1, "048A00000000000000000001")]
137141
[InlineData(128, "049000000000000000000000000000000080")]
142+
[ActiveIssue("https://github.com/dotnet/runtime/issues/72548", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))]
138143
public static void BerNonMinimalLength(int expectedLength, string inputHex)
139144
{
140145
byte[] inputData = inputHex.HexToByteArray();
@@ -156,6 +161,7 @@ public static void BerNonMinimalLength(int expectedLength, string inputHex)
156161
[InlineData(AsnEncodingRules.BER, 4, 0, 5, "0483000000" + "0500")]
157162
[InlineData(AsnEncodingRules.DER, 1, 1, 2, "0101" + "FF")]
158163
[InlineData(AsnEncodingRules.CER, 0x10, null, 2, "3080" + "0500" + "0000")]
164+
[ActiveIssue("https://github.com/dotnet/runtime/issues/72548", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))]
159165
public static void ReadWithDataRemaining(
160166
AsnEncodingRules ruleSet,
161167
int tagValue,

src/libraries/tests.proj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,6 @@
510510
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.DirectoryServices.Protocols\tests\System.DirectoryServices.Protocols.Tests.csproj" />
511511
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Drawing.Primitives\tests\System.Drawing.Primitives.Tests.csproj" />
512512
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Dynamic.Runtime\tests\System.Dynamic.Runtime.Tests.csproj" />
513-
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Formats.Asn1\tests\System.Formats.Asn1.Tests.csproj" />
514513
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Formats.Cbor\tests\System.Formats.Cbor.Tests.csproj" />
515514
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Globalization\tests\System.Globalization.Tests.csproj" />
516515
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Globalization\tests\NlsTests\System.Globalization.Nls.Tests.csproj" />

0 commit comments

Comments
 (0)