decode static method
Implementation
static UVaultHeader decode(Uint8List bytes) {
if (bytes.length < 19 || bytes[0] != _magic[0] || bytes[1] != _magic[1] || bytes[2] != _magic[2] || bytes[3] != _magic[3]) {
throw const FormatException("Not a vault file.");
}
if (bytes[4] != _version) throw FormatException("Unsupported vault version ${bytes[4]}.");
final ByteData view = ByteData.sublistView(bytes);
final int keyLength = view.getUint16(17, Endian.little);
if (bytes.length < 19 + keyLength) throw const FormatException("Truncated vault header.");
return UVaultHeader(
algorithmId: bytes[5],
chunkSize: view.getUint32(6, Endian.little),
noncePrefix: Uint8List.fromList(bytes.sublist(10, 17)),
wrappedKey: Uint8List.fromList(bytes.sublist(19, 19 + keyLength)),
);
}