Package org.forgerock.opendj.io
Class Asn1Tag
- java.lang.Object
-
- org.forgerock.opendj.io.Asn1Tag
-
public final class Asn1Tag extends Object
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.
- Building a Universal, primitive with number 3 tag:
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAsn1Tag.ClassThe Asn1 tag classes.
-
Field Summary
Fields Modifier and Type Field Description static byteUNIVERSAL_BIT_STRING_TYPEThe BER type that is assigned to the universal bit string type.static byteUNIVERSAL_BOOLEAN_TYPEThe BER type that is assigned to the universal Boolean element.static byteUNIVERSAL_ENUMERATED_TYPEThe BER type that is assigned to the universal enumerated type.static byteUNIVERSAL_GENERALIZED_TIME_TYPEThe BER type that is assigned to the generalized time type.static byteUNIVERSAL_INTEGER_TYPEThe BER type that is assigned to the universal integer type.static byteUNIVERSAL_NULL_TYPEThe BER type that is assigned to the universal null type.static byteUNIVERSAL_OBJECT_IDENTIFIERThe BER type that is assigned to the universal object identifier type.static byteUNIVERSAL_OCTET_STRING_TYPEThe BER type that is assigned to the universal octet string type.static byteUNIVERSAL_PRINTABLE_STRING_TYPEThe BER type that is assigned to the universal Printable String type.static byteUNIVERSAL_SEQUENCE_TYPEThe BER type that is assigned to the universal sequence type.static byteUNIVERSAL_SET_TYPEThe BER type that is assigned to the universal set type.static byteUNIVERSAL_UTC_TIME_TYPEThe BER type that is assigned to the utc time type.static byteUNIVERSAL_UTF8_STRING_TYPEThe BER type that is assigned to the universal UTF-8 String type.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Asn1Tagapplication()Returns a primitive ASN.1 tag with the application tag class.Asn1Tagconstructed()Changes this ASN.1 tag from primitive to constructed.static Asn1TagcontextSpecific()Returns a primitive ASN.1 tag with the context-specific tag class.Asn1Tag.ClassgetTagClass()Returns the tag class.longgetTagNumber()Returns the tag number.booleanisConstructed()Returns 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 Asn1TagprivateTag()Returns a primitive ASN.1 tag with the private tag class.StringtoString()Returns the string representation of this Asn1 tag.static Asn1Taguniversal()Returns 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 Detail
-
UNIVERSAL_BOOLEAN_TYPE
public static final byte UNIVERSAL_BOOLEAN_TYPE
The BER type that is assigned to the universal Boolean element.- See Also:
- Constant Field Values
-
UNIVERSAL_INTEGER_TYPE
public static final byte UNIVERSAL_INTEGER_TYPE
The BER type that is assigned to the universal integer type.- See Also:
- Constant Field Values
-
UNIVERSAL_BIT_STRING_TYPE
public static final byte UNIVERSAL_BIT_STRING_TYPE
The BER type that is assigned to the universal bit string type.- See Also:
- Constant Field Values
-
UNIVERSAL_OCTET_STRING_TYPE
public static final byte UNIVERSAL_OCTET_STRING_TYPE
The BER type that is assigned to the universal octet string type.- See Also:
- Constant Field Values
-
UNIVERSAL_NULL_TYPE
public static final byte UNIVERSAL_NULL_TYPE
The BER type that is assigned to the universal null type.- See Also:
- Constant Field Values
-
UNIVERSAL_OBJECT_IDENTIFIER
public static final byte UNIVERSAL_OBJECT_IDENTIFIER
The BER type that is assigned to the universal object identifier type.- See Also:
- Constant Field Values
-
UNIVERSAL_ENUMERATED_TYPE
public static final byte UNIVERSAL_ENUMERATED_TYPE
The BER type that is assigned to the universal enumerated type.- See Also:
- Constant Field Values
-
UNIVERSAL_UTF8_STRING_TYPE
public static final byte UNIVERSAL_UTF8_STRING_TYPE
The BER type that is assigned to the universal UTF-8 String type.- See Also:
- Constant Field Values
-
UNIVERSAL_PRINTABLE_STRING_TYPE
public static final byte UNIVERSAL_PRINTABLE_STRING_TYPE
The BER type that is assigned to the universal Printable String type.- See Also:
- Constant Field Values
-
UNIVERSAL_UTC_TIME_TYPE
public static final byte UNIVERSAL_UTC_TIME_TYPE
The BER type that is assigned to the utc time type.- See Also:
- Constant Field Values
-
UNIVERSAL_GENERALIZED_TIME_TYPE
public static final byte UNIVERSAL_GENERALIZED_TIME_TYPE
The BER type that is assigned to the generalized time type.- See Also:
- Constant Field Values
-
UNIVERSAL_SEQUENCE_TYPE
public static final byte UNIVERSAL_SEQUENCE_TYPE
The BER type that is assigned to the universal sequence type.- See Also:
- Constant Field Values
-
UNIVERSAL_SET_TYPE
public static final byte UNIVERSAL_SET_TYPE
The BER type that is assigned to the universal set type.- See Also:
- Constant Field Values
-
-
Method Detail
-
valueOf
public static Asn1Tag valueOf(byte tag)
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
public static Asn1Tag valueOf(long tag)
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
public static Asn1Tag universal()
Returns a primitive ASN.1 tag with the universal tag class.- Returns:
- A primitive ASN.1 tag with the universal tag class.
-
application
public static Asn1Tag application()
Returns a primitive ASN.1 tag with the application tag class.- Returns:
- A primitive ASN.1 tag with the application tag class.
-
contextSpecific
public static Asn1Tag 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
public static Asn1Tag privateTag()
Returns a primitive ASN.1 tag with the private tag class.- Returns:
- A primitive ASN.1 tag with the private tag class.
-
constructed
public Asn1Tag 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
public Asn1Tag.Class getTagClass()
Returns the tag class.- Returns:
- The tag class.
-
getTagNumber
public long getTagNumber()
Returns the tag number.- Returns:
- the tag number.
-
toString
public String 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)".
-
-