<PackageReference Include="System.Formats.Asn1" Version="10.0.0-preview.4.25258.110" />

AsnWriter

public sealed class AsnWriter
A writer for BER-encoded, CER-encoded, and DER-encoded ASN.1 data.
public struct Scope : IDisposable

Represents a pushed ASN.1 scope.

public AsnEncodingRules RuleSet { get; }

Gets the encoding rules in use by this writer.

public AsnWriter(AsnEncodingRules ruleSet)

Creates a new AsnWriter with a given set of encoding rules.

public AsnWriter(AsnEncodingRules ruleSet, int initialCapacity)

Initializes a new instance of AsnWriter with a given set of encoding rules and an initial capacity.

public void CopyTo(AsnWriter destination)

Copies the value of this writer into another.

public int Encode(Span<byte> destination)

Writes the encoded representation of the data to destination.

public byte[] Encode()

Returns a new array containing the encoded value.

public bool EncodedValueEquals(ReadOnlySpan<byte> other)

Determines if Encode would produce an output identical to other.

public bool EncodedValueEquals(AsnWriter other)

Determines if Encode would produce an output identical to other.

public int GetEncodedLength()

Gets the number of bytes that would be written by TryEncode.

public void PopOctetString(Asn1Tag? tag = default)

Indicate that the open Octet String with the tag UNIVERSAL 4 is closed, returning the writer to the parent context.

public void PopSequence(Asn1Tag? tag = default)

Indicate that the open Sequence with the specified tag is closed, returning the writer to the parent context.

public void PopSetOf(Asn1Tag? tag = default)

Indicate that the open Set-Of with the specified tag is closed, returning the writer to the parent context.

public Scope PushOctetString(Asn1Tag? tag = default)

Begin writing an Octet String value with a specified tag.

public Scope PushSequence(Asn1Tag? tag = default)

Begin writing a Sequence with a specified tag.

public Scope PushSetOf(Asn1Tag? tag = default)

Begin writing a Set-Of with a specified tag.

public void Reset()

Resets the writer to have no data, without releasing resources.

public bool TryEncode(Span<byte> destination, out int bytesWritten)

Attempts to write the encoded representation of the data to destination.

public void WriteBitString(ReadOnlySpan<byte> value, int unusedBitCount = 0, Asn1Tag? tag = default)

Write a Bit String value with a specified tag.

public void WriteBoolean(bool value, Asn1Tag? tag = default)

Write a Boolean value with a specified tag.

public void WriteCharacterString(UniversalTagNumber encodingType, string value, Asn1Tag? tag = default)

Write the provided string using the specified encoding type using the specified tag corresponding to the encoding type.

public void WriteCharacterString(UniversalTagNumber encodingType, ReadOnlySpan<char> str, Asn1Tag? tag = default)

Write the provided string using the specified encoding type using the specified tag corresponding to the encoding type.

public void WriteEncodedValue(ReadOnlySpan<byte> value)

Writes a single value that has already been encoded.

public void WriteEnumeratedValue(Enum value, Asn1Tag? tag = default)

Write a non-[ FlagsAttribute] enum value as an Enumerated with tag UNIVERSAL 10.

public void WriteEnumeratedValue<TEnum>(TEnum value, Asn1Tag? tag = default) where TEnum : Enum

Write a non-[ FlagsAttribute] enum value as an Enumerated with tag UNIVERSAL 10.

public void WriteGeneralizedTime(DateTimeOffset value, bool omitFractionalSeconds = false, Asn1Tag? tag = default)

Write the provided DateTimeOffset as a GeneralizedTime with a specified UNIVERSAL 24, optionally excluding the fractional seconds.

public void WriteInteger(long value, Asn1Tag? tag = default)

Write an Integer value with a specified tag.

public void WriteInteger(ulong value, Asn1Tag? tag = default)

Write an Integer value with a specified tag.

public void WriteInteger(BigInteger value, Asn1Tag? tag = default)

Write an Integer value with a specified tag.

public void WriteInteger(ReadOnlySpan<byte> value, Asn1Tag? tag = default)

Write an Integer value with a specified tag.

public void WriteIntegerUnsigned(ReadOnlySpan<byte> value, Asn1Tag? tag = default)

Write an Integer value with a specified tag.

public void WriteNamedBitList(Enum value, Asn1Tag? tag = default)

Write a [ FlagsAttribute] enum value as a NamedBitList with a specified tag.

public void WriteNamedBitList<TEnum>(TEnum value, Asn1Tag? tag = default) where TEnum : Enum

Write a [ FlagsAttribute] enum value as a NamedBitList with a specified tag.

public void WriteNamedBitList(BitArray value, Asn1Tag? tag = default)

Write a bit array value as a NamedBitList with a specified tag.

public void WriteNull(Asn1Tag? tag = default)

Write NULL with a specified tag.

public void WriteObjectIdentifier(string oidValue, Asn1Tag? tag = default)

Write an Object Identifier with a specified tag.

public void WriteObjectIdentifier(ReadOnlySpan<char> oidValue, Asn1Tag? tag = default)

Write an Object Identifier with a specified tag.

public void WriteOctetString(ReadOnlySpan<byte> value, Asn1Tag? tag = default)

Write an Octet String value with a specified tag.

public void WriteUtcTime(DateTimeOffset value, Asn1Tag? tag = default)

Write the provided value as a UTCTime with a specified tag, accepting the two-digit year as valid in context.

public void WriteUtcTime(DateTimeOffset value, int twoDigitYearMax, Asn1Tag? tag = default)

Write the provided value as a UTCTime with a specified tag, provided the year is in the allowed range.