parseHeader static method
Parses the encrypted asset header (V3 only).
Implementation
static ShieldHeader parseHeader(Uint8List encryptedBytes) {
if (encryptedBytes.lengthInBytes < 28) {
throw const FormatException('Encrypted asset is too short.');
}
for (var i = 0; i < _magic.length; i++) {
if (encryptedBytes[i] != _magic[i]) {
throw const FormatException('Invalid asset header.');
}
}
final version = encryptedBytes[4];
if (version != _version4) {
throw FormatException('Unsupported asset version: $version.');
}
final flags = encryptedBytes[5];
final algo = encryptedBytes[6];
final ivLength = encryptedBytes[7];
if (ivLength != _ivLength) {
throw const FormatException('Invalid IV length.');
}
final chunkSize = _readUint32Le(encryptedBytes, 8);
final originalLength = _readUint32Le(encryptedBytes, 12);
final iv = Uint8List.sublistView(encryptedBytes, 16, 16 + _ivLength);
return ShieldHeader(
version: version,
compressed: (flags & 0x01) != 0,
algorithm: algo,
chunkSize: chunkSize,
originalLength: originalLength,
baseIv: iv,
);
}