allNeededKeys method

Set<String> allNeededKeys()

Implementation

Set<String> allNeededKeys() {
  final secrets = analyzeSecrets();
  secrets.removeWhere(
      (k, v) => v.isEmpty); // we don't care about the failed secrets here
  final keys = <String>{};
  final defaultKeyId = encryption.ssss.defaultKeyId;
  int removeKey(String key) {
    final sizeBefore = secrets.length;
    secrets.removeWhere((k, v) => v.contains(key));
    return sizeBefore - secrets.length;
  }

  // first we want to try the default key id
  if (defaultKeyId != null) {
    if (removeKey(defaultKeyId) > 0) {
      keys.add(defaultKeyId);
    }
  }
  // now we re-try as long as we have keys for all secrets
  while (secrets.isNotEmpty) {
    final key = mostUsedKey(secrets);
    removeKey(key);
    keys.add(key);
  }
  return keys;
}