readFileBySFI method

Future<Uint8List> readFileBySFI(
  1. int sfi
)

Returns raw EF file bytes of selected DF identified by short file identifier sfid from MRTD. Can throw ICCError in case when file doesn't exist, read errors or SM session is not established but required to read file. Can throw ComProviderError in case connection with MRTD is lost.

Implementation

Future<Uint8List> readFileBySFI(int sfi) async {
  _log.debug("Reading file sfi=0x${sfi.hex()}");
  sfi |= 0x80;
  if (sfi > 0x9F) {
    throw ArgumentError.value(sfi, null, "Invalid SFI value");
  }

  // Read chunk of file to obtain file length
  final chunk1 =
      await icc.readBinaryBySFI(sfi: sfi, offset: 0, ne: _readAheadLength);
  final dtl = TLV.decodeTagAndLength(chunk1.data!);

  // Read the rest of the file
  final length = dtl.length.value - (chunk1.data!.length - dtl.encodedLen);
  final chunk2 =
      await _readBinary(offset: chunk1.data!.length, length: length);

  final rawFile = Uint8List.fromList(chunk1.data! + chunk2);
  assert(rawFile.length == dtl.encodedLen + dtl.length.value);
  return rawFile;
}