You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
3.0 KiB
78 lines
3.0 KiB
// recoveryAnnex is annex/recovery.md byte for byte, the copy that
|
|
// tool/recovery_annex_copy.dart writes after each sync of annex/. And
|
|
// annex/recovery.md is §79 of the specification of specVersion under the
|
|
// title and the paragraph of TestRecoveryAnnex of datekeys-go, which names the
|
|
// version and the SHA-256 of the specification: the specification is read
|
|
// from the Go repository next to this one, at the commit that annex/SOURCE.json
|
|
// pins, as test/errors_spec_test.dart reads it.
|
|
@TestOn('vm')
|
|
library;
|
|
|
|
import 'dart:convert';
|
|
import 'dart:io';
|
|
|
|
import 'package:datekeys/datekeys.dart';
|
|
import 'package:datekeys/src/recovery_annex.g.dart' show recoveryAnnexSha256;
|
|
import 'package:datekeys/src/sha256.dart';
|
|
import 'package:test/test.dart';
|
|
|
|
import '../tool/sync_testdata.dart' as vendored;
|
|
|
|
void main() {
|
|
final root = Directory.current;
|
|
final repo = Directory('../datekeys-go');
|
|
|
|
test('recoveryAnnex is annex/recovery.md byte for byte', () {
|
|
final file = File('${root.path}/annex/recovery.md').readAsBytesSync();
|
|
expect(utf8.encode(recoveryAnnex), file);
|
|
expect(toHex(sha256(file)), recoveryAnnexSha256);
|
|
});
|
|
|
|
test(
|
|
'annex/recovery.md is §79 of the specification, as TestRecoveryAnnex',
|
|
() {
|
|
final commit = vendored.check(root, tree: vendored.annexTree).commit;
|
|
final path =
|
|
'$commit:spec/DateKeys_Protocol_Specification_v$specVersion.md';
|
|
final r = Process.runSync(
|
|
'git',
|
|
['-C', repo.path, 'show', path],
|
|
stdoutEncoding: null,
|
|
stderrEncoding: utf8,
|
|
);
|
|
expect(r.exitCode, 0, reason: '${r.stderr}');
|
|
final spec = r.stdout as List<int>;
|
|
expect(
|
|
File('${root.path}/annex/recovery.md').readAsStringSync(),
|
|
annexOf(spec),
|
|
);
|
|
},
|
|
skip: repo.existsSync()
|
|
? false
|
|
: '../datekeys-go is missing: the spec is read from it',
|
|
);
|
|
}
|
|
|
|
// The text of RecoveryAnnex for the specification spec, as recoveryAnnex of
|
|
// annex_test.go of Go: its §79, from its title to the end of the document,
|
|
// under a title of its own and a paragraph that names the version and the
|
|
// SHA-256 of spec.
|
|
String annexOf(List<int> spec) {
|
|
final text = utf8.decode(spec);
|
|
final i = text.indexOf('\n## 79. ');
|
|
if (i < 0) throw StateError('the specification $specVersion has no §79');
|
|
// strings.TrimRight(text[i+1:], " \n")
|
|
var end = text.length;
|
|
while (end > i + 1 && (text[end - 1] == ' ' || text[end - 1] == '\n')) {
|
|
end--;
|
|
}
|
|
return '# Cómo abrir una cápsula DateKeys sin software de DateKeys\n\n'
|
|
'Este texto acompaña a una cápsula del tiempo de DateKeys, un fichero '
|
|
'`.dkc`: dice cómo abrirla, llegada su fecha, sin ningún software de '
|
|
'DateKeys, por si ya no existe. Es el anexo informativo §79 de la '
|
|
'especificación del protocolo DateKeys v$specVersion, cuyo texto tiene '
|
|
'el SHA-256 ${toHex(sha256(spec))}. Es el mismo para toda cápsula: no '
|
|
'lleva ningún dato de esta.\n\n'
|
|
'${text.substring(i + 1, end)}\n';
|
|
}
|