decryptEntry function
Checks and decrypts one entry. Returns the stored bytes, which still need inflating with zlib when PackEntry.compressed is true.
Implementation
Uint8List decryptEntry(Uint8List pack, int dataStart, PackEntry e, PackKeys keys) {
final start = dataStart + e.offset;
if (start + e.storedLength > pack.length) {
throw AssetPackException('Pack is truncated at ${e.path}');
}
final cipher = Uint8List.sublistView(pack, start, start + e.storedLength);
if (!macEquals(e.mac, entryMac(keys.macKey, e.path, e.nonce, cipher))) {
throw AssetPackException('${e.path} failed authentication (damaged or tampered)');
}
return chacha20(keys.encKey, e.nonce, cipher);
}