|
|
@ -88,6 +88,12 @@ void main() { |
|
|
|
Credentials.composite(ProtectedValue.fromString('asdf'), keyFile)); |
|
|
|
Credentials.composite(ProtectedValue.fromString('asdf'), keyFile)); |
|
|
|
expect(file.body.rootGroup.entries, hasLength(1)); |
|
|
|
expect(file.body.rootGroup.entries, hasLength(1)); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
test('Reading chacha20', () async { |
|
|
|
|
|
|
|
final data = await File('test/chacha20.kdbx').readAsBytes(); |
|
|
|
|
|
|
|
final file = |
|
|
|
|
|
|
|
kdbxFormat.read(data, Credentials(ProtectedValue.fromString('asdf'))); |
|
|
|
|
|
|
|
expect(file.body.rootGroup.entries, hasLength(1)); |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
group('Writing', () { |
|
|
|
group('Writing', () { |
|
|
|
test('Create and save', () { |
|
|
|
test('Create and save', () { |
|
|
@ -98,22 +104,8 @@ void main() { |
|
|
|
header: KdbxHeader.createV4(), |
|
|
|
header: KdbxHeader.createV4(), |
|
|
|
); |
|
|
|
); |
|
|
|
final rootGroup = kdbx.body.rootGroup; |
|
|
|
final rootGroup = kdbx.body.rootGroup; |
|
|
|
{ |
|
|
|
_createEntry(kdbx, rootGroup, 'user1', 'LoremIpsum'); |
|
|
|
final entry = KdbxEntry.create(kdbx, rootGroup); |
|
|
|
_createEntry(kdbx, rootGroup, 'user2', 'Second Password'); |
|
|
|
rootGroup.addEntry(entry); |
|
|
|
|
|
|
|
entry.setString(KdbxKey('Username'), PlainValue('user1')); |
|
|
|
|
|
|
|
entry.setString( |
|
|
|
|
|
|
|
KdbxKey('Password'), ProtectedValue.fromString('LoremIpsum')); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
final entry = KdbxEntry.create(kdbx, rootGroup); |
|
|
|
|
|
|
|
rootGroup.addEntry(entry); |
|
|
|
|
|
|
|
entry.setString(KdbxKey('Username'), PlainValue('user2')); |
|
|
|
|
|
|
|
entry.setString( |
|
|
|
|
|
|
|
KdbxKey('Password'), |
|
|
|
|
|
|
|
ProtectedValue.fromString('Second Password'), |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
final saved = kdbx.save(); |
|
|
|
final saved = kdbx.save(); |
|
|
|
|
|
|
|
|
|
|
|
final loadedKdbx = kdbxFormat.read( |
|
|
|
final loadedKdbx = kdbxFormat.read( |
|
|
@ -126,5 +118,26 @@ void main() { |
|
|
|
final file = |
|
|
|
final file = |
|
|
|
kdbxFormat.read(data, Credentials(ProtectedValue.fromString('asdf'))); |
|
|
|
kdbxFormat.read(data, Credentials(ProtectedValue.fromString('asdf'))); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
test('write chacha20', () async { |
|
|
|
|
|
|
|
final data = await File('test/chacha20.kdbx').readAsBytes(); |
|
|
|
|
|
|
|
final file = |
|
|
|
|
|
|
|
kdbxFormat.read(data, Credentials(ProtectedValue.fromString('asdf'))); |
|
|
|
|
|
|
|
expect(file.body.rootGroup.entries, hasLength(1)); |
|
|
|
|
|
|
|
_createEntry(file, file.body.rootGroup, 'user1', 'LoremIpsum'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// and try to write it. |
|
|
|
|
|
|
|
final output = file.save(); |
|
|
|
|
|
|
|
expect(output, isNotNull); |
|
|
|
|
|
|
|
File('test_output_chacha20.kdbx').writeAsBytesSync(output); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
KdbxEntry _createEntry( |
|
|
|
|
|
|
|
KdbxFile file, KdbxGroup group, String username, String password) { |
|
|
|
|
|
|
|
final entry = KdbxEntry.create(file, group); |
|
|
|
|
|
|
|
group.addEntry(entry); |
|
|
|
|
|
|
|
entry.setString(KdbxKey('UserName'), PlainValue(username)); |
|
|
|
|
|
|
|
entry.setString(KdbxKey('Password'), ProtectedValue.fromString(password)); |
|
|
|
|
|
|
|
return entry; |
|
|
|
} |
|
|
|
} |
|
|
|