Package org.apache.tomcat.util.buf
Class Asn1Parser
- java.lang.Object
-
- org.apache.tomcat.util.buf.Asn1Parser
-
public class Asn1Parser extends java.lang.ObjectThis 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 intTAG_ATTRIBUTE_BASEBase value for ASN.1 context-specific attribute tags.static intTAG_INTEGERASN.1 tag for INTEGER type.static intTAG_NULLASN.1 tag for NULL type.static intTAG_OCTET_STRINGASN.1 tag for OCTET STRING type.static intTAG_OIDASN.1 tag for OID type.static intTAG_SEQUENCEASN.1 tag for SEQUENCE type.static intTAG_UTF8STRINGASN.1 tag for UTF8String type.
-
Constructor Summary
Constructors Constructor Description Asn1Parser(byte[] source)Constructs a new Asn1Parser.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleaneof()Returns whether the end of the source data has been reached.intgetNestedSequenceLevel()Returns the current nesting level of SEQUENCE tags.byte[]parseAttributeAsBytes(int index)Parses a context-specific attribute value as raw bytes.voidparseBytes(byte[] dest)Reads raw bytes into the destination array.voidparseFullLength()Validates that the remaining data matches the parsed length.java.math.BigIntegerparseInt()Parses an INTEGER value.intparseLength()Parses an ASN.1 length field.voidparseNull()Parses a NULL value.byte[]parseOctetString()Parses an OCTET STRING value.byte[]parseOIDAsBytes()Parses an OID value as raw bytes.voidparseTag(int tag)Parses and validates an expected tag.voidparseTagSequence()Parses a SEQUENCE tag and tracks nesting.java.lang.StringparseUTF8String()Parses a UTF8String value.intpeekTag()Returns the next ASN.1 tag byte without advancing the position.
-
-
-
Field Detail
-
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
-
-
Method Detail
-
eof
public boolean eof()
Returns whether the end of the source data has been reached.- Returns:
trueif 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 java.math.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 java.lang.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
-
-