Class AsnReader
Reads DER-encoded ASN.1 data (X.690). Cursor-based, forward-only. Constructed types return a new AsnReader scoped to the element's content.
Inherited Members
Namespace: DRIT.Mail.Rfc.Crypto.Asn1
Assembly: DRIT.Mail.dll
Syntax
public sealed class AsnReader
Constructors
View SourceAsnReader(byte[])
Initializes a new instance of the AsnReader class over the given byte array.
Declaration
public AsnReader(byte[] data)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | data | The data to process. |
AsnReader(byte[], int, int)
Initializes a new instance of the AsnReader class over a slice of the given byte array.
Declaration
public AsnReader(byte[] data, int offset, int length)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | data | The data to process. |
| int | offset | The offset within the data. |
| int | length | The length value. |
Properties
View SourceHasData
Gets a value indicating whether this reader has any data left to read.
Declaration
public bool HasData { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Position
Gets the current cursor position relative to the start of this reader's slice.
Declaration
public int Position { get; }
Property Value
| Type | Description |
|---|---|
| int |
Remaining
Gets the number of bytes remaining in this reader.
Declaration
public int Remaining { get; }
Property Value
| Type | Description |
|---|---|
| int |
Methods
View SourceIsContextTag(byte)
Determines whether the next tag is the given context tag number (0–30), regardless of constructed/primitive form.
Declaration
public bool IsContextTag(byte expectedTag)
Parameters
| Type | Name | Description |
|---|---|---|
| byte | expectedTag | The expected tag used by the operation. |
Returns
| Type | Description |
|---|---|
| bool |
PeekTag()
Peeks at the next tag byte without advancing the cursor. Throws if no data.
Declaration
public byte PeekTag()
Returns
| Type | Description |
|---|---|
| byte |
ReadBitString()
Reads a BIT STRING, stripping the unused-bits prefix byte. Returns the bit content bytes.
Declaration
public byte[] ReadBitString()
Returns
| Type | Description |
|---|---|
| byte[] |
ReadBoolean()
Reads a BOOLEAN.
Declaration
public bool ReadBoolean()
Returns
| Type | Description |
|---|---|
| bool |
ReadExplicit(byte)
Reads an EXPLICIT context-tagged element [tag] and returns a new reader
over its content. The tag is the context tag number (0–30).
Declaration
public AsnReader ReadExplicit(byte tag)
Parameters
| Type | Name | Description |
|---|---|---|
| byte | tag | Specifies the tag value. |
Returns
| Type | Description |
|---|---|
| AsnReader |
ReadGeneralizedTime()
Reads a GeneralizedTime and returns a UTC DateTime.
Declaration
public DateTime ReadGeneralizedTime()
Returns
| Type | Description |
|---|---|
| DateTime |
ReadIa5String()
Reads an IA5String (ASCII).
Declaration
public string ReadIa5String()
Returns
| Type | Description |
|---|---|
| string |
ReadImplicit(byte)
Reads an IMPLICIT context-tagged element and returns its raw TLV bytes (tag + length + content).
Declaration
public byte[] ReadImplicit(byte tag)
Parameters
| Type | Name | Description |
|---|---|---|
| byte | tag | Specifies the tag value. |
Returns
| Type | Description |
|---|---|
| byte[] |
ReadInt32()
Reads an INTEGER as a 32-bit signed value. Throws if the value is out of range.
Declaration
public int ReadInt32()
Returns
| Type | Description |
|---|---|
| int |
ReadInteger()
Reads an INTEGER as big-endian bytes (arbitrary size). The result preserves the sign by including a leading 0x00 byte when the high bit of the most significant byte would otherwise be set for a positive value.
Declaration
public byte[] ReadInteger()
Returns
| Type | Description |
|---|---|
| byte[] |
ReadNull()
Reads a NULL and returns nothing. Throws if the element is not NULL.
Declaration
public void ReadNull()
ReadOctetString()
Reads an OCTET STRING.
Declaration
public byte[] ReadOctetString()
Returns
| Type | Description |
|---|---|
| byte[] |
ReadOid()
Reads an OBJECT IDENTIFIER as a dotted-decimal string.
Declaration
public string ReadOid()
Returns
| Type | Description |
|---|---|
| string |
ReadPrintableString()
Reads a PrintableString.
Declaration
public string ReadPrintableString()
Returns
| Type | Description |
|---|---|
| string |
ReadRawTlv()
Reads a full Tag-Length-Value triple and returns the complete raw bytes (tag + length + content). Advances the cursor past the element.
Declaration
public byte[] ReadRawTlv()
Returns
| Type | Description |
|---|---|
| byte[] |
ReadSequence()
Reads a SEQUENCE and returns a new reader over its content.
Declaration
public AsnReader ReadSequence()
Returns
| Type | Description |
|---|---|
| AsnReader |
ReadSet()
Reads a SET and returns a new reader over its content.
Declaration
public AsnReader ReadSet()
Returns
| Type | Description |
|---|---|
| AsnReader |
ReadTlv()
Reads a full Tag-Length-Value triple, returning the tag byte and the content bytes (a copy). Advances the cursor past the element.
Declaration
public (byte tag, byte[] content) ReadTlv()
Returns
| Type | Description |
|---|---|
| (byte tag, byte[] content) |
ReadUtcTime()
Reads a UTCTime and returns a UTC DateTime.
Declaration
public DateTime ReadUtcTime()
Returns
| Type | Description |
|---|---|
| DateTime |
ReadUtf8String()
Reads a UTF8String.
Declaration
public string ReadUtf8String()
Returns
| Type | Description |
|---|---|
| string |
Skip()
Skips the next element without parsing it.
Declaration
public void Skip()