getLocallyCachedPK function
If the PK for atSign
is in the sshnp local cache, then return it.
If it is not, then fetch it via the atClient
, and store it.
The PK (for e.g. @alice) is stored
- in the atClient's storage if
useFileStorage
== false in a "local" record likelocal:alice.cached_pks.sshnp@<atClient's atSign>
- in file storage if
useFileStorage
== true (default) at~/.atsign/sshnp/cached_pks/alice
Note that for storage, the leading @
in the atSign is stripped off.
Implementation
Future<String> getLocallyCachedPK(
AtClient atClient,
String atSign, {
FileSystem? fs,
}) async {
atSign = AtUtils.fixAtSign(atSign);
String? cachedPK = await _fetchFromLocalPKCache(atClient, atSign, fs: fs);
if (cachedPK != null) {
return cachedPK;
}
var s = 'public:publickey$atSign';
final AtValue av = await atClient.get(AtKey.fromString(s));
if (av.value == null) {
throw AtPublicKeyNotFoundException('Failed to retrieve $s');
}
await _storeToLocalPKCache(av.value, atClient, atSign, fs: fs);
return av.value;
}