]> Dogcows Code - chaz/p5-File-KDBX/blobdiff - lib/File/KDBX/Loader/V3.pm
Add support for 32-bit perls
[chaz/p5-File-KDBX] / lib / File / KDBX / Loader / V3.pm
index 68d7f9ce0c35389592889415ae8178aa3819419d..cf69ae65bdf36dc4505aee1b385ae23726a2df1a 100644 (file)
@@ -20,12 +20,12 @@ use Crypt::Digest qw(digest_data);
 use Encode qw(decode);
 use File::KDBX::Constants qw(:header :compression :kdf);
 use File::KDBX::Error;
-use File::KDBX::Util qw(:io assert_64bit erase_scoped);
-use PerlIO::via::File::KDBX::Crypt;
-use PerlIO::via::File::KDBX::HashBlock;
+use File::KDBX::IO::Crypt;
+use File::KDBX::IO::HashBlock;
+use File::KDBX::Util qw(:class :int :io :load erase_scoped);
 use namespace::clean;
 
-use parent 'File::KDBX::Loader';
+extends 'File::KDBX::Loader';
 
 our $VERSION = '999.999'; # VERSION
 
@@ -42,7 +42,7 @@ sub _read_header {
         $buf .= $val;
     }
 
-    $type = KDBX_HEADER($type);
+    $type = to_header_constant($type);
     if ($type == HEADER_END) {
         # done
     }
@@ -62,8 +62,7 @@ sub _read_header {
         # nothing
     }
     elsif ($type == HEADER_TRANSFORM_ROUNDS) {
-        assert_64bit;
-        $val = unpack('Q<', $val);
+        ($val) = unpack_Ql($val);
     }
     elsif ($type == HEADER_ENCRYPTION_IV) {
         # nothing
@@ -75,7 +74,7 @@ sub _read_header {
         # nothing
     }
     elsif ($type == HEADER_INNER_RANDOM_STREAM_ID) {
-        $val = unpack('L<', $val);
+        ($val) = unpack('L<', $val);
     }
     elsif ($type == HEADER_KDF_PARAMETERS ||
            $type == HEADER_PUBLIC_CUSTOM_DATA) {
@@ -127,7 +126,7 @@ sub _read_body {
     push @cleanup, erase_scoped $final_key;
 
     my $cipher = $kdbx->cipher(key => $final_key);
-    PerlIO::via::File::KDBX::Crypt->push($fh, $cipher);
+    $fh = File::KDBX::IO::Crypt->new($fh, cipher => $cipher);
 
     read_all $fh, my $start_bytes, 32 or throw 'Failed to read starting bytes';
 
@@ -138,21 +137,21 @@ sub _read_body {
 
     $kdbx->key($key);
 
-    PerlIO::via::File::KDBX::HashBlock->push($fh);
+    $fh = File::KDBX::IO::HashBlock->new($fh);
 
     my $compress = $kdbx->headers->{+HEADER_COMPRESSION_FLAGS};
     if ($compress == COMPRESSION_GZIP) {
-        require PerlIO::via::File::KDBX::Compression;
-        PerlIO::via::File::KDBX::Compression->push($fh);
+        load_optional('IO::Uncompress::Gunzip');
+        $fh = IO::Uncompress::Gunzip->new($fh)
+            or throw "Failed to initialize compression library: $IO::Uncompress::Gunzip::GunzipError",
+                error => $IO::Uncompress::Gunzip::GunzipError;
     }
     elsif ($compress != COMPRESSION_NONE) {
         throw "Unsupported compression ($compress)\n", compression_flags => $compress;
     }
 
     $self->_read_inner_body($fh);
-
-    binmode($fh, ':pop') if $compress;
-    binmode($fh, ':pop:pop');
+    close($fh);
 
     if (my $header_hash = $kdbx->meta->{header_hash}) {
         my $got_header_hash = digest_data('SHA256', $header_data);
This page took 0.027284 seconds and 4 git commands to generate.