From 700fa117555b87eda7227f9083c0fc0df052c64f Mon Sep 17 00:00:00 2001 From: Charles McGarvey Date: Wed, 11 May 2022 15:51:03 -0600 Subject: [PATCH] Prereq Time::Piece 1.33 to fix KDBX4 datetimes Time::Piece 1.33 supports passing objects to gmtime which is necessary on 32-bit platforms where arguments might be bigints. --- Changes | 2 ++ lib/File/KDBX.pm | 2 +- lib/File/KDBX/Dumper/XML.pm | 2 +- lib/File/KDBX/Entry.pm | 2 +- lib/File/KDBX/Group.pm | 2 +- lib/File/KDBX/Loader/KDB.pm | 4 ++-- lib/File/KDBX/Loader/XML.pm | 7 +++---- lib/File/KDBX/Util.pm | 2 +- t/kdbx4.t | 2 +- 9 files changed, 13 insertions(+), 12 deletions(-) diff --git a/Changes b/Changes index 540ae6d..76956a5 100644 --- a/Changes +++ b/Changes @@ -2,6 +2,8 @@ Revision history for File-KDBX. {{$NEXT}} + * Fix parsing KDBX4 datetimes on 32-bit perls. + 0.902 2022-05-03 19:18:06-0600 * Added support for 32-bit perls. diff --git a/lib/File/KDBX.pm b/lib/File/KDBX.pm index 5d188fb..8730266 100644 --- a/lib/File/KDBX.pm +++ b/lib/File/KDBX.pm @@ -16,7 +16,7 @@ use Hash::Util::FieldHash qw(fieldhashes); use List::Util qw(any first); use Ref::Util qw(is_ref is_arrayref is_plain_hashref); use Scalar::Util qw(blessed); -use Time::Piece; +use Time::Piece 1.33; use boolean; use namespace::clean; diff --git a/lib/File/KDBX/Dumper/XML.pm b/lib/File/KDBX/Dumper/XML.pm index 345439e..c7ff830 100644 --- a/lib/File/KDBX/Dumper/XML.pm +++ b/lib/File/KDBX/Dumper/XML.pm @@ -12,7 +12,7 @@ use File::KDBX::Error; use File::KDBX::Util qw(:class :int erase_scoped gzip snakify); use IO::Handle; use Scalar::Util qw(blessed isdual looks_like_number); -use Time::Piece; +use Time::Piece 1.33; use XML::LibXML; use boolean; use namespace::clean; diff --git a/lib/File/KDBX/Entry.pm b/lib/File/KDBX/Entry.pm index be44ae7..2876b29 100644 --- a/lib/File/KDBX/Entry.pm +++ b/lib/File/KDBX/Entry.pm @@ -15,7 +15,7 @@ use List::Util qw(first sum0); use Ref::Util qw(is_coderef is_hashref is_plain_hashref); use Scalar::Util qw(blessed looks_like_number); use Storable qw(dclone); -use Time::Piece; +use Time::Piece 1.33; use boolean; use namespace::clean; diff --git a/lib/File/KDBX/Group.pm b/lib/File/KDBX/Group.pm index 9ef603b..c5dbafe 100644 --- a/lib/File/KDBX/Group.pm +++ b/lib/File/KDBX/Group.pm @@ -13,7 +13,7 @@ use Hash::Util::FieldHash; use List::Util qw(any sum0); use Ref::Util qw(is_coderef is_ref); use Scalar::Util qw(blessed); -use Time::Piece; +use Time::Piece 1.33; use boolean; use namespace::clean; diff --git a/lib/File/KDBX/Loader/KDB.pm b/lib/File/KDBX/Loader/KDB.pm index cc9104c..685e0a9 100644 --- a/lib/File/KDBX/Loader/KDB.pm +++ b/lib/File/KDBX/Loader/KDB.pm @@ -11,7 +11,7 @@ use File::KDBX::Util qw(:class :empty :io :uuid load_optional); use File::KDBX; use Ref::Util qw(is_arrayref is_hashref); use Scalar::Util qw(looks_like_number); -use Time::Piece; +use Time::Piece 1.33; use boolean; use namespace::clean; @@ -19,7 +19,7 @@ extends 'File::KDBX::Loader'; our $VERSION = '999.999'; # VERSION -my $DEFAULT_EXPIRATION = Time::Piece->new(32503677839); # 2999-12-31 23:59:59 +my $DEFAULT_EXPIRATION = Time::Piece->strptime('2999-12-31 23:59:59', '%Y-%m-%d %H:%M:%S'); sub _read_headers { '' } diff --git a/lib/File/KDBX/Loader/XML.pm b/lib/File/KDBX/Loader/XML.pm index 1931153..68d1abe 100644 --- a/lib/File/KDBX/Loader/XML.pm +++ b/lib/File/KDBX/Loader/XML.pm @@ -11,7 +11,7 @@ use File::KDBX::Error; use File::KDBX::Safe; use File::KDBX::Util qw(:class :int :text gunzip erase_scoped); use Scalar::Util qw(looks_like_number); -use Time::Piece; +use Time::Piece 1.33; use XML::LibXML::Reader; use boolean; use namespace::clean; @@ -496,7 +496,7 @@ sub _read_xml_content { my $decoded = eval { _decode_primitive($content, $type) }; if (my $err = $@) { ref $err and $err->details(node => $reader->nodePath, line => $reader->lineNumber); - throw $err + throw $err; } return $decoded; @@ -536,10 +536,9 @@ sub _decode_datetime { $binary .= \0 x (8 - length($binary)) if length($binary) < 8; my ($seconds_since_ad1) = unpack_Ql($binary); my $epoch = $seconds_since_ad1 - TIME_SECONDS_AD1_TO_UNIX_EPOCH; - return Time::Piece->new($epoch); + return gmtime($epoch); } - my $dt = eval { Time::Piece->strptime($_, '%Y-%m-%dT%H:%M:%SZ') }; if (my $err = $@) { throw 'Failed to parse datetime', text => $_, error => $err; diff --git a/lib/File/KDBX/Util.pm b/lib/File/KDBX/Util.pm index e9bb316..b8c901b 100644 --- a/lib/File/KDBX/Util.pm +++ b/lib/File/KDBX/Util.pm @@ -13,7 +13,7 @@ use List::Util 1.33 qw(any all); use Module::Load; use Ref::Util qw(is_arrayref is_coderef is_hashref is_ref is_refref is_scalarref); use Scalar::Util qw(blessed looks_like_number readonly); -use Time::Piece; +use Time::Piece 1.33; use boolean; use namespace::clean -except => 'import'; diff --git a/t/kdbx4.t b/t/kdbx4.t index 5afceeb..d82dc4b 100644 --- a/t/kdbx4.t +++ b/t/kdbx4.t @@ -111,7 +111,7 @@ subtest 'KDBX4.1 upgrade' => sub { is $kdbx->minimum_version, KDBX_VERSION_4_1, 'Icon with name requires upgrade'; $kdbx->remove_custom_icon($icon_uuid); is $kdbx->minimum_version, KDBX_VERSION_3_1, 'Reset upgrade requirement'; - $icon_uuid = $kdbx->add_custom_icon('data2', last_modification_time => gmtime); + $icon_uuid = $kdbx->add_custom_icon('data2', last_modification_time => scalar gmtime); is $kdbx->minimum_version, KDBX_VERSION_4_1, 'Icon with modtime requires upgrade'; $kdbx->remove_custom_icon($icon_uuid); is $kdbx->minimum_version, KDBX_VERSION_3_1, 'Reset upgrade requirement'; -- 2.45.2