initDelegations method
Future<DecryptedHealthElementDto>
initDelegations(
- UserDto user,
- CryptoConfig<
DecryptedHealthElementDto, HealthElementDto> config, { - Set<
String> ? delegates = null,
Implementation
Future<DecryptedHealthElementDto> initDelegations(UserDto user, CryptoConfig<DecryptedHealthElementDto, HealthElementDto> config, { Set<String>? delegates = null }) async {
final Uuid uuid = Uuid();
Set<String> delegationKeys = Set.from(delegates ?? <String>{})
..addAll(user.autoDelegations["all"] ?? <String>{})
..addAll(user.autoDelegations["medicalInformation"] ?? <String>{});
final String ek = uuid.v4(options: {'rng': UuidUtil.cryptoRNG});
final String sfk = uuid.v4(options: {'rng': UuidUtil.cryptoRNG});
responsible = user.dataOwnerId()!;
author = user.id;
delegations = await (delegationKeys..add(user.dataOwnerId()!)).fold(Future.value({...delegations}), (m, d) async {
final acc = await m;
final keyAndOwner = await config.crypto.encryptAESKeyForHcp(user.dataOwnerId()!, d, id, sfk);
return acc..addEntries([
MapEntry(d, {
DelegationDto(
owner: user.dataOwnerId(), delegatedTo: d, key: keyAndOwner.item1)
})
]);
});
encryptionKeys = await (delegationKeys..add(user.dataOwnerId()!)).fold(Future.value({...encryptionKeys}), (m, d) async {
final acc = await m;
final keyAndOwner = await config.crypto.encryptAESKeyForHcp(user.dataOwnerId()!, d, id, ek);
return acc..addEntries([
MapEntry(d, {
DelegationDto(
owner: user.dataOwnerId(), delegatedTo: d, key: keyAndOwner.item1)
})
]);
}
);
return this;
}