]> Dogcows Code - chaz/p5-File-KDBX/blobdiff - lib/File/KDBX/Dumper/V3.pm
Fix dumping wrong-sized encryption IV
[chaz/p5-File-KDBX] / lib / File / KDBX / Dumper / V3.pm
index 635931fa5c58baea93a18fc0b4cb90261b417a59..e5c8877d7b32b134685a291bc1d3fbbc73615176 100644 (file)
@@ -10,11 +10,11 @@ use File::KDBX::Constants qw(:header :compression);
 use File::KDBX::Error;
 use File::KDBX::IO::Crypt;
 use File::KDBX::IO::HashBlock;
-use File::KDBX::Util qw(:empty assert_64bit erase_scoped);
+use File::KDBX::Util qw(:class :empty :int :load erase_scoped);
 use IO::Handle;
 use namespace::clean;
 
-use parent 'File::KDBX::Dumper';
+extends 'File::KDBX::Dumper';
 
 our $VERSION = '999.999'; # VERSION
 
@@ -31,6 +31,11 @@ sub _write_headers {
     local $headers->{+HEADER_TRANSFORM_SEED} = $kdbx->transform_seed;
     local $headers->{+HEADER_TRANSFORM_ROUNDS} = $kdbx->transform_rounds;
 
+    my $got_iv_size = length($headers->{+HEADER_ENCRYPTION_IV});
+    alert 'Encryption IV should be exactly 16 bytes long',
+        got         => $got_iv_size,
+        expected    => 16 if $got_iv_size != 16;
+
     if (nonempty (my $comment = $headers->{+HEADER_COMMENT})) {
         $buf .= $self->_write_header($fh, HEADER_COMMENT, $comment);
     }
@@ -59,7 +64,7 @@ sub _write_header {
     my $type = shift;
     my $val  = shift // '';
 
-    $type = KDBX_HEADER($type);
+    $type = to_header_constant($type);
     if ($type == HEADER_END) {
         $val = "\r\n\r\n";
     }
@@ -81,8 +86,7 @@ sub _write_header {
         # nothing
     }
     elsif ($type == HEADER_TRANSFORM_ROUNDS) {
-        assert_64bit;
-        $val = pack('Q<', $val);
+        $val = pack_Ql($val);
     }
     elsif ($type == HEADER_ENCRYPTION_IV) {
         # nothing
@@ -152,7 +156,6 @@ sub _write_body {
 
     $fh->print($kdbx->headers->{+HEADER_STREAM_START_BYTES})
         or throw 'Failed to write start bytes';
-    $fh->flush;
 
     $kdbx->key($key);
 
@@ -160,7 +163,7 @@ sub _write_body {
 
     my $compress = $kdbx->headers->{+HEADER_COMPRESSION_FLAGS};
     if ($compress == COMPRESSION_GZIP) {
-        require IO::Compress::Gzip;
+        load_optional('IO::Compress::Gzip');
         $fh = IO::Compress::Gzip->new($fh,
             -Level => IO::Compress::Gzip::Z_BEST_COMPRESSION(),
             -TextFlag => 1,
This page took 0.024874 seconds and 4 git commands to generate.