blib/lib/File/KeePass.pm

filter: Statementstmt 50.3% 559 / 1110 Branchbran 37.4% 251 / 670 Conditioncond 30.2% 156 / 516 MC/DCmcdc 13.2% 38 / 287 Subroutinesub 59.8% 64 / 107 Podpod 88.1% 37 / 42 totaltotal 40.4% 1105 / 2732 CC 586 SCAR 50.5
CC
586
Cov
42%
__ANON__
992.0
_gen_v2_db
812.0
_parse_v2_header
462.0
CRAP 155.8
↑ Summary
1 package File::KeePass;
2  
3 =head1 NAME
4  
5 File::KeePass - Interface to KeePass V1 and V2 database files
6  
7 =cut
8  
9 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Crypt::Rijndael;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Digest::SHA qw(sha256);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶use constant DB_HEADSIZE_V1 => 124;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use constant DB_SIG_1 => 0x9AA2D903;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use constant DB_SIG_2_v1 => 0xB54BFB65;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use constant DB_SIG_2_v2 => 0xB54BFB67;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use constant DB_VER_DW_V1 => 0x00030002;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use constant DB_VER_DW_V2 => 0x00030000; # recent KeePass is 0x0030001
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use constant DB_FLAG_RIJNDAEL => 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use constant DB_FLAG_TWOFISH => 8;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 1 our $VERSION = '2.03';
24 1 my %locker;
25 1 my $salsa20_iv = "\xe8\x30\x09\x4b\x97\x20\x5d\x2a";
26 1 my $qr_date = qr/^(\d\d\d\d)-(\d\d)-(\d\d)[T ](\d\d):(\d\d):(\d\d)(\.\d+|)?Z?$/;
27  
28 5 ▶sub new {
Subroutine new: called CC=2 SCAR=7.6
Pod documented
29 5 my $class = shift;
30 0 ▶ my $args = ref($_[0]) ? {%{shift()}} : {@_};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 5 5
31 5 return bless $args, $class;
32 }
33  
34 9 ▶sub auto_lock {
Subroutine auto_lock: called CC=3 SCAR=11.0
Pod documented
35 9 my $self = shift;
36 9 ▶ $self->{'auto_lock'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 3 6 9
37 9 ▶ return !exists($self->{'auto_lock'}) || $self->{'auto_lock'};
Condition100%3/3
!exists $self->{'auto_lock'} || $self->{'auto_lock'}
l!l&&r!l&&!r
252
MC/DC100%2/2
!exists $self->{'auto_lock'} || $self->{'auto_lock'}
!exists $self->{'auto_lock'} $self->{'auto_lock'}
Truth table100%3/3
not(A) || B
A= !exists $self->{'auto_lock'}B= $self->{'auto_lock'}
ABresult
1X1
011
000
38 }
39  
40 87 ▶sub groups { shift->{'groups'} || die "No groups loaded yet\n" }
Subroutine groups: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
+(shift())->{"groups"} or die "No groups loaded yet\n" 83 4 87
41  
42 12 ▶sub header { shift->{'header'} }
Subroutine header: called CC=1 SCAR=0.0
Pod documented
43  
44 ###----------------------------------------------------------------###
45  
46 3 ▶sub load_db {
Subroutine load_db: called CC=4 SCAR=13.9
Pod documented
47 3 my $self = shift;
48 3 ▶ my $file = shift || die "Missing file\n";
Condition100%2/2
shift() || die("Missing file\n")
l!l
21
MC/DC100%1/1
shift() || die("Missing file\n")
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
49 2 ▶ my $pass = shift || die "Missing pass\n";
Condition100%2/2
shift() || die("Missing pass\n")
l!l
11
MC/DC100%1/1
shift() || die("Missing pass\n")
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
50 1 ▶ my $args = shift || {};
Condition50%1/2
shift() || {}
l!l
01
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
51  
52 1 my $buffer = $self->slurp($file);
53 1 return $self->parse_db($buffer, $pass, $args);
54 }
55  
56 5 ▶sub save_db {
Subroutine save_db: called CC=18 SCAR=32.7
Pod documented
57 5 my ($self, $file, $pass, $head, $groups) = @_;
58 5 ▶ die "Missing file\n" if ! $file;
Branch: 1 branch
BranchTrueFalseTotal
unless $file 1 4 5
59 4 ▶ $head ||= {};
Condition50%1/2
$head ||= {}
l!l
04
MC/DC0%0/1
$head ||= {}
$head
Truth table50%1/2
A
A= $head
Aresult
11
00
60 my $v = $file =~ /\.kdbx$/i ? 2
61 : $file =~ /\.kdb$/i ? 1
62 4 ▶ : $head->{'version'} || $self->{'version'};
Branch: 2 branches
BranchTrueFalseTotal
$file =~ /\.kdbx$/i ? : 0 4 4
$file =~ /\.kdb$/i ? : 4 0 4
Condition0%0/3
$head->{"version"} or $self->{"version"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$head->{"version"} or $self->{"version"}
$head->{"version"} $self->{"version"}
Truth table0%0/3
A or B
A= $head->{"version"}B= $self->{"version"}
ABresult
1X1
011
000
63 4 $head->{'version'} = $v;
64  
65 4 my $buf = $self->gen_db($pass, $head, $groups);
66 3 my $bak = "$file.bak";
67 3 my $tmp = "$file.new.".int(time());
68 3 ▶ open my $fh, '>', $tmp or die "Could not open $tmp: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $tmp or die "Could not open ${tmp}: $!\n" 3 0 3
69 3 binmode $fh;
70 3 print $fh $buf;
71 3 close $fh;
72 3 ▶ if (-s $tmp ne length($buf)) {
Branch: 1 branch
BranchTrueFalseTotal
if (-s $tmp ne length $buf) 0 3 3
73 0 die "Written file size of $tmp didn't match (".(-s $tmp)." != ".length($buf).") - not moving into place\n";
74 0 unlink($tmp);
75 }
76  
77 3 ▶ if (-e $bak) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $bak) 1 2 3
78 1 ▶ unlink($bak) or unlink($tmp) or die "Could not removing already existing backup $bak: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
unlink $bak or unlink $tmp or die "Could not removing already existing backup ${bak}: $!\n" 1 0 1
Condition33%1/3
unlink $bak or unlink $tmp
l!l&&r!l&&!r
100
MC/DC0%0/2
unlink $bak or unlink $tmp
unlink $bak unlink $tmp
Truth table33%1/3
A or B
A= unlink $bakB= unlink $tmp
ABresult
1X1
011
000
79 }
80 3 ▶ if (-e $file) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $file) 2 1 3
81 2 ▶ rename($file, $bak) or unlink($tmp) or die "Could not backup $file to $bak: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
rename $file, $bak or unlink $tmp or die "Could not backup $file to ${bak}: $!\n" 2 0 2
Condition33%1/3
rename $file, $bak or unlink $tmp
l!l&&r!l&&!r
200
MC/DC0%0/2
rename $file, $bak or unlink $tmp
rename $file, $bak unlink $tmp
Truth table33%1/3
A or B
A= rename $file, $bakB= unlink $tmp
ABresult
1X1
011
000
82 }
83 3 ▶ rename($tmp, $file) or die "Could not move $tmp to $file: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
rename $tmp, $file or die "Could not move $tmp to ${file}: $!\n" 3 0 3
84 3 ▶ if (!$self->{'keep_backup'} && -e $bak) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"keep_backup"} and -e $bak) 1 2 3
Condition100%3/3
not $self->{"keep_backup"} and -e $bak
!ll&&!rl&&r
111
MC/DC100%2/2
not $self->{"keep_backup"} and -e $bak
not $self->{"keep_backup"} -e $bak
Truth table100%3/3
not(A) and B
A= not $self->{"keep_backup"}B= -e $bak
ABresult
0X0
100
111
85 1 ▶ unlink($bak) or die "Could not removing temporary backup $bak: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
unlink $bak or die "Could not removing temporary backup ${bak}: $!\n" 1 0 1
86 }
87  
88 3 return 1;
89 }
90  
91 6 ▶sub clear {
Subroutine clear: called CC=2 SCAR=7.1
Pod documented
92 6 my $self = shift;
93 6 ▶ $self->unlock if $self->{'groups'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"groups"} 6 0 6
94 6 delete @$self{qw(header groups)};
95 }
96  
97 5 ▶sub DESTROY { shift->clear }
Subroutine DESTROY: called CC=1 SCAR=0.0
98  
99 ###----------------------------------------------------------------###
100  
101 6 ▶sub parse_db {
Subroutine parse_db: called CC=10 SCAR=24.6
Pod documented
102 6 my ($self, $buffer, $pass, $args) = @_;
103 6 ▶ $self = $self->new($args || {}) if ! ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 6 6
Condition0%0/2
$args || {}
l!l
00
MC/DC0%0/1
$args || {}
$args
Truth table0%0/2
A
A= $args
Aresult
11
00
104 6 ▶ $buffer = $$buffer if ref $buffer;
Branch: 1 branch
BranchTrueFalseTotal
if ref $buffer 0 6 6
105  
106 6 my $head = $self->parse_header($buffer);
107 6 ▶ local $head->{'raw'} = substr $buffer, 0, $head->{'header_size'} if $head->{'version'} == 2;
Branch: 1 branch
BranchTrueFalseTotal
if $head->{"version"} == 2 0 6 6
108 6 $buffer = substr $buffer, $head->{'header_size'};
109  
110 6 ▶ $self->unlock if $self->{'groups'}; # make sure we don't leave dangling keys should we reopen a new db
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"groups"} 5 1 6
111  
112 my $meth = ($head->{'version'} == 1) ? '_parse_v1_body'
113 6 ▶ : ($head->{'version'} == 2) ? '_parse_v2_body'
Branch: 2 branches
BranchTrueFalseTotal
$head->{'version'} == 1 ? : 6 0 6
$head->{'version'} == 2 ? : 0 0 0
114 : die "Unsupported keepass database version ($head->{'version'})\n";
115 6 (my $meta, $self->{'groups'}) = $self->$meth($buffer, $pass, $head);
116 6 $self->{'header'} = {%$head, %$meta};
117 6 ▶ $self->auto_lock($args->{'auto_lock'}) if exists $args->{'auto_lock'};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args->{"auto_lock"} 1 5 6
118  
119 6 ▶ $self->lock if $self->auto_lock;
Branch: 1 branch
BranchTrueFalseTotal
if $self->auto_lock 4 2 6
120 6 return $self;
121 }
122  
123 6 ▶sub parse_header {
Subroutine parse_header: called CC=4 SCAR=17.9
Pod documented
124 6 my ($self, $buffer) = @_;
125 6 my ($sig1, $sig2) = unpack 'LL', $buffer;
126 6 ▶ die "File signature (sig1) did not match ($sig1 != ".DB_SIG_1().")\n" if $sig1 != DB_SIG_1;
Branch: 1 branch
BranchTrueFalseTotal
if $sig1 != 2594363651 0 6 6
127 6 ▶ return $self->_parse_v1_header($buffer) if $sig2 eq DB_SIG_2_v1;
Branch: 1 branch
BranchTrueFalseTotal
if $sig2 eq 3041655653 6 0 6
128 0 ▶ return $self->_parse_v2_header($buffer) if $sig2 eq DB_SIG_2_v2;
Branch: 1 branch
BranchTrueFalseTotal
if $sig2 eq 3041655655 0 0 0
129 0 die "Second file signature did not match ($sig2 != ".DB_SIG_2_v1()." or ".DB_SIG_2_v2().")\n";
130 }
131  
132 6 ▶sub _parse_v1_header {
Subroutine _parse_v1_header: called CC=5 SCAR=17.1
133 6 my ($self, $buffer) = @_;
134 6 my $size = length($buffer);
135 6 ▶ die "File was smaller than db header ($size < ".DB_HEADSIZE_V1().")\n" if $size < DB_HEADSIZE_V1;
Branch: 1 branch
BranchTrueFalseTotal
if $size < 124 0 6 6
136 6 my %h = (version => 1, header_size => DB_HEADSIZE_V1);
137 6 my @f = qw(sig1 sig2 flags ver seed_rand enc_iv n_groups n_entries checksum seed_key rounds);
138 6 my $t = 'L L L L a16 a16 L L a32 a32 L';
139 6 @h{@f} = unpack $t, $buffer;
140 6 ▶ die "Unsupported file version ($h{'ver'}).\n" if $h{'ver'} & 0xFFFFFF00 != DB_VER_DW_V1 & 0xFFFFFF00;
Branch: 1 branch
BranchTrueFalseTotal
if 0 6 6
141 $h{'enc_type'} = ($h{'flags'} & DB_FLAG_RIJNDAEL) ? 'rijndael'
142 6 ▶ : ($h{'flags'} & DB_FLAG_TWOFISH) ? 'twofish'
Branch: 2 branches
BranchTrueFalseTotal
$h{'flags'} & 2 ? : 6 0 6
$h{'flags'} & 8 ? : 0 0 0
143 : die "Unknown encryption type\n";
144 6 return \%h;
145 }
146  
147 0 ▶sub _parse_v2_header {
Subroutine _parse_v2_header: not called CC=21 SCAR=61.4
148 0 my ($self, $buffer) = @_;
149 0 my %h = (version => 2, enc_type => 'rijndael');
150 0 @h{qw(sig1 sig2 ver)} = unpack 'L3', $buffer;
151 0 ▶ die "Unsupported file version2 ($h{'ver'}).\n" if $h{'ver'} & 0xFFFF0000 > 0x00020000 & 0xFFFF0000;
Branch: 1 branch
BranchTrueFalseTotal
if 0 0 0
152 0 my $pos = 12;
153  
154 0 while (1) {
155 0 my ($type, $size) = unpack "\@$pos CS", $buffer;
156 0 $pos += 3;
157 0 my $val = substr $buffer, $pos, $size; # #my ($val) = unpack "\@$pos a$size", $buffer;
158 0 ▶ if (!$type) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($type) 0 0 0
159 0 $h{'0'} = $val;
160 0 $pos += $size;
161 0 last;
162 }
163 0 $pos += $size;
164 0 ▶ if ($type == 1) {
Branch: 10 branches
BranchTrueFalseTotal
if ($type == 1) { } 0 0 0
elsif ($type == 2) { } 0 0 0
elsif ($type == 3) { } 0 0 0
elsif ($type == 4) { } 0 0 0
elsif ($type == 5) { } 0 0 0
elsif ($type == 6) { } 0 0 0
elsif ($type == 7) { } 0 0 0
elsif ($type == 8) { } 0 0 0
elsif ($type == 9) { } 0 0 0
elsif ($type == 10) { } 0 0 0
165 0 $h{'comment'} = $val;
166 } elsif ($type == 2) {
167 0 ▶ warn "Cipher id did not match AES\n" if $val ne "\x31\xc1\xf2\xe6\xbf\x71\x43\x50\xbe\x58\x05\x21\x6a\xfc\x5a\xff";
Branch: 1 branch
BranchTrueFalseTotal
if $val ne "1\301\362\346\277qCP\276X\5!j\374Z\377" 0 0 0
168 0 $h{'cipher'} = 'aes';
169 } elsif ($type == 3) {
170 0 $val = unpack 'V', $val;
171 0 ▶ warn "Compression was too large.\n" if $val > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $val > 1 0 0 0
172 0 $h{'compression'} = $val;
173 } elsif ($type == 4) {
174 0 ▶ warn "Length of seed random was not 32\n" if length($val) != 32;
Branch: 1 branch
BranchTrueFalseTotal
if length $val != 32 0 0 0
175 0 $h{'seed_rand'} = $val;
176 } elsif ($type == 5) {
177 0 ▶ warn "Length of seed key was not 32\n" if length($val) != 32;
Branch: 1 branch
BranchTrueFalseTotal
if length $val != 32 0 0 0
178 0 $h{'seed_key'} = $val;
179 } elsif ($type == 6) {
180 0 $h{'rounds'} = unpack 'L', $val;
181 } elsif ($type == 7) {
182 0 ▶ warn "Length of encryption IV was not 16\n" if length($val) != 16;
Branch: 1 branch
BranchTrueFalseTotal
if length $val != 16 0 0 0
183 0 $h{'enc_iv'} = $val;
184 } elsif ($type == 8) {
185 0 ▶ warn "Length of stream key was not 32\n" if length($val) != 32;
Branch: 1 branch
BranchTrueFalseTotal
if length $val != 32 0 0 0
186 0 $h{'protected_stream_key'} = $val;
187 } elsif ($type == 9) {
188 0 ▶ warn "Length of start bytes was not 32\n" if length($val) != 32;
Branch: 1 branch
BranchTrueFalseTotal
if length $val != 32 0 0 0
189 0 $h{'start_bytes'} = $val;
190 } elsif ($type == 10) {
191 0 ▶ warn "Inner stream id did not match Salsa20\n" if unpack('V', $val) != 2;
Branch: 1 branch
BranchTrueFalseTotal
if unpack("V", $val) != 2 0 0 0
192 0 $h{'protected_stream'} = 'salsa20';
193 } else {
194 0 warn "Found an unknown header type ($type, $val)\n";
195 }
196 }
197  
198 0 $h{'header_size'} = $pos;
199 0 return \%h;
200 }
201  
202 6 ▶sub _parse_v1_body {
Subroutine _parse_v1_body: called CC=6 SCAR=19.9
203 6 my ($self, $buffer, $pass, $head) = @_;
204 6 ▶ die "Unimplemented enc_type $head->{'enc_type'}\n" if $head->{'enc_type'} ne 'rijndael';
Branch: 1 branch
BranchTrueFalseTotal
if $head->{"enc_type"} ne "rijndael" 0 6 6
205 6 my $key = $self->_master_key($pass, $head);
206 6 $buffer = $self->decrypt_rijndael_cbc($buffer, $key, $head->{'enc_iv'});
207  
208 die "The file could not be decrypted either because the key is wrong or the file is damaged.\n"
209 6 ▶ if length($buffer) > 2**32-1 || (!length($buffer) && $head->{'n_groups'});
Branch: 1 branch
BranchTrueFalseTotal
if length $buffer > 4294967295 or not length $buffer and $head->{"n_groups"} 0 6 6
Condition33%2/6
length $buffer > 4294967295 or not length $buffer and $head->{"n_groups"}
l!l&&r!l&&!r
006
not length $buffer and $head->{"n_groups"}
!ll&&!rl&&r
600
MC/DC0%0/3
length $buffer > 4294967295 or not length $buffer and $head->{"n_groups"}
length $buffer > 4294967295 not length $buffer $head->{"n_groups"}
Truth table25%1/4
A or not(B) and C
A= length $buffer > 4294967295B= not length $bufferC= $head->{"n_groups"}
ABCresult
1XX1
0111
00X0
0100
210 die "The file checksum did not match.\nThe key is wrong or the file is damaged\n"
211 6 ▶ if $head->{'checksum'} ne sha256($buffer);
Branch: 1 branch
BranchTrueFalseTotal
if $head->{"checksum"} ne &sha256($buffer) 0 6 6
212  
213 6 my ($groups, $gmap, $pos) = $self->_parse_v1_groups($buffer, $head->{'n_groups'});
214 6 $self->_parse_v1_entries($buffer, $head->{'n_entries'}, $pos, $gmap, $groups);
215 6 return ({}, $groups);
216 }
217  
218 0 ▶sub _parse_v2_body {
Subroutine _parse_v2_body: not called CC=16 SCAR=56.1
219 0 my ($self, $buffer, $pass, $head) = @_;
220 0 my $key = $self->_master_key($pass, $head);
221 0 $buffer = $self->decrypt_rijndael_cbc($buffer, $key, $head->{'enc_iv'});
222 die "The database key appears invalid or else the database is corrupt.\n"
223 0 ▶ if substr($buffer, 0, 32, '') ne $head->{'start_bytes'};
Branch: 1 branch
BranchTrueFalseTotal
if substr($buffer, 0, 32, '') ne $head->{"start_bytes"} 0 0 0
224 0 $buffer = $self->unchunksum($buffer);
225 0 ▶ $buffer = eval { $self->decompress($buffer) } or die "Failed to decompress document: $@" if ($head->{'compression'} || '') eq '1';
Branch: 1 branch
BranchTrueFalseTotal
if ($head->{"compression"} || "") eq 1 0 0 0
Condition0%0/7
($head->{'compression'} || '') eq '1' && (($buffer = eval { do { $self->decompress($buffer) } }) || die("Failed to decompress document: $@"))
!ll&&!rl&&r
000
$head->{'compression'} || ''
l!l
00
$buffer = eval { do { $self->decompress($buffer) } } or die "Failed to decompress document: $@"
l!l
00
MC/DC0%0/2
($head->{'compression'} || '') eq '1' && (($buffer = eval { do { $self->decompress($buffer) } }) || die("Failed to decompress document: $@"))
$head->{'compression'} $buffer = eval { do { $self->decompress($buffer) } }
Truth table0%0/3
A && B
A= $head->{'compression'}B= $buffer = eval { do { $self->decompress($buffer) } }
ABresult
0X0
100
111
226 0 ▶ $self->{'xml_in'} = $buffer if $self->{'keep_xml'} || $head->{'keep_xml'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"keep_xml"} or $head->{"keep_xml"} 0 0 0
Condition0%0/3
$self->{"keep_xml"} or $head->{"keep_xml"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"keep_xml"} or $head->{"keep_xml"}
$self->{"keep_xml"} $head->{"keep_xml"}
Truth table0%0/3
A or B
A= $self->{"keep_xml"}B= $head->{"keep_xml"}
ABresult
1X1
011
000
227  
228 0 ▶ my $uuid = sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
229 0 my $id = shift;
230 0 ▶ if ($id) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id) 0 0 0
231 0 $id = $self->decode_base64($id);
232 0 ▶ $id = 0 if $id eq "\0"x16;
Branch: 1 branch
BranchTrueFalseTotal
if $id eq "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" 0 0 0
233 0 ▶ $id =~ s/^0+(?=\d)// if $id =~ /^\d{16}$/;
Branch: 1 branch
BranchTrueFalseTotal
if $id =~ /^\d{16}$/ 0 0 0
234 }
235 0 return $id;
236 0 };
237  
238 # parse the XML - use our own parser since XML::Simple does not do event based actions
239 0 ▶ my $tri = sub { return !defined($_[0]) ? undef : ('true' eq lc $_[0]) ? 1 : ('false' eq lc $_[0]) ? 0 : undef };
Subroutine __ANON__: not called CC=4 SCAR=30.0
Branch: 3 branches
BranchTrueFalseTotal
!defined($_[0]) ? : 0 0 0
'true' eq lc $_[0] ? : 0 0 0
'false' eq lc $_[0] ? : 0 0 0
240 0 my $s20_stream = $self->salsa20_stream({key => sha256($head->{'protected_stream_key'}), iv => $salsa20_iv, rounds => 20});
241 0 my %BIN;
242 my $META;
243 0 my @GROUPS;
244 0 my $level = 0;
245 my $data = $self->parse_xml($buffer, {
246 top => 'KeePassFile',
247 0 force_array => {map {$_ => 1} qw(Binaries Binary Group Entry String Association Item DeletedObject)},
248 0 ▶ start_handlers => {Group => sub { $level++ }},
Subroutine __ANON__: not called CC=1 SCAR=6.9
249 end_handlers => {
250 0 ▶ Meta => sub {
Subroutine __ANON__: not called CC=10 SCAR=47.0
251 0 my ($node, $parent) = @_;
252 0 ▶ die "Found multiple intances of Meta.\n" if $META;
Branch: 1 branch
BranchTrueFalseTotal
if $META 0 0 0
253 0 $META = {};
254 0 ▶ my $pro = delete($node->{'MemoryProtection'}) || {}; # flatten out protection
Condition0%0/2
delete $node->{'MemoryProtection'} || {}
l!l
00
MC/DC0%0/1
delete $node->{'MemoryProtection'} || {}
delete $node->{'MemoryProtection'}
Truth table0%0/2
A
A= delete $node->{'MemoryProtection'}
Aresult
11
00
255 0 @$node{map {s/Protect/protect_/; lc $_} keys %$pro} = map {$tri->($_)} values %$pro;
256 0 for my $key (keys %$node) {
257 0 ▶ next if $key eq 'Binaries';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "Binaries" 0 0 0
258 0 (my $copy = $key) =~ s/([a-z])([A-Z])/${1}_${2}/g;
259 0 ▶ $META->{lc $copy} = $copy =~ /_changed$/i ? $self->_parse_v2_date($node->{$key}) : $node->{$key};
Branch: 1 branch
BranchTrueFalseTotal
$copy =~ /_changed$/i ? : 0 0 0
260 }
261 0 $META->{'recycle_bin_enabled'} = $tri->($META->{'recycle_bin_enabled'});
262 0 $META->{$_} = $uuid->($META->{$_}) for qw(entry_templates_group last_selected_group last_top_visible_group recycle_bin_uuid);
263 die "HeaderHash recorded in file did not match actual hash of header.\n"
264 0 ▶ if $META->{'header_hash'} && $head->{'raw'} && $META->{'header_hash'} ne $self->encode_base64(sha256($head->{'raw'}));
Branch: 1 branch
BranchTrueFalseTotal
if $META->{"header_hash"} and $head->{"raw"} and $META->{"header_hash"} ne $self->encode_base64(&sha256($head->{"raw"})) 0 0 0
Condition0%0/6
$META->{"header_hash"} and $head->{"raw"} and $META->{"header_hash"} ne $self->encode_base64(&sha256($head->{"raw"}))
!ll&&!rl&&r
000
$META->{"header_hash"} and $head->{"raw"}
!ll&&!rl&&r
000
MC/DC0%0/3
$META->{"header_hash"} and $head->{"raw"} and $META->{"header_hash"} ne $self->encode_base64(&sha256($head->{"raw"}))
$META->{"header_hash"} $head->{"raw"} $META->{"header_hash"} ne $self->encode_base64(&sha256($head->{"raw"}))
Truth table0%0/4
A and B and C
A= $META->{"header_hash"}B= $head->{"raw"}C= $META->{"header_hash"} ne $self->encode_base64(&sha256($head->{"raw"}))
ABCresult
0XX0
10X0
1100
1111
265 },
266 0 ▶ Binary => sub {
Subroutine __ANON__: not called CC=12 SCAR=50.5
267 0 my ($node, $parent, $parent_tag, $tag) = @_;
268 0 ▶ if ($parent_tag eq 'Binaries') {
Branch: 2 branches
BranchTrueFalseTotal
if ($parent_tag eq 'Binaries') { } 0 0 0
elsif ($parent_tag eq 'Entry') { } 0 0 0
269 0 my ($content, $id, $comp) = @$node{qw(content ID Compressed)};
270 0 ▶ $content = '' if ! defined $content;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $content 0 0 0
271 0 ▶ $content = $self->decode_base64($content) if length $content;
Branch: 1 branch
BranchTrueFalseTotal
if length $content 0 0 0
272 0 ▶ if ($comp && $comp eq 'True' && length $content) {
Branch: 1 branch
BranchTrueFalseTotal
if ($comp and $comp eq "True" and length $content) 0 0 0
Condition0%0/6
$comp and $comp eq "True" and length $content
!ll&&!rl&&r
000
$comp and $comp eq "True"
!ll&&!rl&&r
000
MC/DC0%0/3
$comp and $comp eq "True" and length $content
$comp $comp eq "True" length $content
Truth table0%0/4
A and B and C
A= $compB= $comp eq "True"C= length $content
ABCresult
0XX0
10X0
1100
1111
273 0 ▶ eval { $content = $self->decompress($content) } or warn "Could not decompress associated binary ($id): $@";
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $content = $self->decompress($content) } } or warn "Could not decompress associated binary ($id): $@" 0 0 0
274 }
275 0 ▶ warn "Duplicate binary id $id - using most recent.\n" if exists $BIN{$id};
Branch: 1 branch
BranchTrueFalseTotal
if exists $BIN{$id} 0 0 0
276 0 $BIN{$id} = $content;
277 } elsif ($parent_tag eq 'Entry') {
278 0 my $key = $node->{'Key'};
279 0 ▶ $key = do { warn "Missing key for binary."; 'unknown' } if ! defined $key;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $key 0 0 0
280 0 ▶ warn "Duplicate binary key for entry." if $parent->{'__binary__'}->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if $parent->{"__binary__"}{$key} 0 0 0
281 0 $parent->{'__binary__'}->{$key} = $BIN{$node->{'Value'}->{'Ref'}};
282 }
283 },
284 0 ▶ CustomData => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
285 0 my ($node, $parent, $parent_tag, $tag) = @_;
286 0 ▶ $parent->{$tag} = {map {$_->{'Key'} => $_->{'Value'}} @{ $node->{'Item'} || [] }}; # is order important?
Condition0%0/2
$node->{'Item'} || []
l!l
00
MC/DC0%0/1
$node->{'Item'} || []
$node->{'Item'}
Truth table0%0/2
A
A= $node->{'Item'}
Aresult
11
00
287 },
288 0 ▶ Group => sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
289 0 my ($node, $parent, $parent_tag) = @_;
290 my $group = {
291 id => $uuid->($node->{'UUID'}),
292 icon => $node->{'IconID'},
293 title => $node->{'Name'},
294 expanded => $tri->($node->{'IsExpanded'}),
295 level => $level,
296 accessed => $self->_parse_v2_date($node->{'Times'}->{'LastAccessTime'}),
297 expires => $self->_parse_v2_date($node->{'Times'}->{'ExpiryTime'}),
298 created => $self->_parse_v2_date($node->{'Times'}->{'CreationTime'}),
299 modified => $self->_parse_v2_date($node->{'Times'}->{'LastModificationTime'}),
300  
301 auto_type_default => $node->{'DefaultAutoTypeSequence'},
302 auto_type_enabled => $tri->($node->{'EnableAutoType'}),
303 enable_searching => $tri->($node->{'EnableSearching'}),
304 last_top_entry => $uuid->($node->{'LastTopVisibleEntry'}),
305 expires_enabled => $tri->($node->{'Times'}->{'Expires'}),
306 location_changed => $self->_parse_v2_date($node->{'Times'}->{'LocationChanged'}),
307 usage_count => $node->{'Times'}->{'UsageCount'},
308 notes => $node->{'Notes'},
309  
310 entries => delete($node->{'__entries__'}) || [],
311 0 ▶ groups => delete($node->{'__groups__'}) || [],
Condition0%0/4
delete $node->{'__entries__'} || []
l!l
00
delete $node->{'__groups__'} || []
l!l
00
MC/DC0%0/1
delete $node->{'__entries__'} || []
delete $node->{'__entries__'}
MC/DC0%0/1
delete $node->{'__groups__'} || []
delete $node->{'__groups__'}
Truth table0%0/2
A
A= delete $node->{'__entries__'}
Aresult
11
00
Truth table0%0/2
A
A= delete $node->{'__groups__'}
Aresult
11
00
312 };
313 0 ▶ if ($parent_tag eq 'Group') {
Branch: 1 branch
BranchTrueFalseTotal
if ($parent_tag eq 'Group') { } 0 0 0
314 0 push @{ $parent->{'__groups__'} }, $group;
315 } else {
316 0 push @GROUPS, $group;
317 }
318 },
319 0 ▶ Entry => sub {
Subroutine __ANON__: not called CC=11 SCAR=48.8
320 0 my ($node, $parent, $parent_tag) = @_;
321 0 my %str;
322 0 ▶ for my $s (@{ $node->{'String'} || [] }) {
Condition0%0/2
$node->{'String'} || []
l!l
00
MC/DC0%0/1
$node->{'String'} || []
$node->{'String'}
Truth table0%0/2
A
A= $node->{'String'}
Aresult
11
00
323 0 $str{$s->{'Key'}} = $s->{'Value'};
324 0 ▶ $str{'__protected__'}->{$s->{'Key'} =~ /^(Password|UserName|URL|Notes|Title)$/i ? lc($s->{'Key'}) : $s->{'Key'}} = 1 if $s->{'__protected__'};
Branch: 2 branches
BranchTrueFalseTotal
if $s->{"__protected__"} 0 0 0
$s->{'Key'} =~ /^(Password|UserName|URL|Notes|Title)$/i ? : 0 0 0
325 }
326 my $entry = {
327 accessed => $self->_parse_v2_date($node->{'Times'}->{'LastAccessTime'}),
328 created => $self->_parse_v2_date($node->{'Times'}->{'CreationTime'}),
329 expires => $self->_parse_v2_date($node->{'Times'}->{'ExpiryTime'}),
330 modified => $self->_parse_v2_date($node->{'Times'}->{'LastModificationTime'}),
331 comment => delete($str{'Notes'}),
332 icon => $node->{'IconID'},
333 id => $uuid->($node->{'UUID'}),
334 title => delete($str{'Title'}),
335 url => delete($str{'URL'}),
336 username => delete($str{'UserName'}),
337 password => delete($str{'Password'}),
338  
339 expires_enabled => $tri->($node->{'Times'}->{'Expires'}),
340 location_changed => $self->_parse_v2_date($node->{'Times'}->{'LocationChanged'}),
341 usage_count => $node->{'Times'}->{'UsageCount'},
342 tags => $node->{'Tags'},
343 background_color => $node->{'BackgroundColor'},
344 foreground_color => $node->{'ForegroundColor'},
345 override_url => $node->{'OverrideURL'},
346 auto_type => delete($node->{'AutoType'}->{'__auto_type__'}) || [],
347 auto_type_enabled => $tri->($node->{'AutoType'}->{'Enabled'}),
348 auto_type_munge => $node->{'AutoType'}->{'DataTransferObfuscation'} ? 1 : 0,
349 0 ▶ protected => delete($str{'__protected__'}),
Branch: 1 branch
BranchTrueFalseTotal
$node->{'AutoType'}{'DataTransferObfuscation'} ? : 0 0 0
Condition0%0/2
delete $node->{'AutoType'}{'__auto_type__'} || []
l!l
00
MC/DC0%0/1
delete $node->{'AutoType'}{'__auto_type__'} || []
delete $node->{'AutoType'}{'__auto_type__'}
Truth table0%0/2
A
A= delete $node->{'AutoType'}{'__auto_type__'}
Aresult
11
00
350 };
351 0 ▶ $entry->{'history'} = $node->{'History'} if defined $node->{'History'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $node->{"History"} 0 0 0
352 0 ▶ $entry->{'custom_icon_uuid'} = $node->{'CustomIconUUID'} if defined $node->{'CustomIconUUID'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $node->{"CustomIconUUID"} 0 0 0
353 0 ▶ $entry->{'strings'} = \%str if scalar keys %str;
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %str 0 0 0
354 0 ▶ $entry->{'binary'} = delete($node->{'__binary__'}) if $node->{'__binary__'};
Branch: 1 branch
BranchTrueFalseTotal
if $node->{"__binary__"} 0 0 0
355 0 push @{ $parent->{'__entries__'} }, $entry;
356 },
357 0 ▶ String => sub {
Subroutine __ANON__: not called CC=6 SCAR=37.4
358 0 my $node = shift;
359 0 my $val = $node->{'Value'};
360 0 ▶ if (ref($val) eq 'HASH' && $val->{'Protected'} && $val->{'Protected'} eq 'True') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $val eq "HASH" and $val->{"Protected"} and $val->{"Protected"} eq "True") 0 0 0
Condition0%0/6
ref $val eq "HASH" and $val->{"Protected"} and $val->{"Protected"} eq "True"
!ll&&!rl&&r
000
ref $val eq "HASH" and $val->{"Protected"}
!ll&&!rl&&r
000
MC/DC0%0/3
ref $val eq "HASH" and $val->{"Protected"} and $val->{"Protected"} eq "True"
ref $val eq "HASH" $val->{"Protected"} $val->{"Protected"} eq "True"
Truth table0%0/4
A and B and C
A= ref $val eq "HASH"B= $val->{"Protected"}C= $val->{"Protected"} eq "True"
ABCresult
0XX0
10X0
1100
1111
361 0 $val = $val->{'content'};
362 0 ▶ $node->{'Value'} = (defined($val) && length($val)) ? $s20_stream->($self->decode_base64($val)) : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $val && length $val ? : 0 0 0
Condition0%0/3
defined $val and length $val
!ll&&!rl&&r
000
MC/DC0%0/2
defined $val and length $val
defined $val length $val
Truth table0%0/3
A and B
A= defined $valB= length $val
ABresult
0X0
100
111
363 0 $node->{'__protected__'} = 1;
364 }
365 },
366 0 ▶ Association => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
367 0 my ($node, $parent) = @_;
368 0 push @{ $parent->{'__auto_type__'} }, {window => $node->{'Window'}, keys => $node->{'KeystrokeSequence'}};
369 },
370 0 ▶ History => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
371 0 my ($node, $parent, $parent_tag, $tag) = @_;
372 0 ▶ $parent->{$tag} = delete($node->{'__entries__'}) || [];
Condition0%0/2
delete $node->{'__entries__'} || []
l!l
00
MC/DC0%0/1
delete $node->{'__entries__'} || []
delete $node->{'__entries__'}
Truth table0%0/2
A
A= delete $node->{'__entries__'}
Aresult
11
00
373 },
374 0 ▶ Association => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
375 0 my ($node, $parent) = @_;
376 0 push @{ $parent->{'__auto_type__'} }, {window => $node->{'Window'}, keys => $node->{'KeystrokeSequence'}};
377 },
378 0 ▶ DeletedObject => sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
379 0 my ($node) = @_;
380 0 push @{ $GROUPS[0]->{'deleted_objects'} }, {
381 uuid => $self->decode_base64($node->{'UUID'}),
382 date => $self->_parse_v2_date($node->{'DeletionTime'}),
383 0 ▶ } if $GROUPS[0] && $node->{'UUID'} && $node->{'DeletionTime'};
Branch: 1 branch
BranchTrueFalseTotal
if $GROUPS[0] and $node->{"UUID"} and $node->{"DeletionTime"} 0 0 0
Condition0%0/6
$GROUPS[0] and $node->{"UUID"} and $node->{"DeletionTime"}
!ll&&!rl&&r
000
$GROUPS[0] and $node->{"UUID"}
!ll&&!rl&&r
000
MC/DC0%0/3
$GROUPS[0] and $node->{"UUID"} and $node->{"DeletionTime"}
$GROUPS[0] $node->{"UUID"} $node->{"DeletionTime"}
Truth table0%0/4
A and B and C
A= $GROUPS[0]B= $node->{"UUID"}C= $node->{"DeletionTime"}
ABCresult
0XX0
10X0
1100
1111
384 },
385 },
386 0 });
387  
388 0 my $g = $GROUPS[0];
389 0 @GROUPS = @{ $g->{'groups'} } if @GROUPS == 1
390 && $g && $g->{'notes'} && $g->{'notes'} eq "Added as a top group by File::KeePass"
391 0 ▶ && @{ $g->{'groups'} || [] } && !@{ $g->{'entries'} || [] } && !$g->{'auto_type_default'};
Branch: 1 branch
BranchTrueFalseTotal
if @GROUPS == 1 and $g and $g->{"notes"} and $g->{"notes"} eq "Added as a top group by File::KeePass" and @{$g->{"groups"} or [];} and not @{$g->{"entries"} or [];} and not $g->{"auto_type_default"} 0 0 0
Condition0%0/22
@GROUPS == 1 and $g and $g->{"notes"} and $g->{"notes"} eq "Added as a top group by File::KeePass" and @{$g->{"groups"} or [];} and not @{$g->{"entries"} or [];} and not $g->{"auto_type_default"}
!ll&&!rl&&r
000
@GROUPS == 1 and $g and $g->{"notes"} and $g->{"notes"} eq "Added as a top group by File::KeePass" and @{$g->{"groups"} or [];} and not @{$g->{"entries"} or [];}
!ll&&!rl&&r
000
@GROUPS == 1 and $g and $g->{"notes"} and $g->{"notes"} eq "Added as a top group by File::KeePass" and @{$g->{"groups"} or [];}
!ll&&!rl&&r
000
@GROUPS == 1 and $g and $g->{"notes"} and $g->{"notes"} eq "Added as a top group by File::KeePass"
!ll&&!rl&&r
000
@GROUPS == 1 and $g and $g->{"notes"}
!ll&&!rl&&r
000
@GROUPS == 1 and $g
!ll&&!rl&&r
000
$g->{'groups'} || []
l!l
00
$g->{'entries'} || []
l!l
00
MC/DC0%0/7
@GROUPS == 1 and $g and $g->{"notes"} and $g->{"notes"} eq "Added as a top group by File::KeePass" and @{$g->{"groups"} or [];} and not @{$g->{"entries"} or [];} and not $g->{"auto_type_default"}
@GROUPS == 1 $g $g->{"notes"} $g->{"notes"} eq "Added as a top group by File::KeePass" @{$g->{"groups"} or [];} not @{$g->{"entries"} or [];} not $g->{"auto_type_default"}
MC/DC0%0/1
$g->{'groups'} || []
$g->{'groups'}
MC/DC0%0/1
$g->{'entries'} || []
$g->{'entries'}
Truth table0%0/8
A and B and C and D and E and not(F) and not(G)
A= @GROUPS == 1B= $gC= $g->{"notes"}D= $g->{"notes"} eq "Added as a top group by File::KeePass"E= @{$g->{"groups"} or [];}F= not @{$g->{"entries"} or [];}G= not $g->{"auto_type_default"}
ABCDEFGresult
0XXXXXX0
10XXXXX0
110XXXX0
1110XXX0
11110XX0
111110X0
11111100
11111111
Truth table0%0/2
A
A= $g->{'groups'}
Aresult
11
00
Truth table0%0/2
A
A= $g->{'entries'}
Aresult
11
00
392 0 return ($META, \@GROUPS);
393 }
394  
395 6 ▶sub _parse_v1_groups {
Subroutine _parse_v1_groups: called CC=17 SCAR=28.4
396 6 my ($self, $buffer, $n_groups) = @_;
397 6 my $pos = 0;
398  
399 6 my @groups;
400 my %gmap; # allow entries to find their groups (group map)
401 6 my @gref = (\@groups); # group ref pointer stack - let levels nest safely
402 6 my $group = {};
403 6 ▶ while ($n_groups) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n_groups) 189 6 195
404 189 my $type = unpack 'S', substr($buffer, $pos, 2);
405 189 $pos += 2;
406 189 ▶ die "Group header offset is out of range. ($pos)" if $pos >= length($buffer);
Branch: 1 branch
BranchTrueFalseTotal
if $pos >= length $buffer 0 189 189
407  
408 189 my $size = unpack 'L', substr($buffer, $pos, 4);
409 189 $pos += 4;
410 189 ▶ die "Group header offset is out of range. ($pos, $size)" if $pos + $size > length($buffer);
Branch: 1 branch
BranchTrueFalseTotal
if $pos + $size > length $buffer 0 189 189
411  
412 189 ▶ if ($type == 1) {
Branch: 9 branches
BranchTrueFalseTotal
if ($type == 1) { } 21 168 189
elsif ($type == 2) { } 21 147 168
elsif ($type == 3) { } 21 126 147
elsif ($type == 4) { } 21 105 126
elsif ($type == 5) { } 21 84 105
elsif ($type == 6) { } 21 63 84
elsif ($type == 7) { } 21 42 63
elsif ($type == 8) { } 21 21 42
elsif ($type == 65535) { } 21 0 21
413 21 $group->{'id'} = unpack 'L', substr($buffer, $pos, 4);
414 } elsif ($type == 2) {
415 21 ($group->{'title'} = substr($buffer, $pos, $size)) =~ s/\0$//;
416 } elsif ($type == 3) {
417 21 $group->{'created'} = $self->_parse_v1_date(substr($buffer, $pos, $size));
418 } elsif ($type == 4) {
419 21 $group->{'modified'} = $self->_parse_v1_date(substr($buffer, $pos, $size));
420 } elsif ($type == 5) {
421 21 $group->{'accessed'} = $self->_parse_v1_date(substr($buffer, $pos, $size));
422 } elsif ($type == 6) {
423 21 $group->{'expires'} = $self->_parse_v1_date(substr($buffer, $pos, $size));
424 } elsif ($type == 7) {
425 21 $group->{'icon'} = unpack 'L', substr($buffer, $pos, 4);
426 } elsif ($type == 8) {
427 21 $group->{'level'} = unpack 'S', substr($buffer, $pos, 2);
428 } elsif ($type == 0xFFFF) {
429 21 ▶ $group->{'created'} ||= '';
Condition50%1/2
$group->{"created"} ||= ""
l!l
210
MC/DC0%0/1
$group->{"created"} ||= ""
$group->{"created"}
Truth table50%1/2
A
A= $group->{"created"}
Aresult
11
00
430 21 $n_groups--;
431 21 $gmap{$group->{'id'}} = $group;
432 21 ▶ my $level = $group->{'level'} || 0;
Condition100%2/2
$group->{'level'} || 0
l!l
138
MC/DC100%1/1
$group->{'level'} || 0
$group->{'level'}
Truth table100%2/2
A
A= $group->{'level'}
Aresult
11
00
433 21 ▶ if (@gref > $level + 1) { # gref is index base 1 because the root is a pointer to \@groups
Branch: 2 branches
BranchTrueFalseTotal
if (@gref > $level + 1) { } 3 18 21
elsif (@gref < $level + 1) { } 8 10 18
434 3 splice @gref, $level + 1;
435 } elsif (@gref < $level + 1) {
436 8 push @gref, ($gref[-1]->[-1]->{'groups'} = []);
437 }
438 21 push @{ $gref[-1] }, $group;
439 21 $group = {};
440 } else {
441 0 $group->{'unknown'}->{$type} = substr($buffer, $pos, $size);
442 }
443 189 $pos += $size;
444 }
445  
446 6 return (\@groups, \%gmap, $pos);
447 }
448  
449 6 ▶sub _parse_v1_entries {
Subroutine _parse_v1_entries: called CC=28 SCAR=34.5
450 6 my ($self, $buffer, $n_entries, $pos, $gmap, $groups) = @_;
451  
452 6 my $entry = {};
453 6 ▶ while ($n_entries) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n_entries) 150 6 156
454 150 my $type = unpack 'S', substr($buffer, $pos, 2);
455 150 $pos += 2;
456 150 ▶ die "Entry header offset is out of range. ($pos)" if $pos >= length($buffer);
Branch: 1 branch
BranchTrueFalseTotal
if $pos >= length $buffer 0 150 150
457  
458 150 my $size = unpack 'L', substr($buffer, $pos, 4);
459 150 $pos += 4;
460 150 ▶ die "Entry header offset is out of range for type $type. ($pos, ".length($buffer).", $size)" if $pos + $size > length($buffer);
Branch: 1 branch
BranchTrueFalseTotal
if $pos + $size > length $buffer 0 150 150
461  
462 150 ▶ if ($type == 1) {
Branch: 15 branches
BranchTrueFalseTotal
if ($type == 1) { } 10 140 150
elsif ($type == 2) { } 10 130 140
elsif ($type == 3) { } 10 120 130
elsif ($type == 4) { } 10 110 120
elsif ($type == 5) { } 10 100 110
elsif ($type == 6) { } 10 90 100
elsif ($type == 7) { } 10 80 90
elsif ($type == 8) { } 10 70 80
elsif ($type == 9) { } 10 60 70
elsif ($type == 10) { } 10 50 60
elsif ($type == 11) { } 10 40 50
elsif ($type == 12) { } 10 30 40
elsif ($type == 13) { } 10 20 30
elsif ($type == 14) { } 10 10 20
elsif ($type == 65535) { } 10 0 10
463 10 $entry->{'id'} = substr($buffer, $pos, $size);
464 } elsif ($type == 2) {
465 10 $entry->{'group_id'} = unpack 'L', substr($buffer, $pos, 4);
466 } elsif ($type == 3) {
467 10 $entry->{'icon'} = unpack 'L', substr($buffer, $pos, 4);
468 } elsif ($type == 4) {
469 10 ($entry->{'title'} = substr($buffer, $pos, $size)) =~ s/\0$//;
470 } elsif ($type == 5) {
471 10 ($entry->{'url'} = substr($buffer, $pos, $size)) =~ s/\0$//;
472 } elsif ($type == 6) {
473 10 ($entry->{'username'} = substr($buffer, $pos, $size)) =~ s/\0$//;
474 } elsif ($type == 7) {
475 10 ($entry->{'password'} = substr($buffer, $pos, $size)) =~ s/\0$//;
476 } elsif ($type == 8) {
477 10 ($entry->{'comment'} = substr($buffer, $pos, $size)) =~ s/\0$//;
478 } elsif ($type == 9) {
479 10 $entry->{'created'} = $self->_parse_v1_date(substr($buffer, $pos, $size));
480 } elsif ($type == 0xA) {
481 10 $entry->{'modified'} = $self->_parse_v1_date(substr($buffer, $pos, $size));
482 } elsif ($type == 0xB) {
483 10 $entry->{'accessed'} = $self->_parse_v1_date(substr($buffer, $pos, $size));
484 } elsif ($type == 0xC) {
485 10 $entry->{'expires'} = $self->_parse_v1_date(substr($buffer, $pos, $size));
486 } elsif ($type == 0xD) {
487 10 ($entry->{'binary_name'} = substr($buffer, $pos, $size)) =~ s/\0$//;
488 } elsif ($type == 0xE) {
489 10 $entry->{'binary'} = substr($buffer, $pos, $size);
490 } elsif ($type == 0xFFFF) {
491 10 ▶ $entry->{'created'} ||= '';
Condition50%1/2
$entry->{"created"} ||= ""
l!l
100
MC/DC0%0/1
$entry->{"created"} ||= ""
$entry->{"created"}
Truth table50%1/2
A
A= $entry->{"created"}
Aresult
11
00
492 10 $n_entries--;
493 10 my $gid = delete $entry->{'group_id'};
494 10 my $ref = $gmap->{$gid};
495 10 ▶ if (!$ref) { # orphaned nodes go in special group
Branch: 1 branch
BranchTrueFalseTotal
unless ($ref) 0 10 10
496 0 $gid = -1;
497 0 ▶ if (!$gmap->{$gid}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($gmap->{$gid}) 0 0 0
498 0 push @$groups, ($gmap->{$gid} = {id => $gid, title => '*Orphaned*', icon => 0, created => $self->now});
499 }
500 0 $ref = $gmap->{$gid};
501 }
502  
503 10 ▶ if ($entry->{'comment'} && $entry->{'comment'} eq 'KPX_GROUP_TREE_STATE') {
Branch: 1 branch
BranchTrueFalseTotal
if ($entry->{"comment"} and $entry->{"comment"} eq "KPX_GROUP_TREE_STATE") 3 7 10
Condition100%3/3
$entry->{"comment"} and $entry->{"comment"} eq "KPX_GROUP_TREE_STATE"
!ll&&!rl&&r
613
MC/DC100%2/2
$entry->{"comment"} and $entry->{"comment"} eq "KPX_GROUP_TREE_STATE"
$entry->{"comment"} $entry->{"comment"} eq "KPX_GROUP_TREE_STATE"
Truth table100%3/3
A and B
A= $entry->{"comment"}B= $entry->{"comment"} eq "KPX_GROUP_TREE_STATE"
ABresult
0X0
100
111
504 3 ▶ if (!defined($entry->{'binary'}) || length($entry->{'binary'}) < 4) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $entry->{'binary'} or length $entry->{'binary'} < 4) { } 0 3 3
Condition33%1/3
not defined $entry->{"binary"} or length $entry->{"binary"} < 4
l!l&&r!l&&!r
003
MC/DC0%0/2
not defined $entry->{"binary"} or length $entry->{"binary"} < 4
not defined $entry->{"binary"} length $entry->{"binary"} < 4
Truth table33%1/3
not(A) or B
A= not defined $entry->{"binary"}B= length $entry->{"binary"} < 4
ABresult
1X1
011
000
505 0 warn "Discarded metastream KPX_GROUP_TREE_STATE because of a parsing error."
506 } else {
507 3 my $n = unpack 'L', substr($entry->{'binary'}, 0, 4);
508 3 ▶ if ($n * 5 != length($entry->{'binary'}) - 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n * 5 != length($entry->{'binary'}) - 4) { } 0 3 3
509 0 warn "Discarded metastream KPX_GROUP_TREE_STATE because of a parsing error.";
510 } else {
511 3 ▶ for (my $i = 0; $i < $n; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $n) 6 3 9
512 6 my $group_id = unpack 'L', substr($entry->{'binary'}, 4 + $i * 5, 4);
513 6 my $is_expanded = unpack 'C', substr($entry->{'binary'}, 8 + $i * 5, 1);
514 6 $gmap->{$group_id}->{'expanded'} = $is_expanded;
515 }
516 }
517 }
518 3 $entry = {};
519 3 next;
520 }
521  
522 7 $self->_check_v1_binary($entry);
523 7 $self->_check_v1_auto_type($entry);
524 7 push @{ $ref->{'entries'} }, $entry;
525 7 $entry = {};
526 } else {
527 0 $entry->{'unknown'}->{$type} = substr($buffer, $pos, $size);
528 }
529 147 $pos += $size;
530 }
531 }
532  
533 13 ▶sub _check_v1_binary {
Subroutine _check_v1_binary: called CC=8 SCAR=20.9
534 13 my ($self, $e) = @_;
535 13 ▶ if (ref($e->{'binary'}) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $e->{"binary"} eq "HASH") 3 10 13
536 3 delete $e->{'binary_name'};
537 3 return;
538 }
539 10 my $bin = delete $e->{'binary'};
540 10 my $bname = delete $e->{'binary_name'};
541 10 ▶ if ((defined($bin) && length($bin)) || (defined($bname) && length($bname))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $bin and length $bin or defined $bname and length $bname) 2 8 10
Condition77%7/9
defined $bin and length $bin or defined $bname and length $bname
l!l&&r!l&&!r
208
defined $bin and length $bin
!ll&&!rl&&r
262
defined $bname and length $bname
!ll&&!rl&&r
260
MC/DC50%2/4
defined $bin and length $bin or defined $bname and length $bname
defined $bin length $bin defined $bname length $bname
Truth table42%3/7
A and B or C and D
A= defined $binB= length $binC= defined $bnameD= length $bname
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
542 2 ▶ defined($_) or $_ = '' for $bin, $bname;
Branch: 1 branch
BranchTrueFalseTotal
defined $_ or $_ = "" 4 0 4
543 2 $e->{'binary'} = {$bname => $bin};
544 }
545 }
546  
547 13 ▶sub _check_v1_auto_type {
Subroutine _check_v1_auto_type: called CC=16 SCAR=28.3
548 13 my ($self, $e, $del) = @_;
549 13 ▶ $e->{'auto_type'} = [$e->{'auto_type'}] if ref($e->{'auto_type'}) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $e->{"auto_type"} eq "HASH" 0 13 13
550 13 ▶ if (ref($e->{'auto_type'}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $e->{"auto_type"} eq "ARRAY") 1 12 13
551 1 delete $e->{'auto_type_window'};
552 1 return;
553 }
554 12 my @AT;
555 12 my $key = delete $e->{'auto_type'};
556 12 my $win = delete $e->{'auto_type_window'};
557 12 ▶ if ((defined($key) && length($key)) || (defined($win) && length($win))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $key and length $key or defined $win and length $win) 1 11 12
Condition55%5/9
defined $key and length $key or defined $win and length $win
l!l&&r!l&&!r
1011
defined $key and length $key
!ll&&!rl&&r
1101
defined $win and length $win
!ll&&!rl&&r
1100
MC/DC25%1/4
defined $key and length $key or defined $win and length $win
defined $key length $key defined $win length $win
Truth table28%2/7
A and B or C and D
A= defined $keyB= length $keyC= defined $winD= length $win
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
558 1 push @AT, {keys => $key, window => $win};
559 }
560 12 ▶ return if ! $e->{'comment'};
Branch: 1 branch
BranchTrueFalseTotal
unless $e->{"comment"} 8 4 12
561 4 my %atw = my @atw = $e->{'comment'} =~ m{ ^Auto-Type-Window((?:-?\d+)?): [\t ]* (.*?) [\t ]*$ }mxg;
562 4 my %atk = my @atk = $e->{'comment'} =~ m{ ^Auto-Type((?:-?\d+)?): [\t ]* (.*?) [\t ]*$ }mxg;
563 4 $e->{'comment'} =~ s{ ^Auto-Type(?:-Window)?(?:-?\d+)?: .* \n? }{}mxg;
564 4 ▶ while (@atw) {
Branch: 1 branch
BranchTrueFalseTotal
if (@atw) 4 4 8
565 4 my ($n, $w) = (shift(@atw), shift(@atw));
566 4 ▶ push @AT, {window => $w, keys => exists($atk{$n}) ? $atk{$n} : $atk{''}};
Branch: 1 branch
BranchTrueFalseTotal
exists $atk{$n} ? : 4 0 4
567 }
568 4 ▶ while (@atk) {
Branch: 1 branch
BranchTrueFalseTotal
if (@atk) 3 4 7
569 3 my ($n, $k) = (shift(@atk), shift(@atk));
570 3 ▶ push @AT, {keys => $k, window => exists($atw{$n}) ? $atw{$n} : $atw{''}};
Branch: 1 branch
BranchTrueFalseTotal
exists $atw{$n} ? : 3 0 3
571 }
572 4 ▶ for (@AT) { $_->{'window'} = '' if ! defined $_->{'window'}; $_->{'keys'} = '' if ! defined $_->{'keys'} }
Branch: 2 branches
BranchTrueFalseTotal
unless defined $_->{"window"} 0 8 8
unless defined $_->{"keys"} 0 8 8
573 4 my %uniq;
574 4 @AT = grep {!$uniq{"$_->{'window'}\e$_->{'keys'}"}++} @AT;
575 4 ▶ $e->{'auto_type'} = \@AT if @AT;
Branch: 1 branch
BranchTrueFalseTotal
if @AT 2 2 4
576 }
577  
578 124 ▶sub _parse_v1_date {
Subroutine _parse_v1_date: called CC=1 SCAR=0.0
579 124 my ($self, $packed) = @_;
580 124 my @b = unpack('C*', $packed);
581 124 my $year = ($b[0] << 6) | ($b[1] >> 2);
582 124 my $mon = (($b[1] & 0b11) << 2) | ($b[2] >> 6);
583 124 my $day = (($b[2] & 0b111111) >> 1);
584 124 my $hour = (($b[2] & 0b1) << 4) | ($b[3] >> 4);
585 124 my $min = (($b[3] & 0b1111) << 2) | ($b[4] >> 6);
586 124 my $sec = (($b[4] & 0b111111));
587 124 return sprintf "%04d-%02d-%02d %02d:%02d:%02d", $year, $mon, $day, $hour, $min, $sec;
588 }
589  
590 0 ▶sub _parse_v2_date {
Subroutine _parse_v2_date: not called CC=3 SCAR=24.8
591 0 my ($self, $date) = @_;
592 0 ▶ return ($date && $date =~ $qr_date) ? "$1-$2-$3 $4:$5:$6$7" : '';
Branch: 1 branch
BranchTrueFalseTotal
$date && $date =~ /$qr_date/ ? : 0 0 0
Condition0%0/3
$date and $date =~ /$qr_date/
!ll&&!rl&&r
000
MC/DC0%0/2
$date and $date =~ /$qr_date/
$date $date =~ /$qr_date/
Truth table0%0/3
A and B
A= $dateB= $date =~ /$qr_date/
ABresult
0X0
100
111
593 }
594  
595 13 ▶sub _master_key {
Subroutine _master_key: called CC=25 SCAR=45.8
596 13 my ($self, $pass, $head) = @_;
597 13 my $file;
598 13 ▶ ($pass, $file) = @$pass if ref($pass) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $pass eq "ARRAY" 0 13 13
599 13 ▶ $pass = sha256($pass) if defined($pass) && length($pass);
Branch: 1 branch
BranchTrueFalseTotal
if defined $pass and length $pass 13 0 13
Condition33%1/3
defined $pass and length $pass
!ll&&!rl&&r
0013
MC/DC0%0/2
defined $pass and length $pass
defined $pass length $pass
Truth table33%1/3
A and B
A= defined $passB= length $pass
ABresult
0X0
100
111
600 13 ▶ if ($file) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file) 0 13 13
601 0 ▶ $file = ref($file) ? $$file : $self->slurp($file);
Branch: 1 branch
BranchTrueFalseTotal
ref $file ? : 0 0 0
602 0 ▶ if (length($file) == 64) {
Branch: 2 branches
BranchTrueFalseTotal
if (length $file == 64) { } 0 0 0
elsif (length $file != 32) { } 0 0 0
603 0 $file = join '', map {chr hex} ($file =~ /\G([a-f0-9A-F]{2})/g);
604 } elsif (length($file) != 32) {
605 0 $file = sha256($file);
606 }
607 }
608 my $key = (!$pass && !$file) ? die "One or both of password or key file must be passed\n"
609 0 ▶ : ($head->{'version'} && $head->{'version'} eq '2') ? sha256(grep {$_} $pass, $file)
Branch: 4 branches
BranchTrueFalseTotal
!($pass || $file) ? : 0 13 13
$head->{'version'} && $head->{'version'} eq '2' ? : 0 13 13
$pass && $file ? : 0 13 13
$pass ? : 13 0 13
Condition33%3/9
$pass || $file
l!l&&r!l&&!r
1300
$head->{"version"} and $head->{"version"} eq 2
!ll&&!rl&&r
0130
$pass and $file
!ll&&!rl&&r
0130
MC/DC0%0/2
$pass || $file
$pass $file
MC/DC0%0/2
$head->{"version"} and $head->{"version"} eq 2
$head->{"version"} $head->{"version"} eq 2
MC/DC0%0/2
$pass and $file
$pass $file
Truth table33%1/3
A || B
A= $passB= $file
ABresult
1X1
011
000
Truth table33%1/3
A and B
A= $head->{"version"}B= $head->{"version"} eq 2
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= $passB= $file
ABresult
0X0
100
111
610 : ($pass && $file) ? sha256($pass, $file) : $pass ? $pass : $file;
611 13 ▶ $head->{'enc_iv'} ||= join '', map {chr rand 256} 1..16;
Condition66%2/3
$head->{"enc_iv"} ||= join("", map({chr rand 256;} 1..16))
l!l&&r!l&&!r
940
MC/DC0%0/2
$head->{"enc_iv"} ||= join("", map({chr rand 256;} 1..16))
$head->{"enc_iv"} join("", map({chr rand 256;} 1..16))
Truth table66%2/3
A ||= B
A= $head->{"enc_iv"}B= join("", map({chr rand 256;} 1..16))
ABresult
1X1
011
000
612 13 ▶ $head->{'seed_rand'} ||= join '', map {chr rand 256} 1..($head->{'version'} && $head->{'version'} eq '2' ? 32 : 16);
Branch: 1 branch
BranchTrueFalseTotal
$head->{'version'} && $head->{'version'} eq '2' ? : 0 4 4
Condition50%3/6
$head->{"seed_rand"} ||= join("", map({chr rand 256;} 1 .. ($head->{"version"} && $head->{"version"} eq 2 ? 32 : 16)))
l!l&&r!l&&!r
940
$head->{"version"} and $head->{"version"} eq 2
!ll&&!rl&&r
040
MC/DC0%0/2
$head->{"seed_rand"} ||= join("", map({chr rand 256;} 1 .. ($head->{"version"} && $head->{"version"} eq 2 ? 32 : 16)))
$head->{"seed_rand"} join("", map({chr rand 256;} 1 .. ($head->{"version"} && $head->{"version"} eq 2 ? 32 : 16)))
MC/DC0%0/2
$head->{"version"} and $head->{"version"} eq 2
$head->{"version"} $head->{"version"} eq 2
Truth table66%2/3
A ||= B
A= $head->{"seed_rand"}B= join("", map({chr rand 256;} 1 .. ($head->{"version"} && $head->{"version"} eq 2 ? 32 : 16)))
ABresult
1X1
011
000
Truth table33%1/3
A and B
A= $head->{"version"}B= $head->{"version"} eq 2
ABresult
0X0
100
111
613 13 ▶ $head->{'seed_key'} ||= sha256(time.rand(2**32-1).$$);
Condition66%2/3
$head->{"seed_key"} ||= &sha256(time . rand(4294967295) . $$)
l!l&&r!l&&!r
940
MC/DC0%0/2
$head->{"seed_key"} ||= &sha256(time . rand(4294967295) . $$)
$head->{"seed_key"} &sha256(time . rand(4294967295) . $$)
Truth table66%2/3
A ||= B
A= $head->{"seed_key"}B= &sha256(time . rand(4294967295) . $$)
ABresult
1X1
011
000
614 13 ▶ $head->{'rounds'} ||= $self->{'rounds'} || ($head->{'version'} && $head->{'version'} eq '2' ? 6_000 : 50_000);
Branch: 1 branch
BranchTrueFalseTotal
$head->{'version'} && $head->{'version'} eq '2' ? : 0 4 4
Condition44%4/9
$head->{"rounds"} ||= $self->{"rounds"} || ($head->{"version"} && $head->{"version"} eq 2 ? 6000 : 50000)
l!l&&r!l&&!r
940
$self->{'rounds'} || ($head->{'version'} && $head->{'version'} eq '2' ? 6000 : 50000)
l!l&&r!l&&!r
040
$head->{"version"} and $head->{"version"} eq 2
!ll&&!rl&&r
040
MC/DC0%0/4
$head->{"rounds"} ||= $self->{"rounds"} || ($head->{"version"} && $head->{"version"} eq 2 ? 6000 : 50000)
$head->{"rounds"} $self->{'rounds'} $head->{"version"} $head->{"version"} eq 2
Truth table0%0/5
A ||= B || C and D
A= $head->{"rounds"}B= $self->{'rounds'}C= $head->{"version"}D= $head->{"version"} eq 2
ABCDresult
1XXX1
01XX1
00111
000X0
00100
615  
616 13 my $cipher = Crypt::Rijndael->new($head->{'seed_key'}, Crypt::Rijndael::MODE_ECB());
617 13 $key = $cipher->encrypt($key) for 1 .. $head->{'rounds'};
618 13 $key = sha256($key);
619 13 $key = sha256($head->{'seed_rand'}, $key);
620 13 return $key;
621 }
622  
623 ###----------------------------------------------------------------###
624  
625 9 ▶sub gen_db {
Subroutine gen_db: called CC=18 SCAR=34.4
Pod documented
626 9 my ($self, $pass, $head, $groups) = @_;
627 9 ▶ $head ||= {};
Condition100%2/2
$head ||= {}
l!l
45
MC/DC100%1/1
$head ||= {}
$head
Truth table100%2/2
A
A= $head
Aresult
11
00
628 9 ▶ $groups ||= $self->groups;
Condition33%1/3
$groups ||= $self->groups
l!l&&r!l&&!r
090
MC/DC0%0/2
$groups ||= $self->groups
$groups $self->groups
Truth table33%1/3
A ||= B
A= $groupsB= $self->groups
ABresult
1X1
011
000
629 9 ▶ local $self->{'keep_xml'} = $head->{'keep_xml'} if exists $head->{'keep_xml'};
Branch: 1 branch
BranchTrueFalseTotal
if exists $head->{"keep_xml"} 0 9 9
630 9 ▶ my $v = $head->{'version'} || $self->{'version'};
Condition66%2/3
$head->{'version'} || $self->{'version'}
l!l&&r!l&&!r
405
MC/DC50%1/2
$head->{'version'} || $self->{'version'}
$head->{'version'} $self->{'version'}
Truth table66%2/3
A || B
A= $head->{'version'}B= $self->{'version'}
ABresult
1X1
011
000
631 my $reuse = $head->{'reuse_header'} # explicit yes
632 || (!exists($head->{'reuse_header'}) # not explicit no
633 && ($self->{'reuse_header'} # explicit yes
634 9 ▶ || !exists($self->{'reuse_header'}))); # not explicit no
Condition33%3/9
$head->{'reuse_header'} || !exists $head->{'reuse_header'} && ($self->{'reuse_header'} || !exists $self->{'reuse_header'})
l!l&&r!l&&!r
090
not exists $head->{"reuse_header"} and $self->{"reuse_header"} || !exists $self->{"reuse_header"}
!ll&&!rl&&r
009
$self->{"reuse_header"} or not exists $self->{"reuse_header"}
l!l&&r!l&&!r
090
MC/DC0%0/4
$head->{'reuse_header'} || !exists $head->{'reuse_header'} && ($self->{'reuse_header'} || !exists $self->{'reuse_header'})
$head->{'reuse_header'} not exists $head->{"reuse_header"} $self->{"reuse_header"} not exists $self->{"reuse_header"}
Truth table20%1/5
A || not(B) and C or not(D)
A= $head->{'reuse_header'}B= not exists $head->{"reuse_header"}C= $self->{"reuse_header"}D= not exists $self->{"reuse_header"}
ABCDresult
1XXX1
011X1
01011
00XX0
01000
635 9 ▶ if ($reuse) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reuse) 9 0 9
636 9 ▶ ($head, my $args) = ($self->header || {}, $head);
Condition100%2/2
$self->header || {}
l!l
45
MC/DC100%1/1
$self->header || {}
$self->header
Truth table100%2/2
A
A= $self->header
Aresult
11
00
637 9 @$head{keys %$args} = values %$args;
638 }
639 9 ▶ $head->{'version'} = $v ||= $head->{'version'} || '1';
Condition60%3/5
$v ||= $head->{"version"} || 1
l!l&&r!l&&!r
450
$head->{'version'} || '1'
l!l
05
MC/DC0%0/2
$v ||= $head->{"version"} || 1
$v $head->{'version'}
Truth table33%1/3
A ||= B
A= $vB= $head->{'version'}
ABresult
1X1
011
000
640 9 ▶ delete @$head{qw(enc_iv seed_key seed_rand protected_stream_key start_bytes)} if $reuse && $reuse < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $reuse and $reuse < 0 0 9 9
Condition33%1/3
$reuse and $reuse < 0
!ll&&!rl&&r
090
MC/DC0%0/2
$reuse and $reuse < 0
$reuse $reuse < 0
Truth table33%1/3
A and B
A= $reuseB= $reuse < 0
ABresult
0X0
100
111
641  
642 9 ▶ die "Missing pass\n" if ! defined($pass);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pass 2 7 9
643 7 ▶ die "Please unlock before calling gen_db\n" if $self->is_locked($groups);
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_locked($groups) 0 7 7
644  
645 7 ▶ srand(rand(time() ^ $$)) if ! $self->{'no_srand'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"no_srand"} 7 0 7
646 7 ▶ if ($v eq '2') {
Branch: 1 branch
BranchTrueFalseTotal
if ($v eq '2') { } 0 7 7
647 0 return $self->_gen_v2_db($pass, $head, $groups);
648 } else {
649 7 return $self->_gen_v1_db($pass, $head, $groups);
650 }
651 }
652  
653 7 ▶sub _gen_v1_db {
Subroutine _gen_v1_db: called CC=46 SCAR=47.1
654 7 my ($self, $pass, $head, $groups) = @_;
655 7 ▶ if ($head->{'sig2'} && $head->{'sig2'} eq DB_SIG_2_v2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($head->{"sig2"} and $head->{"sig2"} eq 3041655655) 0 7 7
Condition66%2/3
$head->{"sig2"} and $head->{"sig2"} eq 3041655655
!ll&&!rl&&r
430
MC/DC0%0/2
$head->{"sig2"} and $head->{"sig2"} eq 3041655655
$head->{"sig2"} $head->{"sig2"} eq 3041655655
Truth table66%2/3
A and B
A= $head->{"sig2"}B= $head->{"sig2"} eq 3041655655
ABresult
0X0
100
111
656 0 ▶ substr($head->{'seed_rand'}, 16, 16, '') if $head->{'seed_rand'} && length($head->{'seed_rand'}) == 32; # if coming from a v2 db use a smaller key (roundtripable)
Branch: 1 branch
BranchTrueFalseTotal
if $head->{"seed_rand"} and length $head->{"seed_rand"} == 32 0 0 0
Condition0%0/3
$head->{"seed_rand"} and length $head->{"seed_rand"} == 32
!ll&&!rl&&r
000
MC/DC0%0/2
$head->{"seed_rand"} and length $head->{"seed_rand"} == 32
$head->{"seed_rand"} length $head->{"seed_rand"} == 32
Truth table0%0/3
A and B
A= $head->{"seed_rand"}B= length $head->{"seed_rand"} == 32
ABresult
0X0
100
111
657 }
658 7 my $key = $self->_master_key($pass, $head);
659 7 my $buffer = '';
660 7 my $entries = '';
661 7 my %gid;
662 44 ▶ my $gid = sub { # v1 groups id size can only be a 32 bit int - v2 is supposed to be a 16 digit string
Subroutine __ANON__: called CC=6 SCAR=21.4
663 44 local $_ = my $gid = shift;
664 44 ▶ return $gid{$gid} ||= do {
Condition66%2/3
$gid{$gid} ||= do { $_ = /^\d+$/ && $_ < 4294967296 ? $_ : (/^([a-f0-9]{16})/i ? hex $1 : int rand "4294967296"); $_ = int rand "4294967296" while $gid{"\e$_\e"}++; $_ }
l!l&&r!l&&!r
21230
MC/DC0%0/2
$gid{$gid} ||= do { $_ = /^\d+$/ && $_ < 4294967296 ? $_ : (/^([a-f0-9]{16})/i ? hex $1 : int rand "4294967296"); $_ = int rand "4294967296" while $gid{"\e$_\e"}++; $_ }
$gid{$gid} do { $_ = /^\d+$/ && $_ < 4294967296 ? $_ : (/^([a-f0-9]{16})/i ? hex $1 : int rand "4294967296"); $_ = int rand "4294967296" while $gid{"\e$_\e"}++; $_ }
Truth table66%2/3
A ||= B
A= $gid{$gid}B= do { $_ = /^\d+$/ && $_ < 4294967296 ? $_ : (/^([a-f0-9]{16})/i ? hex $1 : int rand "4294967296"); $_ = int rand "4294967296" while $gid{"\e$_\e"}++; $_ }
ABresult
1X1
011
000
665 23 ▶ $_ = (/^\d+$/ && $_ < 2**32) ? $_ : /^([a-f0-9]{16})/i ? hex($1) : int(rand 2**32);
Branch: 2 branches
BranchTrueFalseTotal
/^\d+$/ && $_ < 4294967296 ? : 23 0 23
/^([a-f0-9]{16})/i ? : 0 0 0
Condition33%1/3
/^\d+$/ and $_ < 4294967296
!ll&&!rl&&r
0023
MC/DC0%0/2
/^\d+$/ and $_ < 4294967296
/^\d+$/ $_ < 4294967296
Truth table33%1/3
A and B
A= /^\d+$/B= $_ < 4294967296
ABresult
0X0
100
111
666 23 ▶ $_ = int(rand 2**32) while $gid{"\e$_\e"}++;
Branch: 1 branch
BranchTrueFalseTotal
$gid{"\e$_\e"}++ and do { $_ = int rand "4294967296" } 0 23 23
667 23 $_;
668 };
669 7 };
670 7 my %uniq;
671 7 ▶ my $uuid = sub { return $self->uuid(shift, \%uniq) };
Subroutine __ANON__: called CC=1 SCAR=0.0
672  
673 7 my @g = $self->find_groups({}, $groups);
674 7 ▶ if (grep {$_->{'expanded'}} @g) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_->{"expanded"};} @g) 4 3 7
675 4 my $bin = pack 'L', scalar(@g);
676 4 ▶ $bin .= pack('LC', $gid->($_->{'id'}), $_->{'expanded'} ? 1 : 0) for @g;
Branch: 1 branch
BranchTrueFalseTotal
$_->{'expanded'} ? : 4 4 8
677 4 ▶ my $e = ($self->find_entries({title => 'Meta-Info', username => 'SYSTEM', comment => 'KPX_GROUP_TREE_STATE', url => '$'}))[0] || $self->add_entry({
Condition66%2/3
($self->find_entries({'title', 'Meta-Info', 'username', 'SYSTEM', 'comment', 'KPX_GROUP_TREE_STATE', 'url', '$'}))[0] || $self->add_entry({'comment', 'KPX_GROUP_TREE_STATE', 'title', 'Meta-Info', 'username', 'SYSTEM', 'url', '$', 'id', '0000000000000000', 'group', $g[0], 'binary', {'bin-stream', $bin}})
l!l&&r!l&&!r
220
MC/DC0%0/2
($self->find_entries({'title', 'Meta-Info', 'username', 'SYSTEM', 'comment', 'KPX_GROUP_TREE_STATE', 'url', '$'}))[0] || $self->add_entry({'comment', 'KPX_GROUP_TREE_STATE', 'title', 'Meta-Info', 'username', 'SYSTEM', 'url', '$', 'id', '0000000000000000', 'group', $g[0], 'binary', {'bin-stream', $bin}})
($self->find_entries({'title', 'Meta-Info', 'username', 'SYSTEM', 'comment', 'KPX_GROUP_TREE_STATE', 'url', '$'}))[0] $self->add_entry({'comment', 'KPX_GROUP_TREE_STATE', 'title', 'Meta-Info', 'username', 'SYSTEM', 'url', '$', 'id', '0000000000000000', 'group', $g[0], 'binary', {'bin-stream', $bin}})
Truth table66%2/3
A || B
A= ($self->find_entries({'title', 'Meta-Info', 'username', 'SYSTEM', 'comment', 'KPX_GROUP_TREE_STATE', 'url', '$'}))[0]B= $self->add_entry({'comment', 'KPX_GROUP_TREE_STATE', 'title', 'Meta-Info', 'username', 'SYSTEM', 'url', '$', 'id', '0000000000000000', 'group', $g[0], 'binary', {'bin-stream', $bin}})
ABresult
1X1
011
000
678 comment => 'KPX_GROUP_TREE_STATE',
679 title => 'Meta-Info',
680 username => 'SYSTEM',
681 url => '$',
682 id => '0000000000000000',
683 group => $g[0],
684 binary => {'bin-stream' => $bin},
685 });
686 }
687 7 $head->{'n_groups'} = $head->{'n_entries'} = 0;
688 7 foreach my $g (@g) {
689 23 $head->{'n_groups'}++;
690 my @d = ([1, pack('LL', 4, $gid->($g->{'id'}))],
691 [2, pack('L', length($g->{'title'})+1)."$g->{'title'}\0"],
692 [3, pack('L', 5). $self->_gen_v1_date($g->{'created'} || $self->now)],
693 [4, pack('L', 5). $self->_gen_v1_date($g->{'modified'} || $self->now)],
694 [5, pack('L', 5). $self->_gen_v1_date($g->{'accessed'} || $self->now)],
695 [6, pack('L', 5). $self->_gen_v1_date($g->{'expires'} || $self->default_exp)],
696 [7, pack('LL', 4, $g->{'icon'} || 0)],
697 23 ▶ [8, pack('LS', 2, $g->{'level'} || 0)],
Condition50%8/16
$g->{'created'} || $self->now
l!l&&r!l&&!r
2300
$g->{'modified'} || $self->now
l!l&&r!l&&!r
2300
$g->{'accessed'} || $self->now
l!l&&r!l&&!r
2300
$g->{'expires'} || $self->default_exp
l!l&&r!l&&!r
2300
$g->{'icon'} || 0
l!l
419
$g->{'level'} || 0
l!l
149
MC/DC0%0/2
$g->{'created'} || $self->now
$g->{'created'} $self->now
MC/DC0%0/2
$g->{'modified'} || $self->now
$g->{'modified'} $self->now
MC/DC0%0/2
$g->{'accessed'} || $self->now
$g->{'accessed'} $self->now
MC/DC0%0/2
$g->{'expires'} || $self->default_exp
$g->{'expires'} $self->default_exp
MC/DC100%1/1
$g->{'icon'} || 0
$g->{'icon'}
MC/DC100%1/1
$g->{'level'} || 0
$g->{'level'}
Truth table33%1/3
A || B
A= $g->{'created'}B= $self->now
ABresult
1X1
011
000
Truth table33%1/3
A || B
A= $g->{'modified'}B= $self->now
ABresult
1X1
011
000
Truth table33%1/3
A || B
A= $g->{'accessed'}B= $self->now
ABresult
1X1
011
000
Truth table33%1/3
A || B
A= $g->{'expires'}B= $self->default_exp
ABresult
1X1
011
000
Truth table100%2/2
A
A= $g->{'icon'}
Aresult
11
00
Truth table100%2/2
A
A= $g->{'level'}
Aresult
11
00
698 [0xFFFF, pack('L', 0)]);
699 0 push @d, [$_, map {pack('L',length $_).$_} $g->{'unknown'}->{$_}]
700 0 ▶ for grep {/^\d+$/ && $_ > 8} keys %{ $g->{'unknown'} || {} };
Condition20%1/5
/^\d+$/ && $_ > 8
!ll&&!rl&&r
000
$g->{'unknown'} || {}
l!l
023
MC/DC0%0/2
/^\d+$/ && $_ > 8
/^\d+$/ $_ > 8
MC/DC0%0/1
$g->{'unknown'} || {}
$g->{'unknown'}
Truth table0%0/3
A && B
A= /^\d+$/B= $_ > 8
ABresult
0X0
100
111
Truth table50%1/2
A
A= $g->{'unknown'}
Aresult
11
00
701 23 $buffer .= pack('S',$_->[0]).$_->[1] for sort {$a->[0] <=> $b->[0]} @d;
702 23 ▶ foreach my $e (@{ $g->{'entries'} || [] }) {
Condition100%2/2
$g->{'entries'} || []
l!l
914
MC/DC100%1/1
$g->{'entries'} || []
$g->{'entries'}
Truth table100%2/2
A
A= $g->{'entries'}
Aresult
11
00
703 13 $head->{'n_entries'}++;
704  
705 0 ▶ my $bins = $e->{'binary'} || {}; if (ref($bins) ne 'HASH') { warn "Entry binary field was not a hashref of name/content pairs.\n"; $bins = {} }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $bins ne "HASH") 0 13 13
Condition100%2/2
$e->{'binary'} || {}
l!l
58
MC/DC100%1/1
$e->{'binary'} || {}
$e->{'binary'}
Truth table100%2/2
A
A= $e->{'binary'}
Aresult
11
00
706 13 my @bkeys = sort keys %$bins;
707 13 ▶ warn "Found more than one entry in the binary hashref. Encoding only the first one of (@bkeys) on a version 1 database.\n" if @bkeys > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @bkeys > 1 0 13 13
708 13 ▶ my $bname = @bkeys ? $bkeys[0] : '';
Branch: 1 branch
BranchTrueFalseTotal
@bkeys ? : 5 8 13
709 13 ▶ my $bin = $bins->{$bname}; $bin = '' if ! defined $bin;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bin 8 5 13
710  
711 0 ▶ my $at = $e->{'auto_type'} || []; if (ref($at) ne 'ARRAY') { warn "Entry auto_type field was not an arrayref of auto_type info.\n"; $at = [] }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $at ne "ARRAY") 0 13 13
Condition100%2/2
$e->{'auto_type'} || []
l!l
112
MC/DC100%1/1
$e->{'auto_type'} || []
$e->{'auto_type'}
Truth table100%2/2
A
A= $e->{'auto_type'}
Aresult
11
00
712 13 my %AT; my @AT;
713 13 for (@$at) {
714 3 ▶ my ($k, $w) = map {defined($_) ? $_ : ''} @$_{qw(keys window)};
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 6 0 6
715 3 ▶ push @AT, $k if ! grep {$_ eq $k} @AT;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $k;} @AT 2 1 3
716 3 push @{ $AT{$k} }, $w;
717 }
718 13 my $txt = '';
719 13 for my $i (1 .. @AT) {
720 2 ▶ $txt .= "Auto-Type".($i>1 ? "-$i" : '').": $AT[$i-1]\n";
Branch: 1 branch
BranchTrueFalseTotal
$i > 1 ? : 1 1 2
721 2 ▶ $txt .= "Auto-Type-Window".($i>1 ? "-$i" : '').": $_\n" for @{ $AT{$AT[$i-1]} };
Branch: 1 branch
BranchTrueFalseTotal
$i > 1 ? : 1 2 3
722 }
723 13 ▶ my $com = defined($e->{'comment'}) ? "$txt$e->{'comment'}" : $txt;
Branch: 1 branch
BranchTrueFalseTotal
defined $e->{'comment'} ? : 13 0 13
724 my @d = ([1, pack('L', 16). $uuid->($e->{'id'})],
725 [2, pack('LL', 4, $gid->($g->{'id'}))],
726 [3, pack('LL', 4, $e->{'icon'} || 0)],
727 [4, pack('L', length($e->{'title'})+1)."$e->{'title'}\0"],
728 [5, pack('L', length($e->{'url'})+1). "$e->{'url'}\0"],
729 [6, pack('L', length($e->{'username'})+1). "$e->{'username'}\0"],
730 [7, pack('L', length($e->{'password'})+1). "$e->{'password'}\0"],
731 [8, pack('L', length($com)+1). "$com\0"],
732 [9, pack('L', 5). $self->_gen_v1_date($e->{'created'} || $self->now)],
733 [0xA, pack('L', 5). $self->_gen_v1_date($e->{'modified'} || $self->now)],
734 [0xB, pack('L', 5). $self->_gen_v1_date($e->{'accessed'} || $self->now)],
735 13 ▶ [0xC, pack('L', 5). $self->_gen_v1_date($e->{'expires'} || $self->default_exp)],
Condition35%5/14
$e->{'icon'} || 0
l!l
013
$e->{'created'} || $self->now
l!l&&r!l&&!r
1300
$e->{'modified'} || $self->now
l!l&&r!l&&!r
1300
$e->{'accessed'} || $self->now
l!l&&r!l&&!r
1300
$e->{'expires'} || $self->default_exp
l!l&&r!l&&!r
1300
MC/DC0%0/1
$e->{'icon'} || 0
$e->{'icon'}
MC/DC0%0/2
$e->{'created'} || $self->now
$e->{'created'} $self->now
MC/DC0%0/2
$e->{'modified'} || $self->now
$e->{'modified'} $self->now
MC/DC0%0/2
$e->{'accessed'} || $self->now
$e->{'accessed'} $self->now
MC/DC0%0/2
$e->{'expires'} || $self->default_exp
$e->{'expires'} $self->default_exp
Truth table50%1/2
A
A= $e->{'icon'}
Aresult
11
00
Truth table33%1/3
A || B
A= $e->{'created'}B= $self->now
ABresult
1X1
011
000
Truth table33%1/3
A || B
A= $e->{'modified'}B= $self->now
ABresult
1X1
011
000
Truth table33%1/3
A || B
A= $e->{'accessed'}B= $self->now
ABresult
1X1
011
000
Truth table33%1/3
A || B
A= $e->{'expires'}B= $self->default_exp
ABresult
1X1
011
000
736 [0xD, pack('L', length($bname)+1)."$bname\0"],
737 [0xE, pack('L', length($bin)).$bin],
738 [0xFFFF, pack('L', 0)]);
739 push @d, [$_, pack('L', length($e->{'unknown'}->{$_})).$e->{'unknown'}->{$_}]
740 0 ▶ for grep {/^\d+$/ && $_ > 0xE} keys %{ $e->{'unknown'} || {} };
Condition20%1/5
/^\d+$/ && $_ > 14
!ll&&!rl&&r
000
$e->{'unknown'} || {}
l!l
013
MC/DC0%0/2
/^\d+$/ && $_ > 14
/^\d+$/ $_ > 14
MC/DC0%0/1
$e->{'unknown'} || {}
$e->{'unknown'}
Truth table0%0/3
A && B
A= /^\d+$/B= $_ > 14
ABresult
0X0
100
111
Truth table50%1/2
A
A= $e->{'unknown'}
Aresult
11
00
741 13 $entries .= pack('S',$_->[0]).$_->[1] for sort {$a->[0] <=> $b->[0]} @d;
742 }
743 }
744 7 $buffer .= $entries; $entries = '';
745  
746 7 require utf8;
747 7 utf8::downgrade($buffer);
748 7 $head->{'checksum'} = sha256($buffer);
749  
750 7 return $self->_gen_v1_header($head) . $self->encrypt_rijndael_cbc($buffer, $key, $head->{'enc_iv'});
751 }
752  
753 7 ▶sub _gen_v1_header {
Subroutine _gen_v1_header: called CC=6 SCAR=18.0
754 7 my ($self, $head) = @_;
755 7 $head->{'sig1'} = DB_SIG_1;
756 7 $head->{'sig2'} = DB_SIG_2_v1;
757 7 $head->{'flags'} = DB_FLAG_RIJNDAEL;
758 7 $head->{'ver'} = DB_VER_DW_V1;
759 7 ▶ $head->{'n_groups'} ||= 0;
Condition50%1/2
$head->{"n_groups"} ||= 0
l!l
70
MC/DC0%0/1
$head->{"n_groups"} ||= 0
$head->{"n_groups"}
Truth table50%1/2
A
A= $head->{"n_groups"}
Aresult
11
00
760 7 ▶ $head->{'n_entries'} ||= 0;
Condition100%2/2
$head->{"n_entries"} ||= 0
l!l
52
MC/DC100%1/1
$head->{"n_entries"} ||= 0
$head->{"n_entries"}
Truth table100%2/2
A
A= $head->{"n_entries"}
Aresult
11
00
761 7 die "Length of $_ was not 32 (".length($head->{$_}).")\n" for grep {length($head->{$_}) != 32} qw(seed_key checksum);
762 7 die "Length of $_ was not 16 (".length($head->{$_}).")\n" for grep {length($head->{$_}) != 16} qw(enc_iv seed_rand);
763 7 my @f = qw(sig1 sig2 flags ver seed_rand enc_iv n_groups n_entries checksum seed_key rounds);
764 7 my $t = 'L L L L a16 a16 L L a32 a32 L';
765 7 my $header = pack $t, @$head{@f};
766 7 ▶ die "Invalid generated header\n" if length($header) != DB_HEADSIZE_V1;
Branch: 1 branch
BranchTrueFalseTotal
if length $header != 124 0 7 7
767 7 return $header;
768 }
769  
770 144 ▶sub _gen_v1_date {
Subroutine _gen_v1_date: called CC=3 SCAR=11.4
771 144 my ($self, $date) = @_;
772 144 ▶ return "\0\0\0\0\0" if ! $date;
Branch: 1 branch
BranchTrueFalseTotal
unless $date 0 144 144
773 144 ▶ my ($year, $mon, $day, $hour, $min, $sec) = $date =~ /^(\d\d\d\d)-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)$/ ? ($1,$2,$3,$4,$5,$6) : die "Invalid date ($date)";
Branch: 1 branch
BranchTrueFalseTotal
$date =~ /^(\d\d\d\d)-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)$/ ? : 144 0 144
774 144 return pack('C*',
775 ($year >> 6) & 0b111111,
776 (($year & 0b111111) << 2) | (($mon >> 2) & 0b11),
777 (($mon & 0b11) << 6) | (($day & 0b11111) << 1) | (($hour >> 4) & 0b1),
778 (($hour & 0b1111) << 4) | (($min >> 2) & 0b1111),
779 (($min & 0b11) << 6) | ($sec & 0b111111),
780 );
781 }
782  
783 0 ▶sub _gen_v2_db {
Subroutine _gen_v2_db: not called CC=28 SCAR=67.0
784 0 my ($self, $pass, $head, $groups) = @_;
785 0 ▶ if ($head->{'sig2'} && $head->{'sig2'} eq DB_SIG_2_v1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($head->{"sig2"} and $head->{"sig2"} eq 3041655653) 0 0 0
Condition0%0/3
$head->{"sig2"} and $head->{"sig2"} eq 3041655653
!ll&&!rl&&r
000
MC/DC0%0/2
$head->{"sig2"} and $head->{"sig2"} eq 3041655653
$head->{"sig2"} $head->{"sig2"} eq 3041655653
Truth table0%0/3
A and B
A= $head->{"sig2"}B= $head->{"sig2"} eq 3041655653
ABresult
0X0
100
111
786 0 ▶ $head->{'seed_rand'} = $head->{'seed_rand'}x2 if $head->{'seed_rand'} && length($head->{'seed_rand'}) == 16; # if coming from a v1 db augment the key (roundtripable)
Branch: 1 branch
BranchTrueFalseTotal
if $head->{"seed_rand"} and length $head->{"seed_rand"} == 16 0 0 0
Condition0%0/3
$head->{"seed_rand"} and length $head->{"seed_rand"} == 16
!ll&&!rl&&r
000
MC/DC0%0/2
$head->{"seed_rand"} and length $head->{"seed_rand"} == 16
$head->{"seed_rand"} length $head->{"seed_rand"} == 16
Truth table0%0/3
A and B
A= $head->{"seed_rand"}B= length $head->{"seed_rand"} == 16
ABresult
0X0
100
111
787 }
788 0 ▶ $head->{'compression'} = 1 if ! defined $head->{'compression'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $head->{"compression"} 0 0 0
789 0 ▶ $head->{'start_bytes'} ||= join '', map {chr rand 256} 1 .. 32;
Condition0%0/3
$head->{"start_bytes"} ||= join("", map({chr rand 256;} 1..32))
l!l&&r!l&&!r
000
MC/DC0%0/2
$head->{"start_bytes"} ||= join("", map({chr rand 256;} 1..32))
$head->{"start_bytes"} join("", map({chr rand 256;} 1..32))
Truth table0%0/3
A ||= B
A= $head->{"start_bytes"}B= join("", map({chr rand 256;} 1..32))
ABresult
1X1
011
000
790 0 ▶ $head->{'protected_stream_key'} ||= join '', map {chr rand 256} 1..32;
Condition0%0/3
$head->{"protected_stream_key"} ||= join("", map({chr rand 256;} 1..32))
l!l&&r!l&&!r
000
MC/DC0%0/2
$head->{"protected_stream_key"} ||= join("", map({chr rand 256;} 1..32))
$head->{"protected_stream_key"} join("", map({chr rand 256;} 1..32))
Truth table0%0/3
A ||= B
A= $head->{"protected_stream_key"}B= join("", map({chr rand 256;} 1..32))
ABresult
1X1
011
000
791 0 my $key = $self->_master_key($pass, $head);
792 0 my $header = $self->_gen_v2_header($head);
793  
794 0 my $buffer = '';
795 0 ▶ my $untri = sub { return (!defined($_[0]) && !$_[1]) ? 'null' : !$_[0] ? 'False' : 'True' };
Subroutine __ANON__: not called CC=4 SCAR=30.0
Branch: 2 branches
BranchTrueFalseTotal
!(defined $_[0] || $_[1]) ? : 0 0 0
!$_[0] ? : 0 0 0
Condition0%0/3
defined $_[0] || $_[1]
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $_[0] || $_[1]
defined $_[0] $_[1]
Truth table0%0/3
A || B
A= defined $_[0]B= $_[1]
ABresult
1X1
011
000
796 0 my %uniq;
797 0 ▶ my $uuid = sub { my $id = (defined($_[0]) && $_[0] eq '0') ? "\0"x16 : $self->uuid($_[0], \%uniq); return $self->encode_base64($id) };
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] && $_[0] eq '0' ? : 0 0 0
Condition0%0/3
defined $_[0] and $_[0] eq 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_[0] and $_[0] eq 0
defined $_[0] $_[0] eq 0
Truth table0%0/3
A and B
A= defined $_[0]B= $_[0] eq 0
ABresult
0X0
100
111
798  
799 0 my @mfld = qw(Generator HeaderHash DatabaseName DatabaseNameChanged DatabaseDescription DatabaseDescriptionChanged DefaultUserName DefaultUserNameChanged
800 MaintenanceHistoryDays Color MasterKeyChanged MasterKeyChangeRec MasterKeyChangeForce MemoryProtection
801 RecycleBinEnabled RecycleBinUUID RecycleBinChanged EntryTemplatesGroup EntryTemplatesGroupChanged HistoryMaxItems HistoryMaxSize
802 LastSelectedGroup LastTopVisibleGroup Binaries CustomData);
803 0 my $META = {__sort__ => \@mfld};
804 0 for my $key (@mfld) {
805 0 (my $copy = $key) =~ s/([a-z])([A-Z])/${1}_${2}/g;
806 0 $META->{$key} = $head->{lc $copy};
807 }
808 0 ▶ my $def = sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
809 0 my ($k, $d, $r) = @_;
810 0 ▶ $META->{$k} = $d if !defined($META->{$k}) || ($r and $META->{$k} !~ $r);
Branch: 1 branch
BranchTrueFalseTotal
if not defined $META->{$k} or $r and not $META->{$k} =~ /$r/ 0 0 0
Condition0%0/6
not defined $META->{$k} or $r and not $META->{$k} =~ /$r/
l!l&&r!l&&!r
000
$r and not $META->{$k} =~ /$r/
!ll&&!rl&&r
000
MC/DC0%0/3
not defined $META->{$k} or $r and not $META->{$k} =~ /$r/
not defined $META->{$k} $r not $META->{$k} =~ /$r/
Truth table0%0/4
not(A) or B and not(C)
A= not defined $META->{$k}B= $rC= not $META->{$k} =~ /$r/
ABCresult
1XX1
0111
00X0
0100
811 0 ▶ $META->{$k} = $self->_gen_v2_date($META->{$k}) if $k =~ /Changed$/;
Branch: 1 branch
BranchTrueFalseTotal
if $k =~ /Changed$/ 0 0 0
812 0 };
813 0 my $now = $self->_gen_v2_date;
814 0 $META->{'HeaderHash'} = $self->encode_base64(sha256($header));
815 0 $def->(Color => '');
816 0 $def->(DatabaseDescription => '');
817 0 $def->(DatabaseDescriptionChanged => $now, $qr_date);
818 0 $def->(DatabaseName => '');
819 0 $def->(DatabaseNameChanged => $now, $qr_date);
820 0 $def->(DefaultUserName => '');
821 0 $def->(DefaultUserNameChanged => $now, $qr_date);
822 0 $def->(EntryTemplatesGroupChanged => $now, $qr_date);
823 0 $def->(Generator => ref($self));
824 0 $def->(HistoryMaxItems => 10, qr{^\d+$});
825 0 $def->(HistoryMaxSize => 6291456, qr{^\d+$});
826 0 $def->(MaintenanceHistoryDays => 365, qr{^\d+$});
827 0 $def->(MasterKeyChangeForce => -1);
828 0 $def->(MasterKeyChangeRec => -1);
829 0 $def->(MasterKeyChanged => $now, $qr_date);
830 0 $def->(RecycleBinChanged => $now, $qr_date);
831 0 ▶ $META->{$_} = $uuid->($META->{$_} || 0) for qw(EntryTemplatesGroup LastSelectedGroup LastTopVisibleGroup RecycleBinUUID);
Condition0%0/2
$META->{$_} || 0
l!l
00
MC/DC0%0/1
$META->{$_} || 0
$META->{$_}
Truth table0%0/2
A
A= $META->{$_}
Aresult
11
00
832 0 ▶ $META->{'RecycleBinEnabled'} = $untri->(exists($META->{'RecycleBinEnabled'}) ? $META->{'RecycleBinEnabled'} : 1, 1);
Branch: 1 branch
BranchTrueFalseTotal
exists $META->{'RecycleBinEnabled'} ? : 0 0 0
833 0 ▶ my $p = $META->{'MemoryProtection'} ||= {};
Condition0%0/2
$META->{"MemoryProtection"} ||= {}
l!l
00
MC/DC0%0/1
$META->{"MemoryProtection"} ||= {}
$META->{"MemoryProtection"}
Truth table0%0/2
A
A= $META->{"MemoryProtection"}
Aresult
11
00
834 0 for my $new (qw(ProtectTitle ProtectUserName ProtectPassword ProtectURL ProtectNotes)) { # unflatten protection
835 0 (my $key = lc $new) =~ s/protect/protect_/;
836 0 push @{$p->{'__sort__'}}, $new;
837 0 ▶ $p->{$new} = (exists($META->{$key}) ? delete($META->{$key}) : ($key eq 'protect_password')) ? 'True' : 'False';
Branch: 2 branches
BranchTrueFalseTotal
(exists $META->{$key} ? delete $META->{$key} : $key eq 'protect_password') ? : 0 0 0
exists $META->{$key} ? : 0 0 0
838 }
839 0 ▶ my $cd = $META->{'CustomData'} ||= {};
Condition0%0/2
$META->{"CustomData"} ||= {}
l!l
00
MC/DC0%0/1
$META->{"CustomData"} ||= {}
$META->{"CustomData"}
Truth table0%0/2
A
A= $META->{"CustomData"}
Aresult
11
00
840 0 ▶ $META->{'CustomData'} = {Item => [map {{Key => $_, Value => $cd->{$_}}} sort keys %$cd]} if ref($cd) eq 'HASH' && scalar keys %$cd;
Branch: 1 branch
BranchTrueFalseTotal
if ref $cd eq "HASH" and scalar keys %$cd 0 0 0
Condition0%0/2
ref $cd eq "HASH" and scalar keys %$cd
!ll
00
MC/DC0%0/1
ref $cd eq "HASH" and scalar keys %$cd
ref $cd eq "HASH"
Truth table0%0/2
A
A= ref $cd eq "HASH"
Aresult
00
11
841  
842 0 my @GROUPS;
843 0 my $BIN = $META->{'Binaries'}->{'Binary'} = [];
844 0 my @PROTECT_BIN;
845 my @PROTECT_STR;
846 0 my $data = {
847 Meta => $META,
848 Root => {
849 __sort__ => [qw(Group DeletedObjects)],
850 Group => \@GROUPS,
851 DeletedObjects => undef,
852 },
853 };
854  
855 0 ▶ my $gen_entry; $gen_entry = sub {
Subroutine __ANON__: not called CC=31 SCAR=69.0
856 0 my ($e, $parent) = @_;
857 push @$parent, my $E = {
858 __sort__ => [qw(UUID IconID ForegroundColor BackgroundColor OverrideURL Tags Times String AutoType History)],
859 UUID => $uuid->($e->{'id'}),
860 IconID => $e->{'icon'} || 0,
861 Times => {
862 __sort__ => [qw(LastModificationTime CreationTime LastAccessTime ExpiryTime Expires UsageCount LocationChanged)],
863 Expires => $untri->($e->{'expires_enabled'}, 1),
864 UsageCount => $e->{'usage_count'} || 0,
865 LastAccessTime => $self->_gen_v2_date($e->{'accessed'}),
866 ExpiryTime => $self->_gen_v2_date($e->{'expires'} || $self->default_exp),
867 CreationTime => $self->_gen_v2_date($e->{'created'}),
868 LastModificationTime => $self->_gen_v2_date($e->{'modified'}),
869 LocationChanged => $self->_gen_v2_date($e->{'location_changed'}),
870 },
871 Tags => $e->{'tags'},
872 BackgroundColor => $e->{'background_color'},
873 ForegroundColor => $e->{'foreground_color'},
874 CustomIconUUID => $uuid->($e->{'custom_icon_uuid'} || 0),
875 OverrideURL => $e->{'override_url'},
876 AutoType => {
877 Enabled => $untri->(exists($e->{'auto_type_enabled'}) ? $e->{'auto_type_enabled'} : 1, 1),
878 0 ▶ DataTransferObfuscation => $e->{'auto_type_munge'} ? 1 : 0,
Branch: 2 branches
BranchTrueFalseTotal
exists $e->{'auto_type_enabled'} ? : 0 0 0
$e->{'auto_type_munge'} ? : 0 0 0
Condition0%0/9
$e->{'icon'} || 0
l!l
00
$e->{'usage_count'} || 0
l!l
00
$e->{'expires'} || $self->default_exp
l!l&&r!l&&!r
000
$e->{'custom_icon_uuid'} || 0
l!l
00
MC/DC0%0/1
$e->{'icon'} || 0
$e->{'icon'}
MC/DC0%0/1
$e->{'usage_count'} || 0
$e->{'usage_count'}
MC/DC0%0/2
$e->{'expires'} || $self->default_exp
$e->{'expires'} $self->default_exp
MC/DC0%0/1
$e->{'custom_icon_uuid'} || 0
$e->{'custom_icon_uuid'}
Truth table0%0/2
A
A= $e->{'icon'}
Aresult
11
00
Truth table0%0/2
A
A= $e->{'usage_count'}
Aresult
11
00
Truth table0%0/3
A || B
A= $e->{'expires'}B= $self->default_exp
ABresult
1X1
011
000
Truth table0%0/2
A
A= $e->{'custom_icon_uuid'}
Aresult
11
00
879 },
880 };
881 0 ▶ foreach my $key (sort(keys %{ $e->{'strings'} || {} }), qw(Notes Password Title URL UserName)) {
Condition0%0/2
$e->{'strings'} || {}
l!l
00
MC/DC0%0/1
$e->{'strings'} || {}
$e->{'strings'}
Truth table0%0/2
A
A= $e->{'strings'}
Aresult
11
00
882 0 ▶ my $val = ($key eq 'Notes') ? $e->{'comment'} : ($key=~/^(Password|Title|URL|UserName)$/) ? $e->{lc $key} : $e->{'strings'}->{$key};
Branch: 2 branches
BranchTrueFalseTotal
$key eq 'Notes' ? : 0 0 0
$key =~ /^(Password|Title|URL|UserName)$/ ? : 0 0 0
883 0 ▶ next if ! defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 0 0
884 0 push @{ $E->{'String'} }, my $s = {
885 Key => $key,
886 Value => $val,
887 };
888 0 ▶ if (($META->{'MemoryProtection'}->{"Protect${key}"} || '') eq 'True'
Branch: 2 branches
BranchTrueFalseTotal
if (($META->{"MemoryProtection"}{"Protect$key"} || "") eq "True" or $e->{"protected"}{$key =~ /^(Password|UserName|URL|Notes|Title)$/ ? lc $key : $key}) 0 0 0
$key =~ /^(Password|UserName|URL|Notes|Title)$/ ? : 0 0 0
Condition0%0/5
($META->{"MemoryProtection"}{"Protect$key"} || "") eq "True" or $e->{"protected"}{$key =~ /^(Password|UserName|URL|Notes|Title)$/ ? lc $key : $key}
l!l&&r!l&&!r
000
$META->{'MemoryProtection'}{"Protect$key"} || ''
l!l
00
MC/DC0%0/2
($META->{"MemoryProtection"}{"Protect$key"} || "") eq "True" or $e->{"protected"}{$key =~ /^(Password|UserName|URL|Notes|Title)$/ ? lc $key : $key}
$META->{'MemoryProtection'}{"Protect$key"} $e->{"protected"}{$key =~ /^(Password|UserName|URL|Notes|Title)$/ ? lc $key : $key}
Truth table0%0/3
A or B
A= $META->{'MemoryProtection'}{"Protect$key"}B= $e->{"protected"}{$key =~ /^(Password|UserName|URL|Notes|Title)$/ ? lc $key : $key}
ABresult
1X1
011
000
889 || $e->{'protected'}->{$key =~ /^(Password|UserName|URL|Notes|Title)$/ ? lc($key) : $key}) {
890 0 $s->{'Value'} = {Protected => 'True', content => $val};
891 0 ▶ push @PROTECT_STR, \$s->{'Value'}->{'content'} if length $s->{'Value'}->{'content'};
Branch: 1 branch
BranchTrueFalseTotal
if length $s->{"Value"}{"content"} 0 0 0
892 }
893 }
894 0 ▶ foreach my $at (@{ $e->{'auto_type'} || [] }) {
Condition0%0/2
$e->{'auto_type'} || []
l!l
00
MC/DC0%0/1
$e->{'auto_type'} || []
$e->{'auto_type'}
Truth table0%0/2
A
A= $e->{'auto_type'}
Aresult
11
00
895 0 push @{ $E->{'AutoType'}->{'Association'} }, {
896 Window => $at->{'window'},
897 0 KeystrokeSequence => $at->{'keys'},
898 };
899 }
900 0 ▶ my $bin = $e->{'binary'} || {}; $bin = {__anon__ => $bin} if ref($bin) ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $bin ne "HASH" 0 0 0
Condition0%0/2
$e->{'binary'} || {}
l!l
00
MC/DC0%0/1
$e->{'binary'} || {}
$e->{'binary'}
Truth table0%0/2
A
A= $e->{'binary'}
Aresult
11
00
901 0 ▶ splice @{ $E->{'__sort__'} }, -2, 0, 'Binary' if scalar keys %$bin;
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %$bin 0 0 0
902 0 foreach my $key (sort keys %$bin) {
903 push @$BIN, my $b = {
904 __attr__ => [qw(ID Compressed)],
905 ID => $#$BIN+1,
906 0 ▶ content => defined($bin->{$key}) ? $bin->{$key} : '',
Branch: 1 branch
BranchTrueFalseTotal
defined $bin->{$key} ? : 0 0 0
907 };
908 0 ▶ $b->{'Compressed'} = (length($b->{'content'}) < 100 || $self->{'no_binary_compress'}) ? 'False' : 'True';
Branch: 1 branch
BranchTrueFalseTotal
length $b->{'content'} < 100 || $self->{'no_binary_compress'} ? : 0 0 0
Condition0%0/3
length $b->{"content"} < 100 or $self->{"no_binary_compress"}
l!l&&r!l&&!r
000
MC/DC0%0/2
length $b->{"content"} < 100 or $self->{"no_binary_compress"}
length $b->{"content"} < 100 $self->{"no_binary_compress"}
Truth table0%0/3
A or B
A= length $b->{"content"} < 100B= $self->{"no_binary_compress"}
ABresult
1X1
011
000
909 0 ▶ if ($b->{'Compressed'} eq 'True') {
Branch: 1 branch
BranchTrueFalseTotal
if ($b->{"Compressed"} eq "True") 0 0 0
910 0 ▶ eval { $b->{'content'} = $self->compress($b->{'content'}) } or warn "Could not compress associated binary ($b->{'ID'}): $@";
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $b->{"content"} = $self->compress($b->{"content"}) } } or warn qq[Could not compress associated binary ($b->{"ID"}): $@] 0 0 0
911 }
912 0 $b->{'content'} = $self->encode_base64($b->{'content'});
913 0 push @{ $E->{'Binary'} }, {Key => $key, Value => {__attr__ => [qw(Ref)], Ref => $b->{'ID'}, content => ''}};
914 }
915 0 ▶ foreach my $h (@{ $e->{'history'}||[] }) {
Condition0%0/2
$e->{'history'} || []
l!l
00
MC/DC0%0/1
$e->{'history'} || []
$e->{'history'}
Truth table0%0/2
A
A= $e->{'history'}
Aresult
11
00
916 0 ▶ $gen_entry->($h, $E->{'History'}->{'Entry'} ||= []);
Condition0%0/2
$E->{"History"}{"Entry"} ||= []
l!l
00
MC/DC0%0/1
$E->{"History"}{"Entry"} ||= []
$E->{"History"}{"Entry"}
Truth table0%0/2
A
A= $E->{"History"}{"Entry"}
Aresult
11
00
917 }
918 0 };
919  
920 0 ▶ my $rec; $rec = sub {
Subroutine __ANON__: not called CC=20 SCAR=60.4
921 0 my ($group, $parent) = @_;
922 0 ▶ return if ref($group) ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $group ne "HASH" 0 0 0
923 push @$parent, my $G = {
924 __sort__ => [qw(UUID Name Notes IconID Times IsExpanded DefaultAutoTypeSequence EnableAutoType EnableSearching LastTopVisibleEntry)],
925 UUID => $uuid->($group->{'id'}),
926 Name => $group->{'title'} || '',
927 Notes => $group->{'notes'},
928 IconID => $group->{'icon'} || 0,
929 Times => {
930 __sort__ => [qw(LastModificationTime CreationTime LastAccessTime ExpiryTime Expires UsageCount LocationChanged)],
931 Expires => $untri->($group->{'expires_enabled'}, 1),
932 UsageCount => $group->{'usage_count'} || 0,
933 LastAccessTime => $self->_gen_v2_date($group->{'accessed'}),
934 ExpiryTime => $self->_gen_v2_date($group->{'expires'} || $self->default_exp),
935 CreationTime => $self->_gen_v2_date($group->{'created'}),
936 LastModificationTime => $self->_gen_v2_date($group->{'modified'}),
937 LocationChanged => $self->_gen_v2_date($group->{'location_changed'}),
938 },
939 IsExpanded => $untri->($group->{'expanded'}, 1),
940 DefaultAutoTypeSequence => $group->{'auto_type_default'},
941 EnableAutoType => lc($untri->(exists($group->{'auto_type_enabled'}) ? $group->{'auto_type_enabled'} : 1)),
942 EnableSearching => lc($untri->(exists($group->{'enable_searching'}) ? $group->{'enable_searching'} : 1)),
943 0 ▶ LastTopVisibleEntry => $uuid->($group->{'last_top_entry'} || 0),
Branch: 2 branches
BranchTrueFalseTotal
exists $group->{'auto_type_enabled'} ? : 0 0 0
exists $group->{'enable_searching'} ? : 0 0 0
Condition0%0/11
$group->{'title'} || ''
l!l
00
$group->{'icon'} || 0
l!l
00
$group->{'usage_count'} || 0
l!l
00
$group->{'expires'} || $self->default_exp
l!l&&r!l&&!r
000
$group->{'last_top_entry'} || 0
l!l
00
MC/DC0%0/1
$group->{'title'} || ''
$group->{'title'}
MC/DC0%0/1
$group->{'icon'} || 0
$group->{'icon'}
MC/DC0%0/1
$group->{'usage_count'} || 0
$group->{'usage_count'}
MC/DC0%0/2
$group->{'expires'} || $self->default_exp
$group->{'expires'} $self->default_exp
MC/DC0%0/1
$group->{'last_top_entry'} || 0
$group->{'last_top_entry'}
Truth table0%0/2
A
A= $group->{'title'}
Aresult
11
00
Truth table0%0/2
A
A= $group->{'icon'}
Aresult
11
00
Truth table0%0/2
A
A= $group->{'usage_count'}
Aresult
11
00
Truth table0%0/3
A || B
A= $group->{'expires'}B= $self->default_exp
ABresult
1X1
011
000
Truth table0%0/2
A
A= $group->{'last_top_entry'}
Aresult
11
00
944 };
945 0 ▶ $G->{'CustomIconUUID'} = $uuid->($group->{'custom_icon_uuid'}) if $group->{'custom_icon_uuid'}; # TODO
Branch: 1 branch
BranchTrueFalseTotal
if $group->{"custom_icon_uuid"} 0 0 0
946 0 ▶ push @{$G->{'__sort__'}}, 'Entry' if @{ $group->{'entries'} || [] };
Branch: 1 branch
BranchTrueFalseTotal
if @{$group->{"entries"} or [];} 0 0 0
Condition0%0/2
$group->{'entries'} || []
l!l
00
MC/DC0%0/1
$group->{'entries'} || []
$group->{'entries'}
Truth table0%0/2
A
A= $group->{'entries'}
Aresult
11
00
947 0 ▶ foreach my $e (@{ $group->{'entries'} || [] }) {
Condition0%0/2
$group->{'entries'} || []
l!l
00
MC/DC0%0/1
$group->{'entries'} || []
$group->{'entries'}
Truth table0%0/2
A
A= $group->{'entries'}
Aresult
11
00
948 0 ▶ $gen_entry->($e, $G->{'Entry'} ||= []);
Condition0%0/2
$G->{"Entry"} ||= []
l!l
00
MC/DC0%0/1
$G->{"Entry"} ||= []
$G->{"Entry"}
Truth table0%0/2
A
A= $G->{"Entry"}
Aresult
11
00
949 }
950 0 ▶ push @{$G->{'__sort__'}}, 'Group' if @{ $group->{'groups'} || [] };
Branch: 1 branch
BranchTrueFalseTotal
if @{$group->{"groups"} or [];} 0 0 0
Condition0%0/2
$group->{'groups'} || []
l!l
00
MC/DC0%0/1
$group->{'groups'} || []
$group->{'groups'}
Truth table0%0/2
A
A= $group->{'groups'}
Aresult
11
00
951 0 ▶ $rec->($_, $G->{'Group'} ||= []) for @{ $group->{'groups'} || []};
Condition0%0/4
$group->{'groups'} || []
l!l
00
$G->{"Group"} ||= []
l!l
00
MC/DC0%0/1
$group->{'groups'} || []
$group->{'groups'}
MC/DC0%0/1
$G->{"Group"} ||= []
$G->{"Group"}
Truth table0%0/2
A
A= $group->{'groups'}
Aresult
11
00
Truth table0%0/2
A
A= $G->{"Group"}
Aresult
11
00
952 0 };
953 0 ▶ $groups = [{title => "Database", groups => [@$groups], notes => "Added as a top group by File::KeePass", expanded => 1}] if @$groups > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @$groups > 1 0 0 0
954 0 $rec->($_, \@GROUPS) for @$groups;
955  
956 0 ▶ if (@$groups && $groups->[0]->{'deleted_objects'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$groups and $groups->[0]{"deleted_objects"}) 0 0 0
Condition0%0/3
@$groups and $groups->[0]{"deleted_objects"}
!ll&&!rl&&r
000
MC/DC0%0/2
@$groups and $groups->[0]{"deleted_objects"}
@$groups $groups->[0]{"deleted_objects"}
Truth table0%0/3
A and B
A= @$groupsB= $groups->[0]{"deleted_objects"}
ABresult
0X0
100
111
957 0 foreach my $dob (@{ $groups->[0]->{'deleted_objects'} }) {
958 0 push @{ $data->{'Root'}->{'DeletedObjects'}->{'DeletedObject'} }, {
959 UUID => $self->encode_base64($dob->{'uuid'}),
960 0 DeletionTime => $self->_gen_v2_date($dob->{'date'}),
961 }
962 }
963 }
964  
965 0 my $s20_stream = $self->salsa20_stream({key => sha256($head->{'protected_stream_key'}), iv => $salsa20_iv, rounds => 20});
966 0 for my $ref (@PROTECT_BIN, @PROTECT_STR) {
967 0 $$ref = $self->encode_base64($s20_stream->($$ref));
968 }
969  
970 # gen the XML - use our own generator since XML::Simple does not do event based actions
971 0 $buffer = $self->gen_xml($data, {
972 top => 'KeePassFile',
973 indent => "\t",
974 declaration => '<?xml version="1.0" encoding="utf-8" standalone="yes"?>',
975 sort => {
976 AutoType => [qw(Enabled DataTransferObfuscation Association)],
977 Association => [qw(Window KeystrokeSequence)],
978 DeletedObject => [qw(UUID DeletionTime)],
979 },
980 no_trailing_newline => 1,
981 });
982 0 ▶ $self->{'xml_out'} = $buffer if $self->{'keep_xml'} || $head->{'keep_xml'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"keep_xml"} or $head->{"keep_xml"} 0 0 0
Condition0%0/3
$self->{"keep_xml"} or $head->{"keep_xml"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"keep_xml"} or $head->{"keep_xml"}
$self->{"keep_xml"} $head->{"keep_xml"}
Truth table0%0/3
A or B
A= $self->{"keep_xml"}B= $head->{"keep_xml"}
ABresult
1X1
011
000
983  
984 0 ▶ $buffer = $self->compress($buffer) if $head->{'compression'} eq '1';
Branch: 1 branch
BranchTrueFalseTotal
if $head->{"compression"} eq 1 0 0 0
985 0 $buffer = $self->chunksum($buffer);
986  
987 0 substr $buffer, 0, 0, $head->{'start_bytes'};
988  
989 0 return $header . $self->encrypt_rijndael_cbc($buffer, $key, $head->{'enc_iv'});
990 }
991  
992 0 ▶sub _gen_v2_date {
Subroutine _gen_v2_date: not called CC=4 SCAR=30.0
993 0 my ($self, $date) = @_;
994 0 ▶ $date = $self->now($date) if !$date || $date =~ /^\d+$/;
Branch: 1 branch
BranchTrueFalseTotal
if not $date or $date =~ /^\d+$/ 0 0 0
Condition0%0/3
not $date or $date =~ /^\d+$/
l!l&&r!l&&!r
000
MC/DC0%0/2
not $date or $date =~ /^\d+$/
not $date $date =~ /^\d+$/
Truth table0%0/3
not(A) or B
A= not $dateB= $date =~ /^\d+$/
ABresult
1X1
011
000
995 0 ▶ my ($year, $mon, $day, $hour, $min, $sec) = $date =~ $qr_date ? ($1,$2,$3,$4,$5,$6) : die "Invalid date ($date)";
Branch: 1 branch
BranchTrueFalseTotal
$date =~ /$qr_date/ ? : 0 0 0
996 0 return "${year}-${mon}-${day}T${hour}:${min}:${sec}Z";
997 }
998  
999 0 ▶sub _gen_v2_header {
Subroutine _gen_v2_header: not called CC=12 SCAR=50.5
1000 0 my ($self, $head) = @_;
1001 0 $head->{'sig1'} = DB_SIG_1;
1002 0 $head->{'sig2'} = DB_SIG_2_v2;
1003 0 $head->{'ver'} = DB_VER_DW_V2;
1004 0 ▶ $head->{'comment'} = '' if ! defined $head->{'comment'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $head->{"comment"} 0 0 0
1005 0 ▶ $head->{'compression'} = (!defined($head->{'compression'}) || $head->{'compression'} eq '1') ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
!defined($head->{'compression'}) || $head->{'compression'} eq '1' ? : 0 0 0
Condition0%0/3
not defined $head->{"compression"} or $head->{"compression"} eq 1
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $head->{"compression"} or $head->{"compression"} eq 1
not defined $head->{"compression"} $head->{"compression"} eq 1
Truth table0%0/3
not(A) or B
A= not defined $head->{"compression"}B= $head->{"compression"} eq 1
ABresult
1X1
011
000
1006 0 ▶ $head->{'0'} ||= "\r\n\r\n";
Condition0%0/2
$head->{0} ||= "\r\n\r\n"
l!l
00
MC/DC0%0/1
$head->{0} ||= "\r\n\r\n"
$head->{0}
Truth table0%0/2
A
A= $head->{0}
Aresult
11
00
1007 0 ▶ $head->{'protected_stream_key'} ||= join '', map {chr rand 256} 1..32;
Condition0%0/3
$head->{"protected_stream_key"} ||= join("", map({chr rand 256;} 1..32))
l!l&&r!l&&!r
000
MC/DC0%0/2
$head->{"protected_stream_key"} ||= join("", map({chr rand 256;} 1..32))
$head->{"protected_stream_key"} join("", map({chr rand 256;} 1..32))
Truth table0%0/3
A ||= B
A= $head->{"protected_stream_key"}B= join("", map({chr rand 256;} 1..32))
ABresult
1X1
011
000
1008 0 ▶ die "Missing start_bytes\n" if ! $head->{'start_bytes'};
Branch: 1 branch
BranchTrueFalseTotal
unless $head->{"start_bytes"} 0 0 0
1009 0 die "Length of $_ was not 32 (".length($head->{$_}).")\n" for grep {length($head->{$_}) != 32} qw(seed_rand seed_key protected_stream_key start_bytes);
1010 0 ▶ die "Length of enc_iv was not 16\n" if length($head->{'enc_iv'}) != 16;
Branch: 1 branch
BranchTrueFalseTotal
if length $head->{"enc_iv"} != 16 0 0 0
1011  
1012 0 my $buffer = pack 'L3', @$head{qw(sig1 sig2 ver)};
1013  
1014 0 ▶ my $pack = sub { my ($type, $str) = @_; $buffer .= pack('C S', $type, length($str)) . $str };
Subroutine __ANON__: not called CC=1 SCAR=6.9
1015 0 ▶ $pack->(1, $head->{'comment'}) if defined($head->{'comment'}) && length($head->{'comment'});
Branch: 1 branch
BranchTrueFalseTotal
if defined $head->{"comment"} and length $head->{"comment"} 0 0 0
Condition0%0/3
defined $head->{"comment"} and length $head->{"comment"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $head->{"comment"} and length $head->{"comment"}
defined $head->{"comment"} length $head->{"comment"}
Truth table0%0/3
A and B
A= defined $head->{"comment"}B= length $head->{"comment"}
ABresult
0X0
100
111
1016 0 $pack->(2, "\x31\xc1\xf2\xe6\xbf\x71\x43\x50\xbe\x58\x05\x21\x6a\xfc\x5a\xff"); # aes cipher
1017 0 ▶ $pack->(3, pack 'V', $head->{'compression'} ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$head->{'compression'} ? : 0 0 0
1018 0 $pack->(4, $head->{'seed_rand'});
1019 0 $pack->(5, $head->{'seed_key'});
1020 0 $pack->(6, pack 'LL', $head->{'rounds'}, 0); # a little odd to be double the length but not used
1021 0 $pack->(7, $head->{'enc_iv'});
1022 0 $pack->(8, $head->{'protected_stream_key'});
1023 0 $pack->(9, $head->{'start_bytes'});
1024 0 $pack->(10, pack('V', 2)); # salsa20 protection
1025 0 $pack->(0, $head->{'0'});
1026 0 return $buffer;
1027 }
1028  
1029 ###----------------------------------------------------------------###
1030  
1031 1 ▶sub slurp {
Subroutine slurp: called CC=4 SCAR=14.2
Pod undocumented
1032 1 my ($self, $file) = @_;
1033 1 ▶ open my $fh, '<', $file or die "Could not open $file: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $file or die "Could not open ${file}: $!\n" 1 0 1
1034 1 ▶ my $size = -s $file || die "File $file appears to be empty.\n";
Condition50%1/2
-s $file || die("File $file appears to be empty.\n")
l!l
10
MC/DC0%0/1
-s $file || die("File $file appears to be empty.\n")
-s $file
Truth table50%1/2
A
A= -s $file
Aresult
11
00
1035 1 binmode $fh;
1036 1 read($fh, my $buffer, $size);
1037 1 close $fh;
1038 1 ▶ die "Could not read entire file contents of $file.\n" if length($buffer) != $size;
Branch: 1 branch
BranchTrueFalseTotal
if length $buffer != $size 0 1 1
1039 1 return $buffer;
1040 }
1041  
1042 11 ▶sub decrypt_rijndael_cbc {
Subroutine decrypt_rijndael_cbc: called CC=1 SCAR=0.0
Pod documented
1043 11 my ($self, $buffer, $key, $enc_iv) = @_;
1044 #use Crypt::CBC; return Crypt::CBC->new(-cipher => 'Rijndael', -key => $key, -iv => $enc_iv, -regenerate_key => 0, -prepend_iv => 0)->decrypt($buffer);
1045 11 my $cipher = Crypt::Rijndael->new($key, Crypt::Rijndael::MODE_CBC());
1046 11 $cipher->set_iv($enc_iv);
1047 11 $buffer = $cipher->decrypt($buffer);
1048 11 my $extra = ord(substr $buffer, -1, 1);
1049 11 substr($buffer, length($buffer) - $extra, $extra, '');
1050 11 return $buffer;
1051 }
1052  
1053 13 ▶sub encrypt_rijndael_cbc {
Subroutine encrypt_rijndael_cbc: called CC=3 SCAR=11.0
Pod documented
1054 13 my ($self, $buffer, $key, $enc_iv) = @_;
1055 #use Crypt::CBC; return Crypt::CBC->new(-cipher => 'Rijndael', -key => $key, -iv => $enc_iv, -regenerate_key => 0, -prepend_iv => 0)->encrypt($buffer);
1056 13 my $cipher = Crypt::Rijndael->new($key, Crypt::Rijndael::MODE_CBC());
1057 13 $cipher->set_iv($enc_iv);
1058 13 ▶ my $extra = (16 - length($buffer) % 16) || 16; # always pad so we can always trim
Condition50%1/2
16 - length($buffer) % 16 || 16
l!l
130
MC/DC0%0/1
16 - length($buffer) % 16 || 16
16 - length($buffer) % 16
Truth table50%1/2
A
A= 16 - length($buffer) % 16
Aresult
11
00
1059 13 $buffer .= chr($extra) for 1 .. $extra;
1060 13 return $cipher->encrypt($buffer);
1061 }
1062  
1063 0 ▶sub unchunksum {
Subroutine unchunksum: not called CC=5 SCAR=34.0
Pod documented
1064 0 my ($self, $buffer) = @_;
1065 0 my ($new, $pos) = ('', 0);
1066 0 ▶ while ($pos < length($buffer)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos < length $buffer) 0 0 0
1067 0 my ($index, $hash, $size) = unpack "\@$pos L a32 i", $buffer;
1068 0 $pos += 40;
1069 0 ▶ if ($size == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($size == 0) 0 0 0
1070 0 ▶ warn "Found mismatch for 0 chunksize\n" if $hash ne "\0"x32;
Branch: 1 branch
BranchTrueFalseTotal
if $hash ne "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" 0 0 0
1071 0 last;
1072 }
1073 #print "$index $hash $size\n";
1074 0 my $chunk = substr $buffer, $pos, $size;
1075 0 ▶ die "Chunk hash of index $index did not match\n" if $hash ne sha256($chunk);
Branch: 1 branch
BranchTrueFalseTotal
if $hash ne &sha256($chunk) 0 0 0
1076 0 $pos += $size;
1077 0 $new .= $chunk;
1078 }
1079 0 return $new;
1080 }
1081  
1082 0 ▶sub chunksum {
Subroutine chunksum: not called CC=2 SCAR=17.9
Pod undocumented
1083 0 my ($self, $buffer) = @_;
1084 0 my $new;
1085 0 my $index = 0;
1086 0 my $chunk_size = 8192;
1087 0 my $pos = 0;
1088 0 ▶ while ($pos < length($buffer)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos < length $buffer) 0 0 0
1089 0 my $chunk = substr($buffer, $pos, $chunk_size);
1090 0 $new .= pack "L a32 i", $index++, sha256($chunk), length($chunk);
1091 0 $new .= $chunk;
1092 0 $pos += length($chunk);
1093 }
1094 0 $new .= pack "L a32 i", $index++, "\0"x32, 0;
1095 0 return $new;
1096 }
1097  
1098 0 ▶sub decompress {
Subroutine decompress: not called CC=4 SCAR=30.0
Pod documented
1099 0 my ($self, $buffer) = @_;
1100 0 ▶ eval { require Compress::Raw::Zlib } or die "Cannot load compression library to decompress database: $@";
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require Compress::Raw::Zlib } } or die "Cannot load compression library to decompress database: $@" 0 0 0
1101 0 my ($i, $status) = Compress::Raw::Zlib::Inflate->new(-WindowBits => 31);
1102 0 ▶ die "Failed to initialize inflator ($status)\n" if $status != Compress::Raw::Zlib::Z_OK();
Branch: 1 branch
BranchTrueFalseTotal
if $status != Compress::Raw::Zlib::Z_OK() 0 0 0
1103 0 $status = $i->inflate($buffer, my $out);
1104 0 ▶ die "Failed to uncompress buffer ($status)\n" if $status != Compress::Raw::Zlib::Z_STREAM_END();
Branch: 1 branch
BranchTrueFalseTotal
if $status != Compress::Raw::Zlib::Z_STREAM_END() 0 0 0
1105 0 return $out;
1106 }
1107  
1108 0 ▶sub compress {
Subroutine compress: not called CC=5 SCAR=34.0
Pod documented
1109 0 my ($self, $buffer) = @_;
1110 0 ▶ eval { require Compress::Raw::Zlib } or die "Cannot load compression library to compress database: $@";
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require Compress::Raw::Zlib } } or die "Cannot load compression library to compress database: $@" 0 0 0
1111 0 my ($d, $status) = Compress::Raw::Zlib::Deflate->new(-WindowBits => 31, -AppendOutput => 1);
1112 0 ▶ die "Failed to initialize inflator ($status)\n" if $status != Compress::Raw::Zlib::Z_OK();
Branch: 1 branch
BranchTrueFalseTotal
if $status != Compress::Raw::Zlib::Z_OK() 0 0 0
1113 0 $status = $d->deflate($buffer, my $out);
1114 0 ▶ die "Failed to compress buffer ($status)\n" if $status != Compress::Raw::Zlib::Z_OK();
Branch: 1 branch
BranchTrueFalseTotal
if $status != Compress::Raw::Zlib::Z_OK() 0 0 0
1115 0 $status = $d->flush($out);
1116 0 ▶ die "Failed to compress buffer ($status).\n" if $status != Compress::Raw::Zlib::Z_OK();
Branch: 1 branch
BranchTrueFalseTotal
if $status != Compress::Raw::Zlib::Z_OK() 0 0 0
1117 0 return $out;
1118 }
1119  
1120 0 ▶sub decode_base64 {
Subroutine decode_base64: not called CC=2 SCAR=17.9
Pod documented
1121 0 my ($self, $content) = @_;
1122 0 ▶ eval { require MIME::Base64 } or die "Cannot load Base64 library to decode item: $@";
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require MIME::Base64 } } or die "Cannot load Base64 library to decode item: $@" 0 0 0
1123 0 return MIME::Base64::decode_base64($content);
1124 }
1125  
1126 4 ▶sub encode_base64 {
Subroutine encode_base64: called CC=2 SCAR=7.0
Pod documented
1127 4 my ($self, $content) = @_;
1128 4 ▶ eval { require MIME::Base64 } or die "Cannot load Base64 library to encode item: $@";
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require MIME::Base64 } } or die "Cannot load Base64 library to encode item: $@" 4 0 4
1129 4 ($content = MIME::Base64::encode_base64($content)) =~ s/\n//g;
1130 4 return $content;
1131 }
1132  
1133 0 ▶sub parse_xml {
Subroutine parse_xml: not called CC=6 SCAR=37.4
Pod documented
1134 0 my ($self, $buffer, $args) = @_;
1135 0 ▶ eval { require XML::Parser } or die "Cannot load XML library to parse database: $@";
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require XML::Parser } } or die "Cannot load XML library to parse database: $@" 0 0 0
1136 0 my $top = $args->{'top'};
1137 0 ▶ my $force_array = $args->{'force_array'} || {};
Condition0%0/2
$args->{'force_array'} || {}
l!l
00
MC/DC0%0/1
$args->{'force_array'} || {}
$args->{'force_array'}
Truth table0%0/2
A
A= $args->{'force_array'}
Aresult
11
00
1138 0 ▶ my $s_handlers = $args->{'start_handlers'} || {};
Condition0%0/2
$args->{'start_handlers'} || {}
l!l
00
MC/DC0%0/1
$args->{'start_handlers'} || {}
$args->{'start_handlers'}
Truth table0%0/2
A
A= $args->{'start_handlers'}
Aresult
11
00
1139 0 ▶ my $e_handlers = $args->{'end_handlers'} || $args->{'handlers'} || {};
Condition0%0/5
$args->{'end_handlers'} || $args->{'handlers'} || {}
l!l
00
$args->{"end_handlers"} or $args->{"handlers"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args->{'end_handlers'} || $args->{'handlers'} || {}
$args->{"end_handlers"} $args->{"handlers"}
Truth table0%0/3
A or B
A= $args->{"end_handlers"}B= $args->{"handlers"}
ABresult
1X1
011
000
1140 0 my $data;
1141 my $ptr;
1142 my $x = XML::Parser->new(Handlers => {
1143 0 ▶ Start => sub {
Subroutine __ANON__: not called CC=13 SCAR=52.0
1144 0 my ($x, $tag, %attr) = @_; # loses multiple values of duplicately named attrs
1145 0 my $prev_ptr = $ptr;
1146 0 ▶ $top = $tag if !defined $top;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $top 0 0 0
1147 0 ▶ if ($tag eq $top) {
Branch: 2 branches
BranchTrueFalseTotal
if ($tag eq $top) { } 0 0 0
elsif (exists $prev_ptr->{$tag} or $force_array->{$tag} and $prev_ptr->{$tag} ||= []) { } 0 0 0
1148 0 ▶ die "The $top tag should only be used at the top level.\n" if $ptr || $data;
Branch: 1 branch
BranchTrueFalseTotal
if $ptr or $data 0 0 0
Condition0%0/3
$ptr or $data
l!l&&r!l&&!r
000
MC/DC0%0/2
$ptr or $data
$ptr $data
Truth table0%0/3
A or B
A= $ptrB= $data
ABresult
1X1
011
000
1149 0 $ptr = $data = {};
1150 ▶ } elsif (exists($prev_ptr->{$tag}) || ($force_array->{$tag} and $prev_ptr->{$tag} ||= [])) {
Condition0%0/8
exists $prev_ptr->{$tag} or $force_array->{$tag} and $prev_ptr->{$tag} ||= []
l!l&&r!l&&!r
000
$force_array->{$tag} and $prev_ptr->{$tag} ||= []
!ll&&!rl&&r
000
$prev_ptr->{$tag} ||= []
l!l
00
MC/DC0%0/3
exists $prev_ptr->{$tag} or $force_array->{$tag} and $prev_ptr->{$tag} ||= []
exists $prev_ptr->{$tag} $force_array->{$tag} $prev_ptr->{$tag}
Truth table0%0/4
A or B and C
A= exists $prev_ptr->{$tag}B= $force_array->{$tag}C= $prev_ptr->{$tag}
ABCresult
1XX1
0111
00X0
0100
1151 0 ▶ $prev_ptr->{$tag} = [$prev_ptr->{$tag}] if 'ARRAY' ne ref $prev_ptr->{$tag};
Branch: 1 branch
BranchTrueFalseTotal
if "ARRAY" ne ref $prev_ptr->{$tag} 0 0 0
1152 0 push @{ $prev_ptr->{$tag} }, ($ptr = {});
1153 } else {
1154 0 ▶ $ptr = $prev_ptr->{$tag} ||= {};
Condition0%0/2
$prev_ptr->{$tag} ||= {}
l!l
00
MC/DC0%0/1
$prev_ptr->{$tag} ||= {}
$prev_ptr->{$tag}
Truth table0%0/2
A
A= $prev_ptr->{$tag}
Aresult
11
00
1155 }
1156 0 @$ptr{keys %attr} = values %attr;
1157 0 ▶ $_->($ptr, $prev_ptr, $prev_ptr->{'__tag__'}, $tag) if $_ = $s_handlers->{$tag} || $s_handlers->{'__any__'};
Branch: 1 branch
BranchTrueFalseTotal
if $_ = $s_handlers->{$tag} || $s_handlers->{"__any__"} 0 0 0
Condition0%0/3
$s_handlers->{$tag} || $s_handlers->{'__any__'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$s_handlers->{$tag} || $s_handlers->{'__any__'}
$s_handlers->{$tag} $s_handlers->{'__any__'}
Truth table0%0/3
A || B
A= $s_handlers->{$tag}B= $s_handlers->{'__any__'}
ABresult
1X1
011
000
1158 0 @$ptr{qw(__parent__ __tag__)} = ($prev_ptr, $tag);
1159 },
1160 0 ▶ End => sub {
Subroutine __ANON__: not called CC=9 SCAR=45.0
1161 0 my ($x, $tag) = @_;
1162 0 my $cur_ptr = $ptr;
1163 0 $ptr = delete $cur_ptr->{'__parent__'};
1164 0 ▶ die "End tag mismatch on $tag.\n" if $tag ne delete($cur_ptr->{'__tag__'});
Branch: 1 branch
BranchTrueFalseTotal
if $tag ne delete $cur_ptr->{"__tag__"} 0 0 0
1165 0 my $n_keys = scalar keys %$cur_ptr;
1166 0 ▶ if (!$n_keys) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $n_keys) { } 0 0 0
elsif (exists $cur_ptr->{'content'}) { } 0 0 0
1167 0 $ptr->{$tag} = ''; # SuppressEmpty
1168 } elsif (exists $cur_ptr->{'content'}) {
1169 0 ▶ if ($n_keys == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($n_keys == 1) { } 0 0 0
elsif (not $cur_ptr->{'content'} =~ /\S/) { } 0 0 0
1170 0 ▶ if ($ptr->{$tag} eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ptr->{$tag} eq 'ARRAY') { } 0 0 0
1171 0 $ptr->{$tag}->[-1] = $cur_ptr->{'content'};
1172 } else {
1173 0 $ptr->{$tag} = $cur_ptr->{'content'};
1174 }
1175 } elsif ($cur_ptr->{'content'} !~ /\S/) {
1176 0 delete $cur_ptr->{'content'};
1177 }
1178 }
1179 0 ▶ $_->($cur_ptr, $ptr, $ptr->{'__tag__'}, $tag) if $_ = $e_handlers->{$tag} || $e_handlers->{'__any__'};
Branch: 1 branch
BranchTrueFalseTotal
if $_ = $e_handlers->{$tag} || $e_handlers->{"__any__"} 0 0 0
Condition0%0/3
$e_handlers->{$tag} || $e_handlers->{'__any__'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$e_handlers->{$tag} || $e_handlers->{'__any__'}
$e_handlers->{$tag} $e_handlers->{'__any__'}
Truth table0%0/3
A || B
A= $e_handlers->{$tag}B= $e_handlers->{'__any__'}
ABresult
1X1
011
000
1180 },
1181 0 ▶ Char => sub { if (defined $ptr->{'content'}) { $ptr->{'content'} .= $_[1] } else { $ptr->{'content'} = $_[1] } },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ptr->{'content'}) { } 0 0 0
1182 0 });
1183 0 $x->parse($buffer);
1184 0 return $data;
1185 }
1186  
1187 0 ▶sub gen_xml {
Subroutine gen_xml: not called CC=10 SCAR=47.0
Pod documented
1188 0 my ($self, $ref, $args) = @_;
1189 0 ▶ my $indent = !$args->{'indent'} ? '' : $args->{'indent'} eq "1" ? " " : $args->{'indent'};
Branch: 2 branches
BranchTrueFalseTotal
!$args->{'indent'} ? : 0 0 0
$args->{'indent'} eq '1' ? : 0 0 0
1190 0 my $level = 0;
1191 0 ▶ my $top = $args->{'top'} || 'root';
Condition0%0/2
$args->{'top'} || 'root'
l!l
00
MC/DC0%0/1
$args->{'top'} || 'root'
$args->{'top'}
Truth table0%0/2
A
A= $args->{'top'}
Aresult
11
00
1192 0 ▶ my $xml = $args->{'declaration'} || '';
Condition0%0/2
$args->{'declaration'} || ''
l!l
00
MC/DC0%0/1
$args->{'declaration'} || ''
$args->{'declaration'}
Truth table0%0/2
A
A= $args->{'declaration'}
Aresult
11
00
1193 0 ▶ $xml .= "\n" . ($indent x $level) if $xml && $indent;
Branch: 1 branch
BranchTrueFalseTotal
if $xml and $indent 0 0 0
Condition0%0/3
$xml and $indent
!ll&&!rl&&r
000
MC/DC0%0/2
$xml and $indent
$xml $indent
Truth table0%0/3
A and B
A= $xmlB= $indent
ABresult
0X0
100
111
1194 0 $xml .= "<$top>";
1195 0 ▶ my $rec; $rec = sub {
Subroutine __ANON__: not called CC=19 SCAR=59.4
1196 0 $level++;
1197 0 my ($ref, $tag) = @_;
1198 0 my $n = 0;
1199 0 ▶ my $order = delete($ref->{'__sort__'}) || $args->{'sort'}->{$tag} || [sort grep {$_ ne '__attr__'} keys %$ref];
Condition0%0/5
delete $ref->{'__sort__'} || $args->{'sort'}{$tag} || [sort(grep({$_ ne '__attr__';} keys %$ref))]
l!l
00
delete $ref->{"__sort__"} or $args->{"sort"}{$tag}
l!l&&r!l&&!r
000
MC/DC0%0/2
delete $ref->{'__sort__'} || $args->{'sort'}{$tag} || [sort(grep({$_ ne '__attr__';} keys %$ref))]
delete $ref->{"__sort__"} $args->{"sort"}{$tag}
Truth table0%0/3
A or B
A= delete $ref->{"__sort__"}B= $args->{"sort"}{$tag}
ABresult
1X1
011
000
1200 0 for my $key (@$order) {
1201 0 ▶ next if ! exists $ref->{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $ref->{$key} 0 0 0
1202 0 ▶ for my $node (ref($ref->{$key}) eq 'ARRAY' ? @{ $ref->{$key} } : $ref->{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
ref $ref->{$key} eq 'ARRAY' ? : 0 0 0
1203 0 $n++;
1204 0 ▶ $xml .= "\n" . ($indent x $level) if $indent;
Branch: 1 branch
BranchTrueFalseTotal
if $indent 0 0 0
1205 0 ▶ if (!ref $node) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $node) 0 0 0
1206 0 ▶ $xml .= (!defined($node) || !length($node)) ? "<$key />" : "<$key>".$self->escape_xml($node)."</$key>";
Branch: 1 branch
BranchTrueFalseTotal
!(defined $node && length $node) ? : 0 0 0
Condition0%0/3
defined $node && length $node
!ll&&!rl&&r
000
MC/DC0%0/2
defined $node && length $node
defined $node length $node
Truth table0%0/3
A && B
A= defined $nodeB= length $node
ABresult
0X0
100
111
1207 0 next;
1208 }
1209 0 ▶ if ($node->{'__attr__'} || exists($node->{'content'})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->{'__attr__'} or exists $node->{'content'}) { } 0 0 0
Condition0%0/3
$node->{"__attr__"} or exists $node->{"content"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$node->{"__attr__"} or exists $node->{"content"}
$node->{"__attr__"} exists $node->{"content"}
Truth table0%0/3
A or B
A= $node->{"__attr__"}B= exists $node->{"content"}
ABresult
1X1
011
000
1210 0 ▶ $xml .= "<$key".join('', map {" $_=\"".$self->escape_xml($node->{$_})."\""} @{$node->{'__attr__'}||[sort grep {$_ ne 'content'} keys %$node]}).">";
Condition0%0/2
$node->{'__attr__'} || [sort(grep({$_ ne 'content';} keys %$node))]
l!l
00
MC/DC0%0/1
$node->{'__attr__'} || [sort(grep({$_ ne 'content';} keys %$node))]
$node->{'__attr__'}
Truth table0%0/2
A
A= $node->{'__attr__'}
Aresult
11
00
1211 } else {
1212 0 $xml .= "<$key>";
1213 }
1214 0 ▶ if (exists $node->{'content'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $node->{"content"}) 0 0 0
1215 0 ▶ if (defined($node->{'content'}) && length $node->{'content'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $node->{'content'} and length $node->{'content'}) { } 0 0 0
Condition0%0/3
defined $node->{"content"} and length $node->{"content"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $node->{"content"} and length $node->{"content"}
defined $node->{"content"} length $node->{"content"}
Truth table0%0/3
A and B
A= defined $node->{"content"}B= length $node->{"content"}
ABresult
0X0
100
111
1216 0 $xml .= $self->escape_xml($node->{'content'}) . "</$key>";
1217 } else {
1218 0 $xml =~ s|(>\s*)$| /$1|;
1219 }
1220 0 next;
1221 }
1222 0 ▶ if ($rec->($node, $key)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&$rec($node, $key)) { } 0 0 0
1223 0 ▶ $xml .= "\n" . ($indent x $level) if $indent;
Branch: 1 branch
BranchTrueFalseTotal
if $indent 0 0 0
1224 0 $xml .= "</$key>";
1225 } else {
1226 0 $xml =~ s|(>\s*)$| /$1|;
1227 }
1228 }
1229 }
1230 0 $level--;
1231 0 return $n;
1232 0 };
1233 0 $rec->($ref, $top);
1234 0 ▶ $xml .= "\n" . ($indent x $level) if $indent;
Branch: 1 branch
BranchTrueFalseTotal
if $indent 0 0 0
1235 0 $xml .= "</$top>";
1236 0 ▶ $xml .= "\n" if $indent && ! $args->{'no_trailing_newline'};
Branch: 1 branch
BranchTrueFalseTotal
if $indent and not $args->{"no_trailing_newline"} 0 0 0
Condition0%0/3
$indent and not $args->{"no_trailing_newline"}
!ll&&!rl&&r
000
MC/DC0%0/2
$indent and not $args->{"no_trailing_newline"}
$indent not $args->{"no_trailing_newline"}
Truth table0%0/3
A and not(B)
A= $indentB= not $args->{"no_trailing_newline"}
ABresult
0X0
100
111
1237 0 return $xml;
1238 }
1239  
1240 0 ▶sub escape_xml {
Subroutine escape_xml: not called CC=2 SCAR=17.9
Pod undocumented
1241 0 my $self = shift;
1242 0 local $_ = shift;
1243 0 ▶ return '' if ! defined;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ 0 0 0
1244 0 s/&/&amp;/g;
1245 0 s/</&lt;/g;
1246 0 s/>/&gt;/g;
1247 0 s/"/&quot;/g;
1248 0 s/([^\x00-\x7F])/'&#'.(ord $1).';'/ge;
1249 0 return $_;
1250 }
1251  
1252 19 ▶sub uuid {
Subroutine uuid: called CC=9 SCAR=30.1
Pod undocumented
1253 19 my ($self, $id, $uniq) = @_;
1254 19 ▶ $id = $self->gen_uuid if !defined($id) || !length($id);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $id and length $id 3 16 19
Condition66%2/3
defined $id and length $id
!ll&&!rl&&r
3016
MC/DC50%1/2
defined $id and length $id
defined $id length $id
Truth table66%2/3
A and B
A= defined $idB= length $id
ABresult
0X0
100
111
1255 19 ▶ return $uniq->{$id} ||= do {
Condition33%1/3
$uniq->{$id} ||= do { if (length $id != 16) { $id = substr($self->encode_base64($id), 0, 16) if not $id =~ /^\d+$/ or $id > 4294967295; $id = sprintf("%016s", $id) if $id ne 0; } ; $id = $self->gen_uuid while $uniq->{$id}++; $id }
l!l&&r!l&&!r
0190
MC/DC0%0/2
$uniq->{$id} ||= do { if (length $id != 16) { $id = substr($self->encode_base64($id), 0, 16) if not $id =~ /^\d+$/ or $id > 4294967295; $id = sprintf("%016s", $id) if $id ne 0; } ; $id = $self->gen_uuid while $uniq->{$id}++; $id }
$uniq->{$id} do { if (length $id != 16) { $id = substr($self->encode_base64($id), 0, 16) if not $id =~ /^\d+$/ or $id > 4294967295; $id = sprintf("%016s", $id) if $id ne 0; } ; $id = $self->gen_uuid while $uniq->{$id}++; $id }
Truth table33%1/3
A ||= B
A= $uniq->{$id}B= do { if (length $id != 16) { $id = substr($self->encode_base64($id), 0, 16) if not $id =~ /^\d+$/ or $id > 4294967295; $id = sprintf("%016s", $id) if $id ne 0; } ; $id = $self->gen_uuid while $uniq->{$id}++; $id }
ABresult
1X1
011
000
1256 19 ▶ if (length($id) != 16) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $id != 16) 0 19 19
1257 0 ▶ $id = substr($self->encode_base64($id), 0, 16) if $id !~ /^\d+$/ || $id > 2**32-1;
Branch: 1 branch
BranchTrueFalseTotal
if not $id =~ /^\d+$/ or $id > 4294967295 0 0 0
Condition0%0/3
not $id =~ /^\d+$/ or $id > 4294967295
l!l&&r!l&&!r
000
MC/DC0%0/2
not $id =~ /^\d+$/ or $id > 4294967295
not $id =~ /^\d+$/ $id > 4294967295
Truth table0%0/3
not(A) or B
A= not $id =~ /^\d+$/B= $id > 4294967295
ABresult
1X1
011
000
1258 0 ▶ $id = sprintf '%016s', $id if $id ne '0';
Branch: 1 branch
BranchTrueFalseTotal
if $id ne 0 0 0 0
1259 }
1260 19 ▶ $id = $self->gen_uuid while $uniq->{$id}++;
Branch: 1 branch
BranchTrueFalseTotal
$uniq->{$id}++ and do { $id = $self->gen_uuid } 0 19 19
1261 19 $id;
1262 };
1263 }
1264  
1265 4 ▶sub gen_uuid { shift->encode_base64(join '', map {chr rand 256} 1..12) } # (3072 bit vs 4096) only 8e28 entries vs 3e38 - but readable
Subroutine gen_uuid: called CC=1 SCAR=0.0
Pod undocumented
1266  
1267 ###----------------------------------------------------------------###
1268  
1269 7 ▶sub dump_groups {
Subroutine dump_groups: called CC=6 SCAR=18.4
Pod documented
1270 7 my ($self, $args, $groups) = @_;
1271 7 my $t = '';
1272 0 ▶ my %gargs; for (keys %$args) { $gargs{$2} = $args->{$1} if /^(group_(.+))$/ };
Branch: 1 branch
BranchTrueFalseTotal
if /^(group_(.+))$/ 0 0 0
1273 7 foreach my $g ($self->find_groups(\%gargs, $groups)) {
1274 32 my $indent = ' ' x $g->{'level'};
1275 32 ▶ $t .= $indent.($g->{'expanded'} ? '-' : '+')." $g->{'title'} ($g->{'id'}) $g->{'created'}\n";
Branch: 1 branch
BranchTrueFalseTotal
$g->{'expanded'} ? : 3 29 32
1276 32 local $g->{'groups'}; # don't recurse while looking for entries since we are already flat
1277 32 $t .= "$indent > $_->{'title'}\t($_->{'id'}) $_->{'created'}\n" for $self->find_entries($args, [$g]);
1278 }
1279 7 return $t;
1280 }
1281  
1282 21 ▶sub add_group {
Subroutine add_group: called CC=10 SCAR=23.6
Pod documented
1283 21 my ($self, $args, $top_groups) = @_;
1284 21 $args = {%$args};
1285 21 my $groups;
1286 21 my $parent_group = delete $args->{'group'};
1287 21 ▶ if (defined $parent_group) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $parent_group) 11 10 21
1288 11 ▶ $parent_group = $self->find_group({id => $parent_group}, $top_groups) if ! ref($parent_group);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $parent_group 1 10 11
1289 11 ▶ $groups = $parent_group->{'groups'} ||= [] if $parent_group;
Branch: 1 branch
BranchTrueFalseTotal
if $parent_group 11 0 11
Condition100%2/2
$parent_group->{"groups"} ||= []
l!l
56
MC/DC100%1/1
$parent_group->{"groups"} ||= []
$parent_group->{"groups"}
Truth table100%2/2
A
A= $parent_group->{"groups"}
Aresult
11
00
1290 }
1291 21 ▶ $groups ||= $top_groups || ($self->{'groups'} ||= []);
Condition62%5/8
$groups ||= $top_groups || ($self->{"groups"} ||= [])
l!l&&r!l&&!r
11100
$top_groups || ($self->{'groups'} ||= [])
l!l&&r!l&&!r
0100
$self->{"groups"} ||= []
l!l
55
MC/DC0%0/3
$groups ||= $top_groups || ($self->{"groups"} ||= [])
$groups $top_groups ($self->{'groups'} ||= [])
MC/DC100%1/1
$self->{"groups"} ||= []
$self->{"groups"}
Truth table0%0/4
A ||= B || C
A= $groupsB= $top_groupsC= ($self->{'groups'} ||= [])
ABCresult
1XX1
01X1
0011
0000
Truth table100%2/2
A
A= $self->{"groups"}
Aresult
11
00
1292  
1293 21 $args->{$_} = $self->now for grep {!defined $args->{$_}} qw(created accessed modified);;
1294 21 ▶ $args->{'expires'} ||= $self->default_exp;
Condition33%1/3
$args->{"expires"} ||= $self->default_exp
l!l&&r!l&&!r
0210
MC/DC0%0/2
$args->{"expires"} ||= $self->default_exp
$args->{"expires"} $self->default_exp
Truth table33%1/3
A ||= B
A= $args->{"expires"}B= $self->default_exp
ABresult
1X1
011
000
1295  
1296 21 push @$groups, $args;
1297 21 $self->find_groups({}, $groups); # sets title, level, icon and id
1298 21 return $args;
1299 }
1300  
1301 265 ▶sub finder_tests {
Subroutine finder_tests: called CC=12 SCAR=25.6
Pod documented
1302 265 my ($self, $args) = @_;
1303 265 my @tests;
1304 265 ▶ foreach my $key (keys %{ $args || {} }) {
Condition50%1/2
$args || {}
l!l
2650
MC/DC0%0/1
$args || {}
$args
Truth table50%1/2
A
A= $args
Aresult
11
00
1305 68 ▶ next if ! defined $args->{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args->{$key} 1 67 68
1306 67 ▶ my ($field, $op) = ($key =~ m{ ^ (\w+) \s* (|!|=|!~|=~|gt|lt) $ }x) ? ($1, $2) : die "Invalid find match criteria \"$key\"\n";
Branch: 1 branch
BranchTrueFalseTotal
$key =~ / ^ (\w+) \s* (|!|=|!~|=~|gt|lt) $ /x ? : 67 0 67
1307 89 ▶ push @tests, (!$op || $op eq '=') ? sub { defined($_[0]->{$field}) && $_[0]->{$field} eq $args->{$key} }
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]{$field} and $_[0]{$field} eq $args->{$key} 89 0 89
1308 2 ▶ : ($op eq '!') ? sub { !defined($_[0]->{$field}) || $_[0]->{$field} ne $args->{$key} }
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
not defined $_[0]{$field} or $_[0]{$field} ne $args->{$key} 0 2 2
1309 2 ▶ : ($op eq '=~') ? sub { defined($_[0]->{$field}) && $_[0]->{$field} =~ $args->{$key} }
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]{$field} and $_[0]{$field} =~ /$args->{$key}/ 2 0 2
1310 2 ▶ : ($op eq '!~') ? sub { !defined($_[0]->{$field}) || $_[0]->{$field} !~ $args->{$key} }
Subroutine __ANON__: called CC=2 SCAR=7.2
Condition66%2/3
defined $_[0]{$field} && $_[0]{$field} =~ /$args->{$key}/
!ll&&!rl&&r
011
MC/DC50%1/2
defined $_[0]{$field} && $_[0]{$field} =~ /$args->{$key}/
defined $_[0]{$field} $_[0]{$field} =~ /$args->{$key}/
Truth table66%2/3
A && B
A= defined $_[0]{$field}B= $_[0]{$field} =~ /$args->{$key}/
ABresult
0X0
100
111
1311 4 ▶ : ($op eq 'gt') ? sub { defined($_[0]->{$field}) && $_[0]->{$field} gt $args->{$key} }
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]{$field} and $_[0]{$field} gt $args->{$key} 4 0 4
1312 2 ▶ : ($op eq 'lt') ? sub { defined($_[0]->{$field}) && $_[0]->{$field} lt $args->{$key} }
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]{$field} and $_[0]{$field} lt $args->{$key} 2 0 2
1313 67 ▶ : die "Unknown op \"$op\"\n";
Branch: 6 branches
BranchTrueFalseTotal
!$op || $op eq '=' ? : 56 11 67
$op eq '!' ? : 2 9 11
$op eq '=~' ? : 2 7 9
$op eq '!~' ? : 2 5 7
$op eq 'gt' ? : 3 2 5
$op eq 'lt' ? : 2 0 2
Condition100%3/3
not $op or $op eq "="
l!l&&r!l&&!r
52411
MC/DC100%2/2
not $op or $op eq "="
not $op $op eq "="
Truth table100%3/3
not(A) or B
A= not $opB= $op eq "="
ABresult
1X1
011
000
1314 }
1315 265 return @tests;
1316 }
1317  
1318 207 ▶sub find_groups {
Subroutine find_groups: called CC=13 SCAR=25.8
Pod documented
1319 207 my ($self, $args, $groups, $level) = @_;
1320 207 my @tests = $self->finder_tests($args);
1321 207 my @groups;
1322 my %uniq;
1323 207 ▶ my $container = $groups || $self->groups;
Condition66%2/3
$groups || $self->groups
l!l&&r!l&&!r
162450
MC/DC0%0/2
$groups || $self->groups
$groups $self->groups
Truth table66%2/3
A || B
A= $groupsB= $self->groups
ABresult
1X1
011
000
1324 207 for my $g (@$container) {
1325 259 ▶ $g->{'level'} = $level || 0;
Condition100%2/2
$level || 0
l!l
105154
MC/DC100%1/1
$level || 0
$level
Truth table100%2/2
A
A= $level
Aresult
11
00
1326 259 ▶ $g->{'title'} = '' if ! defined $g->{'title'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $g->{"title"} 2 257 259
1327 259 ▶ $g->{'icon'} ||= 0;
Condition100%2/2
$g->{"icon"} ||= 0
l!l
60199
MC/DC100%1/1
$g->{"icon"} ||= 0
$g->{"icon"}
Truth table100%2/2
A
A= $g->{"icon"}
Aresult
11
00
1328 259 ▶ if ($self->{'force_v2_gid'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'force_v2_gid'}) { } 0 259 259
1329 0 $g->{'id'} = $self->uuid($g->{'id'}, \%uniq);
1330 } else {
1331 259 ▶ $g->{'id'} = int(rand 2**32-1) while !defined($g->{'id'}) || $uniq{$g->{'id'}}++; # the non-v2 gid is compatible with both v1 and our v2 implementation
Branch: 1 branch
BranchTrueFalseTotal
!defined($g->{"id"}) || $uniq{$g->{"id"}}++ and do { $g->{"id"} = int rand 4294967295 } 21 259 280
Condition66%2/3
not defined $g->{"id"} or $uniq{$g->{"id"}}++
l!l&&r!l&&!r
210259
MC/DC50%1/2
not defined $g->{"id"} or $uniq{$g->{"id"}}++
not defined $g->{"id"} $uniq{$g->{"id"}}++
Truth table66%2/3
not(A) or B
A= not defined $g->{"id"}B= $uniq{$g->{"id"}}++
ABresult
1X1
011
000
1332 }
1333  
1334 259 ▶ if (!@tests || !grep{!$_->($g)} @tests) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@tests and grep {not &$_($g);} @tests) 234 25 259
Condition100%3/3
@tests and grep {not &$_($g);} @tests
!ll&&!rl&&r
2171725
MC/DC100%2/2
@tests and grep {not &$_($g);} @tests
@tests grep {not &$_($g);} @tests
Truth table100%3/3
A and B
A= @testsB= grep {not &$_($g);} @tests
ABresult
0X0
100
111
1335 234 push @groups, $g;
1336 234 ▶ push @{ $self->{'__group_groups'} }, $container if $self->{'__group_groups'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"__group_groups"} 7 227 234
1337 }
1338 259 ▶ push @groups, $self->find_groups($args, $g->{'groups'}, $g->{'level'} + 1) if $g->{'groups'};
Branch: 1 branch
BranchTrueFalseTotal
if $g->{"groups"} 86 173 259
1339 }
1340 207 return @groups;
1341 }
1342  
1343 22 ▶sub find_group {
Subroutine find_group: called CC=4 SCAR=13.9
Pod documented
1344 22 my $self = shift;
1345 22 ▶ local $self->{'__group_groups'} = [] if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 6 16 22
1346 22 my @g = $self->find_groups(@_);
1347 22 ▶ die "Found too many groups (@g)\n" if @g > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @g > 1 1 21 22
1348 21 ▶ return wantarray ? ($g[0], $self->{'__group_groups'}->[0]) : $g[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 5 16 21
1349 }
1350  
1351 5 ▶sub delete_group {
Subroutine delete_group: called CC=5 SCAR=16.5
Pod documented
1352 5 my $self = shift;
1353 5 my ($g, $c) = $self->find_group(@_);
1354 4 ▶ return if !$g || !$c;
Branch: 1 branch
BranchTrueFalseTotal
unless $g and $c 0 4 4
Condition33%1/3
$g and $c
!ll&&!rl&&r
004
MC/DC0%0/2
$g and $c
$g $c
Truth table33%1/3
A and B
A= $gB= $c
ABresult
0X0
100
111
1355 4 for my $i (0 .. $#$c) {
1356 8 ▶ next if $c->[$i] ne $g;
Branch: 1 branch
BranchTrueFalseTotal
if $c->[$i] ne $g 4 4 8
1357 4 splice(@$c, $i, 1, ());
1358 4 last;
1359 }
1360 4 return $g;
1361 }
1362  
1363 ###----------------------------------------------------------------###
1364  
1365 6 ▶sub add_entry {
Subroutine add_entry: called CC=16 SCAR=28.7
Pod documented
1366 6 my ($self, $args, $groups) = @_;
1367 6 ▶ $groups ||= eval { $self->groups } || [];
Condition60%3/5
$groups ||= eval { do { $self->groups } } || []
l!l&&r!l&&!r
060
eval { do { $self->groups } } || []
l!l
42
MC/DC0%0/2
$groups ||= eval { do { $self->groups } } || []
$groups eval { do { $self->groups } }
Truth table33%1/3
A ||= B
A= $groupsB= eval { do { $self->groups } }
ABresult
1X1
011
000
1368 6 ▶ die "You must unlock the passwords before adding new entries.\n" if $self->is_locked($groups);
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_locked($groups) 0 6 6
1369 6 $args = {%$args};
1370 6 ▶ my $group = delete($args->{'group'}) || $groups->[0] || $self->add_group({});
Condition83%5/6
delete $args->{'group'} || $groups->[0] || $self->add_group({})
l!l&&r!l&&!r
420
delete $args->{"group"} or $groups->[0]
l!l&&r!l&&!r
312
MC/DC0%0/3
delete $args->{'group'} || $groups->[0] || $self->add_group({})
delete $args->{"group"} $groups->[0] $self->add_group({})
Truth table75%3/4
A or B || C
A= delete $args->{"group"}B= $groups->[0]C= $self->add_group({})
ABCresult
1XX1
01X1
0011
0000
1371 6 ▶ if (! ref($group)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $group) 0 6 6
1372 0 ▶ $group = $self->find_group({id => $group}, $groups) || die "Could not find a matching group to add entry to.\n";
Condition0%0/2
$self->find_group({'id', $group}, $groups) || die("Could not find a matching group to add entry to.\n")
l!l
00
MC/DC0%0/1
$self->find_group({'id', $group}, $groups) || die("Could not find a matching group to add entry to.\n")
$self->find_group({'id', $group}, $groups)
Truth table0%0/2
A
A= $self->find_group({'id', $group}, $groups)
Aresult
11
00
1373 }
1374  
1375 6 my %uniq;
1376 6 foreach my $g ($self->find_groups({}, $groups)) {
1377 8 ▶ $uniq{$_->{'id'}}++ for @{ $g->{'entries'} || [] };
Condition100%2/2
$g->{'entries'} || []
l!l
53
MC/DC100%1/1
$g->{'entries'} || []
$g->{'entries'}
Truth table100%2/2
A
A= $g->{'entries'}
Aresult
11
00
1378 }
1379 6 $args->{'id'} = $self->uuid($args->{'id'}, \%uniq);
1380 6 $args->{$_} = '' for grep {!defined $args->{$_}} qw(title url username password comment);
1381 6 $args->{$_} = 0 for grep {!defined $args->{$_}} qw(icon);
1382 6 $args->{$_} = $self->now for grep {!defined $args->{$_}} qw(created accessed modified);
1383 6 ▶ $args->{'expires'} ||= $self->default_exp;
Condition66%2/3
$args->{"expires"} ||= $self->default_exp
l!l&&r!l&&!r
150
MC/DC0%0/2
$args->{"expires"} ||= $self->default_exp
$args->{"expires"} $self->default_exp
Truth table66%2/3
A ||= B
A= $args->{"expires"}B= $self->default_exp
ABresult
1X1
011
000
1384 6 $self->_check_v1_binary($args);
1385 6 $self->_check_v1_auto_type($args);
1386  
1387  
1388 6 ▶ push @{ $group->{'entries'} ||= [] }, $args;
Condition100%2/2
$group->{"entries"} ||= []
l!l
24
MC/DC100%1/1
$group->{"entries"} ||= []
$group->{"entries"}
Truth table100%2/2
A
A= $group->{"entries"}
Aresult
11
00
1389 6 return $args;
1390 }
1391  
1392 58 ▶sub find_entries {
Subroutine find_entries: called CC=8 SCAR=20.8
Pod documented
1393 58 my ($self, $args, $groups) = @_;
1394 58 ▶ local @{ $args }{'expires gt', 'active'} = ($self->now, undef) if $args->{'active'};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"active"} 1 57 58
1395 58 my @tests = $self->finder_tests($args);
1396 58 my @entries;
1397 58 foreach my $g ($self->find_groups({}, $groups)) {
1398 101 ▶ foreach my $e (@{ $g->{'entries'} || [] }) {
Condition100%2/2
$g->{'entries'} || []
l!l
4556
MC/DC100%1/1
$g->{'entries'} || []
$g->{'entries'}
Truth table100%2/2
A
A= $g->{'entries'}
Aresult
11
00
1399 43 local $e->{'group_id'} = $g->{'id'};
1400 43 local $e->{'group_title'} = $g->{'title'};
1401 43 ▶ if (!@tests || !grep{!$_->($e)} @tests) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@tests and grep {not &$_($e);} @tests) 27 16 43
Condition100%3/3
@tests and grep {not &$_($e);} @tests
!ll&&!rl&&r
141316
MC/DC100%2/2
@tests and grep {not &$_($e);} @tests
@tests grep {not &$_($e);} @tests
Truth table100%3/3
A and B
A= @testsB= grep {not &$_($e);} @tests
ABresult
0X0
100
111
1402 27 push @entries, $e;
1403 27 ▶ push @{ $self->{'__entry_groups'} }, $g if $self->{'__entry_groups'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"__entry_groups"} 5 22 27
1404 }
1405 }
1406 }
1407 58 return @entries;
1408 }
1409  
1410 10 ▶sub find_entry {
Subroutine find_entry: called CC=4 SCAR=13.9
Pod documented
1411 10 my $self = shift;
1412 10 ▶ local $self->{'__entry_groups'} = [] if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 4 6 10
1413 10 my @e = $self->find_entries(@_);
1414 10 ▶ die "Found too many entries (@e)\n" if @e > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @e > 1 1 9 10
1415 9 ▶ return wantarray ? ($e[0], $self->{'__entry_groups'}->[0]) : $e[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 3 6 9
1416 }
1417  
1418 2 ▶sub delete_entry {
Subroutine delete_entry: called CC=6 SCAR=19.0
Pod documented
1419 2 my $self = shift;
1420 2 my ($e, $g) = $self->find_entry(@_);
1421 1 ▶ return if !$e || !$g;
Branch: 1 branch
BranchTrueFalseTotal
unless $e and $g 0 1 1
Condition33%1/3
$e and $g
!ll&&!rl&&r
001
MC/DC0%0/2
$e and $g
$e $g
Truth table33%1/3
A and B
A= $eB= $g
ABresult
0X0
100
111
1422 1 ▶ for my $i (0 .. $#{ $g->{'entries'} || [] }) {
Condition50%1/2
$g->{'entries'} || []
l!l
10
MC/DC0%0/1
$g->{'entries'} || []
$g->{'entries'}
Truth table50%1/2
A
A= $g->{'entries'}
Aresult
11
00
1423 1 ▶ next if $g->{'entries'}->[$i] ne $e;
Branch: 1 branch
BranchTrueFalseTotal
if $g->{"entries"}[$i] ne $e 0 1 1
1424 1 splice(@{ $g->{'entries'} }, $i, 1, ());
1425 1 last;
1426 }
1427 1 return $e;
1428 }
1429  
1430 80 ▶sub now {
Subroutine now: called CC=2 SCAR=7.1
Pod documented
1431 80 my ($self, $time) = @_;
1432 80 ▶ my ($sec, $min, $hour, $day, $mon, $year) = localtime($time || time);
Condition50%1/2
$time || time
l!l
080
MC/DC0%0/1
$time || time
$time
Truth table50%1/2
A
A= $time
Aresult
11
00
1433 80 return sprintf '%04d-%02d-%02d %02d:%02d:%02d', $year+1900, $mon+1, $day, $hour, $min, $sec;
1434 }
1435  
1436 26 ▶sub default_exp { shift->{'default_exp'} || '2999-12-31 23:23:59' }
Subroutine default_exp: called CC=2 SCAR=7.6
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
+(shift())->{"default_exp"} or "2999-12-31 23:23:59" 0 26 26
1437  
1438 ###----------------------------------------------------------------###
1439  
1440 17 ▶sub is_locked {
Subroutine is_locked: called CC=3 SCAR=11.0
Pod documented
1441 17 my $self = shift;
1442 17 ▶ my $groups = shift || $self->groups;
Condition66%2/3
shift() || $self->groups
l!l&&r!l&&!r
1340
MC/DC0%0/2
shift() || $self->groups
shift() $self->groups
Truth table66%2/3
A || B
A= shift()B= $self->groups
ABresult
1X1
011
000
1443 17 ▶ return $locker{"$groups"} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$locker{"$groups"} ? : 2 15 17
1444 }
1445  
1446 5 ▶sub lock {
Subroutine lock: called CC=5 SCAR=16.5
Pod documented
1447 5 my $self = shift;
1448 5 ▶ my $groups = shift || $self->groups;
Condition33%1/3
shift() || $self->groups
l!l&&r!l&&!r
050
MC/DC0%0/2
shift() || $self->groups
shift() $self->groups
Truth table33%1/3
A || B
A= shift()B= $self->groups
ABresult
1X1
011
000
1449 5 ▶ return 2 if $locker{"$groups"}; # not quite as fast as Scalar::Util::refaddr
Branch: 1 branch
BranchTrueFalseTotal
if $locker{"$groups"} 0 5 5
1450  
1451 5 my $ref = $locker{"$groups"} = {};
1452 5 $ref->{'_key'} = join '', map {chr rand 256} 1..32;
1453 5 $ref->{'_enc_iv'} = join '', map {chr rand 256} 1..16;
1454  
1455 5 foreach my $e ($self->find_entries({}, $groups)) {
1456 6 ▶ my $pass = delete $e->{'password'}; $pass = '' if ! defined $pass;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pass 0 6 6
1457 6 $ref->{"$e"} = $self->encrypt_rijndael_cbc($pass, $ref->{'_key'}, $ref->{'_enc_iv'}); # we don't leave plaintext in memory
1458 }
1459  
1460 5 return 1;
1461 }
1462  
1463 13 ▶sub unlock {
Subroutine unlock: called CC=6 SCAR=18.3
Pod documented
1464 13 my $self = shift;
1465 13 ▶ my $groups = shift || $self->groups;
Condition33%1/3
shift() || $self->groups
l!l&&r!l&&!r
0130
MC/DC0%0/2
shift() || $self->groups
shift() $self->groups
Truth table33%1/3
A || B
A= shift()B= $self->groups
ABresult
1X1
011
000
1466 13 ▶ return 2 if !$locker{"$groups"};
Branch: 1 branch
BranchTrueFalseTotal
unless $locker{"$groups"} 8 5 13
1467 5 my $ref = $locker{"$groups"};
1468 5 foreach my $e ($self->find_entries({}, $groups)) {
1469 4 my $pass = $ref->{"$e"};
1470 4 ▶ $pass = eval { $self->decrypt_rijndael_cbc($pass, $ref->{'_key'}, $ref->{'_enc_iv'}) } if $pass;
Branch: 1 branch
BranchTrueFalseTotal
if $pass 4 0 4
1471 4 ▶ $pass = '' if ! defined $pass;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pass 0 4 4
1472 4 $e->{'password'} = $pass;
1473 }
1474 5 delete $locker{"$groups"};
1475 5 return 1;
1476 }
1477  
1478 2 ▶sub locked_entry_password {
Subroutine locked_entry_password: called CC=7 SCAR=20.4
Pod documented
1479 2 my $self = shift;
1480 2 my $entry = shift;
1481 2 ▶ my $groups = shift || $self->groups;
Condition33%1/3
shift() || $self->groups
l!l&&r!l&&!r
020
MC/DC0%0/2
shift() || $self->groups
shift() $self->groups
Truth table33%1/3
A || B
A= shift()B= $self->groups
ABresult
1X1
011
000
1482 2 ▶ my $ref = $locker{"$groups"} || die "Passwords are not locked\n";
Condition100%2/2
$locker{"$groups"} || die("Passwords are not locked\n")
l!l
11
MC/DC100%1/1
$locker{"$groups"} || die("Passwords are not locked\n")
$locker{"$groups"}
Truth table100%2/2
A
A= $locker{"$groups"}
Aresult
11
00
1483 1 ▶ $entry = $self->find_entry({id => $entry}, $groups) if ! ref $entry;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $entry 0 1 1
1484 1 ▶ return if ! $entry;
Branch: 1 branch
BranchTrueFalseTotal
unless $entry 0 1 1
1485 1 my $pass = $ref->{"$entry"};
1486 1 ▶ $pass = eval { $self->decrypt_rijndael_cbc($pass, $ref->{'_key'}, $ref->{'_enc_iv'}) } if $pass;
Branch: 1 branch
BranchTrueFalseTotal
if $pass 1 0 1
1487 1 ▶ $pass = '' if ! defined $pass;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pass 0 1 1
1488 1 $entry->{'accessed'} = $self->now;
1489 1 return $pass;
1490 }
1491  
1492 ###----------------------------------------------------------------###
1493  
1494 0 ▶sub salsa20_stream {
Subroutine salsa20_stream: not called CC=1 SCAR=6.9
Pod documented
1495 0 my ($self, $args) = @_;
1496 0 delete $args->{'data'};
1497 0 my $salsa20 = $self->salsa20($args);
1498 0 my $buffer = '';
1499 0 ▶ return sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
1500 0 my $enc = shift;
1501 0 ▶ $buffer .= $salsa20->("\0" x 64) while length($buffer) < length($enc);
Branch: 1 branch
BranchTrueFalseTotal
length $buffer < length $enc and do { $buffer .= &$salsa20("\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0") } 0 0 0
1502 0 my $data = join '', map {chr(ord(substr $enc, $_, 1) ^ ord(substr $buffer, $_, 1))} 0 .. length($enc)-1;
1503 0 substr $buffer, 0, length($enc), '';
1504 0 return $data;
1505 0 };
1506 }
1507  
1508  
1509 0 ▶sub salsa20 { # http://cr.yp.to/snuffle/salsa20/regs/salsa20.c
Subroutine salsa20: not called CC=8 SCAR=42.8
Pod documented
1510 0 my ($self, $args) = @_;
1511 0 my ($key, $iv, $rounds) = @$args{qw(key iv rounds)};
1512 0 ▶ $rounds ||= 20;
Condition0%0/2
$rounds ||= 20
l!l
00
MC/DC0%0/1
$rounds ||= 20
$rounds
Truth table0%0/2
A
A= $rounds
Aresult
11
00
1513  
1514 0 my (@k, @c);
1515 0 ▶ if (32 == length $key) {
Branch: 2 branches
BranchTrueFalseTotal
if (32 == length $key) { } 0 0 0
elsif (16 == length $key) { } 0 0 0
1516 0 @k = unpack 'L8', $key;
1517 0 @c = (0x61707865, 0x3320646e, 0x79622d32, 0x6b206574); # SIGMA
1518 } elsif (16 == length $key) {
1519 0 @k = unpack 'L8', $key x 2;
1520 0 @c = (0x61707865, 0x3120646e, 0x79622d36, 0x6b206574); # TAU
1521 } else {
1522 0 die "Salsa20 key length must be 16 or 32\n";
1523 }
1524 0 ▶ die "Salsa20 IV length must be 8\n" if length($iv) != 8;
Branch: 1 branch
BranchTrueFalseTotal
if length $iv != 8 0 0 0
1525 0 ▶ die "Salsa20 rounds must be 8, 12, or 20.\n" if !grep {$rounds != $_} 8, 12, 20;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$rounds != $_;} 8, 12, 20 0 0 0
1526 0 my @v = unpack('L2', $iv);
1527  
1528 # 0 5 6 7 10 # 15
1529 0 my @state = ($c[0], $k[0], $k[1], $k[2], $k[3], $c[1], $v[0], $v[1], 0, 0, $c[2], $k[4], $k[5], $k[6], $k[7], $c[3]);
1530  
1531 0 ▶ my $rotl32 = sub { return (($_[0] << $_[1]) | ($_[0] >> (32 - $_[1]))) & 0xffffffff };
Subroutine __ANON__: not called CC=1 SCAR=6.9
1532 0 ▶ my $word_to_byte = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
1533 0 my @x = @state;
1534 0 for (1 .. $rounds/2) {
1535 0 $x[ 4] ^= $rotl32->(($x[ 0] + $x[12]) & 0xffffffff, 7);
1536 0 $x[ 8] ^= $rotl32->(($x[ 4] + $x[ 0]) & 0xffffffff, 9);
1537 0 $x[12] ^= $rotl32->(($x[ 8] + $x[ 4]) & 0xffffffff, 13);
1538 0 $x[ 0] ^= $rotl32->(($x[12] + $x[ 8]) & 0xffffffff, 18);
1539 0 $x[ 9] ^= $rotl32->(($x[ 5] + $x[ 1]) & 0xffffffff, 7);
1540 0 $x[13] ^= $rotl32->(($x[ 9] + $x[ 5]) & 0xffffffff, 9);
1541 0 $x[ 1] ^= $rotl32->(($x[13] + $x[ 9]) & 0xffffffff, 13);
1542 0 $x[ 5] ^= $rotl32->(($x[ 1] + $x[13]) & 0xffffffff, 18);
1543 0 $x[14] ^= $rotl32->(($x[10] + $x[ 6]) & 0xffffffff, 7);
1544 0 $x[ 2] ^= $rotl32->(($x[14] + $x[10]) & 0xffffffff, 9);
1545 0 $x[ 6] ^= $rotl32->(($x[ 2] + $x[14]) & 0xffffffff, 13);
1546 0 $x[10] ^= $rotl32->(($x[ 6] + $x[ 2]) & 0xffffffff, 18);
1547 0 $x[ 3] ^= $rotl32->(($x[15] + $x[11]) & 0xffffffff, 7);
1548 0 $x[ 7] ^= $rotl32->(($x[ 3] + $x[15]) & 0xffffffff, 9);
1549 0 $x[11] ^= $rotl32->(($x[ 7] + $x[ 3]) & 0xffffffff, 13);
1550 0 $x[15] ^= $rotl32->(($x[11] + $x[ 7]) & 0xffffffff, 18);
1551  
1552 0 $x[ 1] ^= $rotl32->(($x[ 0] + $x[ 3]) & 0xffffffff, 7);
1553 0 $x[ 2] ^= $rotl32->(($x[ 1] + $x[ 0]) & 0xffffffff, 9);
1554 0 $x[ 3] ^= $rotl32->(($x[ 2] + $x[ 1]) & 0xffffffff, 13);
1555 0 $x[ 0] ^= $rotl32->(($x[ 3] + $x[ 2]) & 0xffffffff, 18);
1556 0 $x[ 6] ^= $rotl32->(($x[ 5] + $x[ 4]) & 0xffffffff, 7);
1557 0 $x[ 7] ^= $rotl32->(($x[ 6] + $x[ 5]) & 0xffffffff, 9);
1558 0 $x[ 4] ^= $rotl32->(($x[ 7] + $x[ 6]) & 0xffffffff, 13);
1559 0 $x[ 5] ^= $rotl32->(($x[ 4] + $x[ 7]) & 0xffffffff, 18);
1560 0 $x[11] ^= $rotl32->(($x[10] + $x[ 9]) & 0xffffffff, 7);
1561 0 $x[ 8] ^= $rotl32->(($x[11] + $x[10]) & 0xffffffff, 9);
1562 0 $x[ 9] ^= $rotl32->(($x[ 8] + $x[11]) & 0xffffffff, 13);
1563 0 $x[10] ^= $rotl32->(($x[ 9] + $x[ 8]) & 0xffffffff, 18);
1564 0 $x[12] ^= $rotl32->(($x[15] + $x[14]) & 0xffffffff, 7);
1565 0 $x[13] ^= $rotl32->(($x[12] + $x[15]) & 0xffffffff, 9);
1566 0 $x[14] ^= $rotl32->(($x[13] + $x[12]) & 0xffffffff, 13);
1567 0 $x[15] ^= $rotl32->(($x[14] + $x[13]) & 0xffffffff, 18);
1568 }
1569 0 return pack 'L16', map {($x[$_] + $state[$_]) & 0xffffffff} 0 .. 15;
1570 0 };
1571  
1572 0 ▶ my $encoder = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
1573 0 my $enc = shift;
1574 0 my $out = '';
1575 0 ▶ while (length $enc) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $enc) 0 0 0
1576 0 my $stream = $word_to_byte->();
1577 0 $state[8] = ($state[8] + 1) & 0xffffffff;
1578 0 ▶ $state[9] = ($state[9] + 1) & 0xffffffff if $state[8] == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $state[8] == 0 0 0 0
1579 0 my $chunk = substr $enc, 0, 64, '';
1580 0 $out .= join '', map {chr(ord(substr $stream, $_, 1) ^ ord(substr $chunk, $_, 1))} 0 .. length($chunk)-1;
1581 }
1582 0 return $out;
1583 0 };
1584 0 ▶ return $encoder if !exists $args->{'data'};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args->{"data"} 0 0 0
1585 0 ▶ return $encoder->(defined($args->{'data'}) ? $args->{'data'} : '');
Branch: 1 branch
BranchTrueFalseTotal
defined $args->{'data'} ? : 0 0 0
1586 }
1587  
1588 ###----------------------------------------------------------------###
1589  
1590 1 1;
1591  
1592 __END__
↑ Summary