Package de.cardcontact.tlv
Class Tag
- java.lang.Object
-
- de.cardcontact.tlv.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)
-
-
Field Summary
Fields Modifier and Type Field Description static byte
APPLICATION
static int
BIT_STRING
static int
BMPString
static int
BOOLEAN
static byte
CLASS
static byte
CONSTRUCTED
static byte
CONTEXT
static int
EMBEDDED_PDV
static int
END_OF_CONTENTS
static int
ENUMERATED
static int
EXTERNAL_TYPE
static int
GeneralizedTime
static int
GeneralString
static int
IA5String
static int
INTEGER
static int
NULL
static int
NumericString
static int
OBJECT_DESCRIPTOR
static int
OBJECT_IDENTIFIER
static int
OCTET_STRING
static int
PrintableString
static byte
PRIVATE
static int
REAL
static int
RELATIVE_OID
static int
SEQUENCE
static int
SET
static int
T61String
static byte
TAG
static Tag
TAG_BIT_STRING
static Tag
TAG_INTEGER
static Tag
TAG_NumericString
static Tag
TAG_OBJECT_IDENTIFIER
static Tag
TAG_OCTET_STRING
static Tag
TAG_PrintableString
static Tag
TAG_SEQUENCE
static Tag
TAG_SET
static Tag
TAG_UTF8String
static byte
UNIVERSAL
static int
UniversalString
static int
UTCTime
static int
UTF8String
-
Constructor Summary
Constructors Constructor Description Tag(byte[] value)
Create tag from binary presentationTag(byte[] value, int offset)
Create tag from binary presentationTag(int newTag)
Create tag from integer representationTag(int newTag, byte newClass, boolean newConstructed)
Create tag from given componentsTag(ParseBuffer pb)
Create tag from binary presentation in ParseBuffer
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object object)
Test if Tags are equalbyte[]
getBytes()
Get byte array containing binary representation of tagbyte
getClazz()
Tag class getterint
getNumber()
Tag number getterint
getSize()
Get size of tag in number of bytesboolean
isConstructed()
Test if Tag has constructed flag setint
toByteArray(byte[] buffer, int offset)
Fill byte array at given position with binary representation of tag and return new offset.java.lang.String
toString()
Dump tag to string
-
-
-
Field Detail
-
CONSTRUCTED
public static final byte CONSTRUCTED
- See Also:
- Constant Field Values
-
CLASS
public static final byte CLASS
- See Also:
- Constant Field Values
-
TAG
public static final byte TAG
- See Also:
- Constant Field Values
-
UNIVERSAL
public static final byte UNIVERSAL
- See Also:
- Constant Field Values
-
APPLICATION
public static final byte APPLICATION
- See Also:
- Constant Field Values
-
CONTEXT
public static final byte CONTEXT
- See Also:
- Constant Field Values
-
PRIVATE
public static final byte PRIVATE
- See Also:
- Constant Field Values
-
END_OF_CONTENTS
public static final int END_OF_CONTENTS
- See Also:
- Constant Field Values
-
BOOLEAN
public static final int BOOLEAN
- See Also:
- Constant Field Values
-
INTEGER
public static final int INTEGER
- See Also:
- Constant Field Values
-
BIT_STRING
public static final int BIT_STRING
- See Also:
- Constant Field Values
-
OCTET_STRING
public static final int OCTET_STRING
- See Also:
- Constant Field Values
-
NULL
public static final int NULL
- See Also:
- Constant Field Values
-
OBJECT_IDENTIFIER
public static final int OBJECT_IDENTIFIER
- See Also:
- Constant Field Values
-
OBJECT_DESCRIPTOR
public static final int OBJECT_DESCRIPTOR
- See Also:
- Constant Field Values
-
EXTERNAL_TYPE
public static final int EXTERNAL_TYPE
- See Also:
- Constant Field Values
-
REAL
public static final int REAL
- See Also:
- Constant Field Values
-
ENUMERATED
public static final int ENUMERATED
- See Also:
- Constant Field Values
-
EMBEDDED_PDV
public static final int EMBEDDED_PDV
- See Also:
- Constant Field Values
-
UTF8String
public static final int UTF8String
- See Also:
- Constant Field Values
-
RELATIVE_OID
public static final int RELATIVE_OID
- See Also:
- Constant Field Values
-
SEQUENCE
public static final int SEQUENCE
- See Also:
- Constant Field Values
-
SET
public static final int SET
- See Also:
- Constant Field Values
-
NumericString
public static final int NumericString
- See Also:
- Constant Field Values
-
PrintableString
public static final int PrintableString
- See Also:
- Constant Field Values
-
T61String
public static final int T61String
- See Also:
- Constant Field Values
-
IA5String
public static final int IA5String
- See Also:
- Constant Field Values
-
UTCTime
public static final int UTCTime
- See Also:
- Constant Field Values
-
GeneralizedTime
public static final int GeneralizedTime
- See Also:
- Constant Field Values
-
GeneralString
public static final int GeneralString
- See Also:
- Constant Field Values
-
UniversalString
public static final int UniversalString
- See Also:
- Constant Field Values
-
BMPString
public static final int BMPString
- See Also:
- Constant Field Values
-
TAG_INTEGER
public static final Tag TAG_INTEGER
-
TAG_BIT_STRING
public static final Tag TAG_BIT_STRING
-
TAG_OCTET_STRING
public static final Tag TAG_OCTET_STRING
-
TAG_OBJECT_IDENTIFIER
public static final Tag TAG_OBJECT_IDENTIFIER
-
TAG_SEQUENCE
public static final Tag TAG_SEQUENCE
-
TAG_SET
public static final Tag TAG_SET
-
TAG_UTF8String
public static final Tag TAG_UTF8String
-
TAG_PrintableString
public static final Tag TAG_PrintableString
-
TAG_NumericString
public static final Tag TAG_NumericString
-
-
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 tagsnewClass
- Class of tag. Must be one of Tag.UNIVERSAL, Tag.APPLICATION, Tag.CONTEXT oder Tag.PRIVATEnewConstructed
- Boolean flag indicating if TLV object is contructed or primitive
-
Tag
public Tag(ParseBuffer pb) throws TLVEncodingException
Create tag from binary presentation in ParseBuffer- Parameters:
pb
- ParseBuffer- Throws:
TLVEncodingException
-
Tag
public Tag(byte[] value, int offset)
Create tag from binary presentation- Parameters:
value
- Byte array containing binary tagoffset
- Offset in byte array to look at
-
Tag
public Tag(byte[] value)
Create tag from binary presentation- Parameters:
value
- Byte array containing binary tag
-
Tag
public Tag(int newTag) throws TLVEncodingException
Create tag from integer representation- Parameters:
newTag
- Integer tag value (e.g. 0x5F32)- Throws:
TLVEncodingException
-
-
Method Detail
-
equals
public boolean equals(java.lang.Object object)
Test if Tags are equal- Overrides:
equals
in classjava.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 tagoffset
- 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 classjava.lang.Object
-
-