Package org.forgerock.opendj.io
Class Asn1Tag
java.lang.Object
org.forgerock.opendj.io.Asn1Tag
Provides methods for building and analyzing ASN.1 tag bytes.
Examples of usage:
- Building a Universal, primitive with number 3 tag:
Asn1Tag.universal().number(3);
will return 0x03. - Building an application, constructed with number 9 tag:
Asn1Tag.application().constructed().number(9);
will return 0x69.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final byteThe BER type that is assigned to the universal bit string type.static final byteThe BER type that is assigned to the universal Boolean element.static final byteThe BER type that is assigned to the universal enumerated type.static final byteThe BER type that is assigned to the generalized time type.static final byteThe BER type that is assigned to the universal integer type.static final byteThe BER type that is assigned to the universal null type.static final byteThe BER type that is assigned to the universal object identifier type.static final byteThe BER type that is assigned to the universal octet string type.static final byteThe BER type that is assigned to the universal Printable String type.static final byteThe BER type that is assigned to the universal sequence type.static final byteThe BER type that is assigned to the universal set type.static final byteThe BER type that is assigned to the utc time type.static final byteThe BER type that is assigned to the universal UTF-8 String type. -
Method Summary
Modifier and TypeMethodDescriptionstatic Asn1TagReturns a primitive ASN.1 tag with the application tag class.Changes this ASN.1 tag from primitive to constructed.static Asn1TagReturns a primitive ASN.1 tag with the context-specific tag class.Returns the tag class.longReturns the tag number.booleanReturns whether this tag is constructed.bytenumber(int tagNumber) Returns the single byte representation of this tag having the provided tag number.longnumberMultiByte(long tagNumber) Returns the multi-byte representation of this tag having the provided tag number encoded as a long which may then be used for encoding and decoding multi-byte ASN.1 tags.static Asn1TagReturns a primitive ASN.1 tag with the private tag class.toString()Returns the string representation of this Asn1 tag.static Asn1TagReturns a primitive ASN.1 tag with the universal tag class.static Asn1TagvalueOf(byte tag) Converts the provided single byte tag to anAsn1Tag.static Asn1TagvalueOf(long tag) Converts the provided multi-byte tag to anAsn1Tag.
-
Field Details
-
UNIVERSAL_BOOLEAN_TYPE
public static final byte UNIVERSAL_BOOLEAN_TYPEThe BER type that is assigned to the universal Boolean element.- See Also:
-
UNIVERSAL_INTEGER_TYPE
public static final byte UNIVERSAL_INTEGER_TYPEThe BER type that is assigned to the universal integer type.- See Also:
-
UNIVERSAL_BIT_STRING_TYPE
public static final byte UNIVERSAL_BIT_STRING_TYPEThe BER type that is assigned to the universal bit string type.- See Also:
-
UNIVERSAL_OCTET_STRING_TYPE
public static final byte UNIVERSAL_OCTET_STRING_TYPEThe BER type that is assigned to the universal octet string type.- See Also:
-
UNIVERSAL_NULL_TYPE
public static final byte UNIVERSAL_NULL_TYPEThe BER type that is assigned to the universal null type.- See Also:
-
UNIVERSAL_OBJECT_IDENTIFIER
public static final byte UNIVERSAL_OBJECT_IDENTIFIERThe BER type that is assigned to the universal object identifier type.- See Also:
-
UNIVERSAL_ENUMERATED_TYPE
public static final byte UNIVERSAL_ENUMERATED_TYPEThe BER type that is assigned to the universal enumerated type.- See Also:
-
UNIVERSAL_UTF8_STRING_TYPE
public static final byte UNIVERSAL_UTF8_STRING_TYPEThe BER type that is assigned to the universal UTF-8 String type.- See Also:
-
UNIVERSAL_PRINTABLE_STRING_TYPE
public static final byte UNIVERSAL_PRINTABLE_STRING_TYPEThe BER type that is assigned to the universal Printable String type.- See Also:
-
UNIVERSAL_UTC_TIME_TYPE
public static final byte UNIVERSAL_UTC_TIME_TYPEThe BER type that is assigned to the utc time type.- See Also:
-
UNIVERSAL_GENERALIZED_TIME_TYPE
public static final byte UNIVERSAL_GENERALIZED_TIME_TYPEThe BER type that is assigned to the generalized time type.- See Also:
-
UNIVERSAL_SEQUENCE_TYPE
public static final byte UNIVERSAL_SEQUENCE_TYPEThe BER type that is assigned to the universal sequence type.- See Also:
-
UNIVERSAL_SET_TYPE
public static final byte UNIVERSAL_SET_TYPEThe BER type that is assigned to the universal set type.- See Also:
-
-
Method Details
-
valueOf
Converts the provided single byte tag to anAsn1Tag.- Parameters:
tag- The single byte tag to be converted.- Returns:
- The
Asn1Tagcorresponding to the provided tag byte.
-
valueOf
Converts the provided multi-byte tag to anAsn1Tag.- Parameters:
tag- The multi-byte tag to be converted.- Returns:
- The
Asn1Tagcorresponding to the provided tag byte.
-
universal
Returns a primitive ASN.1 tag with the universal tag class.- Returns:
- a primitive ASN.1 tag with the universal tag class
-
application
Returns a primitive ASN.1 tag with the application tag class.- Returns:
- a primitive ASN.1 tag with the application tag class
-
contextSpecific
Returns a primitive ASN.1 tag with the context-specific tag class.- Returns:
- a primitive ASN.1 tag with the context-specific tag class
-
privateTag
Returns a primitive ASN.1 tag with the private tag class.- Returns:
- a primitive ASN.1 tag with the private tag class
-
constructed
Changes this ASN.1 tag from primitive to constructed.- Returns:
- this ASN.1 tag.
-
number
public byte number(int tagNumber) Returns the single byte representation of this tag having the provided tag number. The tag number MUST be less than 31 in order to fit into a single byte. UsenumberMultiByte(long)for handling multi-byte tag numbers.- Parameters:
tagNumber- The tag number which must be less than 31.- Returns:
- The byte representation of this tag having the provided tag number.
- Throws:
IllegalArgumentException- If the tag number was greater than 30 and requires a multi-byte encoding.
-
numberMultiByte
public long numberMultiByte(long tagNumber) Returns the multi-byte representation of this tag having the provided tag number encoded as a long which may then be used for encoding and decoding multi-byte ASN.1 tags. The encoded tag is returned as a long whose lowest bytes contain the reverse ASN.1 encoding of the tag, such that the lowest byte contains the class and form. This ensures that comparisons with single byte encodings work as expected. The tag number MUST be less than 2^50.- Parameters:
tagNumber- The tag number which must be less than 2^50.- Returns:
- The long representation of this tag having the provided tag number.
- Throws:
IllegalArgumentException- If the tag number was greater than 2^50.
-
isConstructed
public boolean isConstructed()Returns whether this tag is constructed.- Returns:
trueif this tag is constructed,falseif it is primitive.
-
getTagClass
Returns the tag class.- Returns:
- the tag class
-
getTagNumber
public long getTagNumber()Returns the tag number.- Returns:
- the tag number
-
toString
Returns the string representation of this Asn1 tag. The string value corresponds to the chain of methods that should be called to produce the same Asn1 tag, e.g."contextSpecific().constructed().number(3)".
-