TLV - Reference Documentation
Implementation of an immutable TLV object with different encoding formats.
Index of Methods
Constants
Type |
Name |
Description |
Number |
EMV |
EMV encoding format, which follows ASN.1 / DER encoding rule |
Number |
DGI |
DGI encoding format using a 2 byte tag and a one or three byte length field |
Number |
L16 |
L16 encoding format using a 2 byte tag and a two byte length field |
Properties
Type |
Name |
Description |
Number |
encodingMode |
Encoding mode used for TLV object. One of TLV.EMV, TLV.DGI or TLV.L16 |
Number |
size |
Combined length of tag, length and value field |
Constructor
Prototype
TLV(Number tag, ByteString value, Number encoding)
Description
Create a TLV object initialized with the arguments given.
TLV objects are composed of a tag, a length and a value field.
The binary encoding format for the tag and length can be defined
with the encoding parameter.
For EMV encoding the tag field has a variable length of up to 4 bytes.
The length field has a variable length of up to 4 byte. Both fields are
encoded as specified as per ASN.1 Basic Encoding Rule (ISO 8825).
For DGI encoding the tag field has a fixed length of two bytes.
The length field contains one byte for values between 0 and 254. The length
is encoded in three bytes for values between 255 and 65535, with the first byte
set to 'FF'.
For L16 encoding the tag field has a fixed length of two bytes.
The length field is always two byte long and is encoded in big endian /
little endian format.
Arguments
Type |
Name |
Description |
Number
|
tag |
Tag value |
ByteString
|
value |
Value field of TLV object |
Number
|
encoding |
Encoding for tag and length field. Must be one of TLV.EMV, TLV.DGI or TLV.L16. |
Exceptions
Name |
Value |
Description |
GPError |
GPError.ARGUMENTS_MISSING |
Too few arguments in call |
GPError |
GPError.INVALID_ARGUMENTS |
Too many arguments in call |
GPError |
GPError.INVALID_TYPE |
Type of argument is invalid for call |
GPError |
GPError.INVALID_ENCODING |
The argument encoding is invalid |
GPError |
GPError.INVALID_TAG |
The tag value is invalid for the selected encoding format |
GPError |
GPError.DATA_TOO_LARGE |
The data supplied for the value fields exceeds the maximum length |
Example
t = new TLV(0x06, new ByteString("2A1234", HEX), TLV.EMV);
assert(t.encodingMode == TLV.EMV);
assert(t.size == 5);
t = new TLV(0x0601, new ByteString("2A1234", HEX), TLV.EMV);
assert(t.encodingMode == TLV.EMV);
assert(t.size == 6);
try {
// Invalid tag for EMV
t = new TLV(0x6FFFFF, new ByteString("2A1234", HEX), TLV.EMV);
} catch (e) {
assert(e instanceof GPError);
}
t = new TLV(0x1201, new ByteString("561000", ASCII), TLV.DGI);
assert(t.encodingMode == TLV.DGI);
assert(t.size == 9);
t = new TLV(0x12, new ByteString("561000", ASCII), TLV.DGI);
assert(t.encodingMode == TLV.DGI);
assert(t.size == 9);
t = new TLV(0x3221, new ByteString("123456", HEX), TLV.L16);
assert(t.encodingMode == TLV.L16);
assert(t.size == 7);
t = new TLV(0x32, new ByteString("123456", HEX), TLV.L16);
assert(t.encodingMode == TLV.L16);
assert(t.size == 7);
getL()
Prototype
ByteString getL()
Description
Return the value of the length field of the TLV object.
Return
ByteString
|
The length field of the object |
Exceptions
Name |
Value |
Description |
GPError |
GPError.INVALID_ARGUMENTS |
Too many arguments in call |
Example
t = new TLV(0x06, new ByteString("2A1234", HEX), TLV.EMV);
assert(t.getL().toString(HEX) == "03");
// 130 bytes
t = new TLV(0x06, new ByteString(
"00010203040506070809000102030405060708090001020304050607080900010203040" +
"50607080900010203040506070809000102030405060708090001020304050607080900" +
"01020304050607080900010203040506070809000102030405060708090001020304050" +
"60708090001020304050607080900010203040506070809", HEX), TLV.EMV);
assert(t.getL().toString(HEX) == "8182");
// 260 bytes
t = new TLV(0x06, new ByteString(
"00010203040506070809000102030405060708090001020304050607080900010203040" +
"50607080900010203040506070809000102030405060708090001020304050607080900" +
"01020304050607080900010203040506070809000102030405060708090001020304050" +
"60708090001020304050607080900010203040506070809000102030405060708090001" +
"02030405060708090001020304050607080900010203040506070809000102030405060" +
"70809000102030405060708090001020304050607080900010203040506070809000102" +
"03040506070809000102030405060708090001020304050607080900010203040506070" +
"80900010203040506070809", HEX), TLV.EMV);
assert(t.getL().toString(HEX) == "820104");
t = new TLV(0x06, new ByteString("2A1234", HEX), TLV.L16);
assert(t.getL().toString(HEX) == "0003");
t = new TLV(0x06, new ByteString(
"00010203040506070809000102030405060708090001020304050607080900010203040" +
"50607080900010203040506070809000102030405060708090001020304050607080900" +
"01020304050607080900010203040506070809000102030405060708090001020304050" +
"60708090001020304050607080900010203040506070809000102030405060708090001" +
"02030405060708090001020304050607080900010203040506070809000102030405060" +
"70809000102030405060708090001020304050607080900010203040506070809000102" +
"03040506070809000102030405060708090001020304050607080900010203040506070" +
"80900010203040506070809", HEX), TLV.L16);
assert(t.getL().toString(HEX) == "0104");
t = new TLV(0x06, new ByteString("2A1234", HEX), TLV.DGI);
assert(t.getL().toString(HEX) == "03");
t = new TLV(0x06, new ByteString(
"00010203040506070809000102030405060708090001020304050607080900010203040" +
"50607080900010203040506070809000102030405060708090001020304050607080900" +
"01020304050607080900010203040506070809000102030405060708090001020304050" +
"60708090001020304050607080900010203040506070809000102030405060708090001" +
"02030405060708090001020304050607080900010203040506070809000102030405060" +
"70809000102030405060708090001020304050607080900010203040506070809000102" +
"03040506070809000102030405060708090001020304050607080900010203040506070" +
"80900010203040506070809", HEX), TLV.DGI);
assert(t.getL().toString(HEX) == "FF0104");
getLV()
Prototype
ByteString getLV()
Description
Return the combined length and value field of the object
Return
ByteString
|
The combined length and value field |
Exceptions
Name |
Value |
Description |
GPError |
GPError.INVALID_ARGUMENTS |
Too many arguments in call |
Example
t = new TLV(0x06, new ByteString("2A1234", HEX), TLV.EMV);
assert(t.getLV().toString(HEX) == "032A1234");
t = new TLV(0x06, new ByteString("2A1234", HEX), TLV.L16);
assert(t.getLV().toString(HEX) == "00032A1234");
t = new TLV(0x06, new ByteString("2A1234", HEX), TLV.DGI);
assert(t.getLV().toString(HEX) == "032A1234");
getTag()
Prototype
Number getTag()
Description
Return the value of the tag field as numeric value-
Return
Number
|
Numeric value of the tag field |
Exceptions
Name |
Value |
Description |
GPError |
GPError.INVALID_ARGUMENTS |
Too many arguments in call |
Example
t = new TLV(0x06, new ByteString("2A1234", HEX), TLV.EMV);
assert(typeof(t.getTag()) == "number");
assert(t.getTag() == 0x06);
t = new TLV(0x9F03, new ByteString("2A1234", HEX), TLV.EMV);
assert(typeof(t.getTag()) == "number");
assert(t.getTag() == 0x9F03);
t = new TLV(0x06, new ByteString("2A1234", HEX), TLV.L16);
assert(t.getTag() == 0x06);
t = new TLV(0x061F, new ByteString("2A1234", HEX), TLV.DGI);
assert(t.getTag() == 0x061F);
getTLV()
Prototype
ByteString getTLV()
Description
Return the concatenation of tag, length and value as a sequence of byte using the encoding mode
specified in the constructor
Return
ByteString
|
The concatenation of tag, length and value |
Exceptions
Example
t = new TLV(0x06, new ByteString("2A1234", HEX), TLV.EMV);
assert(t.getTLV().toString(HEX) == "06032A1234");
t = new TLV(0x1201, new ByteString("561000", ASCII), TLV.DGI);
assert(t.getTLV().toString(HEX) == "120106353631303030");
t = new TLV(0x3221, new ByteString("123456", HEX), TLV.L16);
assert(t.getTLV().toString(HEX) == "32210003123456");
getTV()
Prototype
ByteString getTV()
Description
Return the field tag and value of the TLV in the specified encoding format.
Return
ByteString
|
Concatenated tag and length field |
Exceptions
Name |
Value |
Description |
GPError |
GPError.INVALID_ARGUMENTS |
Too many arguments in call |
Example
t = new TLV(0x06, new ByteString("2A1234", HEX), TLV.EMV);
assert(t.getTV().toString(HEX) == "062A1234");
t = new TLV(0x06, new ByteString("2A1234", HEX), TLV.L16);
assert(t.getTV().toString(HEX) == "00062A1234");
t = new TLV(0x061F, new ByteString("2A1234", HEX), TLV.DGI);
assert(t.getTV().toString(HEX) == "061F2A1234");
getValue()
Prototype
ByteString getValue()
Description
Return the value field of the TLV object
Return
ByteString
|
The value field of the TLV object |
Exceptions
Name |
Value |
Description |
GPError |
GPError.INVALID_ARGUMENTS |
Too many arguments in call |
Example
t = new TLV(0x06, new ByteString("2A1234", HEX), TLV.EMV);
assert(t.getValue().toString(HEX) == "2A1234");
t = new TLV(0x06, new ByteString("2A1234", HEX), TLV.L16);
assert(t.getValue().toString(HEX) == "2A1234");
t = new TLV(0x061F, new ByteString("2A1234", HEX), TLV.DGI);
assert(t.getValue().toString(HEX) == "2A1234");
© Copyright 2003 - 2013 CardContact
Software & System Consulting, Minden, Germany