| 1 | package File::KeePass::KDBX; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Read and write KDBX files (using the File::KDBX backend) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use Crypt::PRNG qw(irand); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 5 | ▶ | use Crypt::Misc 0.029 qw(decode_b64 encode_b64); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 5 | ▶ | use File::KDBX 0.900; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 5 | ▶ | use File::KDBX::Constants qw(:header :magic :version); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 5 | ▶ | use File::KDBX::Loader::KDB; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 5 | ▶ | use File::KDBX::Util qw(clone_nomagic generate_uuid load_optional); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 5 | ▶ | use Hash::Util::FieldHash qw(fieldhashes); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 5 | ▶ | use Module::Load; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 5 | ▶ | use Scalar::Util qw(blessed looks_like_number weaken); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 5 | ▶ | use boolean; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 5 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 5 | our $VERSION = '0.901'; # VERSION | |||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 5 | fieldhashes \my (%KDBX, %TIED); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 5 | ▶ | our @ISA; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 5 | ▶ | @ISA = qw(File::KeePass) if $INC{'File/KeePass.pm'}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 9 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=12 SCAR=30.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | # copy constructor | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 9 | ▶ | return $_[0]->clone if @_ == 1 && (blessed $_[0] // '') eq __PACKAGE__; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition60%3/5
@_ == 1 and (builtin::blessed($_[0]) // "") eq __PACKAGE__
builtin::blessed($_[0]) // ""
MC/DC0%0/2
@_ == 1 and (builtin::blessed($_[0]) // "") eq __PACKAGE__
@_ == 1
builtin::blessed($_[0])
Truth table66%2/3
A and B
A= @_ == 1B= builtin::blessed($_[0])
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 9 | ▶ | if (@_ == 1 && blessed $_[0] && $_[0]->isa('File::KeePass')) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
@_ == 1 and builtin::blessed($_[0]) and $_[0]->isa("File::KeePass")
@_ == 1 and builtin::blessed($_[0])
MC/DC0%0/3
@_ == 1 and builtin::blessed($_[0]) and $_[0]->isa("File::KeePass")
@_ == 1
builtin::blessed($_[0])
$_[0]->isa("File::KeePass")
Truth table50%2/4
A and B and C
A= @_ == 1B= builtin::blessed($_[0])C= $_[0]->isa("File::KeePass")
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | return $class->from_fkp(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 9 | ▶ | if (@_ == 1 && blessed $_[0] && $_[0]->isa('File::KDBX')) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
@_ == 1 and builtin::blessed($_[0]) and $_[0]->isa("File::KDBX")
@_ == 1 and builtin::blessed($_[0])
MC/DC0%0/3
@_ == 1 and builtin::blessed($_[0]) and $_[0]->isa("File::KDBX")
@_ == 1
builtin::blessed($_[0])
$_[0]->isa("File::KDBX")
Truth table50%2/4
A and B and C
A= @_ == 1B= builtin::blessed($_[0])C= $_[0]->isa("File::KDBX")
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | my $self = bless {}, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | $self->kdbx($_[0]); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 9 | ▶ | my $args = ref $_[0] ? {%{$_[0]}} : {@_}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 9 | my $self = bless $args, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 9 | ▶ | exists $args->{kdbx} and $self->kdbx(delete $args->{kdbx}); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 9 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 1 | ▶ | sub DESTROY { $_[0]->clear } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | sub clone { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clone: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | require Storable; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | return Storable::dclone($self); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | sub STORABLE_freeze { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
STORABLE_freeze: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | my $copy = {%$self}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | delete @$self{qw(header groups)}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | return '', $copy, $KDBX{$self}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | sub STORABLE_thaw { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
STORABLE_thaw: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | my $cloning = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | shift; # empty | |||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | my $copy = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | my $kdbx = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | @$self{keys %$copy} = values %$copy; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | $self->kdbx($kdbx) if $kdbx; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | sub clear { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 3 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clear: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 3 | delete $KDBX{$self}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 3 | delete $TIED{$self}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 3 | delete @$self{qw(header groups)}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | sub kdbx { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 420 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
kdbx: called CC=4 SCAR=15.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 420 | ▶ | $self = $self->new if !ref $self; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 420 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | $self->clear; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | $KDBX{$self} = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 420 | ▶ | $KDBX{$self} //= File::KDBX->new; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$KDBX{$self} //= "File::KDBX"->new
MC/DC0%0/2
$KDBX{$self} //= "File::KDBX"->new
$KDBX{$self}
"File::KDBX"->new
Truth table66%2/3
A //= B
A= $KDBX{$self}B= "File::KDBX"->new
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | sub to_fkp { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_fkp: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | load_optional('File::KeePass'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | return File::KeePass->new(clone_nomagic({%$self, header => $self->header, groups => $self->groups})); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | sub from_fkp { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
from_fkp: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | my $k = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | my $kdbx = File::KDBX::Loader::KDB::convert_keepass_to_kdbx($k); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | my $self = bless {}, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | $self->kdbx($kdbx); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | sub load_db { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 6 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
load_db: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 6 | ▶ | my $file = shift or die "Missing file\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 4 | ▶ | my $pass = shift or die "Missing pass\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 2 | ▶ | my $args = shift || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || {}
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 2 | ▶ | open(my $fh, '<:raw', $file) or die "Could not open $file: $!\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 2 | $self->_load($fh, $pass, $args); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | sub parse_db { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 10 | ▶ | my ($self, $buf, $pass, $args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_db: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 10 | ▶ | my $ref = ref $buf ? $buf : \$buf; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 10 | ▶ | open(my $fh, '<:raw', $ref) or die "Could not open buffer: $!\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 10 | $self->_load($fh, $pass, $args); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | sub _load { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 12 | ▶ | my ($self, $fh, $pass, $args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_load: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 12 | ▶ | $self = $self->new($args) if !ref $self; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 12 | ▶ | my $unlock = defined $args->{auto_lock} ? !$args->{auto_lock} : !$self->auto_lock; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 12 | $self->kdbx->load_handle($fh, $pass); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 12 | ▶ | $self->kdbx->unlock if $unlock; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 12 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | sub parse_header { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | my ($self, $buf) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_header: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | open(my $fh, '<:raw', \$buf) or die "Could not open buffer: $!\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | # detect filetype and version | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | my $loader = File::KDBX::Loader->new; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | my ($sig1, $sig2, $version) = $loader->read_magic_numbers($fh); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | ▶ | if ($sig2 == KDBX_SIG2_1 || $version < KDBX_VERSION_2_0) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$sig2 == 3041655653 or $version < 131072
MC/DC0%0/2
$sig2 == 3041655653 or $version < 131072
$sig2 == 3041655653
$version < 131072
Truth table0%0/3
A or B
A= $sig2 == 3041655653B= $version < 131072
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | close($fh); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | load_optional('File::KeePass'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | return File::KeePass->parse_header($buf); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | my %header_transform = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | HEADER_COMMENT() => ['comment'], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | ▶ | HEADER_CIPHER_ID() => ['cipher', sub { $self->_cipher_name($_[0]) }], | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | HEADER_COMPRESSION_FLAGS() => ['compression'], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | HEADER_MASTER_SEED() => ['seed_rand'], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | HEADER_TRANSFORM_SEED() => ['seed_key'], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | HEADER_TRANSFORM_ROUNDS() => ['rounds'], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | HEADER_ENCRYPTION_IV() => ['enc_iv'], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | HEADER_INNER_RANDOM_STREAM_KEY() => ['protected_stream_key'], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | HEADER_STREAM_START_BYTES() => ['start_bytes'], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | ▶ | HEADER_INNER_RANDOM_STREAM_ID() => ['protected_stream', sub { $self->_inner_random_stream_name($_[0]) }], | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | HEADER_KDF_PARAMETERS() => ['kdf_parameters'], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | HEADER_PUBLIC_CUSTOM_DATA() => ['public_custom_data'], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | my %head; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | ▶ | while (my ($type, $val) = $loader->_read_header($fh)) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | last if $type == HEADER_END; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | ▶ | my ($name, $filter) = @{$header_transform{$type} || ["$type"]}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | ▶ | $head{$name} = $filter ? $filter->($val) : $val; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | return \%head; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | sub save_db { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 10 | ▶ | my ($self, $file, $pass, $head) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
save_db: called CC=6 SCAR=18.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 10 | ▶ | die "Missing file\n" if !$file; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 8 | ▶ | die "Missing pass\n" if !$pass; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 6 | ▶ | shift if @_ % 2 == 1; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 6 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 6 | local $self->kdbx->{headers} = $self->_gen_headers($head); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 6 | ▶ | $args{randomize_seeds} = 0 if $head && $head->{reuse_header}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$head and $head->{"reuse_header"}
MC/DC0%0/2
$head and $head->{"reuse_header"}
$head
$head->{"reuse_header"}
Truth table33%1/3
A and B
A= $headB= $head->{"reuse_header"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 6 | $self->kdbx->dump_file($file, $pass, %args); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 6 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | sub gen_db { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 10 | ▶ | my ($self, $pass, $head) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
gen_db: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 10 | ▶ | die "Missing pass\n" if !$pass; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 8 | ▶ | shift if @_ % 2 == 1; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 8 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 8 | local $self->kdbx->{headers} = $self->_gen_headers($head); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 8 | ▶ | $args{randomize_seeds} = 0 if $head && $head->{reuse_header}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$head and $head->{"reuse_header"}
MC/DC0%0/2
$head and $head->{"reuse_header"}
$head
$head->{"reuse_header"}
Truth table66%2/3
A and B
A= $headB= $head->{"reuse_header"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 8 | my $dump = $self->kdbx->dump_string($pass, %args); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 8 | return $$dump; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | sub _gen_headers { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 14 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_gen_headers: called CC=13 SCAR=32.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 14 | ▶ | my $head = shift || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
shift() || {}
MC/DC100%1/1
shift() || {}
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 14 | ▶ | my $v = $head->{'version'} || $self->header->{'version'}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$head->{'version'} || $self->header->{'version'}
MC/DC0%0/2
$head->{'version'} || $self->header->{'version'}
$head->{'version'}
$self->header->{'version'}
Truth table33%1/3
A || B
A= $head->{'version'}B= $self->header->{'version'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | my $reuse = $head->{'reuse_header'} # explicit yes | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | || (!exists($head->{'reuse_header'}) # not explicit no | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | && ($self->{'reuse_header'} # explicit yes | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 14 | ▶ | || !exists($self->{'reuse_header'}))); # not explicit no | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%3/9
$head->{'reuse_header'} || !exists $head->{'reuse_header'} && ($self->{'reuse_header'} || !exists $self->{'reuse_header'})
not exists $head->{"reuse_header"} and $self->{"reuse_header"} || !exists $self->{"reuse_header"}
$self->{"reuse_header"} or not exists $self->{"reuse_header"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 14 | ▶ | if ($reuse) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 14 | ▶ | ($head, my $args) = ($self->header || {}, $head); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->header || {}
MC/DC0%0/1
$self->header || {}
$self->header
Truth table50%1/2
A
A= $self->header
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 14 | @$head{keys %$args} = values %$args; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 14 | ▶ | $head->{'version'} = $v ||= $head->{'version'} || '1'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition20%1/5
$v ||= $head->{"version"} || 1
$head->{'version'} || '1'
MC/DC0%0/2
$v ||= $head->{"version"} || 1
$v
$head->{'version'}
Truth table33%1/3
A ||= B
A= $vB= $head->{'version'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 14 | ▶ | delete @$head{qw(enc_iv seed_key seed_rand protected_stream_key start_bytes)} if $reuse && $reuse < 0; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$reuse and $reuse < 0
MC/DC0%0/2
$reuse and $reuse < 0
$reuse
$reuse < 0
Truth table33%1/3
A and B
A= $reuseB= $reuse < 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 14 | ▶ | if ($head->{version} == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | $head->{enc_type} = 'rijndael'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | $head->{cipher} = 'aes'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 14 | my $temp_kdbx = File::KDBX::Loader::KDB::_convert_keepass_to_kdbx_headers($head, File::KDBX->new); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 14 | return $temp_kdbx->headers; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | sub header { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 34 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
header: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 34 | ▶ | return if !exists $KDBX{$self}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 32 | ▶ | $self->{header} //= $self->_tie({}, 'Header', $self->kdbx); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"header"} //= $self->_tie({}, "Header", $self->kdbx)
MC/DC0%0/2
$self->{"header"} //= $self->_tie({}, "Header", $self->kdbx)
$self->{"header"}
$self->_tie({}, "Header", $self->kdbx)
Truth table66%2/3
A //= B
A= $self->{"header"}B= $self->_tie({}, "Header", $self->kdbx)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | sub groups { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 79 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
groups: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 79 | ▶ | return if !exists $KDBX{$self}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 75 | ▶ | $self->{groups} //= $self->_tie([], 'GroupList', $self->kdbx); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"groups"} //= $self->_tie([], "GroupList", $self->kdbx)
MC/DC0%0/2
$self->{"groups"} //= $self->_tie([], "GroupList", $self->kdbx)
$self->{"groups"}
$self->_tie([], "GroupList", $self->kdbx)
Truth table66%2/3
A //= B
A= $self->{"groups"}B= $self->_tie([], "GroupList", $self->kdbx)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | # Copied from File::KeePass - thanks paul | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | sub dump_groups { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 13 | ▶ | my ($self, $args, $groups) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dump_groups: called CC=6 SCAR=18.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 13 | my $t = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 13 | ▶ | my %gargs; for (keys %$args) { $gargs{$2} = $args->{$1} if /^(group_(.+))$/ }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 13 | foreach my $g ($self->find_groups(\%gargs, $groups)) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 63 | my $indent = ' ' x $g->{'level'}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 63 | ▶ | $t .= $indent.($g->{'expanded'} ? '-' : '+')." $g->{'title'} ($g->{'id'}) $g->{'created'}\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 63 | local $g->{'groups'}; # don't recurse while looking for entries since we are already flat | |||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 63 | $t .= "$indent > $_->{'title'}\t($_->{'id'}) $_->{'created'}\n" for $self->find_entries($args, [$g]); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 13 | return $t; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | sub add_group { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 35 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_group: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 35 | my $group = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 35 | my $parent = delete local $group->{group}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 35 | ▶ | $parent = $parent->{id} if ref $parent; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 35 | ▶ | $group->{expires} //= $self->default_exp; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$group->{"expires"} //= $self->default_exp
MC/DC0%0/2
$group->{"expires"} //= $self->default_exp
$group->{"expires"}
$self->default_exp
Truth table33%1/3
A //= B
A= $group->{"expires"}B= $self->default_exp
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 35 | my $group_info = File::KDBX::Loader::KDB::_convert_keepass_to_kdbx_group($group); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 35 | my $group_obj = $self->kdbx->add_group($group_info, group => $parent); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 35 | return $self->_tie({}, 'Group', $group_obj); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | # Copied from File::KeePass - thanks paul | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | sub find_groups { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 439 | ▶ | my ($self, $args, $groups, $level) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_groups: called CC=13 SCAR=26.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 439 | my @tests = $self->finder_tests($args); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 439 | my @groups; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | my %uniq; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 439 | ▶ | my $container = $groups || $self->groups; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$groups || $self->groups
MC/DC0%0/2
$groups || $self->groups
$groups
$self->groups
Truth table66%2/3
A || B
A= $groupsB= $self->groups
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 439 | for my $g (@$container) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 303 | ▶ | $g->{'level'} = $level || 0; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$level || 0
MC/DC100%1/1
$level || 0
$level
Truth table100%2/2
A
A= $level
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 303 | ▶ | $g->{'title'} = '' if ! defined $g->{'title'}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 303 | ▶ | $g->{'icon'} ||= 0; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$g->{"icon"} ||= 0
MC/DC0%0/1
$g->{"icon"} ||= 0
$g->{"icon"}
Truth table50%1/2
A
A= $g->{"icon"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 303 | ▶ | if ($self->{'force_v2_gid'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | $g->{'id'} = $self->uuid($g->{'id'}, \%uniq); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 303 | ▶ | $g->{'id'} = irand while !defined($g->{'id'}) || $uniq{$g->{'id'}}++; # the non-v2 gid is compatible with both v1 and our v2 implementation | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $g->{"id"} or $uniq{$g->{"id"}}++
MC/DC0%0/2
not defined $g->{"id"} or $uniq{$g->{"id"}}++
not defined $g->{"id"}
$uniq{$g->{"id"}}++
Truth table33%1/3
not(A) or B
A= not defined $g->{"id"}B= $uniq{$g->{"id"}}++
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 303 | ▶ | if (!@tests || !grep{!$_->($g)} @tests) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@tests and grep {not &$_($g);} @tests
MC/DC0%0/2
@tests and grep {not &$_($g);} @tests
@tests
grep {not &$_($g);} @tests
Truth table33%1/3
A and B
A= @testsB= grep {not &$_($g);} @tests
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 265 | push @groups, $g; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 265 | ▶ | push @{ $self->{'__group_groups'} }, $container if $self->{'__group_groups'}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 303 | ▶ | push @groups, $self->find_groups($args, $g->{'groups'}, $g->{'level'} + 1) if $g->{'groups'}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 439 | return @groups; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | # Copied from File::KeePass - thanks paul | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | sub find_group { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 36 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_group: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 36 | ▶ | local $self->{'__group_groups'} = [] if wantarray; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 36 | my @g = $self->find_groups(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 36 | ▶ | die "Found too many groups (@g)\n" if @g > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 34 | ▶ | return wantarray ? ($g[0], $self->{'__group_groups'}->[0]) : $g[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | sub delete_group { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 7 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
delete_group: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 7 | my $group_info = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 7 | ▶ | my $group = $self->find_group($group_info) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 5 | $group->{__object}->remove; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 5 | return $group; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | sub add_entry { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 7 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_entry: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 7 | my $entry = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 7 | my $parent = delete local $entry->{group}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 7 | ▶ | $parent = $parent->{id} if ref $parent; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 7 | ▶ | $entry->{expires} //= $self->default_exp; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$entry->{"expires"} //= $self->default_exp
MC/DC0%0/2
$entry->{"expires"} //= $self->default_exp
$entry->{"expires"}
$self->default_exp
Truth table66%2/3
A //= B
A= $entry->{"expires"}B= $self->default_exp
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 7 | my $entry_info = File::KDBX::Loader::KDB::_convert_keepass_to_kdbx_entry($entry); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 7 | ▶ | $parent = $self->kdbx->root->groups->[0] if !$parent && $self->kdbx->_has_implicit_root; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $parent and $self->kdbx->_has_implicit_root
MC/DC50%1/2
not $parent and $self->kdbx->_has_implicit_root
not $parent
$self->kdbx->_has_implicit_root
Truth table66%2/3
not(A) and B
A= not $parentB= $self->kdbx->_has_implicit_root
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 7 | my $entry_obj = $self->kdbx->add_entry($entry_info, group => $parent); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 7 | return $self->_tie({}, 'Entry', $entry_obj); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | # Copied from File::KeePass - thanks paul | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | sub find_entries { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 87 | ▶ | my ($self, $args, $groups) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_entries: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 87 | ▶ | local @{ $args }{'expires gt', 'active'} = ($self->now, undef) if $args->{'active'}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 87 | my @tests = $self->finder_tests($args); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 87 | my @entries; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 87 | foreach my $g ($self->find_groups({}, $groups)) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 169 | ▶ | foreach my $e (@{ $g->{'entries'} || [] }) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 48 | local $e->{'group_id'} = $g->{'id'}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 48 | local $e->{'group_title'} = $g->{'title'}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 48 | ▶ | if (!@tests || !grep{!$_->($e)} @tests) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@tests and grep {not &$_($e);} @tests
MC/DC0%0/2
@tests and grep {not &$_($e);} @tests
@tests
grep {not &$_($e);} @tests
Truth table33%1/3
A and B
A= @testsB= grep {not &$_($e);} @tests
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 32 | push @entries, $e; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 32 | ▶ | push @{ $self->{'__entry_groups'} }, $g if $self->{'__entry_groups'}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 87 | return @entries; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | # Copied from File::KeePass - thanks paul | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | sub find_entry { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 20 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_entry: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 20 | ▶ | local $self->{'__entry_groups'} = [] if wantarray; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 20 | my @e = $self->find_entries(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 20 | ▶ | die "Found too many entries (@e)\n" if @e > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 18 | ▶ | return wantarray ? ($e[0], $self->{'__entry_groups'}->[0]) : $e[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | sub delete_entry { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 4 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
delete_entry: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 4 | my $entry_info = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 4 | ▶ | my $entry = $self->find_entry($entry_info) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 2 | $entry->{__object}->remove; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 2 | return $entry; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | ############################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | # Copied from File::KeePass - thanks paul | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | sub finder_tests { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 526 | ▶ | my ($self, $args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
finder_tests: called CC=12 SCAR=25.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 526 | my @tests; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 526 | ▶ | foreach my $key (keys %{ $args || {} }) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 125 | ▶ | next if ! defined $args->{$key}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 123 | ▶ | my ($field, $op) = ($key =~ m{ ^ (\w+) \s* (|!|=|!~|=~|gt|lt) $ }x) ? ($1, $2) : die "Invalid find match criteria \"$key\"\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 81 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 4 | ▶ | : ($op eq '!') ? sub { !defined($_[0]->{$field}) || $_[0]->{$field} ne $args->{$key} } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 4 | ▶ | : ($op eq '=~') ? sub { defined($_[0]->{$field}) && $_[0]->{$field} =~ $args->{$key} } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 4 | ▶ | : ($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}/
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}/
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 8 | ▶ | : ($op eq 'gt') ? sub { defined($_[0]->{$field}) && $_[0]->{$field} gt $args->{$key} } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 4 | ▶ | : ($op eq 'lt') ? sub { defined($_[0]->{$field}) && $_[0]->{$field} lt $args->{$key} } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 123 | ▶ | : die "Unknown op \"$op\"\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
Condition100%3/3
not $op or $op eq "="
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 "="
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 526 | return @tests; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 40 | ▶ | sub default_exp { $_[0]->{default_exp} || '2999-12-31 23:23:59' } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_exp: called CC=2 SCAR=7.6
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | # Copied from File::KeePass - thanks paul | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | sub now { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 2 | ▶ | my ($self, $time) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
now: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 2 | ▶ | my ($sec, $min, $hour, $day, $mon, $year) = gmtime($time || time); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$time || time
MC/DC0%0/2
$time || time
$time
time
Truth table33%1/3
A || B
A= $timeB= time
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 2 | return sprintf '%04d-%02d-%02d %02d:%02d:%02d', $year+1900, $mon+1, $day, $hour, $min, $sec; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | ▶ | sub encode_base64 { encode_b64($_[1]) } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
encode_base64: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | ▶ | sub decode_base64 { decode_b64($_[1]) } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
decode_base64: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 2 | ▶ | sub gen_uuid { generate_uuid(printable => 1) } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
gen_uuid: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | # Copied from File::KeePass - thanks paul | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | sub uuid { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 0 | ▶ | my ($self, $id, $uniq) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
uuid: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | ▶ | $id = $self->gen_uuid if !defined($id) || !length($id); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $id and length $id
MC/DC0%0/2
defined $id and length $id
defined $id
length $id
Truth table0%0/3
A and B
A= defined $idB= length $id
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 0 | ▶ | return $uniq->{$id} ||= do { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/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
}
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 table0%0/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
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 0 | ▶ | if (length($id) != 16) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | ▶ | $id = substr($self->encode_base64($id), 0, 16) if $id !~ /^\d+$/ || $id > 2**32-1; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $id =~ /^\d+$/ or $id > 4294967295
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | ▶ | $id = sprintf '%016s', $id if $id ne '0'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | ▶ | $id = $self->gen_uuid while $uniq->{$id}++; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | $id; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | ############################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | sub auto_lock { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 14 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
auto_lock: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 14 | ▶ | $self->{auto_lock} = shift if @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 14 | ▶ | $self->{auto_lock} //= 1; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"auto_lock"} //= 1
MC/DC100%1/1
$self->{"auto_lock"} //= 1
$self->{"auto_lock"}
Truth table100%2/2
A
A= $self->{"auto_lock"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 12 | ▶ | sub is_locked { $_[0]->kdbx->is_locked } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_locked: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 2 | ▶ | sub lock { $_[0]->kdbx->lock } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lock: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 4 | ▶ | sub unlock { $_[0]->kdbx->unlock } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unlock: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | sub locked_entry_password { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 4 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
locked_entry_password: called CC=5 SCAR=16.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 4 | my $entry = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 4 | ▶ | $self->is_locked or die "Passwords are not locked\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 2 | ▶ | $entry = $self->find_entry({id => $entry}) if !ref $entry; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 2 | ▶ | return if !$entry; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 2 | ▶ | my $entry_obj = $entry->{__object} or return; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 2 | return $entry_obj->string_peek('Password'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | ############################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | sub _tie { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 1254 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_tie: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 1254 | ▶ | my $ref = shift // \my %h; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() // \my %h
MC/DC0%0/1
shift() // \my %h
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 1254 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 1254 | my $obj = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 1254 | ▶ | my $cache = $TIED{$self} //= {}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$TIED{$self} //= {}
MC/DC100%1/1
$TIED{$self} //= {}
$TIED{$self}
Truth table100%2/2
A
A= $TIED{$self}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 1254 | ▶ | $class = __PACKAGE__."::Tie::$class" if $class !~ s/^\+//; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 1254 | my $key = "$class:" . Hash::Util::FieldHash::id($obj); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 1254 | my $hit = $cache->{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 1254 | ▶ | return $hit if defined $hit; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 691 | load $class; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 691 | ▶ | tie((ref $ref eq 'ARRAY' ? @$ref : %$ref), $class, $obj, @_, $self); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 691 | $hit = $cache->{$key} = $ref; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 691 | weaken $cache->{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 691 | return $hit; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | ### convert datetime from KDBX to KeePass format | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | sub _decode_datetime { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 179 | ▶ | local $_ = shift or return; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_decode_datetime: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 173 | return $_->strftime('%Y-%m-%d %H:%M:%S'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | ### convert datetime from KeePass to KDBX format | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | sub _encode_datetime { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 0 | ▶ | local $_ = shift or return; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_encode_datetime: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 0 | return Time::Piece->strptime($_, '%Y-%m-%d %H:%M:%S'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | ### convert UUID from KeePass to KDBX format | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | sub _encode_uuid { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 0 | ▶ | local $_ = shift // return; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_encode_uuid: not called CC=4 SCAR=30.0
Condition0%0/2
shift() // (return)
MC/DC0%0/1
shift() // (return)
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | # Group IDs in KDB files are 32-bit integers | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 0 | ▶ | return sprintf('%016x', $_) if length($_) != 16 && looks_like_number($_); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
length $_ != 16 and &looks_like_number($_)
MC/DC0%0/2
length $_ != 16 and &looks_like_number($_)
length $_ != 16
&looks_like_number($_)
Truth table0%0/3
A and B
A= length $_ != 16B= &looks_like_number($_)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 0 | return $_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | ### convert tristate from KDBX to KeePass format | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | sub _decode_tristate { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 0 | ▶ | local $_ = shift // return; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_decode_tristate: not called CC=3 SCAR=24.8
Condition0%0/2
shift() // (return)
MC/DC0%0/1
shift() // (return)
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 0 | ▶ | return $_ ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | ### convert tristate from KeePass to KDBX format | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | sub _encode_tristate { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 0 | ▶ | local $_ = shift // return; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_encode_tristate: not called CC=2 SCAR=17.9
Condition0%0/2
shift() // (return)
MC/DC0%0/1
shift() // (return)
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 0 | return boolean($_); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 5 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||