diff --git a/lib/src/kdbx_times.dart b/lib/src/kdbx_times.dart index 982fc2f..f7d5a7a 100644 --- a/lib/src/kdbx_times.dart +++ b/lib/src/kdbx_times.dart @@ -5,6 +5,10 @@ import 'package:kdbx/src/kdbx_xml.dart'; import 'package:quiver/iterables.dart'; import 'package:xml/xml.dart'; +import 'package:logging/logging.dart'; + +final _logger = Logger('kdbx_times'); + class KdbxTimes extends KdbxNode implements KdbxNodeContext { KdbxTimes.create(this.ctx) : super.create('Times') { final now = clock.now().toUtc(); @@ -16,15 +20,32 @@ class KdbxTimes extends KdbxNode implements KdbxNodeContext { usageCount.set(0); locationChanged.set(now); } - KdbxTimes.read(XmlElement node, this.ctx) : super.read(node); + KdbxTimes.read(XmlElement node, this.ctx) : super.read(node) { + // backward compatibility - there was a bug setting/reading + // modification, lastAccess and expiryTime. Make sure they are defined. + final checkDates = { + lastModificationTime: () => creationTime.get() ?? clock.now().toUtc(), + lastAccessTime: () => lastModificationTime.get() ?? clock.now().toUtc(), + expiryTime: () { + expires.set(false); + return clock.now().toUtc(); + }, + }; + for (final check in checkDates.entries) { + if (check.key.get() == null) { + final val = check.value(); + _logger.warning('${check.key.name} was not defined. setting to $val'); + check.key.set(val); + } + } + } @override final KdbxReadWriteContext ctx; DateTimeUtcNode get creationTime => DateTimeUtcNode(this, 'CreationTime'); DateTimeUtcNode get lastModificationTime => - DateTimeUtcNode(this, 'LastModificationTime', - defaultValue: () => creationTime.get() ?? DateTimeUtcNode.minDate); + DateTimeUtcNode(this, 'LastModificationTime'); DateTimeUtcNode get lastAccessTime => DateTimeUtcNode(this, 'LastAccessTime'); DateTimeUtcNode get expiryTime => DateTimeUtcNode(this, 'ExpiryTime'); BooleanNode get expires => BooleanNode(this, 'Expires'); diff --git a/lib/src/kdbx_xml.dart b/lib/src/kdbx_xml.dart index d102f20..29ff563 100644 --- a/lib/src/kdbx_xml.dart +++ b/lib/src/kdbx_xml.dart @@ -231,11 +231,9 @@ class BooleanNode extends KdbxSubTextNode { } class DateTimeUtcNode extends KdbxSubTextNode { - DateTimeUtcNode(KdbxNodeContext node, String name, {this.defaultValue}) - : super(node, name); + DateTimeUtcNode(KdbxNodeContext node, String name) : super(node, name); static const EpochSeconds = 62135596800; - final DateTime Function() defaultValue; KdbxReadWriteContext get _ctx => (node as KdbxNodeContext).ctx; static final minDate = DateTime.fromMillisecondsSinceEpoch(0, isUtc: true); @@ -250,7 +248,7 @@ class DateTimeUtcNode extends KdbxSubTextNode { @override DateTime decode(String value) { if (value == null) { - return defaultValue?.call(); + return null; } if (value.contains(':')) { return DateTime.parse(value);