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.
dateKeys-dart/test/encrypt3_vm_test.dart

62 lines
1.8 KiB

// The writer of capsules with the CSPRNG of the platform, which Node.js does
// not give inside the tests: two capsules of the same options differ in
// every random value, and both open.
@TestOn('vm')
library;
import 'dart:convert';
import 'package:datekeys/datekeys.dart';
import 'package:test/test.dart';
import 'capsule_writer_support.dart';
void main() {
test('two capsules of the same options differ, and both open', () async {
final releases = {
1000: fromHex(
'b44679b9a59af2ec876b1a6b1ad52ea9b1615fc3982b19576350f93447cb1125'
'e342b73a8dd2bacbe47e4b6b63ed5e39',
),
};
final written = <(EncryptResult, CapsuleSink)>[];
for (var i = 0; i < 2; i++) {
final sink = CapsuleSink();
final res = await encryptFiles(
sink,
[FileSource.bytes('a.txt', utf8.encode('Hola.\n'))],
EncryptOptions(
profile: quicknet(),
unlockAt: roundTime(quicknet(), 1000),
now: () => genesis,
policy: AccessPolicy.timeAndKey,
newPortableKey: true,
),
);
written.add((res, sink));
}
final [(a, sa), (b, sb)] = written;
expect(a.capsuleId, isNot(b.capsuleId));
expect(a.head.salt, isNot(b.head.salt));
expect(a.portableKey!.material, isNot(b.portableKey!.material));
expect(a.portableKey!.credentialId, isNot(b.portableKey!.credentialId));
expect(sa.length, sb.length);
for (final (res, sink) in written) {
final o = await openedJson(
const {'policy': 'time_and_key'},
sink.bytes,
releases,
dkk: encodeAccessKey(res.portableKey!),
);
expect(o['result'], 'ok');
expect(o['files'], [
{
'path': 'a.txt',
'size': 6,
'sha256': toHex(sha256Of(utf8.encode('Hola.\n'))),
},
]);
}
});
}

Powered by TurnKey Linux.