decryptDataDO method

  1. @visibleForTesting
Uint8List? decryptDataDO(
  1. DecodedTV? dtv
)

Implementation

@visibleForTesting
Uint8List? decryptDataDO(final DecodedTV? dtv) {
  _log.verbose("Decrypting data=${dtv?.value.hex()}");
  if (dtv == null || dtv.value.isEmpty) {
    return null;
  }

  final tag = dtv.tag.value;
  if (tag != SecureMessaging.tagDO85 && tag != SecureMessaging.tagDO87) {
    throw SMError(
        "Can't decrypt invalid data DO with tag=$tag value=${dtv.value.hex()}");
  }

  final bool isDO87 = tag == SecureMessaging.tagDO87;
  final bool padded =
      !isDO87 || dtv.value[0] == 0x01; // Defined in ISO/IEC 7816-4 part 5
  var data = cipher.decrypt(dtv.value.sublist(isDO87 ? 1 : 0),
      ssc: _ssc); // SSC is used only in AES
  _log.sdVerbose("Decrypted data=${data.hex()}");
  _log.sdVerbose("Decrypted data is padded: $padded");
  if (padded) {
    data = ISO9797.unpad(data);
    _log.sdVerbose("Unpadded data=${data.hex()}");
  }
  return data;
}