Package net.aifusion.asn
Enum Tag
- All Implemented Interfaces:
Serializable
,Comparable<Tag>
,java.lang.constant.Constable
Enumeration to handle ASN.1 Tags
- Author:
- Sharad Singhal
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
Enum Constant Summary
Enum ConstantDescriptionan arbitrary string of bits (ones and zeroes)BMP String value.BOOLEAN valueCharacter String valueEmbedded PDV valueEnd of contentEnumerated valueExternalGeneral String valueGeneralized Time valueGraphic stringan arbitrary string of IA5 (ASCII) charactersInstance ofInteger valueISO 646 Stringa null valueNumeric stringObject Descriptoran object identifieran arbitrary string of octets (eight-bit values)an arbitrary string of printable charactersReal numberRelative OIDReservedReservedan ordered collection of zero or more typesan ordered collection of one or more occurrences of a given typean unordered collection of zero or more typesan unordered collection of one or more typesan arbitrary string of T.61 (eight-bit) charactersTeletex stringUniversal String valueUser Defined taga "coordinated universal time" or Greenwich Mean Time (GMT) valueutf-8 string valueVideoTex StringVisible String -
Method Summary
Modifier and TypeMethodDescriptionbyte[]
Get the encoded value of this tagstatic byte[]
getEncoded
(long tagNumber, TagClass c, TagEncoding e) Tag Encodingbyte
Return the identifier associated with this taglong
Get the length needed to encode this tagstatic int
getRequiredLength
(long tagNumber) Get the number of bytes needed to encode a given tag number
Note that the standard allows the tag number to be an arbitrary precision unsigned integer.Get the class associated with this tagGet the encoding associated with this taglong
Get the number associated with this tagstatic long
getTagNumber
(byte[] encoding, int cursor) Get the tag number from an encoded value Note that the standard allows the tag number to be an arbitrary precision unsigned integer.static Tag
locate
(byte identifier) Locate the tag corresponding a given identifier
Note that in some cases (e.g., SEQUENCE and SEQUENCE_OF) two tags have the same identifier.static Tag
Returns the enum constant of this type with the specified name.static Tag[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.Methods inherited from class java.lang.Enum
compareTo, describeConstable, equals, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
-
Enum Constant Details
-
END_OF_CONTENT
End of content -
BOOLEAN
BOOLEAN value -
INTEGER
Integer value -
BIT_STRING
an arbitrary string of bits (ones and zeroes) -
OCTET_STRING
an arbitrary string of octets (eight-bit values) -
NULL
a null value -
OBJECT_IDENTIFIER
an object identifier -
OBJECT_DESCRIPTOR
Object Descriptor -
INSTANCE_OF
Instance of -
EXTERNAL
External -
REAL
Real number -
ENUMERATED
Enumerated value -
EMBEDDED_PDV
Embedded PDV value -
UTF8_STRING
utf-8 string value -
RELATIVE_OID
Relative OID -
RESERVED_1
Reserved -
RESERVED_2
Reserved -
SEQUENCE
an ordered collection of zero or more types -
SEQUENCE_OF
an ordered collection of one or more occurrences of a given type -
SET
an unordered collection of zero or more types -
SET_OF
an unordered collection of one or more types -
NUMERIC_STRING
Numeric string -
PRINTABLE_STRING
an arbitrary string of printable characters -
T61_STRING
an arbitrary string of T.61 (eight-bit) characters -
TELETEX_STRING
Teletex string -
VIDEOTEX_STRING
VideoTex String -
IA5_STRING
an arbitrary string of IA5 (ASCII) characters -
UTC_TIME
a "coordinated universal time" or Greenwich Mean Time (GMT) value -
GENERALIZED_TIME
Generalized Time value -
GRAPHIC_STRING
Graphic string -
VISIBLE_STRING
Visible String -
ISO646_STRING
ISO 646 String -
GENERAL_STRING
General String value -
UNIVERSAL_STRING
Universal String value -
CHARACTER_STRING
Character String value -
BMP_STRING
BMP String value. -
USER_DEFINED
User Defined tag
-
-
Method Details
-
values
Returns an array containing the constants of this enum type, in the order they are declared.- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is null
-
getTagNumber
public long getTagNumber()Get the number associated with this tag- Returns:
- - tag number [0..31]
-
getTagClass
Get the class associated with this tag- Returns:
- - UNIVERSAL or CONTEXT_SPECIFIC
-
getTagEncoding
Get the encoding associated with this tag- Returns:
- - encoding CONSTRUCTED or PRIMITIVE
-
getIdentifier
public byte getIdentifier()Return the identifier associated with this tag- Returns:
- - byte including tag class, encoding and tag number
-
getLength
public long getLength()Get the length needed to encode this tag- Returns:
- - number of bytes needed to encode this tag
-
getEncoded
public byte[] getEncoded()Get the encoded value of this tag- Returns:
- - encoded value for this tag
-
locate
Locate the tag corresponding a given identifier
Note that in some cases (e.g., SEQUENCE and SEQUENCE_OF) two tags have the same identifier. In that case the first tag in the enum will be returned.- Parameters:
identifier
- - identifier for the tag to locate- Returns:
- - corresponding tag, if pre-defined
-
getRequiredLength
public static int getRequiredLength(long tagNumber) Get the number of bytes needed to encode a given tag number
Note that the standard allows the tag number to be an arbitrary precision unsigned integer. We restrict the tag number to be no more than 63 bits to fit in a long.- Parameters:
tagNumber
- - value of the tag (must be a positive number)- Returns:
- - number of bytes needed to encode the tag (identifier+tagNumber)
-
getEncoded
Tag Encoding____________________________________________________________________ |Octet 1 | Octet 2 onwards | |8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | |Tag Class|P/C| Tag Number(0-30) | NA | | | | 31 | more | Tag Number | |_________|___|___________________|__________________________________|
Tag class can be {Universal, Application, ContextSensitive, or Private}
Encoding can {Primitive, Constructed}
Tag Number is encoded either as part of the first byte (for tag values < 31), or as the first byte followed by one or more bytes using the long form. The initial octet encodes the tag class and encoding as before, and bits 1..5 are 1. The tag number is encoded in the following octets, where bit 8 of each is 1 if there are more octets, and bits 1..7 encode the tag number. The tag number bits combined, big-endian, encode the tag number. The least number of following octets should be encoded; that is, bits 1..7 should not all be 0 in the first following octet.
Note that the standard allows the tag number to be an arbitrary precision unsigned integer. We restrict the tag length to be no more than 63 bits to fit in a long.- Parameters:
tagNumber
- - tag numberc
- - tag classe
- - encoding type- Returns:
- - byte sequence containing the encoded value of the tag (identifier + tagNumber)
-
getTagNumber
public static long getTagNumber(byte[] encoding, int cursor) Get the tag number from an encoded value Note that the standard allows the tag number to be an arbitrary precision unsigned integer. We restrict the tag length to be no more than 63 bits to fit in a long.- Parameters:
encoding
- - byte array containing the encoded value of the tagcursor
- - starting offset within the array- Returns:
- - tag number
-