readBinaryExt method

Future<ResponseAPDU> readBinaryExt({
  1. required int offset,
  2. required int ne,
  3. int cla = ISO7816_CLA.NO_SM,
})

Sends Extended READ BINARY (odd ins 'B1') command to ICC. It returns ne long chunk of data at offset. offset can be greater than 32 767. Can throw ICCError if R-APDU returns no data and error status or ComProviderError.

Implementation

Future<ResponseAPDU> readBinaryExt({ required int offset, required int ne, int cla = ISO7816_CLA.NO_SM }) async {
  // Returned data will be encoded in BER-TLV with tag 0x53.
  // We add additional bytes to ne for this extra data.
  final enNeLen  = TLV.encodeLength(ne).length;
  final addBytes =  1 /*byte = tag*/ + enNeLen;
		ne = ne <= 256 ? min(256, ne + addBytes) : ne + addBytes;

  final data  =  TLV.encodeIntValue(0x54, offset);
  final rapdu = await _readBinary(
    CommandAPDU(cla: cla, ins: ISO7816_INS.READ_BINARY_EXT, p1: 0x00, p2: 0x00, data: data, ne: ne)
  );

  final rtlv = TLV.fromBytes(rapdu.data!);
  if(rtlv.tag != 0x53) {
    throw ICCError(
      "readBinaryExt failed. Received invalid BER-TLV encoded data with tag=0x${rtlv.tag.hex()}, expected tag=0x53",
      rapdu.status,
      rapdu.data
    );
  }
  return ResponseAPDU(rapdu.status, rtlv.value);
}