X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=lib%2FFile%2FKDBX%2FUtil.pm;h=b8c901b048d6c73f1187a8d7d5454f409dbc479e;hb=700fa117555b87eda7227f9083c0fc0df052c64f;hp=62515f53300bcf8c430514fc6c074ebf8aafb36f;hpb=16c035abaa2ff6c53076f4ff6ae3215130acb56f;p=chaz%2Fp5-File-KDBX diff --git a/lib/File/KDBX/Util.pm b/lib/File/KDBX/Util.pm index 62515f5..b8c901b 100644 --- a/lib/File/KDBX/Util.pm +++ b/lib/File/KDBX/Util.pm @@ -1,6 +1,7 @@ package File::KDBX::Util; # ABSTRACT: Utility functions for working with KDBX files +use 5.010; use warnings; use strict; @@ -12,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'; @@ -598,7 +599,7 @@ sub pack_Ql { my $num = shift; require Config; if ($Config::Config{ivsize} < 8) { - if (blessed $num && $num->can('to_hex')) { + if (blessed $num && $num->can('as_hex')) { return "\xff\xff\xff\xff\xff\xff\xff\xff" if Math::BigInt->new('18446744073709551615') <= $num; return "\x00\x00\x00\x00\x00\x00\x00\x80" if $num <= Math::BigInt->new('-9223372036854775808'); my $neg; @@ -606,7 +607,9 @@ sub pack_Ql { $neg = 1; $num = -$num; } - my $bytes = reverse pack('H16', substr(('0' x 15) . $num->to_hex, -16)); + my $hex = $num->as_hex; + $hex =~ s/^0x/000000000000000/; + my $bytes = reverse pack('H16', substr($hex, -16)); $bytes .= "\0" x (8 - length $bytes) if length $bytes < 8; if ($neg) { # two's compliment @@ -646,7 +649,7 @@ sub unpack_Ql { require Config; if ($Config::Config{ivsize} < 8) { require Math::BigInt; - return (Math::BigInt->new('0x' . unpack('H*', scalar reverse $bytes))); + return Math::BigInt->new('0x' . unpack('H*', scalar reverse $bytes)); } return unpack('Q<', $bytes); } @@ -665,14 +668,14 @@ sub unpack_ql { if ($Config::Config{ivsize} < 8) { require Math::BigInt; if (ord(substr($bytes, -1, 1)) & 128) { - return (Math::BigInt->new('-9223372036854775808')) if $bytes eq "\x00\x00\x00\x00\x00\x00\x00\x80"; + return Math::BigInt->new('-9223372036854775808') if $bytes eq "\x00\x00\x00\x00\x00\x00\x00\x80"; # two's compliment substr($bytes, 0, 1, chr(ord(substr($bytes, 0, 1)) - 1)); $bytes = join('', map { chr(~ord($_) & 0xff) } split(//, $bytes)); - return (-Math::BigInt->new('0x' . unpack('H*', scalar reverse $bytes))); + return -Math::BigInt->new('0x' . unpack('H*', scalar reverse $bytes)); } else { - return (Math::BigInt->new('0x' . unpack('H*', scalar reverse $bytes))); + return Math::BigInt->new('0x' . unpack('H*', scalar reverse $bytes)); } } return unpack('q<', $bytes);