Asn1Parser (Apache Tomcat 11.0.24 API Documentation)
Description: declaration: package: org.apache.tomcat.util.buf, class: Asn1Parser

# Class Asn1Parser

java.lang.Object
org.apache.tomcat.util.buf.Asn1Parser

public class Asn1Parser extends Object
This is a very basic ASN.1 parser that provides the limited functionality required by Tomcat. It is a long way from a complete parser.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final int`
  `TAG_ATTRIBUTE_BASE`
  Base value for ASN.1 context-specific attribute tags.
  `static final int`
  `TAG_INTEGER`
  ASN.1 tag for INTEGER type.
  `static final int`
  `TAG_NULL`
  ASN.1 tag for NULL type.
  `static final int`
  `TAG_OCTET_STRING`
  ASN.1 tag for OCTET STRING type.
  `static final int`
  `TAG_OID`
  ASN.1 tag for OID type.
  `static final int`
  `TAG_SEQUENCE`
  ASN.1 tag for SEQUENCE type.
  `static final int`
  `TAG_UTF8STRING`
  ASN.1 tag for UTF8String type.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Asn1Parser(byte[] source)`
  Constructs a new Asn1Parser.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `eof()`
  Returns whether the end of the source data has been reached.
  `int`
  `getNestedSequenceLevel()`
  Returns the current nesting level of SEQUENCE tags.
  `byte[]`
  `parseAttributeAsBytes(int index)`
  Parses a context-specific attribute value as raw bytes.
  `void`
  `parseBytes(byte[] dest)`
  Reads raw bytes into the destination array.
  `void`
  `parseFullLength()`
  Validates that the remaining data matches the parsed length.
  `BigInteger`
  `parseInt()`
  Parses an INTEGER value.
  `int`
  `parseLength()`
  Parses an ASN.1 length field.
  `void`
  `parseNull()`
  Parses a NULL value.
  `byte[]`
  `parseOctetString()`
  Parses an OCTET STRING value.
  `byte[]`
  `parseOIDAsBytes()`
  Parses an OID value as raw bytes.
  `void`
  `parseTag(int tag)`
  Parses and validates an expected tag.
  `void`
  `parseTagSequence()`
  Parses a SEQUENCE tag and tracks nesting.
  `String`
  `parseUTF8String()`
  Parses a UTF8String value.
  `int`
  `peekTag()`
  Returns the next ASN.1 tag byte without advancing the position.

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### TAG_INTEGER

    public static final int TAG_INTEGER
    ASN.1 tag for INTEGER type.
    See Also:
      - Constant Field Values

  - ### TAG_OCTET_STRING

    public static final int TAG_OCTET_STRING
    ASN.1 tag for OCTET STRING type.
    See Also:
      - Constant Field Values

  - ### TAG_NULL

    public static final int TAG_NULL
    ASN.1 tag for NULL type.
    See Also:
      - Constant Field Values

  - ### TAG_OID

    public static final int TAG_OID
    ASN.1 tag for OID type.
    See Also:
      - Constant Field Values

  - ### TAG_UTF8STRING

    public static final int TAG_UTF8STRING
    ASN.1 tag for UTF8String type.
    See Also:
      - Constant Field Values

  - ### TAG_SEQUENCE

    public static final int TAG_SEQUENCE
    ASN.1 tag for SEQUENCE type.
    See Also:
      - Constant Field Values

  - ### TAG_ATTRIBUTE_BASE

    public static final int TAG_ATTRIBUTE_BASE
    Base value for ASN.1 context-specific attribute tags.
    See Also:
      - Constant Field Values

- ## Constructor Details

  - ### Asn1Parser

    public Asn1Parser(byte[] source)
    Constructs a new Asn1Parser.
    Parameters:
      `source` - the source byte array to parse

- ## Method Details

  - ### eof

    public boolean eof()
    Returns whether the end of the source data has been reached.
    Returns:
      `true` if the end of the source data has been reached

  - ### peekTag

    public int peekTag()
    Returns the next ASN.1 tag byte without advancing the position.
    Returns:
      the next tag byte value

  - ### parseTagSequence

    public void parseTagSequence()
    Parses a SEQUENCE tag and tracks nesting.

  - ### parseTag

    public void parseTag(int tag)
    Parses and validates an expected tag.
    Parameters:
      `tag` - the expected tag value

  - ### parseFullLength

    public void parseFullLength()
    Validates that the remaining data matches the parsed length.

  - ### parseLength

    public int parseLength()
    Parses an ASN.1 length field.
    Returns:
      the parsed length value

  - ### parseInt

    public BigInteger parseInt()
    Parses an INTEGER value.
    Returns:
      the parsed integer as a `BigInteger`

  - ### parseOctetString

    public byte[] parseOctetString()
    Parses an OCTET STRING value.
    Returns:
      the parsed octet string bytes

  - ### parseNull

    public void parseNull()
    Parses a NULL value.

  - ### parseOIDAsBytes

    public byte[] parseOIDAsBytes()
    Parses an OID value as raw bytes.
    Returns:
      the parsed OID bytes

  - ### parseUTF8String

    public String parseUTF8String()
    Parses a UTF8String value.
    Returns:
      the parsed UTF-8 string

  - ### parseAttributeAsBytes

    public byte[] parseAttributeAsBytes(int index)
    Parses a context-specific attribute value as raw bytes.
    Parameters:
      `index` - the context-specific attribute index
    Returns:
      the parsed attribute bytes

  - ### parseBytes

    public void parseBytes(byte[] dest)
    Reads raw bytes into the destination array.
    Parameters:
      `dest` - the destination byte array

  - ### getNestedSequenceLevel

    public int getNestedSequenceLevel()
    Returns the current nesting level of SEQUENCE tags.
    Returns:
      the number of nested SEQUENCE tags