KDBX/Entry.pm

filter: Statementstmt 90.9% 444 / 488 Branchbran 64.7% 176 / 272 Conditioncond 61.7% 121 / 196 MC/DCmcdc 34.5% 39 / 113 Subroutinesub 95.6% 87 / 91 Podpod 96.0% 48 / 50 totaltotal 75.6% 915 / 1210 CC 220 SCAR 23.0
CC
220
Cov
78%
expand_keystroke_sequence
42.0
size
38.5
prune_history
25.9
CRAP 9.9
« KDBX/IO.pm ↑ Summary KDBX/KDF/AES.pm »
1 package File::KDBX::Entry;
2 # ABSTRACT: A KDBX database entry
3  
4 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 11 ▶use Crypt::Misc 0.049 qw(decode_b64 encode_b32r);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 11 ▶use Devel::GlobalDestruction;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 11 ▶use Encode qw(encode);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 11 ▶use File::KDBX::Constants qw(:history :icon);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 11 ▶use File::KDBX::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 11 ▶use File::KDBX::Util qw(:assert :class :coercion :erase :function :uri generate_uuid load_optional);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 11 ▶use Hash::Util::FieldHash;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 11 ▶use List::Util qw(any first sum0);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 11 ▶use Ref::Util qw(is_coderef is_hashref is_plain_hashref);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 11 ▶use Scalar::Util qw(blessed looks_like_number);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 11 ▶use Storable qw(dclone);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 11 ▶use Time::Piece 1.33;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 11 ▶use boolean;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 11 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 11 extends 'File::KDBX::Object';
23  
24 11 our $VERSION = '0.905'; # VERSION
25  
26 11 my $PLACEHOLDER_MAX_DEPTH = 10;
27 11 my %PLACEHOLDERS;
28 11 my %STANDARD_STRINGS = map { $_ => 1 } qw(Title UserName Password URL Notes);
29  
30  
31 sub uuid {
32 449 ▶ my $self = shift;
Subroutine uuid: called CC=8 SCAR=20.8
Pod documented
33 449 ▶ if (@_ || !defined $self->{uuid}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ or not defined $self->{"uuid"}) 98 351 449
Condition100%3/3
@_ or not defined $self->{"uuid"}
l!l&&r!l&&!r
1385351
MC/DC100%2/2
@_ or not defined $self->{"uuid"}
@_ not defined $self->{"uuid"}
Truth table100%3/3
A or not(B)
A= @_B= not defined $self->{"uuid"}
ABresult
1X1
011
000
34 98 ▶ my %args = @_ % 2 == 1 ? (uuid => shift, @_) : @_;
Branch: 1 branch
BranchTrueFalseTotal
@_ % 2 == 1 ? : 13 85 98
35 98 my $old_uuid = $self->{uuid};
36 98 ▶ my $uuid = $self->{uuid} = delete $args{uuid} // generate_uuid;
Condition66%2/3
delete $args{"uuid"} // generate_uuid()
l!l&&r!l&&!r
13850
MC/DC0%0/2
delete $args{"uuid"} // generate_uuid()
delete $args{"uuid"} generate_uuid()
Truth table66%2/3
A // B
A= delete $args{"uuid"}B= generate_uuid()
ABresult
1X1
011
000
37 98 for my $entry (@{$self->history}) {
38 6 $entry->{uuid} = $uuid;
39 }
40 98 ▶ $self->_signal('uuid.changed', $uuid, $old_uuid) if defined $old_uuid && $self->is_current;
Branch: 1 branch
BranchTrueFalseTotal
if defined $old_uuid and $self->is_current 13 85 98
Condition66%2/3
defined $old_uuid and $self->is_current
!ll&&!rl&&r
85013
MC/DC50%1/2
defined $old_uuid and $self->is_current
defined $old_uuid $self->is_current
Truth table66%2/3
A and B
A= defined $old_uuidB= $self->is_current
ABresult
0X0
100
111
41 }
42 449 $self->{uuid};
43 182 ▶}
Subroutine icon_id: called CC=4 SCAR=14.2
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($_[0]) 0 182 182
44 182 ▶ 
Subroutine custom_icon_uuid: called CC=4 SCAR=14.1
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
if $#_ 86 96 182
unless builtin::blessed($_[0]) 0 98 98
45 182 ▶# has uuid => sub { generate_uuid(printable => 1) };
Subroutine foreground_color: called CC=4 SCAR=14.5
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
if $#_ 5 93 98
unless builtin::blessed($_[0]) 0 84 84
Condition66%2/3
$_[0]{"icon_id"} //= $default
l!l&&r!l&&!r
134480
MC/DC0%0/2
$_[0]{"icon_id"} //= $default
$_[0]{"icon_id"} $default
Truth table66%2/3
A //= B
A= $_[0]{"icon_id"}B= $default
ABresult
1X1
011
000
46 98 ▶has icon_id => ICON_PASSWORD, coerce => \&to_icon_constant;
Subroutine background_color: called CC=4 SCAR=15.0
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
if $#_ 0 84 84
unless builtin::blessed($_[0]) 0 84 84
Condition100%2/2
$_[0]{"custom_icon_uuid"} //= undef
l!l
1088
MC/DC100%1/1
$_[0]{"custom_icon_uuid"} //= undef
$_[0]{"custom_icon_uuid"}
Truth table100%2/2
A
A= $_[0]{"custom_icon_uuid"}
Aresult
11
00
47 84 ▶has custom_icon_uuid => undef, coerce => \&to_uuid;
Subroutine override_url: called CC=4 SCAR=15.6
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
if $#_ 0 84 84
unless builtin::blessed($_[0]) 0 84 84
Condition33%1/3
$_[0]{"foreground_color"} //= $default
l!l&&r!l&&!r
0084
MC/DC0%0/2
$_[0]{"foreground_color"} //= $default
$_[0]{"foreground_color"} $default
Truth table33%1/3
A //= B
A= $_[0]{"foreground_color"}B= $default
ABresult
1X1
011
000
48 84 ▶has foreground_color => '', coerce => \&to_string;
Subroutine tags: called CC=4 SCAR=15.2
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
if $#_ 0 84 84
unless builtin::blessed($_[0]) 0 87 87
Condition33%1/3
$_[0]{"background_color"} //= $default
l!l&&r!l&&!r
0084
MC/DC0%0/2
$_[0]{"background_color"} //= $default
$_[0]{"background_color"} $default
Truth table33%1/3
A //= B
A= $_[0]{"background_color"}B= $default
ABresult
1X1
011
000
49 84 ▶has background_color => '', coerce => \&to_string;
Subroutine auto_type: called CC=4 SCAR=14.5
Pod undocumented
Branch: 2 branches
BranchTrueFalseTotal
if $#_ 0 87 87
unless builtin::blessed($_[0]) 0 511 511
Condition33%1/3
$_[0]{"override_url"} //= $default
l!l&&r!l&&!r
0084
MC/DC0%0/2
$_[0]{"override_url"} //= $default
$_[0]{"override_url"} $default
Truth table33%1/3
A //= B
A= $_[0]{"override_url"}B= $default
ABresult
1X1
011
000
50 87 ▶has override_url => '', coerce => \&to_string;
Subroutine previous_parent_group: called CC=4 SCAR=14.0
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
if $#_ 0 511 511
unless builtin::blessed($_[0]) 0 113 113
Condition66%2/3
$_[0]{"tags"} //= $default
l!l&&r!l&&!r
3084
MC/DC50%1/2
$_[0]{"tags"} //= $default
$_[0]{"tags"} $default
Truth table66%2/3
A //= B
A= $_[0]{"tags"}B= $default
ABresult
1X1
011
000
51 511 ▶has tags => '', coerce => \&to_string;
Subroutine quality_check: called CC=4 SCAR=14.0
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
if $#_ 2 111 113
unless builtin::blessed($_[0]) 0 138 138
Condition100%2/2
$_[0]{"auto_type"} //= scalar &$default($_[0])
l!l
42784
MC/DC100%1/1
$_[0]{"auto_type"} //= scalar &$default($_[0])
$_[0]{"auto_type"}
Truth table100%2/2
A
A= $_[0]{"auto_type"}
Aresult
11
00
52 113 ▶has auto_type => {};
Subroutine strings: called CC=4 SCAR=14.3
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
if $#_ 2 136 138
unless builtin::blessed($_[0]) 0 134 134
Condition100%2/2
$_[0]{"previous_parent_group"} //= undef
l!l
2111
MC/DC100%1/1
$_[0]{"previous_parent_group"} //= undef
$_[0]{"previous_parent_group"}
Truth table100%2/2
A
A= $_[0]{"previous_parent_group"}
Aresult
11
00
53 138 ▶has previous_parent_group => undef, coerce => \&to_uuid;
Subroutine binaries: called CC=4 SCAR=14.5
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
if $#_ 0 134 134
unless builtin::blessed($_[0]) 0 134 134
Condition66%2/3
$_[0]{"quality_check"} //= $default
l!l&&r!l&&!r
51870
MC/DC0%0/2
$_[0]{"quality_check"} //= $default
$_[0]{"quality_check"} $default
Truth table66%2/3
A //= B
A= $_[0]{"quality_check"}B= $default
ABresult
1X1
011
000
54 134 ▶has quality_check => true, coerce => \&to_bool;
Subroutine times: called CC=4 SCAR=14.1
Pod undocumented
Branch: 2 branches
BranchTrueFalseTotal
if $#_ 0 134 134
unless builtin::blessed($_[0]) 0 720 720
Condition50%1/2
$_[0]{"strings"} //= scalar &$default($_[0])
l!l
1340
MC/DC0%0/1
$_[0]{"strings"} //= scalar &$default($_[0])
$_[0]{"strings"}
Truth table50%1/2
A
A= $_[0]{"strings"}
Aresult
11
00
55 134 ▶has strings => {};
Branch: 1 branch
BranchTrueFalseTotal
if $#_ 0 720 720
Condition100%2/2
$_[0]{"binaries"} //= scalar &$default($_[0])
l!l
5084
MC/DC100%1/1
$_[0]{"binaries"} //= scalar &$default($_[0])
$_[0]{"binaries"}
Truth table100%2/2
A
A= $_[0]{"binaries"}
Aresult
11
00
56 720 ▶has binaries => {};
Condition100%2/2
$_[0]{"times"} //= scalar &$default($_[0])
l!l
63684
MC/DC100%1/1
$_[0]{"times"} //= scalar &$default($_[0])
$_[0]{"times"}
Truth table100%2/2
A
A= $_[0]{"times"}
Aresult
11
00
57 11 has times => {};
58 100 ▶# has custom_data => {};
Subroutine last_modification_time: called CC=4 SCAR=14.0
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($_[0]) 0 100 100
59 100 ▶# has history => [];
Subroutine creation_time: called CC=4 SCAR=13.9
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
if $#_ 10 90 100
unless builtin::blessed($_[0]) 0 87 87
60 100 ▶ 
Subroutine last_access_time: called CC=4 SCAR=13.9
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
if $#_ 1 86 87
unless builtin::blessed($_[0]) 0 92 92
Condition100%2/2
$_[0]->times->{"last_modification_time"} //= scalar &$default($_[0])
l!l
1783
MC/DC100%1/1
$_[0]->times->{"last_modification_time"} //= scalar &$default($_[0])
$_[0]->times->{"last_modification_time"}
Truth table100%2/2
A
A= $_[0]->times->{"last_modification_time"}
Aresult
11
00
61 87 ▶has last_modification_time => sub { gmtime }, store => 'times', coerce => \&to_time;
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine expiry_time: called CC=4 SCAR=14.1
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
if $#_ 8 84 92
unless builtin::blessed($_[0]) 0 84 84
Condition100%2/2
$_[0]->times->{"creation_time"} //= scalar &$default($_[0])
l!l
384
MC/DC100%1/1
$_[0]->times->{"creation_time"} //= scalar &$default($_[0])
$_[0]->times->{"creation_time"}
Truth table100%2/2
A
A= $_[0]->times->{"creation_time"}
Aresult
11
00
62 92 ▶has creation_time => sub { gmtime }, store => 'times', coerce => \&to_time;
Subroutine __ANON__: called CC=1 SCAR=0.1
Subroutine expires: called CC=4 SCAR=14.6
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
if $#_ 0 84 84
unless builtin::blessed($_[0]) 0 84 84
Condition100%2/2
$_[0]->times->{"last_access_time"} //= scalar &$default($_[0])
l!l
884
MC/DC100%1/1
$_[0]->times->{"last_access_time"} //= scalar &$default($_[0])
$_[0]->times->{"last_access_time"}
Truth table100%2/2
A
A= $_[0]->times->{"last_access_time"}
Aresult
11
00
63 84 ▶has last_access_time => sub { gmtime }, store => 'times', coerce => \&to_time;
Subroutine __ANON__: called CC=1 SCAR=0.2
Subroutine usage_count: called CC=4 SCAR=14.8
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
if $#_ 0 84 84
unless builtin::blessed($_[0]) 0 84 84
Condition50%1/2
$_[0]->times->{"expiry_time"} //= scalar &$default($_[0])
l!l
084
MC/DC0%0/1
$_[0]->times->{"expiry_time"} //= scalar &$default($_[0])
$_[0]->times->{"expiry_time"}
Truth table50%1/2
A
A= $_[0]->times->{"expiry_time"}
Aresult
11
00
64 84 ▶has expiry_time => sub { gmtime }, store => 'times', coerce => \&to_time;
Subroutine __ANON__: called CC=1 SCAR=0.4
Subroutine location_changed: called CC=4 SCAR=14.5
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
if $#_ 0 84 84
unless builtin::blessed($_[0]) 0 85 85
Condition33%1/3
$_[0]->times->{"expires"} //= $default
l!l&&r!l&&!r
0084
MC/DC0%0/2
$_[0]->times->{"expires"} //= $default
$_[0]->times->{"expires"} $default
Truth table33%1/3
A //= B
A= $_[0]->times->{"expires"}B= $default
ABresult
1X1
011
000
65 84 ▶has expires => false, store => 'times', coerce => \&to_bool;
Branch: 1 branch
BranchTrueFalseTotal
if $#_ 1 84 85
Condition33%1/3
$_[0]->times->{"usage_count"} //= $default
l!l&&r!l&&!r
0084
MC/DC0%0/2
$_[0]->times->{"usage_count"} //= $default
$_[0]->times->{"usage_count"} $default
Truth table33%1/3
A //= B
A= $_[0]->times->{"usage_count"}B= $default
ABresult
1X1
011
000
66 85 ▶has usage_count => 0, store => 'times', coerce => \&to_number;
Condition100%2/2
$_[0]->times->{"location_changed"} //= scalar &$default($_[0])
l!l
184
MC/DC100%1/1
$_[0]->times->{"location_changed"} //= scalar &$default($_[0])
$_[0]->times->{"location_changed"}
Truth table100%2/2
A
A= $_[0]->times->{"location_changed"}
Aresult
11
00
67 84 ▶has location_changed => sub { gmtime }, store => 'times', coerce => \&to_time;
Subroutine __ANON__: called CC=1 SCAR=0.1
Subroutine auto_type_obfuscation: called CC=4 SCAR=15.2
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($_[0]) 0 84 84
68 84 ▶ 
Branch: 1 branch
BranchTrueFalseTotal
if $#_ 0 84 84
69 84 ▶# has 'auto_type.auto_type_enabled' => true, coerce => \&to_bool;
Subroutine auto_type_default_sequence: called CC=4 SCAR=16.0
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($_[0]) 0 84 84
Condition33%1/3
$_[0]->auto_type->{"data_transfer_obfuscation"} //= $default
l!l&&r!l&&!r
0084
MC/DC0%0/2
$_[0]->auto_type->{"data_transfer_obfuscation"} //= $default
$_[0]->auto_type->{"data_transfer_obfuscation"} $default
Truth table33%1/3
A //= B
A= $_[0]->auto_type->{"data_transfer_obfuscation"}B= $default
ABresult
1X1
011
000
70 84 ▶has 'auto_type_obfuscation' => 0, path => 'auto_type.data_transfer_obfuscation',
Branch: 1 branch
BranchTrueFalseTotal
if $#_ 0 84 84
71 84 ▶ coerce => \&to_number;
Subroutine auto_type_associations: called CC=4 SCAR=14.8
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($_[0]) 0 87 87
Condition33%1/3
$_[0]->auto_type->{"default_sequence"} //= $default
l!l&&r!l&&!r
0840
MC/DC0%0/2
$_[0]->auto_type->{"default_sequence"} //= $default
$_[0]->auto_type->{"default_sequence"} $default
Truth table33%1/3
A //= B
A= $_[0]->auto_type->{"default_sequence"}B= $default
ABresult
1X1
011
000
72 87 ▶has 'auto_type_default_sequence' => '{USERNAME}{TAB}{PASSWORD}{ENTER}',
Branch: 1 branch
BranchTrueFalseTotal
if $#_ 0 87 87
73 87 ▶ path => 'auto_type.default_sequence', coerce => \&to_string;
Condition100%2/2
$_[0]->auto_type->{"associations"} //= scalar &$default($_[0])
l!l
384
MC/DC100%1/1
$_[0]->auto_type->{"associations"} //= scalar &$default($_[0])
$_[0]->auto_type->{"associations"}
Truth table100%2/2
A
A= $_[0]->auto_type->{"associations"}
Aresult
11
00
74 11 has 'auto_type_associations' => [], path => 'auto_type.associations';
75  
76 11 my %ATTRS_STRINGS = (
77 title => 'Title',
78 username => 'UserName',
79 password => 'Password',
80 url => 'URL',
81 notes => 'Notes',
82 );
83 11 ▶while (my ($attr, $string_key) = each %ATTRS_STRINGS) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %ATTRS_STRINGS) 55 11 66
84 11 ▶ no strict 'refs'; ## no critic (ProhibitNoStrict)
Subroutine BEGIN: called CC=1 SCAR=0.0
85 479 ▶ *{$attr} = sub { shift->string_value($string_key, @_) };
Subroutine __ANON__: called CC=1 SCAR=0.0
86 323 ▶ *{"expand_${attr}"} = sub { shift->expand_string_value($string_key, @_) };
Subroutine __ANON__: called CC=1 SCAR=0.0
87 }
88  
89 11 my @ATTRS = qw(uuid custom_data history auto_type_enabled);
90 sub _set_nonlazy_attributes {
91 84 ▶ my $self = shift;
Subroutine _set_nonlazy_attributes: called CC=2 SCAR=6.9
92 84 $self->$_ for @ATTRS, keys %ATTRS_STRINGS, list_attributes(ref $self);
93 }
94  
95 sub init {
96 104 ▶ my $self = shift;
Subroutine init: called CC=3 SCAR=11.0
Pod documented
97 104 my %args = @_;
98  
99 104 ▶ while (my ($key, $val) = each %args) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %args) 156 104 260
100 156 ▶ if (my $method = $self->can($key)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $method = $self->can($key)) { } 154 2 156
101 154 $self->$method($val);
102 }
103 else {
104 2 $self->string($key => $val);
105 }
106 }
107  
108 104 return $self;
109 }
110  
111 ##############################################################################
112  
113  
114 sub string {
115 1263 ▶ my $self = shift;
Subroutine string: called CC=12 SCAR=29.3
Pod documented
116 1263 ▶ my %args = @_ == 2 ? (key => shift, value => shift)
Branch: 2 branches
BranchTrueFalseTotal
@_ == 2 ? : 145 1118 1263
@_ % 2 == 1 ? : 1118 0 1118
117 : @_ % 2 == 1 ? (key => shift, @_) : @_;
118  
119 1263 ▶ if (!defined $args{key} && !defined $args{value}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"key"} or defined $args{"value"}) 0 1263 1263
Condition33%1/3
defined $args{"key"} or defined $args{"value"}
l!l&&r!l&&!r
126300
MC/DC0%0/2
defined $args{"key"} or defined $args{"value"}
defined $args{"key"} defined $args{"value"}
Truth table33%1/3
A or B
A= defined $args{"key"}B= defined $args{"value"}
ABresult
1X1
011
000
120 0 my %standard = (value => 1, protect => 1);
121 0 my @other_keys = grep { !$standard{$_} } keys %args;
122 0 ▶ if (@other_keys == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@other_keys == 1) 0 0 0
123 0 my $key = $args{key} = $other_keys[0];
124 0 $args{value} = delete $args{$key};
125 }
126 }
127  
128 1263 ▶ my $key = delete $args{key} or throw 'Must provide a string key to access';
Branch: 1 branch
BranchTrueFalseTotal
my $key = delete $args{"key"} or throw("Must provide a string key to access") 0 1263 1263
129  
130 1263 ▶ return $self->{strings}{$key} = $args{value} if is_plain_hashref($args{value});
Branch: 1 branch
BranchTrueFalseTotal
if Ref::Util::XS::is_plain_hashref($args{"value"}) 0 1263 1263
131  
132 1263 ▶ while (my ($field, $value) = each %args) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %args) 145 1263 1408
133 145 $self->{strings}{$key}{$field} = $value;
134 }
135  
136 # Auto-vivify the standard strings.
137 1263 ▶ if ($STANDARD_STRINGS{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($STANDARD_STRINGS{$key}) 809 454 1263
138 809 ▶ return $self->{strings}{$key} //= {value => '', $self->_protect($key) ? (protect => true) : ()};
Branch: 1 branch
BranchTrueFalseTotal
$self->_protect($key) ? : 79 269 348
Condition100%2/2
$self->{"strings"}{$key} //= {"value", "", $self->_protect($key) ? ("protect", &true()) : ()}
l!l
461348
MC/DC100%1/1
$self->{"strings"}{$key} //= {"value", "", $self->_protect($key) ? ("protect", &true()) : ()}
$self->{"strings"}{$key}
Truth table100%2/2
A
A= $self->{"strings"}{$key}
Aresult
11
00
139 }
140 454 return $self->{strings}{$key};
141 }
142  
143 ### Get whether or not a standard string is configured to be protected
144 sub _protect {
145 348 ▶ my $self = shift;
Subroutine _protect: called CC=4 SCAR=14.0
146 348 my $key = shift;
147 348 ▶ return false if !$STANDARD_STRINGS{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless $STANDARD_STRINGS{$key} 0 348 348
148 348 ▶ if (my $kdbx = eval { $self->kdbx }) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $kdbx = eval { do { $self->kdbx } }) 89 259 348
149 89 my $protect = $kdbx->memory_protection($key);
150 89 ▶ return $protect if defined $protect;
Branch: 1 branch
BranchTrueFalseTotal
if defined $protect 89 0 89
151 }
152 259 return $key eq 'Password';
153 }
154  
155  
156 sub string_value {
157 875 ▶ my $self = shift;
Subroutine string_value: called CC=2 SCAR=6.9
Pod documented
158 875 ▶ my $string = $self->string(@_) // return undef;
Condition100%2/2
$self->string(@_) // (return undef)
l!l
599276
MC/DC100%1/1
$self->string(@_) // (return undef)
$self->string(@_)
Truth table100%2/2
A
A= $self->string(@_)
Aresult
11
00
159 599 return $string->{value};
160 }
161  
162  
163 sub _expand_placeholder {
164 43 ▶ my $self = shift;
Subroutine _expand_placeholder: called CC=6 SCAR=18.0
165 43 my $placeholder = shift;
166 43 my $arg = shift;
167  
168 43 require File::KDBX;
169  
170 43 my $placeholder_key = $placeholder;
171 43 ▶ if (defined $arg) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $arg) 12 31 43
172 12 ▶ $placeholder_key = $File::KDBX::PLACEHOLDERS{"${placeholder}:${arg}"} ? "${placeholder}:${arg}"
Branch: 1 branch
BranchTrueFalseTotal
$File::KDBX::PLACEHOLDERS{"${placeholder}:$arg"} ? : 0 12 12
173 : "${placeholder}:";
174 }
175 43 ▶ return if !defined $File::KDBX::PLACEHOLDERS{$placeholder_key};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $File::KDBX::PLACEHOLDERS{$placeholder_key} 1 42 43
176  
177 42 my $local_key = join('/', Hash::Util::FieldHash::id($self), $placeholder_key);
178 42 ▶ local $PLACEHOLDERS{$local_key} = my $handler = $PLACEHOLDERS{$local_key} // do {
Condition66%2/3
$PLACEHOLDERS{$local_key} // do { my $handler = $File::KDBX::PLACEHOLDERS{$placeholder_key} or next; memoize(recurse_limit($handler, $PLACEHOLDER_MAX_DEPTH, sub { alert("Detected deep recursion while expanding $placeholder placeholder", "placeholder", $placeholder); return; } )) }
l!l&&r!l&&!r
19230
MC/DC0%0/2
$PLACEHOLDERS{$local_key} // do { my $handler = $File::KDBX::PLACEHOLDERS{$placeholder_key} or next; memoize(recurse_limit($handler, $PLACEHOLDER_MAX_DEPTH, sub { alert("Detected deep recursion while expanding $placeholder placeholder", "placeholder", $placeholder); return; } )) }
$PLACEHOLDERS{$local_key} do { my $handler = $File::KDBX::PLACEHOLDERS{$placeholder_key} or next; memoize(recurse_limit($handler, $PLACEHOLDER_MAX_DEPTH, sub { alert("Detected deep recursion while expanding $placeholder placeholder", "placeholder", $placeholder); return; } )) }
Truth table66%2/3
A // B
A= $PLACEHOLDERS{$local_key}B= do { my $handler = $File::KDBX::PLACEHOLDERS{$placeholder_key} or next; memoize(recurse_limit($handler, $PLACEHOLDER_MAX_DEPTH, sub { alert("Detected deep recursion while expanding $placeholder placeholder", "placeholder", $placeholder); return; } )) }
ABresult
1X1
011
000
179 23 ▶ my $handler = $File::KDBX::PLACEHOLDERS{$placeholder_key} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $handler = $File::KDBX::PLACEHOLDERS{$placeholder_key} or next 0 23 23
180 memoize recurse_limit($handler, $PLACEHOLDER_MAX_DEPTH, sub {
181 1 ▶ alert "Detected deep recursion while expanding $placeholder placeholder",
Subroutine __ANON__: called CC=1 SCAR=0.0
182 placeholder => $placeholder;
183 1 return; # undef
184 23 });
185 };
186  
187 42 return $handler->($self, $arg, $placeholder);
188 }
189  
190 sub _expand_string {
191 323 ▶ my $self = shift;
Subroutine _expand_string: called CC=3 SCAR=11.2
192 323 my $str = shift;
193  
194 323 my $expand = memoize $self->can('_expand_placeholder'), $self;
195  
196 # placeholders (including field references):
197 323 ▶ $str =~ s!\{([^:\}]+)(?::([^\}]*))?\}!$expand->(uc($1), $2, @_) // $&!egi;
Condition66%2/3
&$expand(uc $1, $2, @_) // $&
l!l&&r!l&&!r
4130
MC/DC0%0/2
&$expand(uc $1, $2, @_) // $&
&$expand(uc $1, $2, @_) $&
Truth table66%2/3
A // B
A= &$expand(uc $1, $2, @_)B= $&
ABresult
1X1
011
000
198  
199 # environment variables (alt syntax):
200 323 my $vars = join('|', map { quotemeta($_) } keys %ENV);
201 323 ▶ $str =~ s!\%($vars)\%!$expand->(ENV => $1, @_) // $&!eg;
Condition33%1/3
&$expand("ENV", $1, @_) // $&
l!l&&r!l&&!r
200
MC/DC0%0/2
&$expand("ENV", $1, @_) // $&
&$expand("ENV", $1, @_) $&
Truth table33%1/3
A // B
A= &$expand("ENV", $1, @_)B= $&
ABresult
1X1
011
000
202  
203 323 return $str;
204 }
205  
206 sub expand_string_value {
207 323 ▶ my $self = shift;
Subroutine expand_string_value: called CC=2 SCAR=7.0
Pod documented
208 323 ▶ my $str = $self->string_peek(@_) // return undef;
Condition50%1/2
$self->string_peek(@_) // (return undef)
l!l
3230
MC/DC0%0/1
$self->string_peek(@_) // (return undef)
$self->string_peek(@_)
Truth table50%1/2
A
A= $self->string_peek(@_)
Aresult
11
00
209 323 my $cleanup = erase_scoped $str;
210 323 return $self->_expand_string($str);
211 }
212  
213  
214 sub other_strings {
215 5 ▶ my $self = shift;
Subroutine other_strings: called CC=2 SCAR=7.0
Pod documented
216 5 ▶ my $delim = shift // "\n";
Condition50%1/2
shift() // "\n"
l!l
05
MC/DC0%0/1
shift() // "\n"
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
217  
218 5 my @strings = map { $self->string_value($_) } grep { !$STANDARD_STRINGS{$_} } sort keys %{$self->strings};
219 5 return join($delim, @strings);
220 }
221  
222  
223 sub string_peek {
224 325 ▶ my $self = shift;
Subroutine string_peek: called CC=2 SCAR=6.9
Pod documented
225 325 my $string = $self->string(@_);
226 325 ▶ return defined $string->{value} ? $string->{value} : $self->kdbx->peek($string);
Branch: 1 branch
BranchTrueFalseTotal
defined $string->{'value'} ? : 321 4 325
227 }
228  
229 ##############################################################################
230  
231  
232 sub add_auto_type_association {
233 2 ▶ my $self = shift;
Subroutine add_auto_type_association: called CC=1 SCAR=0.0
Pod documented
234 2 my $association = shift;
235 2 push @{$self->auto_type_associations}, $association;
236 }
237  
238  
239 sub expand_keystroke_sequence {
240 0 ▶ my $self = shift;
Subroutine expand_keystroke_sequence: not called CC=6 SCAR=37.4
Pod documented
241 0 my $association = shift;
242  
243 0 my $keys;
244 0 ▶ if ($association) {
Branch: 1 branch
BranchTrueFalseTotal
if ($association) 0 0 0
245 $keys = is_hashref($association) && exists $association->{keystroke_sequence} ?
246 0 ▶ $association->{keystroke_sequence} : defined $association ? $association : '';
Branch: 2 branches
BranchTrueFalseTotal
Ref::Util::XS::is_hashref($association) && exists $association->{'keystroke_sequence'} ? : 0 0 0
defined $association ? : 0 0 0
Condition0%0/3
Ref::Util::XS::is_hashref($association) and exists $association->{"keystroke_sequence"}
!ll&&!rl&&r
000
MC/DC0%0/2
Ref::Util::XS::is_hashref($association) and exists $association->{"keystroke_sequence"}
Ref::Util::XS::is_hashref($association) exists $association->{"keystroke_sequence"}
Truth table0%0/3
A and B
A= Ref::Util::XS::is_hashref($association)B= exists $association->{"keystroke_sequence"}
ABresult
0X0
100
111
247 }
248  
249 0 ▶ $keys = $self->auto_type_default_sequence if !$keys;
Branch: 1 branch
BranchTrueFalseTotal
unless $keys 0 0 0
250 # TODO - Fall back to getting default sequence from parent group, which probably means we shouldn't be
251 # setting a default value in the entry..
252  
253 0 return $self->_expand_string($keys);
254 }
255  
256 ##############################################################################
257  
258  
259 sub binary {
260 3 ▶ my $self = shift;
Subroutine binary: called CC=9 SCAR=32.2
Pod documented
261 3 ▶ my %args = @_ == 2 ? (key => shift, value => shift)
Branch: 2 branches
BranchTrueFalseTotal
@_ == 2 ? : 0 3 3
@_ % 2 == 1 ? : 3 0 3
262 : @_ % 2 == 1 ? (key => shift, @_) : @_;
263  
264 3 ▶ if (!defined $args{key} && !defined $args{value}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"key"} or defined $args{"value"}) 0 3 3
Condition33%1/3
defined $args{"key"} or defined $args{"value"}
l!l&&r!l&&!r
300
MC/DC0%0/2
defined $args{"key"} or defined $args{"value"}
defined $args{"key"} defined $args{"value"}
Truth table33%1/3
A or B
A= defined $args{"key"}B= defined $args{"value"}
ABresult
1X1
011
000
265 0 my %standard = (value => 1, protect => 1);
266 0 my @other_keys = grep { !$standard{$_} } keys %args;
267 0 ▶ if (@other_keys == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@other_keys == 1) 0 0 0
268 0 my $key = $args{key} = $other_keys[0];
269 0 $args{value} = delete $args{$key};
270 }
271 }
272  
273 3 ▶ my $key = delete $args{key} or throw 'Must provide a binary key to access';
Branch: 1 branch
BranchTrueFalseTotal
my $key = delete $args{"key"} or throw("Must provide a binary key to access") 0 3 3
274  
275 3 ▶ return $self->{binaries}{$key} = $args{value} if is_plain_hashref($args{value});
Branch: 1 branch
BranchTrueFalseTotal
if Ref::Util::XS::is_plain_hashref($args{"value"}) 0 3 3
276  
277 3 ▶ assert { !defined $args{value} || !utf8::is_utf8($args{value}) };
Subroutine __ANON__: not called CC=2 SCAR=14.0
Condition0%0/3
defined $args{'value'} && utf8::is_utf8($args{'value'})
!ll&&!rl&&r
000
MC/DC0%0/2
defined $args{'value'} && utf8::is_utf8($args{'value'})
defined $args{'value'} utf8::is_utf8($args{'value'})
Truth table0%0/3
A && B
A= defined $args{'value'}B= utf8::is_utf8($args{'value'})
ABresult
0X0
100
111
278 3 ▶ while (my ($field, $value) = each %args) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %args) 0 3 3
279 0 $self->{binaries}{$key}{$field} = $value;
280 }
281 3 return $self->{binaries}{$key};
282 }
283  
284  
285 sub binary_value {
286 1 ▶ my $self = shift;
Subroutine binary_value: called CC=2 SCAR=7.1
Pod documented
287 1 ▶ my $binary = $self->binary(@_) // return undef;
Condition50%1/2
$self->binary(@_) // (return undef)
l!l
10
MC/DC0%0/1
$self->binary(@_) // (return undef)
$self->binary(@_)
Truth table50%1/2
A
A= $self->binary(@_)
Aresult
11
00
288 1 return $binary->{value};
289 }
290  
291 ##############################################################################
292  
293  
294 sub hmac_otp {
295 27 ▶ my $self = shift;
Subroutine hmac_otp: called CC=5 SCAR=16.7
Pod documented
296 27 load_optional('Pass::OTP');
297  
298 27 my %params = ($self->_hotp_params, @_);
299 27 ▶ return if !defined $params{type} || !defined $params{secret};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $params{"type"} and defined $params{"secret"} 0 27 27
Condition33%1/3
defined $params{"type"} and defined $params{"secret"}
!ll&&!rl&&r
0027
MC/DC0%0/2
defined $params{"type"} and defined $params{"secret"}
defined $params{"type"} defined $params{"secret"}
Truth table33%1/3
A and B
A= defined $params{"type"}B= defined $params{"secret"}
ABresult
0X0
100
111
300  
301 27 ▶ $params{secret} = encode_b32r($params{secret}) if !$params{base32};
Branch: 1 branch
BranchTrueFalseTotal
unless $params{"base32"} 15 12 27
302 27 $params{base32} = 1;
303  
304 27 my $otp = eval { Pass::OTP::otp(%params, @_) };
305 27 ▶ if (my $err = $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $@) 0 27 27
306 0 throw 'Unable to generate HOTP', error => $err;
307 }
308  
309 27 $self->_hotp_increment_counter($params{counter});
310  
311 27 return $otp;
312 }
313  
314  
315 sub time_otp {
316 10 ▶ my $self = shift;
Subroutine time_otp: called CC=5 SCAR=17.4
Pod documented
317 10 load_optional('Pass::OTP');
318  
319 10 my %params = ($self->_totp_params, @_);
320 10 ▶ return if !defined $params{type} || !defined $params{secret};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $params{"type"} and defined $params{"secret"} 0 10 10
Condition33%1/3
defined $params{"type"} and defined $params{"secret"}
!ll&&!rl&&r
0010
MC/DC0%0/2
defined $params{"type"} and defined $params{"secret"}
defined $params{"type"} defined $params{"secret"}
Truth table33%1/3
A and B
A= defined $params{"type"}B= defined $params{"secret"}
ABresult
0X0
100
111
321  
322 10 ▶ $params{secret} = encode_b32r($params{secret}) if !$params{base32};
Branch: 1 branch
BranchTrueFalseTotal
unless $params{"base32"} 0 10 10
323 10 $params{base32} = 1;
324  
325 10 my $otp = eval { Pass::OTP::otp(%params, @_) };
326 10 ▶ if (my $err = $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $@) 0 10 10
327 0 throw 'Unable to generate TOTP', error => $err;
328 }
329  
330 10 return $otp;
331 }
332  
333  
334 9 ▶sub hmac_otp_uri { $_[0]->_otp_uri($_[0]->_hotp_params) }
Subroutine hmac_otp_uri: called CC=1 SCAR=0.0
Pod documented
335 11 ▶sub time_otp_uri { $_[0]->_otp_uri($_[0]->_totp_params) }
Subroutine time_otp_uri: called CC=1 SCAR=0.0
Pod documented
336  
337 sub _otp_uri {
338 20 ▶ my $self = shift;
Subroutine _otp_uri: called CC=19 SCAR=29.5
339 20 my %params = @_;
340  
341 20 ▶ return if 4 != grep { defined } @params{qw(type secret issuer account)};
Branch: 1 branch
BranchTrueFalseTotal
if 4 != grep({defined $_;} @params{"type", "secret", "issuer", "account"}) 0 20 20
342 20 ▶ return if $params{type} !~ /^[ht]otp$/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $params{"type"} =~ /^[ht]otp$/i 0 20 20
343  
344 20 my $label = delete $params{label};
345 20 $params{$_} = uri_escape_utf8($params{$_}) for keys %params;
346  
347 20 my $type = lc($params{type});
348 20 my $issuer = $params{issuer};
349 20 my $account = $params{account};
350  
351 20 ▶ $label //= "$issuer:$account";
Condition100%2/2
$label //= "${issuer}:$account"
l!l
812
MC/DC100%1/1
$label //= "${issuer}:$account"
$label
Truth table100%2/2
A
A= $label
Aresult
11
00
352  
353 20 my $secret = $params{secret};
354 20 ▶ $secret = uc(encode_b32r($secret)) if !$params{base32};
Branch: 1 branch
BranchTrueFalseTotal
unless $params{"base32"} 5 15 20
355  
356 20 ▶ delete $params{algorithm} if defined $params{algorithm} && $params{algorithm} eq 'sha1';
Branch: 1 branch
BranchTrueFalseTotal
if defined $params{"algorithm"} and $params{"algorithm"} eq "sha1" 9 11 20
Condition100%3/3
defined $params{"algorithm"} and $params{"algorithm"} eq "sha1"
!ll&&!rl&&r
929
MC/DC100%2/2
defined $params{"algorithm"} and $params{"algorithm"} eq "sha1"
defined $params{"algorithm"} $params{"algorithm"} eq "sha1"
Truth table100%3/3
A and B
A= defined $params{"algorithm"}B= $params{"algorithm"} eq "sha1"
ABresult
0X0
100
111
357 20 ▶ delete $params{period} if defined $params{period} && $params{period} == 30;
Branch: 1 branch
BranchTrueFalseTotal
if defined $params{"period"} and $params{"period"} == 30 9 11 20
Condition100%3/3
defined $params{"period"} and $params{"period"} == 30
!ll&&!rl&&r
929
MC/DC100%2/2
defined $params{"period"} and $params{"period"} == 30
defined $params{"period"} $params{"period"} == 30
Truth table100%3/3
A and B
A= defined $params{"period"}B= $params{"period"} == 30
ABresult
0X0
100
111
358 20 ▶ delete $params{digits} if defined $params{digits} && $params{digits} == 6;
Branch: 1 branch
BranchTrueFalseTotal
if defined $params{"digits"} and $params{"digits"} == 6 16 4 20
Condition66%2/3
defined $params{"digits"} and $params{"digits"} == 6
!ll&&!rl&&r
0416
MC/DC50%1/2
defined $params{"digits"} and $params{"digits"} == 6
defined $params{"digits"} $params{"digits"} == 6
Truth table66%2/3
A and B
A= defined $params{"digits"}B= $params{"digits"} == 6
ABresult
0X0
100
111
359 20 ▶ delete $params{counter} if defined $params{counter} && $params{counter} == 0;
Branch: 1 branch
BranchTrueFalseTotal
if defined $params{"counter"} and $params{"counter"} == 0 5 15 20
Condition100%3/3
defined $params{"counter"} and $params{"counter"} == 0
!ll&&!rl&&r
1325
MC/DC100%2/2
defined $params{"counter"} and $params{"counter"} == 0
defined $params{"counter"} $params{"counter"} == 0
Truth table100%3/3
A and B
A= defined $params{"counter"}B= $params{"counter"} == 0
ABresult
0X0
100
111
360  
361 20 my $uri = "otpauth://$type/$label?secret=$secret&issuer=$issuer";
362  
363 20 ▶ if (defined $params{encoder}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params{"encoder"}) 1 19 20
364 1 $uri .= "&encoder=$params{encoder}";
365 1 return $uri;
366 }
367 19 ▶ $uri .= '&algorithm=' . uc($params{algorithm}) if defined $params{algorithm};
Branch: 1 branch
BranchTrueFalseTotal
if defined $params{"algorithm"} 2 17 19
368 19 ▶ $uri .= "&digits=$params{digits}" if defined $params{digits};
Branch: 1 branch
BranchTrueFalseTotal
if defined $params{"digits"} 3 16 19
369 19 ▶ $uri .= "&counter=$params{counter}" if defined $params{counter};
Branch: 1 branch
BranchTrueFalseTotal
if defined $params{"counter"} 2 17 19
370 19 ▶ $uri .= "&period=$params{period}" if defined $params{period};
Branch: 1 branch
BranchTrueFalseTotal
if defined $params{"period"} 2 17 19
371  
372 19 return $uri;
373 }
374  
375 sub _hotp_params {
376 36 ▶ my $self = shift;
Subroutine _hotp_params: called CC=7 SCAR=19.7
377  
378 36 ▶ my %params = (
Condition100%6/6
$self->expand_title || 'KDBX'
l!l
432
$self->expand_username || 'none'
l!l
432
$self->string_value("HmacOtp-Counter") // 0
l!l
2214
MC/DC100%1/1
$self->expand_title || 'KDBX'
$self->expand_title
MC/DC100%1/1
$self->expand_username || 'none'
$self->expand_username
MC/DC100%1/1
$self->string_value("HmacOtp-Counter") // 0
$self->string_value("HmacOtp-Counter")
Truth table100%2/2
A
A= $self->expand_title
Aresult
11
00
Truth table100%2/2
A
A= $self->expand_username
Aresult
11
00
Truth table100%2/2
A
A= $self->string_value("HmacOtp-Counter")
Aresult
11
00
379 type => 'hotp',
380 issuer => $self->expand_title || 'KDBX',
381 account => $self->expand_username || 'none',
382 digits => 6,
383 counter => $self->string_value('HmacOtp-Counter') // 0,
384 $self->_otp_secret_params('Hmac'),
385 );
386 36 ▶ return %params if $params{secret};
Branch: 1 branch
BranchTrueFalseTotal
if $params{"secret"} 24 12 36
387  
388 12 my %otp_params = $self->_otp_params;
389 12 ▶ return () if !$otp_params{secret} || $otp_params{type} ne 'hotp';
Branch: 1 branch
BranchTrueFalseTotal
if not $otp_params{"secret"} or $otp_params{"type"} ne "hotp" 0 12 12
Condition33%1/3
not $otp_params{"secret"} or $otp_params{"type"} ne "hotp"
l!l&&r!l&&!r
0012
MC/DC0%0/2
not $otp_params{"secret"} or $otp_params{"type"} ne "hotp"
not $otp_params{"secret"} $otp_params{"type"} ne "hotp"
Truth table33%1/3
not(A) or B
A= not $otp_params{"secret"}B= $otp_params{"type"} ne "hotp"
ABresult
1X1
011
000
390  
391 # $otp_params{counter} = 0
392  
393 12 return (%params, %otp_params);
394 }
395  
396 sub _totp_params {
397 21 ▶ my $self = shift;
Subroutine _totp_params: called CC=10 SCAR=23.2
398  
399 21 my %algorithms = (
400 'HMAC-SHA-1' => 'sha1',
401 'HMAC-SHA-256' => 'sha256',
402 'HMAC-SHA-512' => 'sha512',
403 );
404 my %params = (
405 type => 'totp',
406 issuer => $self->expand_title || 'KDBX',
407 account => $self->expand_username || 'none',
408 digits => $self->string_value('TimeOtp-Length') // 6,
409 21 ▶ algorithm => $algorithms{$self->string_value('TimeOtp-Algorithm') || ''} || 'sha1',
Condition100%12/12
$self->expand_title || 'KDBX'
l!l
219
$self->expand_username || 'none'
l!l
219
$self->string_value("TimeOtp-Length") // 6
l!l
219
$algorithms{$self->string_value('TimeOtp-Algorithm') or ''} || 'sha1'
l!l
219
$self->string_value('TimeOtp-Algorithm') || ''
l!l
219
$self->string_value("TimeOtp-Period") // 30
l!l
219
MC/DC100%1/1
$self->expand_title || 'KDBX'
$self->expand_title
MC/DC100%1/1
$self->expand_username || 'none'
$self->expand_username
MC/DC100%1/1
$self->string_value("TimeOtp-Length") // 6
$self->string_value("TimeOtp-Length")
MC/DC100%1/1
$algorithms{$self->string_value('TimeOtp-Algorithm') or ''} || 'sha1'
$algorithms{$self->string_value('TimeOtp-Algorithm') or ''}
MC/DC100%1/1
$self->string_value('TimeOtp-Algorithm') || ''
$self->string_value('TimeOtp-Algorithm')
MC/DC100%1/1
$self->string_value("TimeOtp-Period") // 30
$self->string_value("TimeOtp-Period")
Truth table100%2/2
A
A= $self->expand_title
Aresult
11
00
Truth table100%2/2
A
A= $self->expand_username
Aresult
11
00
Truth table100%2/2
A
A= $self->string_value("TimeOtp-Length")
Aresult
11
00
Truth table100%2/2
A
A= $algorithms{$self->string_value('TimeOtp-Algorithm') or ''}
Aresult
11
00
Truth table100%2/2
A
A= $self->string_value('TimeOtp-Algorithm')
Aresult
11
00
Truth table100%2/2
A
A= $self->string_value("TimeOtp-Period")
Aresult
11
00
410 period => $self->string_value('TimeOtp-Period') // 30,
411 $self->_otp_secret_params('Time'),
412 );
413 21 ▶ return %params if $params{secret};
Branch: 1 branch
BranchTrueFalseTotal
if $params{"secret"} 11 10 21
414  
415 10 my %otp_params = $self->_otp_params;
416 10 ▶ return () if !$otp_params{secret} || $otp_params{type} ne 'totp';
Branch: 1 branch
BranchTrueFalseTotal
if not $otp_params{"secret"} or $otp_params{"type"} ne "totp" 0 10 10
Condition33%1/3
not $otp_params{"secret"} or $otp_params{"type"} ne "totp"
l!l&&r!l&&!r
0010
MC/DC0%0/2
not $otp_params{"secret"} or $otp_params{"type"} ne "totp"
not $otp_params{"secret"} $otp_params{"type"} ne "totp"
Truth table33%1/3
not(A) or B
A= not $otp_params{"secret"}B= $otp_params{"type"} ne "totp"
ABresult
1X1
011
000
417  
418 10 return (%params, %otp_params);
419 }
420  
421 # KeePassXC style
422 sub _otp_params {
423 22 ▶ my $self = shift;
Subroutine _otp_params: called CC=12 SCAR=26.1
424 22 load_optional('Pass::OTP::URI');
425  
426 22 ▶ my $uri = $self->string_value('otp') || '';
Condition50%1/2
$self->string_value('otp') || ''
l!l
220
MC/DC0%0/1
$self->string_value('otp') || ''
$self->string_value('otp')
Truth table50%1/2
A
A= $self->string_value('otp')
Aresult
11
00
427 22 my %params;
428 22 ▶ %params = Pass::OTP::URI::parse($uri) if $uri =~ m!^otpauth://!;
Branch: 1 branch
BranchTrueFalseTotal
if $uri =~ m[^otpauth://] 22 0 22
429 22 ▶ return () if !$params{secret} || !$params{type};
Branch: 1 branch
BranchTrueFalseTotal
unless $params{"secret"} and $params{"type"} 0 22 22
Condition33%1/3
$params{"secret"} and $params{"type"}
!ll&&!rl&&r
0022
MC/DC0%0/2
$params{"secret"} and $params{"type"}
$params{"secret"} $params{"type"}
Truth table33%1/3
A and B
A= $params{"secret"}B= $params{"type"}
ABresult
0X0
100
111
430  
431 22 ▶ if (($params{encoder} // '') eq 'steam') {
Branch: 1 branch
BranchTrueFalseTotal
if (($params{"encoder"} // "") eq "steam") 2 20 22
Condition100%2/2
$params{"encoder"} // ""
l!l
220
MC/DC100%1/1
$params{"encoder"} // ""
$params{"encoder"}
Truth table100%2/2
A
A= $params{"encoder"}
Aresult
11
00
432 2 $params{digits} = 5;
433 2 $params{chars} = '23456789BCDFGHJKMNPQRTVWXY';
434 }
435  
436 # Pass::OTP::URI doesn't provide the issuer and account separately, so get them from the label
437 22 ▶ my ($issuer, $user) = split(':', $params{label} // ':', 2);
Condition50%1/2
$params{"label"} // ":"
l!l
220
MC/DC0%0/1
$params{"label"} // ":"
$params{"label"}
Truth table50%1/2
A
A= $params{"label"}
Aresult
11
00
438 22 ▶ $params{issuer} //= uri_unescape_utf8($issuer);
Condition66%2/3
$params{"issuer"} //= uri_unescape_utf8($issuer)
l!l&&r!l&&!r
2020
MC/DC0%0/2
$params{"issuer"} //= uri_unescape_utf8($issuer)
$params{"issuer"} uri_unescape_utf8($issuer)
Truth table66%2/3
A //= B
A= $params{"issuer"}B= uri_unescape_utf8($issuer)
ABresult
1X1
011
000
439 22 ▶ $params{account} //= uri_unescape_utf8($user);
Condition33%1/3
$params{"account"} //= uri_unescape_utf8($user)
l!l&&r!l&&!r
0220
MC/DC0%0/2
$params{"account"} //= uri_unescape_utf8($user)
$params{"account"} uri_unescape_utf8($user)
Truth table33%1/3
A //= B
A= $params{"account"}B= uri_unescape_utf8($user)
ABresult
1X1
011
000
440  
441 22 ▶ $params{algorithm} = lc($params{algorithm}) if $params{algorithm};
Branch: 1 branch
BranchTrueFalseTotal
if $params{"algorithm"} 2 20 22
442 22 ▶ $params{counter} = $self->string_value('HmacOtp-Counter') if $params{type} eq 'hotp';
Branch: 1 branch
BranchTrueFalseTotal
if $params{"type"} eq "hotp" 12 10 22
443  
444 22 return %params;
445 }
446  
447 sub _otp_secret_params {
448 57 ▶ my $self = shift;
Subroutine _otp_secret_params: called CC=7 SCAR=19.5
449 57 ▶ my $type = shift // return ();
Condition50%1/2
shift() // (return ())
l!l
570
MC/DC0%0/1
shift() // (return ())
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
450  
451 57 my $secret_txt = $self->string_value("${type}Otp-Secret");
452 57 my $secret_hex = $self->string_value("${type}Otp-Secret-Hex");
453 57 my $secret_b32 = $self->string_value("${type}Otp-Secret-Base32");
454 57 my $secret_b64 = $self->string_value("${type}Otp-Secret-Base64");
455  
456 57 my $count = grep { defined } ($secret_txt, $secret_hex, $secret_b32, $secret_b64);
457 57 ▶ return () if $count == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $count == 0 22 35 57
458 35 ▶ alert "Found multiple ${type}Otp-Secret strings", count => $count if 1 < $count;
Branch: 1 branch
BranchTrueFalseTotal
if 1 < $count 1 34 35
459  
460 35 ▶ return (secret => $secret_b32, base32 => 1) if defined $secret_b32;
Branch: 1 branch
BranchTrueFalseTotal
if defined $secret_b32 15 20 35
461 20 ▶ return (secret => decode_b64($secret_b64)) if defined $secret_b64;
Branch: 1 branch
BranchTrueFalseTotal
if defined $secret_b64 4 16 20
462 16 ▶ return (secret => pack('H*', $secret_hex)) if defined $secret_hex;
Branch: 1 branch
BranchTrueFalseTotal
if defined $secret_hex 4 12 16
463 12 return (secret => encode('UTF-8', $secret_txt));
464 }
465  
466 sub _hotp_increment_counter {
467 27 ▶ my $self = shift;
Subroutine _hotp_increment_counter: called CC=4 SCAR=14.0
468 27 ▶ my $counter = shift // $self->string_value('HmacOtp-Counter') || 0;
Condition80%4/5
(shift() // $self->string_value('HmacOtp-Counter')) || 0
l!l
207
shift() // $self->string_value("HmacOtp-Counter")
l!l&&r!l&&!r
2502
MC/DC50%1/2
(shift() // $self->string_value('HmacOtp-Counter')) || 0
shift() $self->string_value("HmacOtp-Counter")
Truth table66%2/3
A // B
A= shift()B= $self->string_value("HmacOtp-Counter")
ABresult
1X1
011
000
469  
470 27 ▶ looks_like_number($counter) or throw 'HmacOtp-Counter value must be a number', value => $counter;
Branch: 1 branch
BranchTrueFalseTotal
&looks_like_number($counter) or throw("HmacOtp-Counter value must be a number", "value", $counter) 0 27 27
471 27 my $next = $counter + 1;
472 27 $self->string('HmacOtp-Counter', $next);
473 27 return $next;
474 }
475  
476 ##############################################################################
477  
478  
479 sub size {
480 3 ▶ my $self = shift;
Subroutine size: called CC=14 SCAR=36.5
Pod documented
481  
482 3 my $size = 0;
483  
484 # tags
485 3 ▶ $size += length(encode('UTF-8', $self->tags // ''));
Condition50%1/2
$self->tags // ""
l!l
30
MC/DC0%0/1
$self->tags // ""
$self->tags
Truth table50%1/2
A
A= $self->tags
Aresult
11
00
486  
487 # attributes (strings)
488 3 ▶ while (my ($key, $string) = each %{$self->strings}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$self->strings;}) 15 3 18
489 15 ▶ next if !defined $string->{value};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $string->{"value"} 0 15 15
490 15 ▶ $size += length(encode('UTF-8', $key)) + length(encode('UTF-8', $string->{value} // ''));
Condition50%1/2
$string->{"value"} // ""
l!l
150
MC/DC0%0/1
$string->{"value"} // ""
$string->{"value"}
Truth table50%1/2
A
A= $string->{"value"}
Aresult
11
00
491 }
492  
493 # custom data
494 3 ▶ while (my ($key, $item) = each %{$self->custom_data}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$self->custom_data;}) 0 3 3
495 0 ▶ next if !defined $item->{value};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $item->{"value"} 0 0 0
496 0 ▶ $size += length(encode('UTF-8', $key)) + length(encode('UTF-8', $item->{value} // ''));
Condition0%0/2
$item->{"value"} // ""
l!l
00
MC/DC0%0/1
$item->{"value"} // ""
$item->{"value"}
Truth table0%0/2
A
A= $item->{"value"}
Aresult
11
00
497 }
498  
499 # binaries
500 3 ▶ while (my ($key, $binary) = each %{$self->binaries}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$self->binaries;}) 0 3 3
501 0 ▶ next if !defined $binary->{value};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $binary->{"value"} 0 0 0
502 my $value_len = utf8::is_utf8($binary->{value}) ? length(encode('UTF-8', $binary->{value}))
503 0 ▶ : length($binary->{value});
Branch: 1 branch
BranchTrueFalseTotal
utf8::is_utf8($binary->{'value'}) ? : 0 0 0
504 0 $size += length(encode('UTF-8', $key)) + $value_len;
505 }
506  
507 # autotype associations
508 3 ▶ for my $association (@{$self->auto_type->{associations} || []}) {
Branch: 1 branch
BranchTrueFalseTotal
$self->auto_type->{"associations"} or [] 0 3 3
509 $size += length(encode('UTF-8', $association->{window}))
510 0 ▶ + length(encode('UTF-8', $association->{keystroke_sequence} // ''));
Condition0%0/2
$association->{"keystroke_sequence"} // ""
l!l
00
MC/DC0%0/1
$association->{"keystroke_sequence"} // ""
$association->{"keystroke_sequence"}
Truth table0%0/2
A
A= $association->{"keystroke_sequence"}
Aresult
11
00
511 }
512  
513 3 return $size;
514 }
515  
516 ##############################################################################
517  
518 sub history {
519 280 ▶ my $self = shift;
Subroutine history: called CC=4 SCAR=13.9
Pod documented
520 280 ▶ my $entries = $self->{history} //= [];
Condition100%2/2
$self->{"history"} //= []
l!l
18595
MC/DC100%1/1
$self->{"history"} //= []
$self->{"history"}
Truth table100%2/2
A
A= $self->{"history"}
Aresult
11
00
521 280 ▶ if (@$entries && !blessed($entries->[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$entries and not builtin::blessed($entries->[0])) 4 276 280
Condition100%3/3
@$entries and not builtin::blessed($entries->[0])
!ll&&!rl&&r
248284
MC/DC100%2/2
@$entries and not builtin::blessed($entries->[0])
@$entries not builtin::blessed($entries->[0])
Truth table100%3/3
A and not(B)
A= @$entriesB= not builtin::blessed($entries->[0])
ABresult
0X0
100
111
522 4 @$entries = map { $self->_wrap_entry($_, $self->kdbx) } @$entries;
523 }
524 280 ▶ assert { !any { !blessed $_ } @$entries };
Subroutine __ANON__: not called CC=1 SCAR=2.6
525 280 return $entries;
526 }
527  
528  
529 sub history_size {
530 2 ▶ my $self = shift;
Subroutine history_size: called CC=1 SCAR=0.0
Pod documented
531 2 return sum0 map { $_->size } @{$self->history};
532 }
533  
534  
535 sub prune_history {
536 2 ▶ my $self = shift;
Subroutine prune_history: called CC=14 SCAR=32.5
Pod documented
537 2 my %args = @_;
538  
539 2 ▶ my $max_items = $args{max_items} // eval { $self->kdbx->history_max_items } // HISTORY_DEFAULT_MAX_ITEMS;
Condition40%2/5
($args{"max_items"} // eval { do { $self->kdbx->history_max_items } }) // 10
l!l
20
$args{"max_items"} // eval { do { $self->kdbx->history_max_items } }
l!l&&r!l&&!r
200
MC/DC0%0/2
($args{"max_items"} // eval { do { $self->kdbx->history_max_items } }) // 10
$args{"max_items"} eval { do { $self->kdbx->history_max_items } }
Truth table33%1/3
A // B
A= $args{"max_items"}B= eval { do { $self->kdbx->history_max_items } }
ABresult
1X1
011
000
540 2 ▶ my $max_size = $args{max_size} // eval { $self->kdbx->history_max_size } // HISTORY_DEFAULT_MAX_SIZE;
Condition40%2/5
($args{"max_size"} // eval { do { $self->kdbx->history_max_size } }) // 6291456
l!l
20
$args{"max_size"} // eval { do { $self->kdbx->history_max_size } }
l!l&&r!l&&!r
200
MC/DC0%0/2
($args{"max_size"} // eval { do { $self->kdbx->history_max_size } }) // 6291456
$args{"max_size"} eval { do { $self->kdbx->history_max_size } }
Truth table33%1/3
A // B
A= $args{"max_size"}B= eval { do { $self->kdbx->history_max_size } }
ABresult
1X1
011
000
541 2 ▶ my $max_age = $args{max_age} // eval { $self->kdbx->maintenance_history_days } // HISTORY_DEFAULT_MAX_AGE;
Condition40%2/5
($args{"max_age"} // eval { do { $self->kdbx->maintenance_history_days } }) // 365
l!l
20
$args{"max_age"} // eval { do { $self->kdbx->maintenance_history_days } }
l!l&&r!l&&!r
200
MC/DC0%0/2
($args{"max_age"} // eval { do { $self->kdbx->maintenance_history_days } }) // 365
$args{"max_age"} eval { do { $self->kdbx->maintenance_history_days } }
Truth table33%1/3
A // B
A= $args{"max_age"}B= eval { do { $self->kdbx->maintenance_history_days } }
ABresult
1X1
011
000
542  
543 # history is ordered oldest to newest
544 2 my $history = $self->history;
545  
546 2 my @removed;
547  
548 2 ▶ if (0 <= $max_items && $max_items < @$history) {
Branch: 1 branch
BranchTrueFalseTotal
if (0 <= $max_items and $max_items < @$history) 0 2 2
Condition33%1/3
0 <= $max_items and $max_items < @$history
!ll&&!rl&&r
020
MC/DC0%0/2
0 <= $max_items and $max_items < @$history
0 <= $max_items $max_items < @$history
Truth table33%1/3
A and B
A= 0 <= $max_itemsB= $max_items < @$history
ABresult
0X0
100
111
549 0 push @removed, splice @$history, -$max_items;
550 }
551  
552 2 ▶ if (0 <= $max_size) {
Branch: 1 branch
BranchTrueFalseTotal
if (0 <= $max_size) 2 0 2
553 2 my $current_size = $self->history_size;
554 2 ▶ while ($max_size < $current_size) {
Branch: 1 branch
BranchTrueFalseTotal
if ($max_size < $current_size) 0 2 2
555 0 push @removed, my $entry = shift @$history;
556 0 $current_size -= $entry->size;
557 }
558 }
559  
560 2 ▶ if (0 <= $max_age) {
Branch: 1 branch
BranchTrueFalseTotal
if (0 <= $max_age) 2 0 2
561 2 my $cutoff = gmtime - ($max_age * 86400);
562 2 ▶ for (my $i = @$history - 1; 0 <= $i; --$i) {
Branch: 1 branch
BranchTrueFalseTotal
if (0 <= $i) 3 2 5
563 3 my $entry = $history->[$i];
564 3 ▶ next if $cutoff <= $entry->last_modification_time;
Branch: 1 branch
BranchTrueFalseTotal
if $cutoff <= $entry->last_modification_time 2 1 3
565 1 push @removed, splice @$history, $i, 1;
566 }
567 }
568  
569 2 @removed = sort { $a->last_modification_time <=> $b->last_modification_time } @removed;
570 2 return @removed;
571 }
572  
573  
574 sub add_historical_entry {
575 8 ▶ my $self = shift;
Subroutine add_historical_entry: called CC=3 SCAR=11.0
Pod documented
576 8 delete $_->{history} for @_;
577 8 ▶ push @{$self->{history} //= []}, map { $self->_wrap_entry($_) } @_;
Condition100%2/2
$self->{"history"} //= []
l!l
71
MC/DC100%1/1
$self->{"history"} //= []
$self->{"history"}
Truth table100%2/2
A
A= $self->{"history"}
Aresult
11
00
578 }
579  
580  
581 sub remove_historical_entry {
582 33 ▶ my $self = shift;
Subroutine remove_historical_entry: called CC=3 SCAR=11.3
Pod documented
583 33 my $entry = shift;
584 33 my $history = $self->history;
585  
586 33 my @removed;
587 33 ▶ for (my $i = @$history - 1; 0 <= $i; --$i) {
Branch: 1 branch
BranchTrueFalseTotal
if (0 <= $i) 3 33 36
588 3 my $item = $history->[$i];
589 3 ▶ next if Hash::Util::FieldHash::id($entry) != Hash::Util::FieldHash::id($item);
Branch: 1 branch
BranchTrueFalseTotal
if &Hash::Util::FieldHash::id($entry) != &Hash::Util::FieldHash::id($item) 3 0 3
590 0 push @removed, splice @{$self->{history}}, $i, 1;
591 }
592 33 return @removed;
593 }
594  
595  
596 sub current_entry {
597 50 ▶ my $self = shift;
Subroutine current_entry: called CC=3 SCAR=11.0
Pod documented
598 50 my $parent = $self->group;
599  
600 50 ▶ if ($parent) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parent) 9 41 50
601 9 my $id = $self->uuid;
602 9 ▶ my $entry = first { $id eq $_->uuid } @{$parent->entries};
Subroutine __ANON__: called CC=1 SCAR=0.0
603 9 ▶ return $entry if $entry;
Branch: 1 branch
BranchTrueFalseTotal
if $entry 9 0 9
604 }
605  
606 41 return $self;
607 }
608  
609  
610 sub is_current {
611 16 ▶ my $self = shift;
Subroutine is_current: called CC=1 SCAR=0.0
Pod documented
612 16 my $current = $self->current_entry;
613 16 return Hash::Util::FieldHash::id($self) == Hash::Util::FieldHash::id($current);
614 }
615  
616  
617 1 ▶sub is_historical { !$_[0]->is_current }
Subroutine is_historical: called CC=1 SCAR=0.0
Pod documented
618  
619  
620 sub remove {
621 33 ▶ my $self = shift;
Subroutine remove: called CC=2 SCAR=7.0
Pod documented
622 33 my $current = $self->current_entry;
623 33 ▶ return $self if $current->remove_historical_entry($self);
Branch: 1 branch
BranchTrueFalseTotal
if $current->remove_historical_entry($self) 0 33 33
624 33 $self->SUPER::remove(@_);
625 }
626  
627 ##############################################################################
628  
629  
630 sub searching_enabled {
631 0 ▶ my $self = shift;
Subroutine searching_enabled: not called CC=2 SCAR=17.9
Pod documented
632 0 my $parent = $self->group;
633 0 ▶ return $parent->effective_enable_searching if $parent;
Branch: 1 branch
BranchTrueFalseTotal
if $parent 0 0 0
634 0 return true;
635 }
636  
637 sub auto_type_enabled {
638 84 ▶ my $self = shift;
Subroutine auto_type_enabled: called CC=6 SCAR=19.0
Pod documented
639 84 ▶ $self->auto_type->{enabled} = to_bool(shift) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 84 84
640 84 ▶ $self->auto_type->{enabled} //= true;
Condition33%1/3
$self->auto_type->{"enabled"} //= &true()
l!l&&r!l&&!r
0840
MC/DC0%0/2
$self->auto_type->{"enabled"} //= &true()
$self->auto_type->{"enabled"} &true()
Truth table33%1/3
A //= B
A= $self->auto_type->{"enabled"}B= &true()
ABresult
1X1
011
000
641 84 ▶ return false if !$self->auto_type->{enabled};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->auto_type->{"enabled"} 0 84 84
642 84 ▶ return true if !$self->is_connected;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_connected 59 25 84
643 25 my $parent = $self->group;
644 25 ▶ return $parent->effective_enable_auto_type if $parent;
Branch: 1 branch
BranchTrueFalseTotal
if $parent 0 25 25
645 25 return true;
646 }
647  
648 ##############################################################################
649  
650 sub _signal {
651 45 ▶ my $self = shift;
Subroutine _signal: called CC=1 SCAR=0.0
652 45 my $type = shift;
653 45 return $self->SUPER::_signal("entry.$type", @_);
654 }
655  
656 sub _commit {
657 8 ▶ my $self = shift;
Subroutine _commit: called CC=1 SCAR=0.0
658 8 my $orig = shift;
659 8 $self->add_historical_entry($orig);
660 8 my $time = gmtime;
661 8 $self->last_modification_time($time);
662 8 $self->last_access_time($time);
663 }
664  
665 138 ▶sub label { shift->expand_title(@_) }
Subroutine label: called CC=1 SCAR=0.0
Pod documented
666  
667 ### Name of the parent attribute expected to contain the object
668 22 ▶sub _parent_container { 'entries' }
Subroutine _parent_container: called CC=1 SCAR=0.0
669  
670 11 1;
671  
672 __END__
« KDBX/IO.pm ↑ Summary KDBX/KDF/AES.pm »