From 33342f3283c2612817d097917fc6c63ee7b26e95 Mon Sep 17 00:00:00 2001 From: Herbert Poul Date: Mon, 14 Sep 2020 15:10:35 +0200 Subject: [PATCH] added error log for exception while reading time. --- lib/src/kdbx_xml.dart | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/lib/src/kdbx_xml.dart b/lib/src/kdbx_xml.dart index 29ff563..80f3dcf 100644 --- a/lib/src/kdbx_xml.dart +++ b/lib/src/kdbx_xml.dart @@ -10,6 +10,10 @@ import 'package:kdbx/src/kdbx_consts.dart'; import 'package:meta/meta.dart'; import 'package:xml/xml.dart'; +import 'package:logging/logging.dart'; + +final _logger = Logger('kdbx_xml'); + class KdbxXml { static const NODE_STRING = 'String'; static const NODE_KEY = 'Key'; @@ -250,17 +254,23 @@ class DateTimeUtcNode extends KdbxSubTextNode { if (value == null) { return null; } - if (value.contains(':')) { - return DateTime.parse(value); + try { + if (value.contains(':')) { + return DateTime.parse(value); + } + // kdbx 4.x uses base64 encoded date. + final decoded = base64.decode(value); + + final secondsFrom00 = ReaderHelper(decoded).readUint64(); + + return DateTime.fromMillisecondsSinceEpoch( + (secondsFrom00 - EpochSeconds) * 1000, + isUtc: true); + } catch (e, stackTrace) { + _logger.severe( + 'Error while parsing time for {$name}: {$value}', e, stackTrace); + rethrow; } - // kdbx 4.x uses base64 encoded date. - final decoded = base64.decode(value); - - final secondsFrom00 = ReaderHelper(decoded).readUint64(); - - return DateTime.fromMillisecondsSinceEpoch( - (secondsFrom00 - EpochSeconds) * 1000, - isUtc: true); } @override