Class AsnWriter
Writes DER-encoded ASN.1 data (X.690). Constructed types use callback scoping so that the length is computed automatically after the content is written.
Inherited Members
Namespace: DRIT.Mail.Rfc.Crypto.Asn1
Assembly: DRIT.Mail.dll
Syntax
public sealed class AsnWriter
Methods
View SourceToArray()
Gets the encoded bytes as a new array.
Declaration
public byte[] ToArray()
Returns
| Type | Description |
|---|---|
| byte[] |
WriteBitString(byte[], int)
Writes a BIT STRING with the given content bytes and unused-bits count.
Declaration
public void WriteBitString(byte[] value, int unusedBits = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | value | The value to process. |
| int | unusedBits | The unused bits used by the operation. |
WriteBoolean(bool)
Writes a BOOLEAN.
Declaration
public void WriteBoolean(bool value)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | value | The value to process. |
WriteEncoded(byte[])
Writes a pre-encoded TLV (tag + length + content) verbatim.
Declaration
public void WriteEncoded(byte[] tlv)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | tlv | Specifies the tlv value. |
WriteExplicit(byte, Action<AsnWriter>)
Writes an EXPLICIT context-tagged element [tag] wrapping the content
produced by the callback.
Declaration
public void WriteExplicit(byte tag, Action<AsnWriter> content)
Parameters
| Type | Name | Description |
|---|---|---|
| byte | tag | Specifies the tag value. |
| Action<AsnWriter> | content | Specifies the content value. |
WriteGeneralizedTime(DateTime)
Writes a GeneralizedTime. The value must be UTC and at year 2050 or later.
Declaration
public void WriteGeneralizedTime(DateTime value)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTime | value | The value to process. |
WriteIa5String(string)
Writes an IA5String.
Declaration
public void WriteIa5String(string value)
Parameters
| Type | Name | Description |
|---|---|---|
| string | value | The value to process. |
WriteImplicit(byte, byte[])
Writes an IMPLICIT context-tagged element using pre-encoded content bytes (already including the inner length+value, but not the implicit tag).
Declaration
public void WriteImplicit(byte tag, byte[] content)
Parameters
| Type | Name | Description |
|---|---|---|
| byte | tag | Specifies the tag value. |
| byte[] | content | Specifies the content value. |
WriteImplicitConstructed(byte, byte[])
Writes a constructed IMPLICIT context-tagged element using pre-encoded content bytes. The constructed bit is set on the tag (0xA0 | tag).
Declaration
public void WriteImplicitConstructed(byte tag, byte[] content)
Parameters
| Type | Name | Description |
|---|---|---|
| byte | tag | Specifies the tag value. |
| byte[] | content | Specifies the content value. |
WriteInt32(int)
Writes a 32-bit signed INTEGER.
Declaration
public void WriteInt32(int value)
Parameters
| Type | Name | Description |
|---|---|---|
| int | value | The value to process. |
WriteInteger(byte[])
Writes an INTEGER from big-endian bytes. A leading 0x00 byte is added when needed to keep the value positive (per DER).
Declaration
public void WriteInteger(byte[] bigEndianValue)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | bigEndianValue | The big endian value used by the operation. |
WriteNull()
Writes a NULL.
Declaration
public void WriteNull()
WriteOctetString(byte[])
Writes an OCTET STRING.
Declaration
public void WriteOctetString(byte[] value)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | value | The value to process. |
WriteOid(string)
Writes an OBJECT IDENTIFIER from a dotted-decimal string.
Declaration
public void WriteOid(string oid)
Parameters
| Type | Name | Description |
|---|---|---|
| string | oid | The oid identifier. |
WritePrintableString(string)
Writes a PrintableString.
Declaration
public void WritePrintableString(string value)
Parameters
| Type | Name | Description |
|---|---|---|
| string | value | The value to process. |
WriteSequence(Action<AsnWriter>)
Writes a SEQUENCE, invoking content to populate the body.
Declaration
public void WriteSequence(Action<AsnWriter> content)
Parameters
| Type | Name | Description |
|---|---|---|
| Action<AsnWriter> | content | Specifies the content value. |
WriteSet(Action<AsnWriter>)
Writes a SET, invoking content to populate the body. DER
requires SET elements to be sorted by tag; the caller is responsible for
ordering.
Declaration
public void WriteSet(Action<AsnWriter> content)
Parameters
| Type | Name | Description |
|---|---|---|
| Action<AsnWriter> | content | Specifies the content value. |
WriteUtcTime(DateTime)
Writes a UTCTime. The value must be UTC and within the year range 1950–2049.
Declaration
public void WriteUtcTime(DateTime value)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTime | value | The value to process. |
WriteUtf8String(string)
Writes a UTF8String.
Declaration
public void WriteUtf8String(string value)
Parameters
| Type | Name | Description |
|---|---|---|
| string | value | The value to process. |