SSE4E

Home

GPError
GPSystem
ByteString
ByteBuffer
TLV
TLVList
Card
Atr
Key
Crypto
Application GPApplication GPSecDomain

ASN1
CardFile
IsoSecureChannel
ApplFactory
GPXML
JsScript
CardSim

X509
CRL
KeyStore
CMSSignedData
CMSGenerator
XMLSignature
OCSPQuery
LDAP
SOAP
URLConnection

PKCS11Provider
PKCS11Session
PKCS11Object

OutlineNode

OpenSCDP

TLV - Reference Documentation

Implementation of an immutable TLV object with different encoding formats.

Index of Methods

Constants

TypeNameDescription
NumberEMVEMV encoding format, which follows ASN.1 / DER encoding rule
NumberDGIDGI encoding format using a 2 byte tag and a one or three byte length field
NumberL16L16 encoding format using a 2 byte tag and a two byte length field

Properties

TypeNameDescription
NumberencodingModeEncoding mode used for TLV object. One of TLV.EMV, TLV.DGI or TLV.L16
NumbersizeCombined 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

TypeNameDescription
NumbertagTag value
ByteStringvalueValue field of TLV object
NumberencodingEncoding for tag and length field. Must be one of TLV.EMV, TLV.DGI or TLV.L16.

Exceptions

NameValueDescription
GPErrorGPError.ARGUMENTS_MISSINGToo few arguments in call
GPErrorGPError.INVALID_ARGUMENTSToo many arguments in call
GPErrorGPError.INVALID_TYPEType of argument is invalid for call
GPErrorGPError.INVALID_ENCODINGThe argument encoding is invalid
GPErrorGPError.INVALID_TAGThe tag value is invalid for the selected encoding format
GPErrorGPError.DATA_TOO_LARGEThe 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

ByteStringThe length field of the object

Exceptions

NameValueDescription
GPErrorGPError.INVALID_ARGUMENTSToo 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("00010203040506070809000102030405060708090001020304050607080900010203040506070809000102030405060708090001020304050607080900010203040506070809000102030405060708090001020304050607080900010203040506070809000102030405060708090001020304050607080900010203040506070809", HEX), TLV.EMV);
assert(t.getL().toString(HEX) == "8182");

// 260 bytes
t = new TLV(0x06, new ByteString("0001020304050607080900010203040506070809000102030405060708090001020304050607080900010203040506070809000102030405060708090001020304050607080900010203040506070809000102030405060708090001020304050607080900010203040506070809000102030405060708090001020304050607080900010203040506070809000102030405060708090001020304050607080900010203040506070809000102030405060708090001020304050607080900010203040506070809000102030405060708090001020304050607080900010203040506070809000102030405060708090001020304050607080900010203040506070809", 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("0001020304050607080900010203040506070809000102030405060708090001020304050607080900010203040506070809000102030405060708090001020304050607080900010203040506070809000102030405060708090001020304050607080900010203040506070809000102030405060708090001020304050607080900010203040506070809000102030405060708090001020304050607080900010203040506070809000102030405060708090001020304050607080900010203040506070809000102030405060708090001020304050607080900010203040506070809000102030405060708090001020304050607080900010203040506070809", 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("0001020304050607080900010203040506070809000102030405060708090001020304050607080900010203040506070809000102030405060708090001020304050607080900010203040506070809000102030405060708090001020304050607080900010203040506070809000102030405060708090001020304050607080900010203040506070809000102030405060708090001020304050607080900010203040506070809000102030405060708090001020304050607080900010203040506070809000102030405060708090001020304050607080900010203040506070809000102030405060708090001020304050607080900010203040506070809", 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

ByteStringThe combined length and value field

Exceptions

NameValueDescription
GPErrorGPError.INVALID_ARGUMENTSToo 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

NumberNumeric value of the tag field

Exceptions

NameValueDescription
GPErrorGPError.INVALID_ARGUMENTSToo 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

ByteStringThe concatenation of tag, length and value

Exceptions

NameValueDescription

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

ByteStringConcatenated tag and length field

Exceptions

NameValueDescription
GPErrorGPError.INVALID_ARGUMENTSToo 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

ByteStringThe value field of the TLV object

Exceptions

NameValueDescription
GPErrorGPError.INVALID_ARGUMENTSToo 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");