clearLocallyCachedPKs function

Future<void> clearLocallyCachedPKs({
  1. required AtSignLogger logger,
  2. FileSystem? fs,
  3. AtClient? atClient,
})

Remove all PKs which this atSign has cached in filesystem or in atClient storage

Implementation

Future<void> clearLocallyCachedPKs({
  required AtSignLogger logger,
  FileSystem? fs,
  AtClient? atClient,
}) async {
  if (fs != null) {
    String dirName = path
        .normalize('${getHomeDirectory()}/.atsign/sshnp/cached_pks')
        .replaceAll('/', Platform.pathSeparator);
    Directory d = fs.directory(dirName);
    if (await d.exists()) {
      logger.shout('Deleting $dirName');
      await d.delete(recursive: true);
    }
  }

  if (atClient != null) {
    // find all `local:` keys which end with `.cached_pks.sshnp`
    List<AtKey> keys = await atClient.getAtKeys(
      regex: r'^local:.*\.cached_pks\.sshnp',
    );
    for (final key in keys) {
      logger.shout('Deleting $key');
      await atClient.delete(key);
    }
  }
}