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 Details

    • TAG_INTEGER

      public static final int TAG_INTEGER
      ASN.1 tag for INTEGER type.
      See Also:
    • TAG_OCTET_STRING

      public static final int TAG_OCTET_STRING
      ASN.1 tag for OCTET STRING type.
      See Also:
    • TAG_NULL

      public static final int TAG_NULL
      ASN.1 tag for NULL type.
      See Also:
    • TAG_OID

      public static final int TAG_OID
      ASN.1 tag for OID type.
      See Also:
    • TAG_UTF8STRING

      public static final int TAG_UTF8STRING
      ASN.1 tag for UTF8String type.
      See Also:
    • TAG_SEQUENCE

      public static final int TAG_SEQUENCE
      ASN.1 tag for SEQUENCE type.
      See Also:
    • TAG_ATTRIBUTE_BASE

      public static final int TAG_ATTRIBUTE_BASE
      Base value for ASN.1 context-specific attribute tags.
      See Also:
  • 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.
    • isAtEndOfSequence

      public boolean isAtEndOfSequence()
      Is the parser at the expected end of a sequence (based on the stated length of the sequence).
      Returns:
      true if the parser is at the expected end of the sequence, otherwise false
    • 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
      Throws:
      IllegalArgumentException - if the length uses a form that is not supported by this implementation, if the decoded length cannot be represented by this implementation, or if the decoded length exceeds the number of bytes remaining in the input data
    • 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