diff --git a/lib/src/kdbx_binary.dart b/lib/src/kdbx_binary.dart index 8477fb6..ae33987 100644 --- a/lib/src/kdbx_binary.dart +++ b/lib/src/kdbx_binary.dart @@ -9,10 +9,14 @@ import 'package:quiver/core.dart'; import 'package:xml/xml.dart'; class KdbxBinary { - KdbxBinary({this.isInline, this.isProtected, this.value}); - final bool? isInline; - final bool? isProtected; - final Uint8List? value; + KdbxBinary({ + required this.isInline, + required this.isProtected, + required this.value, + }); + final bool isInline; + final bool isProtected; + final Uint8List value; int? _valueHashCode; static KdbxBinary readBinaryInnerHeader(InnerHeaderField field) { @@ -26,16 +30,16 @@ class KdbxBinary { ); } - int get valueHashCode => _valueHashCode ??= hashObjects(value!); + int get valueHashCode => _valueHashCode ??= hashObjects(value); bool valueEqual(KdbxBinary other) => - valueHashCode == other.valueHashCode && ByteUtils.eq(value!, value!); + valueHashCode == other.valueHashCode && ByteUtils.eq(value, other.value); InnerHeaderField writeToInnerHeader() { final writer = WriterHelper(); - final flags = isProtected! ? 0x01 : 0x00; + final flags = isProtected ? 0x01 : 0x00; writer.writeUint8(flags); - writer.writeBytes(value!); + writer.writeBytes(value); return InnerHeaderField( InnerHeaderFields.Binary, writer.output.takeBytes()); } @@ -56,8 +60,8 @@ class KdbxBinary { } void saveToXml(XmlElement valueNode) { - final content = base64.encode(gzip.encode(value!)); - valueNode.addAttributeBool(KdbxXml.ATTR_PROTECTED, isProtected!); + final content = base64.encode(gzip.encode(value)); + valueNode.addAttributeBool(KdbxXml.ATTR_PROTECTED, isProtected); valueNode.addAttributeBool(KdbxXml.ATTR_COMPRESSED, true); valueNode.children.add(XmlText(content)); } diff --git a/lib/src/kdbx_entry.dart b/lib/src/kdbx_entry.dart index c29c5fa..d1e5783 100644 --- a/lib/src/kdbx_entry.dart +++ b/lib/src/kdbx_entry.dart @@ -267,7 +267,7 @@ class KdbxEntry extends KdbxObject { final key = binaryEntry.key; final binary = binaryEntry.value; final value = XmlElement(XmlName(KdbxXml.NODE_VALUE)); - if (binary.isInline!) { + if (binary.isInline) { binary.saveToXml(value); } else { final binaryIndex = ctx.findBinaryId(binary); diff --git a/lib/src/kdbx_format.dart b/lib/src/kdbx_format.dart index 7c017ff..622388f 100644 --- a/lib/src/kdbx_format.dart +++ b/lib/src/kdbx_format.dart @@ -90,11 +90,11 @@ class KdbxReadWriteContext { /// finds the ID of the given binary. /// if it can't be found, [KdbxCorruptedFileException] is thrown. int findBinaryId(KdbxBinary binary) { - assert(!binary.isInline!); + assert(!binary.isInline); final id = _binaries.indexOf(binary); if (id < 0) { throw KdbxCorruptedFileException('Unable to find binary.' - ' (${binary.value!.length},${binary.isInline})'); + ' (${binary.value.length},${binary.isInline})'); } return id; } @@ -231,7 +231,7 @@ class KdbxBody extends KdbxNode { if (ctx.findBinaryByValue(binary) == null) { ctx.addBinary(binary); mergeContext.trackChange(this, - debug: 'adding new binary ${binary.value!.length}'); + debug: 'adding new binary ${binary.value.length}'); } } meta.merge(other.meta); diff --git a/lib/src/utils/print_utils.dart b/lib/src/utils/print_utils.dart index 7f32e8b..3b0d00f 100644 --- a/lib/src/utils/print_utils.dart +++ b/lib/src/utils/print_utils.dart @@ -34,7 +34,7 @@ class KdbxPrintUtils { .join('\n')); } buf.writeln(entry.binaryEntries - .map((b) => '$indent `- file: ${b.key} - ${b.value.value!.length}') + .map((b) => '$indent `- file: ${b.key} - ${b.value.value.length}') .join('\n')); } } diff --git a/test/kdbx_binaries_test.dart b/test/kdbx_binaries_test.dart index 000fef1..cd3decf 100644 --- a/test/kdbx_binaries_test.dart +++ b/test/kdbx_binaries_test.dart @@ -55,10 +55,10 @@ void main() { for (final binary in binaries) { switch (binary.key.key) { case 'example1.txt': - expect(utf8.decode(binary.value.value!), 'content1 example\n\n'); + expect(utf8.decode(binary.value.value), 'content1 example\n\n'); break; case 'example2.txt': - expect(utf8.decode(binary.value.value!), 'content2 example\n\n'); + expect(utf8.decode(binary.value.value), 'content2 example\n\n'); break; case 'keepasslogo.jpeg': expect(binary.value.value, hasLength(7092)); @@ -126,7 +126,7 @@ void main() { final entry = file.body.rootGroup.entries.first; for (final name in ['a', 'b', 'c', 'd', 'e']) { expect( - utf8.decode(entry.getBinary(KdbxKey('$name.txt'))!.value!).trim(), + utf8.decode(entry.getBinary(KdbxKey('$name.txt'))!.value).trim(), name, ); }