Class Tag


  • public class Tag
    extends java.lang.Object
    Class representing a tag that is part of a TLV structure. This implementation supports invalid encodings which are common in EMV and ICAO specifications. Such tags encode a tag number in the range 0 to 30 in a two byte tag (e.g. 9F02).
    Author:
    Andreas Schwier (www.cardcontact.de)
    • Constructor Detail

      • Tag

        public Tag​(int newTag,
                   byte newClass,
                   boolean newConstructed)
        Create tag from given components
        Parameters:
        newTag - Tag number. Range 0 to 30 are single byte tags, Range 31 to 127 are double byte tags, Range 128 to 16383 are triple byte tags
        newClass - Class of tag. Must be one of Tag.UNIVERSAL, Tag.APPLICATION, Tag.CONTEXT oder Tag.PRIVATE
        newConstructed - Boolean flag indicating if TLV object is contructed or primitive
      • Tag

        public Tag​(byte[] value,
                   int offset)
        Create tag from binary presentation
        Parameters:
        value - Byte array containing binary tag
        offset - Offset in byte array to look at
      • Tag

        public Tag​(byte[] value)
        Create tag from binary presentation
        Parameters:
        value - Byte array containing binary tag
    • Method Detail

      • equals

        public boolean equals​(java.lang.Object object)
        Test if Tags are equal
        Overrides:
        equals in class java.lang.Object
      • isConstructed

        public boolean isConstructed()
        Test if Tag has constructed flag set
        Returns:
        true if constructed
      • getNumber

        public int getNumber()
        Tag number getter
        Returns:
        tag number
      • getClazz

        public byte getClazz()
        Tag class getter
        Returns:
        class number
      • toByteArray

        public int toByteArray​(byte[] buffer,
                               int offset)
        Fill byte array at given position with binary representation of tag and return new offset.
        Parameters:
        buffer - Byte arrays to receive binary tag
        offset - Offset in byte array that receives the bytes
        Returns:
        New offset after storing the tag
      • getBytes

        public byte[] getBytes()
        Get byte array containing binary representation of tag
        Returns:
        Binary data for tag
      • getSize

        public int getSize()
        Get size of tag in number of bytes
        Returns:
        Number of bytes
      • toString

        public java.lang.String toString()
        Dump tag to string
        Overrides:
        toString in class java.lang.Object