| 1 | package File::KDBX::Loader::XML; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Load unencrypted XML KeePass files | ||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||
| 4 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 6 | ▶ | use Crypt::Misc 0.029 qw(decode_b64); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 6 | ▶ | use Encode qw(decode); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 6 | ▶ | use File::KDBX::Constants qw(:version :time); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 6 | ▶ | use File::KDBX::Error; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 6 | ▶ | use File::KDBX::Safe; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 6 | ▶ | use File::KDBX::Util qw(:class :int :text gunzip erase_scoped); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 6 | ▶ | use Scalar::Util qw(looks_like_number); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 6 | ▶ | use Time::Piece 1.33; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 6 | ▶ | use XML::LibXML::Reader; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 6 | ▶ | use boolean; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 6 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 6 | extends 'File::KDBX::Loader'; | |||||||||||||||||||||||||||||||||||||||||
| 20 | 2686 | ▶ | |||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_reader: called CC=3 SCAR=11.8
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 39 | ▶ | our $VERSION = '0.905'; # VERSION | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_safe: called CC=3 SCAR=11.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 2686 | ▶ | |||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$_[0]{"_reader"} //= undef
MC/DC0%0/1
$_[0]{"_reader"} //= undef
$_[0]{"_reader"}
Truth table50%1/2
A
A= $_[0]{"_reader"}
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 39 | ▶ | has '_reader', is => 'ro'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$_[0]{"_safe"} //= scalar &$default($_[0])
MC/DC100%1/1
$_[0]{"_safe"} //= scalar &$default($_[0])
$_[0]{"_safe"}
Truth table100%2/2
A
A= $_[0]{"_safe"}
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 12 | ▶ | has '_safe', is => 'ro', default => sub { File::KDBX::Safe->new(cipher => $_[0]->kdbx->random_stream) }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | sub _read { | ||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | my $fh = shift; | |||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | $self->_read_inner_body($fh); | |||||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | sub _read_inner_body { | ||||||||||||||||||||||||||||||||||||||||||
| 34 | 21 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_inner_body: called CC=8 SCAR=21.5
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 21 | my $fh = shift; | |||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 21 | my $reader = $self->{_reader} = XML::LibXML::Reader->new(IO => $fh); | |||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 21 | delete $self->{_safe}; | |||||||||||||||||||||||||||||||||||||||||
| 40 | 21 | my $root_done; | |||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 21 | my $pattern = XML::LibXML::Pattern->new('/KeePassFile/Meta|/KeePassFile/Root'); | |||||||||||||||||||||||||||||||||||||||||
| 43 | 21 | ▶ | while ($reader->nextPatternMatch($pattern) == 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 42 | ▶ | next if $reader->nodeType != XML_READER_TYPE_ELEMENT; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 42 | my $name = $reader->localName; | |||||||||||||||||||||||||||||||||||||||||
| 46 | 42 | ▶ | if ($name eq 'Meta') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 21 | $self->_read_xml_meta; | |||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||
| 49 | elsif ($name eq 'Root') { | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 21 | ▶ | if ($root_done) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | alert 'Ignoring extra Root element in KeePass XML file', line => $reader->lineNumber; | |||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 21 | $self->_read_xml_root; | |||||||||||||||||||||||||||||||||||||||||
| 55 | 21 | $root_done = 1; | |||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 21 | ▶ | if ($reader->readState == XML_READER_ERROR) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | throw 'Failed to parse KeePass XML'; | |||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 21 | ▶ | $self->kdbx->_safe($self->_safe) if $self->{_safe}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 21 | $self->_resolve_binary_refs; | |||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | sub _read_xml_meta { | ||||||||||||||||||||||||||||||||||||||||||
| 69 | 21 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_xml_meta: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 21 | $self->_read_xml_element($self->kdbx->meta, | |||||||||||||||||||||||||||||||||||||||||
| 72 | Generator => 'text', | ||||||||||||||||||||||||||||||||||||||||||
| 73 | HeaderHash => 'binary', | ||||||||||||||||||||||||||||||||||||||||||
| 74 | DatabaseName => 'text', | ||||||||||||||||||||||||||||||||||||||||||
| 75 | DatabaseNameChanged => 'datetime', | ||||||||||||||||||||||||||||||||||||||||||
| 76 | DatabaseDescription => 'text', | ||||||||||||||||||||||||||||||||||||||||||
| 77 | DatabaseDescriptionChanged => 'datetime', | ||||||||||||||||||||||||||||||||||||||||||
| 78 | DefaultUserName => 'text', | ||||||||||||||||||||||||||||||||||||||||||
| 79 | DefaultUserNameChanged => 'datetime', | ||||||||||||||||||||||||||||||||||||||||||
| 80 | MaintenanceHistoryDays => 'number', | ||||||||||||||||||||||||||||||||||||||||||
| 81 | Color => 'text', | ||||||||||||||||||||||||||||||||||||||||||
| 82 | MasterKeyChanged => 'datetime', | ||||||||||||||||||||||||||||||||||||||||||
| 83 | MasterKeyChangeRec => 'number', | ||||||||||||||||||||||||||||||||||||||||||
| 84 | MasterKeyChangeForce => 'number', | ||||||||||||||||||||||||||||||||||||||||||
| 85 | MemoryProtection => \&_read_xml_memory_protection, | ||||||||||||||||||||||||||||||||||||||||||
| 86 | CustomIcons => \&_read_xml_custom_icons, | ||||||||||||||||||||||||||||||||||||||||||
| 87 | RecycleBinEnabled => 'bool', | ||||||||||||||||||||||||||||||||||||||||||
| 88 | RecycleBinUUID => 'uuid', | ||||||||||||||||||||||||||||||||||||||||||
| 89 | RecycleBinChanged => 'datetime', | ||||||||||||||||||||||||||||||||||||||||||
| 90 | EntryTemplatesGroup => 'uuid', | ||||||||||||||||||||||||||||||||||||||||||
| 91 | EntryTemplatesGroupChanged => 'datetime', | ||||||||||||||||||||||||||||||||||||||||||
| 92 | LastSelectedGroup => 'uuid', | ||||||||||||||||||||||||||||||||||||||||||
| 93 | LastTopVisibleGroup => 'uuid', | ||||||||||||||||||||||||||||||||||||||||||
| 94 | HistoryMaxItems => 'number', | ||||||||||||||||||||||||||||||||||||||||||
| 95 | HistoryMaxSize => 'number', | ||||||||||||||||||||||||||||||||||||||||||
| 96 | SettingsChanged => 'datetime', | ||||||||||||||||||||||||||||||||||||||||||
| 97 | Binaries => \&_read_xml_binaries, | ||||||||||||||||||||||||||||||||||||||||||
| 98 | CustomData => \&_read_xml_custom_data, | ||||||||||||||||||||||||||||||||||||||||||
| 99 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | sub _read_xml_memory_protection { | ||||||||||||||||||||||||||||||||||||||||||
| 103 | 21 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_xml_memory_protection: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 21 | ▶ | my $meta = shift // $self->kdbx->meta; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
shift() // $self->kdbx->meta
MC/DC0%0/2
shift() // $self->kdbx->meta
shift()
$self->kdbx->meta
Truth table33%1/3
A // B
A= shift()B= $self->kdbx->meta
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | 21 | return $self->_read_xml_element( | |||||||||||||||||||||||||||||||||||||||||
| 107 | ProtectTitle => 'bool', | ||||||||||||||||||||||||||||||||||||||||||
| 108 | ProtectUserName => 'bool', | ||||||||||||||||||||||||||||||||||||||||||
| 109 | ProtectPassword => 'bool', | ||||||||||||||||||||||||||||||||||||||||||
| 110 | ProtectURL => 'bool', | ||||||||||||||||||||||||||||||||||||||||||
| 111 | ProtectNotes => 'bool', | ||||||||||||||||||||||||||||||||||||||||||
| 112 | AutoEnableVisualHiding => 'bool', | ||||||||||||||||||||||||||||||||||||||||||
| 113 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | sub _read_xml_binaries { | ||||||||||||||||||||||||||||||||||||||||||
| 117 | 12 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_xml_binaries: called CC=1 SCAR=0.2
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | 12 | my $kdbx = $self->kdbx; | |||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | my $binaries = $self->_read_xml_element( | ||||||||||||||||||||||||||||||||||||||||||
| 121 | Binary => sub { | ||||||||||||||||||||||||||||||||||||||||||
| 122 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=18.7
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 2 | my $id = $self->_read_xml_attribute('ID'); | |||||||||||||||||||||||||||||||||||||||||
| 124 | 2 | my $compressed = $self->_read_xml_attribute('Compressed', 'bool', false); | |||||||||||||||||||||||||||||||||||||||||
| 125 | 2 | my $protected = $self->_read_xml_attribute('Protected', 'bool', false); | |||||||||||||||||||||||||||||||||||||||||
| 126 | 2 | my $data = $self->_read_xml_content('binary'); | |||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 2 | ▶ | my $binary = { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | value => $data, | ||||||||||||||||||||||||||||||||||||||||||
| 130 | $protected ? (protect => true) : (), | ||||||||||||||||||||||||||||||||||||||||||
| 131 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | 2 | ▶ | if ($protected) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | # if compressed, decompress later when the safe is unlocked | ||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | $self->_safe->add_protected($compressed ? \&gunzip : (), $binary); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||
| 137 | elsif ($compressed) { | ||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | $binary->{value} = gunzip($data); | |||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | 2 | $id => $binary; | |||||||||||||||||||||||||||||||||||||||||
| 142 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 143 | 12 | ); | |||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | 12 | $kdbx->binaries({%{$kdbx->binaries}, %$binaries}); | |||||||||||||||||||||||||||||||||||||||||
| 146 | 12 | return (); # do not add to meta | |||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | sub _read_xml_custom_data { | ||||||||||||||||||||||||||||||||||||||||||
| 150 | 32 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_xml_custom_data: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | return $self->_read_xml_element( | ||||||||||||||||||||||||||||||||||||||||||
| 153 | Item => sub { | ||||||||||||||||||||||||||||||||||||||||||
| 154 | 10 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | 10 | my $item = $self->_read_xml_element( | |||||||||||||||||||||||||||||||||||||||||
| 156 | Key => 'text', | ||||||||||||||||||||||||||||||||||||||||||
| 157 | Value => 'text', | ||||||||||||||||||||||||||||||||||||||||||
| 158 | LastModificationTime => 'datetime', # KDBX4.1 | ||||||||||||||||||||||||||||||||||||||||||
| 159 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 160 | 10 | $item->{key} => $item; | |||||||||||||||||||||||||||||||||||||||||
| 161 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 162 | 32 | ); | |||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | sub _read_xml_custom_icons { | ||||||||||||||||||||||||||||||||||||||||||
| 166 | 14 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_xml_custom_icons: called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||
| 168 | return $self->_read_xml_element([], | ||||||||||||||||||||||||||||||||||||||||||
| 169 | Icon => sub { | ||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | $self->_read_xml_element( | |||||||||||||||||||||||||||||||||||||||||
| 172 | UUID => 'uuid', | ||||||||||||||||||||||||||||||||||||||||||
| 173 | Data => 'binary', | ||||||||||||||||||||||||||||||||||||||||||
| 174 | Name => 'text', # KDBX4.1 | ||||||||||||||||||||||||||||||||||||||||||
| 175 | LastModificationTime => 'datetime', # KDBX4.1 | ||||||||||||||||||||||||||||||||||||||||||
| 176 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 177 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 178 | 14 | ); | |||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | sub _read_xml_root { | ||||||||||||||||||||||||||||||||||||||||||
| 182 | 21 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_xml_root: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | 21 | my $kdbx = $self->kdbx; | |||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | 21 | my $root = $self->_read_xml_element( | |||||||||||||||||||||||||||||||||||||||||
| 186 | Group => \&_read_xml_group, | ||||||||||||||||||||||||||||||||||||||||||
| 187 | DeletedObjects => \&_read_xml_deleted_objects, | ||||||||||||||||||||||||||||||||||||||||||
| 188 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||
| 190 | 21 | $kdbx->deleted_objects($root->{deleted_objects}); | |||||||||||||||||||||||||||||||||||||||||
| 191 | 21 | ▶ | $kdbx->root($root->{group}) if $root->{group}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | sub _read_xml_group { | ||||||||||||||||||||||||||||||||||||||||||
| 195 | 53 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_xml_group: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||
| 197 | 53 | return $self->_read_xml_element({entries => [], groups => []}, | |||||||||||||||||||||||||||||||||||||||||
| 198 | UUID => 'uuid', | ||||||||||||||||||||||||||||||||||||||||||
| 199 | Name => 'text', | ||||||||||||||||||||||||||||||||||||||||||
| 200 | Notes => 'text', | ||||||||||||||||||||||||||||||||||||||||||
| 201 | Tags => 'text', # KDBX4.1 | ||||||||||||||||||||||||||||||||||||||||||
| 202 | IconID => 'number', | ||||||||||||||||||||||||||||||||||||||||||
| 203 | CustomIconUUID => 'uuid', | ||||||||||||||||||||||||||||||||||||||||||
| 204 | Times => \&_read_xml_times, | ||||||||||||||||||||||||||||||||||||||||||
| 205 | IsExpanded => 'bool', | ||||||||||||||||||||||||||||||||||||||||||
| 206 | DefaultAutoTypeSequence => 'text', | ||||||||||||||||||||||||||||||||||||||||||
| 207 | EnableAutoType => 'tristate', | ||||||||||||||||||||||||||||||||||||||||||
| 208 | EnableSearching => 'tristate', | ||||||||||||||||||||||||||||||||||||||||||
| 209 | LastTopVisibleEntry => 'uuid', | ||||||||||||||||||||||||||||||||||||||||||
| 210 | CustomData => \&_read_xml_custom_data, # KDBX4 | ||||||||||||||||||||||||||||||||||||||||||
| 211 | PreviousParentGroup => 'uuid', # KDBX4.1 | ||||||||||||||||||||||||||||||||||||||||||
| 212 | Entry => [entries => \&_read_xml_entry], | ||||||||||||||||||||||||||||||||||||||||||
| 213 | Group => [groups => \&_read_xml_group], | ||||||||||||||||||||||||||||||||||||||||||
| 214 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | sub _read_xml_entry { | ||||||||||||||||||||||||||||||||||||||||||
| 218 | 18 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_xml_entry: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | my $entry = $self->_read_xml_element({strings => [], binaries => []}, | ||||||||||||||||||||||||||||||||||||||||||
| 221 | UUID => 'uuid', | ||||||||||||||||||||||||||||||||||||||||||
| 222 | IconID => 'number', | ||||||||||||||||||||||||||||||||||||||||||
| 223 | CustomIconUUID => 'uuid', | ||||||||||||||||||||||||||||||||||||||||||
| 224 | ForegroundColor => 'text', | ||||||||||||||||||||||||||||||||||||||||||
| 225 | BackgroundColor => 'text', | ||||||||||||||||||||||||||||||||||||||||||
| 226 | OverrideURL => 'text', | ||||||||||||||||||||||||||||||||||||||||||
| 227 | Tags => 'text', | ||||||||||||||||||||||||||||||||||||||||||
| 228 | Times => \&_read_xml_times, | ||||||||||||||||||||||||||||||||||||||||||
| 229 | AutoType => \&_read_xml_entry_auto_type, | ||||||||||||||||||||||||||||||||||||||||||
| 230 | PreviousParentGroup => 'uuid', # KDBX4.1 | ||||||||||||||||||||||||||||||||||||||||||
| 231 | QualityCheck => 'bool', # KDBX4.1 | ||||||||||||||||||||||||||||||||||||||||||
| 232 | String => [strings => \&_read_xml_entry_string], | ||||||||||||||||||||||||||||||||||||||||||
| 233 | Binary => [binaries => \&_read_xml_entry_binary], | ||||||||||||||||||||||||||||||||||||||||||
| 234 | CustomData => \&_read_xml_custom_data, # KDBX4 | ||||||||||||||||||||||||||||||||||||||||||
| 235 | History => sub { | ||||||||||||||||||||||||||||||||||||||||||
| 236 | 8 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 237 | 8 | return $self->_read_xml_element([], | |||||||||||||||||||||||||||||||||||||||||
| 238 | Entry => \&_read_xml_entry, | ||||||||||||||||||||||||||||||||||||||||||
| 239 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 240 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 241 | 18 | ); | |||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||
| 243 | 18 | my %strings; | |||||||||||||||||||||||||||||||||||||||||
| 244 | 18 | ▶ | for my $string (@{$entry->{strings} || []}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 245 | 95 | $strings{$string->{key}} = $string->{value}; | |||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||
| 247 | 18 | $entry->{strings} = \%strings; | |||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||
| 249 | 18 | my %binaries; | |||||||||||||||||||||||||||||||||||||||||
| 250 | 18 | ▶ | for my $binary (@{$entry->{binaries} || []}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 251 | 7 | $binaries{$binary->{key}} = $binary->{value}; | |||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||
| 253 | 18 | $entry->{binaries} = \%binaries; | |||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||
| 255 | 18 | return $entry; | |||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | sub _read_xml_times { | ||||||||||||||||||||||||||||||||||||||||||
| 259 | 71 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_xml_times: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||
| 261 | 71 | return $self->_read_xml_element( | |||||||||||||||||||||||||||||||||||||||||
| 262 | LastModificationTime => 'datetime', | ||||||||||||||||||||||||||||||||||||||||||
| 263 | CreationTime => 'datetime', | ||||||||||||||||||||||||||||||||||||||||||
| 264 | LastAccessTime => 'datetime', | ||||||||||||||||||||||||||||||||||||||||||
| 265 | ExpiryTime => 'datetime', | ||||||||||||||||||||||||||||||||||||||||||
| 266 | Expires => 'bool', | ||||||||||||||||||||||||||||||||||||||||||
| 267 | UsageCount => 'number', | ||||||||||||||||||||||||||||||||||||||||||
| 268 | LocationChanged => 'datetime', | ||||||||||||||||||||||||||||||||||||||||||
| 269 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||
| 272 | sub _read_xml_entry_string { | ||||||||||||||||||||||||||||||||||||||||||
| 273 | 95 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_xml_entry_string: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||
| 275 | return $self->_read_xml_element( | ||||||||||||||||||||||||||||||||||||||||||
| 276 | Key => 'text', | ||||||||||||||||||||||||||||||||||||||||||
| 277 | Value => sub { | ||||||||||||||||||||||||||||||||||||||||||
| 278 | 95 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||
| 280 | 95 | my $protected = $self->_read_xml_attribute('Protected', 'bool', false); | |||||||||||||||||||||||||||||||||||||||||
| 281 | 95 | my $protect_in_memory = $self->_read_xml_attribute('ProtectInMemory', 'bool', false); | |||||||||||||||||||||||||||||||||||||||||
| 282 | 95 | ▶ | my $protect = $protected || $protect_in_memory; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$protected || $protect_in_memory
MC/DC50%1/2
$protected || $protect_in_memory
$protected
$protect_in_memory
Truth table66%2/3
A || B
A= $protectedB= $protect_in_memory
| |||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||
| 284 | 95 | ▶ | my $val = $self->_read_xml_content($protected ? 'binary' : 'text'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||
| 286 | 95 | ▶ | my $string = { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 287 | value => $val, | ||||||||||||||||||||||||||||||||||||||||||
| 288 | $protect ? (protect => true) : (), | ||||||||||||||||||||||||||||||||||||||||||
| 289 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||
| 291 | 95 | ▶ | $self->_safe->add_protected(sub { decode('UTF-8', $_[0]) }, $string) if $protected; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||
| 293 | 95 | $string; | |||||||||||||||||||||||||||||||||||||||||
| 294 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 295 | 95 | ); | |||||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||
| 298 | sub _read_xml_entry_binary { | ||||||||||||||||||||||||||||||||||||||||||
| 299 | 7 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_xml_entry_binary: called CC=1 SCAR=0.2
| |||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||
| 301 | return $self->_read_xml_element( | ||||||||||||||||||||||||||||||||||||||||||
| 302 | Key => 'text', | ||||||||||||||||||||||||||||||||||||||||||
| 303 | Value => sub { | ||||||||||||||||||||||||||||||||||||||||||
| 304 | 7 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||
| 306 | 7 | my $ref = $self->_read_xml_attribute('Ref'); | |||||||||||||||||||||||||||||||||||||||||
| 307 | 7 | my $compressed = $self->_read_xml_attribute('Compressed', 'bool', false); | |||||||||||||||||||||||||||||||||||||||||
| 308 | 7 | my $protected = $self->_read_xml_attribute('Protected', 'bool', false); | |||||||||||||||||||||||||||||||||||||||||
| 309 | 7 | my $binary = {}; | |||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||
| 311 | 7 | ▶ | if (defined $ref) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 312 | 4 | $binary->{ref} = $ref; | |||||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||||
| 314 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 315 | 3 | $binary->{value} = $self->_read_xml_content('binary'); | |||||||||||||||||||||||||||||||||||||||||
| 316 | 3 | ▶ | $binary->{protect} = true if $protected; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||
| 318 | 3 | ▶ | if ($protected) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 319 | # if compressed, decompress later when the safe is unlocked | ||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | ▶ | $self->_safe->add_protected($compressed ? \&gunzip : (), $binary); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||||||||||||||
| 322 | elsif ($compressed) { | ||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | $binary->{value} = gunzip($binary->{value}); | |||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||
| 327 | 7 | $binary; | |||||||||||||||||||||||||||||||||||||||||
| 328 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 329 | 7 | ); | |||||||||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||
| 332 | sub _read_xml_entry_auto_type { | ||||||||||||||||||||||||||||||||||||||||||
| 333 | 18 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_xml_entry_auto_type: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||
| 335 | return $self->_read_xml_element({associations => []}, | ||||||||||||||||||||||||||||||||||||||||||
| 336 | Enabled => 'bool', | ||||||||||||||||||||||||||||||||||||||||||
| 337 | DataTransferObfuscation => 'number', | ||||||||||||||||||||||||||||||||||||||||||
| 338 | DefaultSequence => 'text', | ||||||||||||||||||||||||||||||||||||||||||
| 339 | Association => [associations => sub { | ||||||||||||||||||||||||||||||||||||||||||
| 340 | 11 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 341 | 11 | return $self->_read_xml_element( | |||||||||||||||||||||||||||||||||||||||||
| 342 | Window => 'text', | ||||||||||||||||||||||||||||||||||||||||||
| 343 | KeystrokeSequence => 'text', | ||||||||||||||||||||||||||||||||||||||||||
| 344 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 345 | 18 | }], | |||||||||||||||||||||||||||||||||||||||||
| 346 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||
| 349 | sub _read_xml_deleted_objects { | ||||||||||||||||||||||||||||||||||||||||||
| 350 | 21 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_xml_deleted_objects: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||
| 352 | return $self->_read_xml_element( | ||||||||||||||||||||||||||||||||||||||||||
| 353 | DeletedObject => sub { | ||||||||||||||||||||||||||||||||||||||||||
| 354 | 14 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 355 | 14 | my $object = $self->_read_xml_element( | |||||||||||||||||||||||||||||||||||||||||
| 356 | UUID => 'uuid', | ||||||||||||||||||||||||||||||||||||||||||
| 357 | DeletionTime => 'datetime', | ||||||||||||||||||||||||||||||||||||||||||
| 358 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 359 | 14 | $object->{uuid} => $object; | |||||||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||||||||
| 361 | 21 | ); | |||||||||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||
| 364 | ############################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||
| 366 | sub _resolve_binary_refs { | ||||||||||||||||||||||||||||||||||||||||||
| 367 | 21 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_resolve_binary_refs: called CC=8 SCAR=21.7
| |||||||||||||||||||||||||||||||||||||||||||
| 368 | 21 | my $kdbx = $self->kdbx; | |||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||
| 370 | 21 | my $pool = $kdbx->binaries; | |||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||
| 372 | 21 | my $entries = $kdbx->entries(history => 1); | |||||||||||||||||||||||||||||||||||||||||
| 373 | 21 | ▶ | while (my $entry = $entries->next) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 374 | 18 | ▶ | while (my ($key, $binary) = each %{$entry->binaries}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 375 | 7 | ▶ | my $ref = $binary->{ref} // next; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$binary->{"ref"} // (next)
MC/DC100%1/1
$binary->{"ref"} // (next)
$binary->{"ref"}
Truth table100%2/2
A
A= $binary->{"ref"}
| |||||||||||||||||||||||||||||||||||||||||||
| 376 | 4 | ▶ | next if defined $binary->{value}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||
| 378 | 4 | my $data = $pool->{$ref}; | |||||||||||||||||||||||||||||||||||||||||
| 379 | 4 | ▶ | if (!defined $data || !defined $data->{value}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $data and defined $data->{"value"}
MC/DC0%0/2
defined $data and defined $data->{"value"}
defined $data
defined $data->{"value"}
Truth table33%1/3
A and B
A= defined $dataB= defined $data->{"value"}
| |||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | alert "Found a reference to a missing binary: $key", key => $key, ref => $ref; | |||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||||||||||
| 383 | 4 | $binary->{value} = $data->{value}; | |||||||||||||||||||||||||||||||||||||||||
| 384 | 4 | ▶ | $binary->{protect} = true if $data->{protect}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 385 | 4 | delete $binary->{ref}; | |||||||||||||||||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||
| 390 | ############################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||
| 392 | sub _read_xml_element { | ||||||||||||||||||||||||||||||||||||||||||
| 393 | 447 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_xml_element: called CC=16 SCAR=28.4
| |||||||||||||||||||||||||||||||||||||||||||
| 394 | 447 | ▶ | my $args = @_ % 2 == 1 ? shift : {}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 395 | 447 | my %spec = @_; | |||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||
| 397 | 447 | my $reader = $self->_reader; | |||||||||||||||||||||||||||||||||||||||||
| 398 | 447 | my $path = $reader->nodePath; | |||||||||||||||||||||||||||||||||||||||||
| 399 | 447 | $path =~ s!\Q/text()\E$!!; | |||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||
| 401 | 447 | ▶ | return $args if $reader->isEmptyElement; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||
| 403 | my $store = ref $args eq 'CODE' ? $args | ||||||||||||||||||||||||||||||||||||||||||
| 404 | : ref $args eq 'HASH' ? sub { | ||||||||||||||||||||||||||||||||||||||||||
| 405 | 2218 | ▶ | my ($key, $val) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.3
| |||||||||||||||||||||||||||||||||||||||||||
| 406 | 2218 | ▶ | if (ref $args->{$key} eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | $args->{$key}{$key} = $val; | |||||||||||||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||||||||||||
| 409 | elsif (ref $args->{$key} eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||
| 410 | 146 | push @{$args->{$key}}, $val; | |||||||||||||||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||||||||||||||||
| 412 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 413 | 2072 | ▶ | exists $args->{$key} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 414 | and alert 'Overwriting value', node => $reader->nodePath, line => $reader->lineNumber; | ||||||||||||||||||||||||||||||||||||||||||
| 415 | 2072 | $args->{$key} = $val; | |||||||||||||||||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||||||||||||||||
| 417 | } : ref $args eq 'ARRAY' ? sub { | ||||||||||||||||||||||||||||||||||||||||||
| 418 | 5 | ▶ | my ($key, $val) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 419 | 5 | push @$args, $val; | |||||||||||||||||||||||||||||||||||||||||
| 420 | 375 | ▶ | } : sub {}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.2
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||
| 422 | 375 | my $pattern = XML::LibXML::Pattern->new("${path}|${path}/*"); | |||||||||||||||||||||||||||||||||||||||||
| 423 | 375 | ▶ | while ($reader->nextPatternMatch($pattern) == 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 424 | 4397 | ▶ | last if $reader->nodePath eq $path && $reader->nodeType == XML_READER_TYPE_END_ELEMENT; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$reader->nodePath eq $path and $reader->nodeType == 15
MC/DC50%1/2
$reader->nodePath eq $path and $reader->nodeType == 15
$reader->nodePath eq $path
$reader->nodeType == 15
Truth table66%2/3
A and B
A= $reader->nodePath eq $pathB= $reader->nodeType == 15
| |||||||||||||||||||||||||||||||||||||||||||
| 425 | 4022 | ▶ | next if $reader->nodeType != XML_READER_TYPE_ELEMENT; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||
| 427 | 2353 | my $name = $reader->localName; | |||||||||||||||||||||||||||||||||||||||||
| 428 | 2353 | my $key = snakify($name); | |||||||||||||||||||||||||||||||||||||||||
| 429 | 2353 | my $type = $spec{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 430 | 2353 | ▶ | ($key, $type) = @$type if ref $type eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||
| 432 | 2353 | ▶ | if (!defined $type) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | ▶ | exists $spec{$name} or alert "Ignoring unknown element: $name", | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 434 | node => $reader->nodePath, | ||||||||||||||||||||||||||||||||||||||||||
| 435 | line => $reader->lineNumber; | ||||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||
| 439 | 2353 | ▶ | if (ref $type eq 'CODE') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 440 | 509 | my @result = $self->$type($args, $reader->nodePath); | |||||||||||||||||||||||||||||||||||||||||
| 441 | 509 | ▶ | if (@result == 2) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 442 | 26 | $store->(@result); | |||||||||||||||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||||||||||||||||
| 444 | elsif (@result == 1) { | ||||||||||||||||||||||||||||||||||||||||||
| 445 | 471 | $store->($key, @result); | |||||||||||||||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||||||||||||||||
| 448 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 449 | 1844 | $store->($key, $self->_read_xml_content($type)); | |||||||||||||||||||||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||
| 453 | 375 | return $args; | |||||||||||||||||||||||||||||||||||||||||
| 454 | } | ||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||
| 456 | sub _read_xml_attribute { | ||||||||||||||||||||||||||||||||||||||||||
| 457 | 217 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_xml_attribute: called CC=8 SCAR=21.1
| |||||||||||||||||||||||||||||||||||||||||||
| 458 | 217 | my $name = shift; | |||||||||||||||||||||||||||||||||||||||||
| 459 | 217 | ▶ | my $type = shift // 'text'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
shift() // "text"
MC/DC100%1/1
shift() // "text"
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 460 | 217 | my $default = shift; | |||||||||||||||||||||||||||||||||||||||||
| 461 | 217 | my $reader = $self->_reader; | |||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||
| 463 | 217 | ▶ | return $default if !$reader->hasAttributes; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||||||||
| 465 | 72 | my $value = trim($reader->getAttribute($name)); | |||||||||||||||||||||||||||||||||||||||||
| 466 | 72 | ▶ | if (!defined $value) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 467 | # try again after reading in all the attributes | ||||||||||||||||||||||||||||||||||||||||||
| 468 | 39 | $reader->moveToFirstAttribute; | |||||||||||||||||||||||||||||||||||||||||
| 469 | 39 | ▶ | while ($self->_reader->readAttributeValue == 1) {} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 470 | 39 | $reader->moveToElement; | |||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||
| 472 | 39 | $value = trim($reader->getAttribute($name)); | |||||||||||||||||||||||||||||||||||||||||
| 473 | } | ||||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||
| 475 | 72 | ▶ | return $default if !defined $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||||||||||
| 477 | 33 | my $decoded = eval { _decode_primitive($value, $type) }; | |||||||||||||||||||||||||||||||||||||||||
| 478 | 33 | ▶ | if (my $err = $@) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 479 | 0 | ▶ | ref $err and $err->details(attribute => $name, node => $reader->nodePath, line => $reader->lineNumber); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 480 | 0 | throw $err | |||||||||||||||||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||||||
| 483 | 33 | return $decoded; | |||||||||||||||||||||||||||||||||||||||||
| 484 | } | ||||||||||||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||||||||||
| 486 | sub _read_xml_content { | ||||||||||||||||||||||||||||||||||||||||||
| 487 | 1944 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_xml_content: called CC=5 SCAR=16.8
| |||||||||||||||||||||||||||||||||||||||||||
| 488 | 1944 | my $type = shift; | |||||||||||||||||||||||||||||||||||||||||
| 489 | 1944 | my $reader = $self->_reader; | |||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||||
| 491 | 1944 | ▶ | $reader->read if !$reader->isEmptyElement; # step into element | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 492 | 1944 | ▶ | return '' if !$reader->hasValue; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||
| 494 | 1669 | my $content = trim($reader->value); | |||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||
| 496 | 1669 | my $decoded = eval { _decode_primitive($content, $type) }; | |||||||||||||||||||||||||||||||||||||||||
| 497 | 1669 | ▶ | if (my $err = $@) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 498 | 0 | ▶ | ref $err and $err->details(node => $reader->nodePath, line => $reader->lineNumber); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 499 | 0 | throw $err; | |||||||||||||||||||||||||||||||||||||||||
| 500 | } | ||||||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||||
| 502 | 1669 | return $decoded; | |||||||||||||||||||||||||||||||||||||||||
| 503 | } | ||||||||||||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||||||||||
| 505 | ############################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||||||
| 507 | 1702 | ▶ | sub _decode_primitive { goto &{__PACKAGE__."::_decode_$_[1]"} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_decode_primitive: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||
| 509 | sub _decode_binary { | ||||||||||||||||||||||||||||||||||||||||||
| 510 | 246 | ▶ | local $_ = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_decode_binary: called CC=6 SCAR=20.2
| |||||||||||||||||||||||||||||||||||||||||||
| 511 | 246 | ▶ | return '' if !defined || (ref && !defined $$_); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
not defined $_ or ref $_ and not defined $$_
ref $_ and not defined $$_
MC/DC0%0/3
not defined $_ or ref $_ and not defined $$_
not defined $_
ref $_
not defined $$_
Truth table0%0/4
not(A) or B and not(C)
A= not defined $_B= ref $_C= not defined $$_
| |||||||||||||||||||||||||||||||||||||||||||
| 512 | 246 | ▶ | $_ = eval { decode_b64(ref $_ ? $$_ : $_) }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 513 | 246 | my $err = $@; | |||||||||||||||||||||||||||||||||||||||||
| 514 | 246 | my $cleanup = erase_scoped $_; | |||||||||||||||||||||||||||||||||||||||||
| 515 | 246 | ▶ | $err and throw 'Failed to parse binary', error => $err; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 516 | 246 | return $_; | |||||||||||||||||||||||||||||||||||||||||
| 517 | } | ||||||||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||||||||
| 519 | sub _decode_bool { | ||||||||||||||||||||||||||||||||||||||||||
| 520 | 296 | ▶ | local $_ = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_decode_bool: called CC=4 SCAR=17.1
| |||||||||||||||||||||||||||||||||||||||||||
| 521 | 296 | ▶ | return true if /^True$/i; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 522 | 157 | ▶ | return false if /^False$/i; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 523 | 0 | ▶ | return false if length($_) == 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 524 | 0 | throw 'Expected boolean', text => $_; | |||||||||||||||||||||||||||||||||||||||||
| 525 | } | ||||||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||||||
| 527 | sub _decode_datetime { | ||||||||||||||||||||||||||||||||||||||||||
| 528 | 501 | ▶ | local $_ = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_decode_datetime: called CC=6 SCAR=18.6
| |||||||||||||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||||||||||||
| 530 | 501 | ▶ | if (/^[A-Za-z0-9\+\/\=]+$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 531 | 131 | my $binary = eval { decode_b64($_) }; | |||||||||||||||||||||||||||||||||||||||||
| 532 | 131 | ▶ | if (my $err = $@) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 533 | 0 | throw 'Failed to parse binary datetime', text => $_, error => $err; | |||||||||||||||||||||||||||||||||||||||||
| 534 | } | ||||||||||||||||||||||||||||||||||||||||||
| 535 | 131 | ▶ | throw $@ if $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 536 | 131 | ▶ | $binary .= \0 x (8 - length($binary)) if length($binary) < 8; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 537 | 131 | my ($seconds_since_ad1) = unpack_Ql($binary); | |||||||||||||||||||||||||||||||||||||||||
| 538 | 131 | my $epoch = $seconds_since_ad1 - TIME_SECONDS_AD1_TO_UNIX_EPOCH; | |||||||||||||||||||||||||||||||||||||||||
| 539 | 131 | return gmtime($epoch); | |||||||||||||||||||||||||||||||||||||||||
| 540 | } | ||||||||||||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||||||||||||
| 542 | 370 | my $dt = eval { Time::Piece->strptime($_, '%Y-%m-%dT%H:%M:%SZ') }; | |||||||||||||||||||||||||||||||||||||||||
| 543 | 370 | ▶ | if (my $err = $@) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 544 | 0 | throw 'Failed to parse datetime', text => $_, error => $err; | |||||||||||||||||||||||||||||||||||||||||
| 545 | } | ||||||||||||||||||||||||||||||||||||||||||
| 546 | 370 | return $dt; | |||||||||||||||||||||||||||||||||||||||||
| 547 | } | ||||||||||||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||||||||||
| 549 | sub _decode_tristate { | ||||||||||||||||||||||||||||||||||||||||||
| 550 | 106 | ▶ | local $_ = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_decode_tristate: called CC=3 SCAR=18.1
| |||||||||||||||||||||||||||||||||||||||||||
| 551 | 106 | ▶ | return undef if /^null$/i; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 552 | 0 | my $tristate = eval { _decode_bool($_) }; | |||||||||||||||||||||||||||||||||||||||||
| 553 | 0 | ▶ | $@ and throw 'Expected tristate', text => $_, error => $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 554 | 0 | return $tristate; | |||||||||||||||||||||||||||||||||||||||||
| 555 | } | ||||||||||||||||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||||||||||||||||
| 557 | sub _decode_number { | ||||||||||||||||||||||||||||||||||||||||||
| 558 | 257 | ▶ | local $_ = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_decode_number: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 559 | 257 | $_ = _decode_text($_); | |||||||||||||||||||||||||||||||||||||||||
| 560 | 257 | ▶ | looks_like_number($_) or throw 'Expected number', text => $_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 561 | 257 | return $_+0; | |||||||||||||||||||||||||||||||||||||||||
| 562 | } | ||||||||||||||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||||||||||||
| 564 | sub _decode_text { | ||||||||||||||||||||||||||||||||||||||||||
| 565 | 553 | ▶ | local $_ = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_decode_text: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||
| 566 | 553 | ▶ | return '' if !defined; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 567 | 553 | return $_; | |||||||||||||||||||||||||||||||||||||||||
| 568 | } | ||||||||||||||||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||||||||||||||||
| 570 | sub _decode_uuid { | ||||||||||||||||||||||||||||||||||||||||||
| 571 | 207 | ▶ | local $_ = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_decode_uuid: called CC=3 SCAR=11.2
| |||||||||||||||||||||||||||||||||||||||||||
| 572 | 207 | my $uuid = eval { _decode_binary($_) }; | |||||||||||||||||||||||||||||||||||||||||
| 573 | 207 | ▶ | $@ and throw 'Expected UUID', text => $_, error => $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 574 | 207 | ▶ | length($uuid) == 16 or throw 'Invalid UUID size', size => length($uuid); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 575 | 207 | return $uuid; | |||||||||||||||||||||||||||||||||||||||||
| 576 | } | ||||||||||||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||||||||||||
| 578 | 6 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||||||||||||||||
| 580 | __END__ | ||||||||||||||||||||||||||||||||||||||||||