Class Asn1Parser
java.lang.Object
org.apache.tomcat.util.buf.Asn1Parser
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
FieldsModifier and TypeFieldDescriptionstatic final intBase value for ASN.1 context-specific attribute tags.static final intASN.1 tag for INTEGER type.static final intASN.1 tag for NULL type.static final intASN.1 tag for OCTET STRING type.static final intASN.1 tag for OID type.static final intASN.1 tag for SEQUENCE type.static final intASN.1 tag for UTF8String type. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleaneof()Returns whether the end of the source data has been reached.intReturns 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.voidValidates that the remaining data matches the parsed length.parseInt()Parses an INTEGER value.intParses an ASN.1 length field.voidParses a NULL value.byte[]Parses an OCTET STRING value.byte[]Parses an OID value as raw bytes.voidparseTag(int tag) Parses and validates an expected tag.voidParses a SEQUENCE tag and tracks nesting.Parses a UTF8String value.intpeekTag()Returns the next ASN.1 tag byte without advancing the position.
-
Field Details
-
TAG_INTEGER
public static final int TAG_INTEGERASN.1 tag for INTEGER type.- See Also:
-
TAG_OCTET_STRING
public static final int TAG_OCTET_STRINGASN.1 tag for OCTET STRING type.- See Also:
-
TAG_NULL
public static final int TAG_NULLASN.1 tag for NULL type.- See Also:
-
TAG_OID
public static final int TAG_OIDASN.1 tag for OID type.- See Also:
-
TAG_UTF8STRING
public static final int TAG_UTF8STRINGASN.1 tag for UTF8String type.- See Also:
-
TAG_SEQUENCE
public static final int TAG_SEQUENCEASN.1 tag for SEQUENCE type.- See Also:
-
TAG_ATTRIBUTE_BASE
public static final int TAG_ATTRIBUTE_BASEBase 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:
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
-
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
-
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
-