contactCryptoConfig function
Implementation
BaseCryptoConfig<DecryptedContactDto, ContactDto> contactCryptoConfig(UserDto user, Crypto crypto) {
return BaseCryptoConfig(crypto, (dec) async {
var key = (await crypto.decryptEncryptionKeys(user.dataOwnerId()!, dec.encryptionKeys)).firstOrNull?.formatAsKey().fromHexString();
if (key == null) {
throw FormatException("Cannot get encryption key for ${dec.id} and hcp ${user.dataOwnerId()}");
}
return Tuple2(
ContactDto.fromJson({
...dec.toJson(),
'services': (await crypto.encryptServices(
user.dataOwnerId()!,
<String>{...(user.autoDelegations["all"] ?? {}), ...(user.autoDelegations["medicalInformation"] ?? {})},
key,
dec.services.toList()))
.toList()
})!,
Uint8List.fromList(json.encode({}).codeUnits));
}, (cry, data) async {
var key = (await crypto.decryptEncryptionKeys(user.dataOwnerId()!, cry.encryptionKeys)).firstOrNull?.formatAsKey().fromHexString();
if (key == null) {
throw FormatException("Cannot get encryption key for ${cry.id} and hcp ${user.dataOwnerId()}");
}
return DecryptedContactDto.fromJson({
...cry.toJson(),
'services': (await crypto.decryptServices(user.dataOwnerId()!, key, cry.services.toList())).toList(),
...(data != null ? json.decode(String.fromCharCodes(data)) : {})
})!;
});
}