X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=lib%2FFile%2FKDBX%2FLoader.pm;h=6d289be0f091e94973de72a0bfedb9d3e9cbbbe4;hb=37b09e0f2832514b33de4499a83f22d5ffe7c0a3;hp=844f038098e8426518b1f77f5d2dd42fef4c2164;hpb=f63182fc62b25269b1c38588dca2b3535ed1a1a2;p=chaz%2Fp5-File-KDBX diff --git a/lib/File/KDBX/Loader.pm b/lib/File/KDBX/Loader.pm index 844f038..6d289be 100644 --- a/lib/File/KDBX/Loader.pm +++ b/lib/File/KDBX/Loader.pm @@ -6,7 +6,7 @@ use strict; use File::KDBX::Constants qw(:magic :header :version); use File::KDBX::Error; -use File::KDBX::Util qw(:io); +use File::KDBX::Util qw(:class :io); use File::KDBX; use IO::Handle; use Module::Load (); @@ -212,14 +212,32 @@ sub kdbx { =attr format -TODO +Get the file format used for reading the database. Normally the format is auto-detected from the data stream. +This auto-detection works well, so there's not really a good reason to explicitly specify the format. +Possible formats: + +=for :list +* C +* C +* C +* C +* C + +=attr inner_format + +Get the format of the data inside the KDBX envelope. This only applies to C and C formats. Possible +formats: + +=for :list +* C - Read the database groups and entries as XML (default) +* C - Read parsing and store the result in L =cut -sub format { $_[0]->{format} } -sub inner_format { $_[0]->{inner_format} // 'XML' } +has format => undef, is => 'ro'; +has inner_format => 'XML', is => 'ro'; -=attr min_version +=method min_version $min_version = File::KDBX::Loader->min_version; @@ -303,7 +321,17 @@ sub _read { my $headers = $self->_read_headers($fh); - $self->_read_body($fh, $key, "$magic$headers"); + eval { + $self->_read_body($fh, $key, "$magic$headers"); + }; + if (my $err = $@) { + throw "Failed to load KDBX file: $err", + error => $err, + compression_error => $IO::Uncompress::Gunzip::GunzipError, + crypt_error => $File::KDBX::IO::Crypt::ERROR, + hash_error => $File::KDBX::IO::HashBLock::ERROR, + hmac_error => $File::KDBX::IO::HmacBLock::ERROR; + } } sub _read_headers { @@ -336,3 +364,9 @@ sub _read_inner_body { } 1; +__END__ + +=head1 DESCRIPTION + + +=cut