Enum Tag

java.lang.Object
java.lang.Enum<Tag>
net.aifusion.asn.Tag
All Implemented Interfaces:
Serializable, Comparable<Tag>, java.lang.constant.Constable

public enum Tag extends Enum<Tag>
Enumeration to handle ASN.1 Tags
Author:
Sharad Singhal
  • Enum Constant Details

    • END_OF_CONTENT

      public static final Tag END_OF_CONTENT
      End of content
    • BOOLEAN

      public static final Tag BOOLEAN
      BOOLEAN value
    • INTEGER

      public static final Tag INTEGER
      Integer value
    • BIT_STRING

      public static final Tag BIT_STRING
      an arbitrary string of bits (ones and zeroes)
    • OCTET_STRING

      public static final Tag OCTET_STRING
      an arbitrary string of octets (eight-bit values)
    • NULL

      public static final Tag NULL
      a null value
    • OBJECT_IDENTIFIER

      public static final Tag OBJECT_IDENTIFIER
      an object identifier
    • OBJECT_DESCRIPTOR

      public static final Tag OBJECT_DESCRIPTOR
      Object Descriptor
    • INSTANCE_OF

      public static final Tag INSTANCE_OF
      Instance of
    • EXTERNAL

      public static final Tag EXTERNAL
      External
    • REAL

      public static final Tag REAL
      Real number
    • ENUMERATED

      public static final Tag ENUMERATED
      Enumerated value
    • EMBEDDED_PDV

      public static final Tag EMBEDDED_PDV
      Embedded PDV value
    • UTF8_STRING

      public static final Tag UTF8_STRING
      utf-8 string value
    • RELATIVE_OID

      public static final Tag RELATIVE_OID
      Relative OID
    • RESERVED_1

      public static final Tag RESERVED_1
      Reserved
    • RESERVED_2

      public static final Tag RESERVED_2
      Reserved
    • SEQUENCE

      public static final Tag SEQUENCE
      an ordered collection of zero or more types
    • SEQUENCE_OF

      public static final Tag SEQUENCE_OF
      an ordered collection of one or more occurrences of a given type
    • SET

      public static final Tag SET
      an unordered collection of zero or more types
    • SET_OF

      public static final Tag SET_OF
      an unordered collection of one or more types
    • NUMERIC_STRING

      public static final Tag NUMERIC_STRING
      Numeric string
    • PRINTABLE_STRING

      public static final Tag PRINTABLE_STRING
      an arbitrary string of printable characters
    • T61_STRING

      public static final Tag T61_STRING
      an arbitrary string of T.61 (eight-bit) characters
    • TELETEX_STRING

      public static final Tag TELETEX_STRING
      Teletex string
    • VIDEOTEX_STRING

      public static final Tag VIDEOTEX_STRING
      VideoTex String
    • IA5_STRING

      public static final Tag IA5_STRING
      an arbitrary string of IA5 (ASCII) characters
    • UTC_TIME

      public static final Tag UTC_TIME
      a "coordinated universal time" or Greenwich Mean Time (GMT) value
    • GENERALIZED_TIME

      public static final Tag GENERALIZED_TIME
      Generalized Time value
    • GRAPHIC_STRING

      public static final Tag GRAPHIC_STRING
      Graphic string
    • VISIBLE_STRING

      public static final Tag VISIBLE_STRING
      Visible String
    • ISO646_STRING

      public static final Tag ISO646_STRING
      ISO 646 String
    • GENERAL_STRING

      public static final Tag GENERAL_STRING
      General String value
    • UNIVERSAL_STRING

      public static final Tag UNIVERSAL_STRING
      Universal String value
    • CHARACTER_STRING

      public static final Tag CHARACTER_STRING
      Character String value
    • BMP_STRING

      public static final Tag BMP_STRING
      BMP String value.
    • USER_DEFINED

      public static final Tag USER_DEFINED
      User Defined tag
  • Method Details

    • values

      public static Tag[] 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

      public static Tag valueOf(String name)
      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 name
      NullPointerException - if the argument is null
    • getTagNumber

      public long getTagNumber()
      Get the number associated with this tag
      Returns:
      - tag number [0..31]
    • getTagClass

      public TagClass getTagClass()
      Get the class associated with this tag
      Returns:
      - UNIVERSAL or CONTEXT_SPECIFIC
    • getTagEncoding

      public TagEncoding 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

      public 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. 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

      public static byte[] getEncoded(long tagNumber, TagClass c, TagEncoding e)
      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 number
      c - - tag class
      e - - 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 tag
      cursor - - starting offset within the array
      Returns:
      - tag number