archiveCramKey method
Implementation
Future<String> archiveCramKey(String atSign) async {
await ensureReady();
final sourceFile = File(
path.join(_directory!.path, _fileNameForAtSign(atSign)),
);
if (!await sourceFile.exists()) {
throw Exception('CRAM key file not found for ${normalizeAtSign(atSign)}');
}
final destinationFile = File(
path.join(_oldDirectory!.path, _fileNameForAtSign(atSign)),
);
if (await destinationFile.exists()) {
await destinationFile.delete();
}
final raw = await sourceFile.readAsString();
final decoded = jsonDecode(raw);
final payload = decoded is Map<String, dynamic>
? decoded
: decoded is Map
? decoded.cast<String, dynamic>()
: <String, dynamic>{};
payload['onboardedAtUtc'] = DateTime.now().toUtc().toIso8601String();
await destinationFile.writeAsString(
const JsonEncoder.withIndent(' ').convert(payload),
);
await sourceFile.delete();
return destinationFile.path;
}