Stage 4c: the public note and the head of format 3
lib/src/note.dart ports CheckNote, NewNote and Note of package extension
of datekeys-go at c531e93: checkNote and checkNoteData check the length,
the UTF-8 and the rules of text of the declared author, in that order and
with the texts of Go, on the bytes of the note as Go reads its string;
newNote, publicNote and unusableNote, and Header.publicNote and
Header.unusableNote. StandardExtensions checks the data of a note as the
Standard of Go does, and its parameter validateNote, which could replace
those rules, is gone.
lib/src/head.dart ports DecodeHead, EncodeHead and CheckHeadEnd of
format3.go: the limit of HEAD_LEN, the type tag and the version, the CDDL
with R1 and R8 on the UTF-8 bytes of the paths, never on the UTF-16 code
units of a String, and then the comment, the declared author and the files
with the rules of pathrule and their layout, by subtraction, and R7 and R9,
as ERR_HEAD_INVALID with the text of Go, and the critical extensions of the
head. decodeWrittenHead is the decoder without the critical extensions, for
the self-check of the writer of stage 6.
The tests read open_heads.json, open_notes.json, head_schema.json with the
detail of each ERR_HEAD_INVALID, the trees of paths.json as heads of files
of 0 bytes, and the head of each fixture of format 3.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 days ago
|
|
|
// The public note of spec §24.1 against Go: test/vectors/open_notes.json,
|
|
|
|
|
// which tool/open_go_vectors.go writes with extension.CheckNote, Note,
|
|
|
|
|
// Header.UnusableNote and extension.Standard of the reference; and
|
|
|
|
|
// testdata/vectors/note.json, the cases of the list of v0.11 of spec §64.
|
Stage 4c: the public note and the head of format 3
lib/src/note.dart ports CheckNote, NewNote and Note of package extension
of datekeys-go at c531e93: checkNote and checkNoteData check the length,
the UTF-8 and the rules of text of the declared author, in that order and
with the texts of Go, on the bytes of the note as Go reads its string;
newNote, publicNote and unusableNote, and Header.publicNote and
Header.unusableNote. StandardExtensions checks the data of a note as the
Standard of Go does, and its parameter validateNote, which could replace
those rules, is gone.
lib/src/head.dart ports DecodeHead, EncodeHead and CheckHeadEnd of
format3.go: the limit of HEAD_LEN, the type tag and the version, the CDDL
with R1 and R8 on the UTF-8 bytes of the paths, never on the UTF-16 code
units of a String, and then the comment, the declared author and the files
with the rules of pathrule and their layout, by subtraction, and R7 and R9,
as ERR_HEAD_INVALID with the text of Go, and the critical extensions of the
head. decodeWrittenHead is the decoder without the critical extensions, for
the self-check of the writer of stage 6.
The tests read open_heads.json, open_notes.json, head_schema.json with the
detail of each ERR_HEAD_INVALID, the trees of paths.json as heads of files
of 0 bytes, and the head of each fixture of format 3.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 days ago
|
|
|
@TestOn('vm')
|
|
|
|
|
library;
|
|
|
|
|
|
|
|
|
|
import 'dart:convert';
|
|
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
|
|
import 'package:datekeys/datekeys.dart';
|
|
|
|
|
import 'package:test/test.dart';
|
|
|
|
|
|
|
|
|
|
import 'open_vectors_support.dart';
|
|
|
|
|
|
|
|
|
|
Json readJson(String path) => jsonDecode(File(path).readAsStringSync()) as Json;
|
|
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
|
test('open_notes.json: every note as in Go', () {
|
|
|
|
|
final f = readJson('test/vectors/open_notes.json');
|
|
|
|
|
expect(f['spec'], specVersion);
|
|
|
|
|
final check = (f['check']! as List).cast<Json>();
|
|
|
|
|
expect(check, hasLength(greaterThan(300)));
|
|
|
|
|
expect(check.where((c) => c['result'] == 'ok'), hasLength(greaterThan(10)));
|
|
|
|
|
checkNoteCases(
|
|
|
|
|
check,
|
|
|
|
|
(f['note']! as List).cast<Json>(),
|
|
|
|
|
(f['standard']! as List).cast<Json>(),
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('note.json: the data of each note and the result of its rules', () {
|
|
|
|
|
final f = readJson('testdata/vectors/note.json');
|
|
|
|
|
expect(f['spec'], specVersion);
|
|
|
|
|
final notes = (f['notes']! as List).cast<Json>();
|
|
|
|
|
expect(notes, hasLength(16));
|
|
|
|
|
expect(notes.where((c) => c['result'] == 'ok'), hasLength(4));
|
|
|
|
|
for (final c in notes) {
|
|
|
|
|
final data = fromHex(c['data']! as String);
|
|
|
|
|
final reason = c['name'] as String?;
|
|
|
|
|
// detail is the text of the rule, without the code.
|
|
|
|
|
final want = c['result'] == 'ok'
|
|
|
|
|
? ['ok', '']
|
|
|
|
|
: [c['result'], '${c['detail']}: ${c['result']}'];
|
|
|
|
|
String? text;
|
|
|
|
|
expect(outcomeOf(() => text = checkNoteData(data)), want, reason: reason);
|
|
|
|
|
// A reader shows the note only when it is ok, and otherwise treats it
|
|
|
|
|
// as unusable, never the capsule (spec §54).
|
|
|
|
|
final exts = [Extension(noteExtensionId, 1, data.isEmpty ? null : data)];
|
|
|
|
|
expect(
|
|
|
|
|
[publicNote(exts), unusableNote(exts)],
|
|
|
|
|
c['result'] == 'ok' ? [text, false] : [null, true],
|
|
|
|
|
reason: reason,
|
|
|
|
|
);
|
|
|
|
|
expect(
|
|
|
|
|
[
|
|
|
|
|
for (final u in checkNoncritical(
|
|
|
|
|
exts,
|
|
|
|
|
const StandardExtensions(),
|
|
|
|
|
ExtensionObject.publicHeader,
|
|
|
|
|
))
|
|
|
|
|
u.error.code.code,
|
|
|
|
|
],
|
|
|
|
|
c['result'] == 'ok' ? isEmpty : [c['result']],
|
|
|
|
|
reason: reason,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
Stage 4c: the public note and the head of format 3
lib/src/note.dart ports CheckNote, NewNote and Note of package extension
of datekeys-go at c531e93: checkNote and checkNoteData check the length,
the UTF-8 and the rules of text of the declared author, in that order and
with the texts of Go, on the bytes of the note as Go reads its string;
newNote, publicNote and unusableNote, and Header.publicNote and
Header.unusableNote. StandardExtensions checks the data of a note as the
Standard of Go does, and its parameter validateNote, which could replace
those rules, is gone.
lib/src/head.dart ports DecodeHead, EncodeHead and CheckHeadEnd of
format3.go: the limit of HEAD_LEN, the type tag and the version, the CDDL
with R1 and R8 on the UTF-8 bytes of the paths, never on the UTF-16 code
units of a String, and then the comment, the declared author and the files
with the rules of pathrule and their layout, by subtraction, and R7 and R9,
as ERR_HEAD_INVALID with the text of Go, and the critical extensions of the
head. decodeWrittenHead is the decoder without the critical extensions, for
the self-check of the writer of stage 6.
The tests read open_heads.json, open_notes.json, head_schema.json with the
detail of each ERR_HEAD_INVALID, the trees of paths.json as heads of files
of 0 bytes, and the head of each fixture of format 3.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 days ago
|
|
|
test('the note of a header, as PublicNote and UnusableNote of Go', () {
|
|
|
|
|
final r = jsonDecode(
|
|
|
|
|
File('testdata/fixtures/time_only_extensions.json').readAsStringSync(),
|
|
|
|
|
) as Json;
|
|
|
|
|
final h = decodeHeader(fromHex(r['public_header']! as String));
|
|
|
|
|
expect([h.publicNote, h.unusableNote], [null, false]);
|
|
|
|
|
final noted = Header(
|
|
|
|
|
capsuleId: h.capsuleId,
|
|
|
|
|
dateKey: h.dateKey,
|
|
|
|
|
policy: h.policy,
|
|
|
|
|
noncritical: [newNote('Cartas del viaje a Lisboa'), ...h.noncritical],
|
|
|
|
|
);
|
|
|
|
|
expect(
|
|
|
|
|
[noted.publicNote, noted.unusableNote],
|
|
|
|
|
['Cartas del viaje a Lisboa', false],
|
|
|
|
|
);
|
|
|
|
|
final bad = Header(
|
|
|
|
|
capsuleId: h.capsuleId,
|
|
|
|
|
dateKey: h.dateKey,
|
|
|
|
|
policy: h.policy,
|
|
|
|
|
noncritical: [Extension(noteExtensionId, 1, fromHex('610962'))],
|
|
|
|
|
);
|
|
|
|
|
expect([bad.publicNote, bad.unusableNote], [null, true]);
|
|
|
|
|
});
|
|
|
|
|
}
|