<PackageReference Include="System.Formats.Asn1" Version="7.0.0" />

AsnDecoder

public static class AsnDecoder
Provides stateless methods for decoding BER-encoded, CER-encoded, and DER-encoded ASN.1 data.
public static byte[] ReadBitString(ReadOnlySpan<byte> source, AsnEncodingRules ruleSet, out int unusedBitCount, out int bytesConsumed, Asn1Tag? expectedTag = default)

Reads a Bit String value from source with a specified tag under the specified encoding rules, returning the contents in a new array.

public static bool ReadBoolean(ReadOnlySpan<byte> source, AsnEncodingRules ruleSet, out int bytesConsumed, Asn1Tag? expectedTag = default)

Reads a Boolean value from source with a specified tag under the specified encoding rules.

public static string ReadCharacterString(ReadOnlySpan<byte> source, AsnEncodingRules ruleSet, UniversalTagNumber encodingType, out int bytesConsumed, Asn1Tag? expectedTag = default)

Reads the next value as character string with the specified tag and encoding type, returning the decoded string.

public static Asn1Tag ReadEncodedValue(ReadOnlySpan<byte> source, AsnEncodingRules ruleSet, out int contentOffset, out int contentLength, out int bytesConsumed)

Locates the contents range for the encoded value at the beginning of the source buffer using the specified encoding rules.

public static ReadOnlySpan<byte> ReadEnumeratedBytes(ReadOnlySpan<byte> source, AsnEncodingRules ruleSet, out int bytesConsumed, Asn1Tag? expectedTag = default)

Reads an Enumerated value from source with a specified tag under the specified encoding rules, returning the contents as a slice of the buffer.

public static TEnum ReadEnumeratedValue<TEnum>(ReadOnlySpan<byte> source, AsnEncodingRules ruleSet, out int bytesConsumed, Asn1Tag? expectedTag = default) where TEnum : Enum

Reads an Enumerated from source with a specified tag under the specified encoding rules, converting it to the non-[ FlagsAttribute] enum specified by TEnum.

public static Enum ReadEnumeratedValue(ReadOnlySpan<byte> source, AsnEncodingRules ruleSet, Type enumType, out int bytesConsumed, Asn1Tag? expectedTag = default)

Reads an Enumerated from source with a specified tag under the specified encoding rules, converting it to the non-[ FlagsAttribute] enum specified by enumType.

public static DateTimeOffset ReadGeneralizedTime(ReadOnlySpan<byte> source, AsnEncodingRules ruleSet, out int bytesConsumed, Asn1Tag? expectedTag = default)

Reads a GeneralizedTime value from source with a specified tag under the specified encoding rules.

public static BigInteger ReadInteger(ReadOnlySpan<byte> source, AsnEncodingRules ruleSet, out int bytesConsumed, Asn1Tag? expectedTag = default)

Reads an Integer value from source with a specified tag under the specified encoding rules.

public static ReadOnlySpan<byte> ReadIntegerBytes(ReadOnlySpan<byte> source, AsnEncodingRules ruleSet, out int bytesConsumed, Asn1Tag? expectedTag = default)

Reads an Integer value from source with a specified tag under the specified encoding rules, returning the contents as a slice of the buffer.

public static BitArray ReadNamedBitList(ReadOnlySpan<byte> source, AsnEncodingRules ruleSet, out int bytesConsumed, Asn1Tag? expectedTag = default)

Reads a NamedBitList from source with a specified tag under the specified encoding rules.

public static TFlagsEnum ReadNamedBitListValue<TFlagsEnum>(ReadOnlySpan<byte> source, AsnEncodingRules ruleSet, out int bytesConsumed, Asn1Tag? expectedTag = default) where TFlagsEnum : Enum

Reads a NamedBitList from source with a specified tag under the specified encoding rules, converting it to the [ FlagsAttribute] enum specified by TFlagsEnum.

public static Enum ReadNamedBitListValue(ReadOnlySpan<byte> source, AsnEncodingRules ruleSet, Type flagsEnumType, out int bytesConsumed, Asn1Tag? expectedTag = default)

Reads a NamedBitList from source with a specified tag under the specified encoding rules, converting it to the [ FlagsAttribute] enum specified by flagsEnumType.

public static void ReadNull(ReadOnlySpan<byte> source, AsnEncodingRules ruleSet, out int bytesConsumed, Asn1Tag? expectedTag = default)

Reads a null value from source with a specified tag under the specified encoding rules.

public static string ReadObjectIdentifier(ReadOnlySpan<byte> source, AsnEncodingRules ruleSet, out int bytesConsumed, Asn1Tag? expectedTag = default)

Reads an Object Identifier value from source with a specified tag under the specified encoding rules.

public static byte[] ReadOctetString(ReadOnlySpan<byte> source, AsnEncodingRules ruleSet, out int bytesConsumed, Asn1Tag? expectedTag = default)

Reads an Octet String value from source with a specified tag under the specified encoding rules, returning the contents in a new array.

public static void ReadSequence(ReadOnlySpan<byte> source, AsnEncodingRules ruleSet, out int contentOffset, out int contentLength, out int bytesConsumed, Asn1Tag? expectedTag = default)

Reads a Sequence or Sequence-Of value from source with a specified tag under the specified encoding rules.

public static void ReadSetOf(ReadOnlySpan<byte> source, AsnEncodingRules ruleSet, out int contentOffset, out int contentLength, out int bytesConsumed, bool skipSortOrderValidation = false, Asn1Tag? expectedTag = default)

Reads a Set-Of value from source with a specified tag under the specified encoding rules.

public static DateTimeOffset ReadUtcTime(ReadOnlySpan<byte> source, AsnEncodingRules ruleSet, out int bytesConsumed, int twoDigitYearMax = 2049, Asn1Tag? expectedTag = default)

Reads a UtcTime value from source with a specified tag under the specified encoding rules.

public static bool TryReadBitString(ReadOnlySpan<byte> source, Span<byte> destination, AsnEncodingRules ruleSet, out int unusedBitCount, out int bytesConsumed, out int bytesWritten, Asn1Tag? expectedTag = default)

Attempts to copy a Bit String value from source with a specified tag under the specified encoding rules into destination.

public static bool TryReadCharacterString(ReadOnlySpan<byte> source, Span<char> destination, AsnEncodingRules ruleSet, UniversalTagNumber encodingType, out int bytesConsumed, out int charsWritten, Asn1Tag? expectedTag = default)

Reads a character string value from source with a specified tag under the specified encoding rules, copying the decoded string into a provided destination buffer.

public static bool TryReadCharacterStringBytes(ReadOnlySpan<byte> source, Span<byte> destination, AsnEncodingRules ruleSet, Asn1Tag expectedTag, out int bytesConsumed, out int bytesWritten)

Attempts to read a character string value from source with a specified tag under the specified encoding rules, copying the unprocessed bytes into the provided destination buffer.

public static bool TryReadEncodedValue(ReadOnlySpan<byte> source, AsnEncodingRules ruleSet, out Asn1Tag tag, out int contentOffset, out int contentLength, out int bytesConsumed)

Attempts locate the contents range for the encoded value at the beginning of the source buffer using the specified encoding rules.

public static bool TryReadInt32(ReadOnlySpan<byte> source, AsnEncodingRules ruleSet, out int value, out int bytesConsumed, Asn1Tag? expectedTag = default)

Attempts to read an Integer value from source with a specified tag under the specified encoding rules as a signed 32-bit value.

public static bool TryReadInt64(ReadOnlySpan<byte> source, AsnEncodingRules ruleSet, out long value, out int bytesConsumed, Asn1Tag? expectedTag = default)

Attempts to read an Integer value from source with a specified tag under the specified encoding rules as a signed 64-bit value.

public static bool TryReadOctetString(ReadOnlySpan<byte> source, Span<byte> destination, AsnEncodingRules ruleSet, out int bytesConsumed, out int bytesWritten, Asn1Tag? expectedTag = default)

Attempts to get an Octet String value from source with a specified tag under the specified encoding rules, copying the value into the provided destination buffer.

public static bool TryReadPrimitiveBitString(ReadOnlySpan<byte> source, AsnEncodingRules ruleSet, out int unusedBitCount, out ReadOnlySpan value, out int bytesConsumed, Asn1Tag? expectedTag = default)

Attempts to get a Bit String value from source with a specified tag under the specified encoding rules, if the value is contained in a single (primitive) encoding.

public static bool TryReadPrimitiveCharacterStringBytes(ReadOnlySpan<byte> source, AsnEncodingRules ruleSet, Asn1Tag expectedTag, out ReadOnlySpan value, out int bytesConsumed)

Attempts to get an unprocessed character string value from source with a specified tag under the specified encoding rules, if the value is contained in a single (primitive) encoding.

public static bool TryReadPrimitiveOctetString(ReadOnlySpan<byte> source, AsnEncodingRules ruleSet, out ReadOnlySpan value, out int bytesConsumed, Asn1Tag? expectedTag = default)

Attempts to get an Octet String value from source with a specified tag under the specified encoding rules, if the value is contained in a single (primitive) encoding.

public static bool TryReadUInt32(ReadOnlySpan<byte> source, AsnEncodingRules ruleSet, out uint value, out int bytesConsumed, Asn1Tag? expectedTag = default)

Attempts to read an Integer value from source with a specified tag under the specified encoding rules as an unsigned 32-bit value.

public static bool TryReadUInt64(ReadOnlySpan<byte> source, AsnEncodingRules ruleSet, out ulong value, out int bytesConsumed, Asn1Tag? expectedTag = default)

Attempts to read an Integer value from source with a specified tag under the specified encoding rules as an unsigned 64-bit value.