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.
90 lines
2.7 KiB
90 lines
2.7 KiB
// The differential of the CMS reader against the Go reference on the VM,
|
|
// with every case of test/vectors/cms_*.json and the fixtures of testdata/
|
|
// whose security area holds a signature of alg 2 or a seal of seal_type 2.
|
|
// And the part of those files that cms_vectors.g.dart holds for the tests
|
|
// compiled to JavaScript: for each section, the cases whose index is a
|
|
// multiple of the step that "every" gives.
|
|
@TestOn('vm')
|
|
library;
|
|
|
|
import 'dart:convert';
|
|
import 'dart:io';
|
|
|
|
import 'package:test/test.dart';
|
|
|
|
import 'cms_support.dart';
|
|
import 'vectors/cms_vectors.g.dart';
|
|
|
|
const _embedded = {
|
|
'ecdsa': cmsEcdsaJson,
|
|
'rsa': cmsRsaJson,
|
|
'certs': cmsCertsJson,
|
|
'signatures': cmsSignaturesJson,
|
|
'algorithms': cmsAlgorithmsJson,
|
|
'tokens': cmsTokensJson,
|
|
'mutations': cmsMutationsJson,
|
|
'corpus': cmsCorpusJson,
|
|
};
|
|
|
|
void main() {
|
|
final files = {
|
|
for (final n in cmsFiles)
|
|
n: jsonDecode(
|
|
File('test/vectors/cms_$n.json').readAsStringSync(),
|
|
) as Json,
|
|
};
|
|
|
|
test('every file is of the draft v0.12 and of its generator', () {
|
|
for (final f in files.values) {
|
|
expect(f['spec'], '0.12 draft');
|
|
expect(f['generator'], startsWith('tool/cms_go_vectors_test.go, go'));
|
|
expect(f['source'], startsWith('datekeys-go c531e93'));
|
|
}
|
|
});
|
|
|
|
group('cms_vectors.g.dart', () {
|
|
for (final n in cmsFiles) {
|
|
test('holds the part of cms_$n.json of its steps', () {
|
|
final full = files[n]!;
|
|
final part = jsonDecode(_embedded[n]!) as Json;
|
|
final every = part['every']! as Json;
|
|
expect(part.keys.toSet(), {...full.keys, 'every'});
|
|
for (final MapEntry(:key, :value) in full.entries) {
|
|
final step = every[key] as int?;
|
|
if (step == null) {
|
|
expect(part[key], value, reason: key);
|
|
continue;
|
|
}
|
|
expect(part[key], [
|
|
for (final (i, c) in (value! as List).indexed)
|
|
if (step != 0 && i % step == 0) c,
|
|
], reason: key);
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
group('ECDSA', () => ecdsaTests(files['ecdsa']!));
|
|
group('RSA', () => rsaTests(files['rsa']!));
|
|
group('certificates', () => certTests(files['certs']!));
|
|
group(
|
|
'signatures',
|
|
() => signatureTests(files['signatures']!, const ['form']),
|
|
);
|
|
group(
|
|
'algorithms',
|
|
() => signatureTests(files['algorithms']!, const ['algorithms', 'keys']),
|
|
);
|
|
group('tokens', () => tokenTests(files['tokens']!));
|
|
group('mutations', () => mutationTests(files['mutations']!));
|
|
group(
|
|
'corpus',
|
|
() => corpusTests(
|
|
files['corpus']!,
|
|
fixture: (name) =>
|
|
jsonDecode(File('testdata/fixtures/$name.json').readAsStringSync())
|
|
as Json,
|
|
),
|
|
);
|
|
}
|