// Writes the samples of the interoperability of the writer of capsules of // datekeys-dart, stage 6b: the capsules of the recipes of // test/capsule_interop_support.dart, which this library writes with // SeededRandomSource or with the CSPRNG of the platform, their .dkk, and // samples.json, the recipes with the name of each file, into a directory. // tool/capsule_interop_go_verdicts.go then opens them with Go and writes // test/vectors/capsule_interop.json; the tests write the seeded ones again // and compare them with what Go read. // // dart run tool/capsule_interop_dart_samples.dart // // ignore_for_file: avoid_print import 'dart:convert'; import 'dart:io'; import '../test/capsule_interop_support.dart'; Future main(List args) async { if (args.length != 1) { stderr.writeln( 'usage: dart run tool/capsule_interop_dart_samples.dart ', ); exit(2); } final dir = Directory(args.single)..createSync(recursive: true); final samples = interopSamples(); for (var i = 0; i < samples.length; i++) { final s = samples[i]; final w = await writeSample(s); File('${dir.path}/$i.dkc').writeAsBytesSync(w.dkc); s['file'] = '$i.dkc'; final dkk = w.dkk; if (dkk != null) { File('${dir.path}/$i.dkk').writeAsBytesSync(dkk); s['dkk'] = '$i.dkk'; } print('${s['name']}: ${w.dkc.length} bytes'); } File('${dir.path}/samples.json').writeAsStringSync( const JsonEncoder.withIndent(' ').convert({'samples': samples}), ); print('wrote ${samples.length} samples to ${dir.path}'); }