transmit method
Sends command and returns the response, data then status bytes.
Throws a CardTransportException when the card cannot be reached.
Implementation
@override
Future<Uint8List> transmit(Uint8List bytes) async {
if (latency > Duration.zero) await Future<void>.delayed(latency);
if (!_inserted) {
throw const CardTransportException('No chip on the simulated reader');
}
final CommandApdu command;
try {
command = CommandApdu.parse(bytes);
} on FormatException {
return _status(0x6700);
}
final session = _session;
if (command.cla & 0x0C == 0x0C) {
if (session == null) return _status(0x6988);
final plain = session.unwrap(command);
if (plain == null) {
_reset();
return _status(0x6988);
}
final (data, status) = _process(plain);
final answer = session.wrap(data, status);
// Chip Authentication switches keys after its answer.
if (identical(_session, session) && session.next != null) {
_session = session.next;
}
return answer;
}
// A plain command ends secure messaging, as on a real chip.
_session = null;
final (data, status) = _process(command);
return concat([data, _status(status)]);
}