Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DefineConstants>$(DefineConstants);CP_NO_ZEROMEMORY</DefineConstants>
<IsPackable>true</IsPackable>
<EnableAOTAnalyzer>true</EnableAOTAnalyzer>
<PackageDescription>Provides classes that can read and write the ASN.1 BER, CER, and DER data formats.

Commonly Used Types:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,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) ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public static Enum ReadNamedBitListValue(
}

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

bool read = TryReadBitString(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/// <summary>
/// Get the number of bytes between the start of <paramref name="source" /> and
/// the End-of-Contents marker
Expand Down