]> Dogcows Code - chaz/p5-File-KDBX/blobdiff - lib/File/KDBX/Dumper/XML.pm
Remove min_version and clean up a lot of pod
[chaz/p5-File-KDBX] / lib / File / KDBX / Dumper / XML.pm
index a079aed4a6871e80c1788d7ee280fbbc036b5d53..7dd23d52ea0ef95aa357698ec65d4ffab933ba61 100644 (file)
@@ -9,15 +9,15 @@ use Crypt::Misc 0.029 qw(encode_b64);
 use Encode qw(encode);
 use File::KDBX::Constants qw(:version :time);
 use File::KDBX::Error;
-use File::KDBX::Util qw(assert_64bit erase_scoped gzip snakify);
+use File::KDBX::Util qw(:class assert_64bit erase_scoped gzip snakify);
 use IO::Handle;
-use Scalar::Util qw(isdual looks_like_number);
+use Scalar::Util qw(blessed isdual looks_like_number);
 use Time::Piece;
 use XML::LibXML;
 use boolean;
 use namespace::clean;
 
-use parent 'File::KDBX::Dumper';
+extends 'File::KDBX::Dumper';
 
 our $VERSION = '999.999'; # VERSION
 
@@ -27,28 +27,12 @@ our $VERSION = '999.999'; # VERSION
 
 Get whether or not protected strings and binaries should be written in an encrypted stream. Default: C<TRUE>
 
-=cut
-
-sub allow_protection {
-    my $self = shift;
-    $self->{allow_protection} = shift if @_;
-    $self->{allow_protection} //= 1;
-}
-
 =attr binaries
 
     $bool = $dumper->binaries;
 
 Get whether or not binaries within the database should be written. Default: C<TRUE>
 
-=cut
-
-sub binaries {
-    my $self = shift;
-    $self->{binaries} = shift if @_;
-    $self->{binaries} //= $self->kdbx->version < KDBX_VERSION_4_0;
-}
-
 =attr compress_binaries
 
     $tristate = $dumper->compress_binaries;
@@ -60,14 +44,6 @@ Get whether or not to compress binaries. Possible values:
 * C<FALSE> - Never compress binaries
 * C<undef> - Compress binaries if it results in smaller database sizes (default)
 
-=cut
-
-sub compress_binaries {
-    my $self = shift;
-    $self->{compress_binaries} = shift if @_;
-    $self->{compress_binaries};
-}
-
 =attr compress_datetimes
 
     $bool = $dumper->compress_datetimes;
@@ -77,14 +53,6 @@ string format of C<1970-01-01T00:00:00Z>, but they can also be written in a comp
 bytes. The default is to write compressed datetimes if the KDBX file version is 4+, otherwise use the
 human-readable format.
 
-=cut
-
-sub compress_datetimes {
-    my $self = shift;
-    $self->{compress_datetimes} = shift if @_;
-    $self->{compress_datetimes};
-}
-
 =attr header_hash
 
     $octets = $dumper->header_hash;
@@ -94,11 +62,16 @@ the authenticity of header data. This is unnecessary and should not be used with
 format uses HMAC-SHA256 to detect tampering.
 
 L<File::KDBX::Dumper::V3> automatically calculates the header hash an provides it to this module, and plain
-XML files which don't have a KDBX wrapper don't have headers and so should have a header hash. Therefore there
-is probably never any reason to set this manually.
+XML files which don't have a KDBX wrapper don't have headers and so should not have a header hash. Therefore
+there is probably never any reason to set this manually.
 
 =cut
 
+has allow_protection => 1;
+has binaries => sub { $_[0]->kdbx->version < KDBX_VERSION_4_0 };
+has 'compress_binaries';
+has 'compress_datetimes';
+
 sub header_hash { $_[0]->{header_hash} }
 
 sub _binaries_written { $_[0]->{_binaries_written} //= {} }
@@ -205,8 +178,8 @@ sub _write_xml_binaries {
     my $new_ref = keys %{$self->_binaries_written};
     my $written = $self->_binaries_written;
 
-    my $entries = $kdbx->all_entries(history => true);
-    for my $entry (@$entries) {
+    my $entries = $kdbx->entries(history => 1);
+    while (my $entry = $entries->next) {
         for my $key (keys %{$entry->binaries}) {
             my $binary = $entry->binaries->{$key};
             if (defined $binary->{ref} && defined $kdbx->binaries->{$binary->{ref}}) {
@@ -276,10 +249,10 @@ sub _write_xml_custom_icons {
     my $self = shift;
     my $node = shift;
 
-    my $custom_icons = $self->kdbx->meta->{custom_icons} || {};
+    my $custom_icons = $self->kdbx->custom_icons;
 
-    for my $uuid (sort keys %$custom_icons) {
-        my $icon = $custom_icons->{$uuid};
+    for my $icon (@$custom_icons) {
+        $icon->{uuid} && $icon->{data} or next;
         my $icon_node = $node->addNewChild(undef, 'Icon');
 
         $self->_write_xml_from_pairs($icon_node, $icon,
@@ -323,7 +296,7 @@ sub _write_xml_root {
 
     if (my $group = $kdbx->root) {
         my $group_node = $node->addNewChild(undef, 'Group');
-        $self->_write_xml_group($group_node, $group->_confirmed);
+        $self->_write_xml_group($group_node, $group->_committed);
     }
 
     undef $guard;   # re-lock if needed, as early as possible
@@ -364,12 +337,12 @@ sub _write_xml_group {
 
     for my $entry (@{$group->entries}) {
         my $entry_node = $node->addNewChild(undef, 'Entry');
-        $self->_write_xml_entry($entry_node, $entry->_confirmed);
+        $self->_write_xml_entry($entry_node, $entry->_committed);
     }
 
     for my $group (@{$group->groups}) {
         my $group_node = $node->addNewChild(undef, 'Group');
-        $self->_write_xml_group($group_node, $group->_confirmed);
+        $self->_write_xml_group($group_node, $group->_committed);
     }
 }
 
@@ -450,7 +423,7 @@ sub _write_xml_entry {
             my $history_node = $node->addNewChild(undef, 'History');
             for my $historical (@history) {
                 my $historical_node = $history_node->addNewChild(undef, 'Entry');
-                $self->_write_xml_entry($historical_node, $historical->_confirmed, 1);
+                $self->_write_xml_entry($historical_node, $historical->_committed, 1);
             }
         }
     }
@@ -592,7 +565,6 @@ sub _encode_bool {
 }
 
 sub _encode_datetime {
-    goto &_encode_datetime_binary if defined $_[2] && KDBX_VERSION_4_0 <= $_[2];
     local $_ = shift;
     return $_->strftime('%Y-%m-%dT%H:%M:%SZ');
 }
This page took 0.02177 seconds and 4 git commands to generate.