deserializeCombinedCipherFromJson function
Deserializes the combined ciphertext from a parsed JSON object The object should contain the keys 'kemCt', 'nonce', 'ciphertext', and 'salt'.
Implementation
ASECombinedCipher deserializeCombinedCipherFromJson(Map<String, dynamic> m) {
if (!m.containsKey('kemCt') ||
!m.containsKey('nonce') ||
!m.containsKey('ciphertext') ||
!m.containsKey('salt')) {
throw FormatException('Invalid ciphertext format');
}
var kem = m['kemCt'] as Map;
if (!kem.containsKey('u') || !kem.containsKey('v')) {
throw FormatException('Invalid KEM ciphertext format');
}
var uList = kem['u'] as List;
if (uList.length != k) {
throw FormatException('Invalid KEM ciphertext dimension');
}
var polys = uList.map((elem) => Poly(List<int>.from(elem as List))).toList();
var uVec = PolyVec(polys);
var v = Poly(List<int>.from(kem['v'] as List));
var nonce = Uint8List.fromList(List<int>.from(m['nonce'] as List));
var sym = Uint8List.fromList(List<int>.from(m['ciphertext'] as List));
var salt = Uint8List.fromList(List<int>.from(m['salt'] as List));
if (nonce.length != 12) throw FormatException('Invalid nonce length');
if (sym.length < 16) throw FormatException('Invalid ciphertext length');
return ASECombinedCipher(
ASECiphertextKEM(uVec, v), nonce, sym, Uint8List(0), salt);
}