| 1 | package File::KDBX::Key; | ||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: A credential that can protect a KDBX file | ||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||
| 4 | 14 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 5 | 14 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||
| 7 | 14 | ▶ | use Devel::GlobalDestruction; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 8 | 14 | ▶ | use File::KDBX::Error; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 9 | 14 | ▶ | use File::KDBX::Safe; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 10 | 14 | ▶ | use File::KDBX::Util qw(erase); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 11 | 14 | ▶ | use Hash::Util::FieldHash qw(fieldhashes); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 12 | 14 | ▶ | use Module::Load; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 13 | 14 | ▶ | use Ref::Util qw(is_arrayref is_coderef is_hashref is_ref is_scalarref); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 14 | 14 | ▶ | use Scalar::Util qw(blessed openhandle); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 15 | 14 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||
| 17 | 14 | our $VERSION = '0.904'; # VERSION | |||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||
| 19 | 14 | fieldhashes \my %SAFE; | |||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||
| 22 | sub new { | ||||||||||||||||||||||||||||||||||||||
| 23 | 193 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 24 | 193 | ▶ | my %args = @_ % 2 == 1 ? (primitive => shift, @_) : @_; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||
| 26 | 193 | my $primitive = $args{primitive}; | |||||||||||||||||||||||||||||||||||||
| 27 | 193 | ▶ | delete $args{primitive} if !$args{keep_primitive}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 28 | 193 | ▶ | return $primitive->hide if blessed $primitive && $primitive->isa($class); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($primitive) and $primitive->isa($class)
MC/DC50%1/2
builtin::blessed($primitive) and $primitive->isa($class)
builtin::blessed($primitive)
$primitive->isa($class)
Truth table66%2/3
A and B
A= builtin::blessed($primitive)B= $primitive->isa($class)
| |||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||
| 30 | 157 | my $self = bless \%args, $class; | |||||||||||||||||||||||||||||||||||||
| 31 | 157 | ▶ | return $self->init($primitive) if defined $primitive; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 32 | 13 | return $self; | |||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||
| 35 | sub DESTROY { | ||||||||||||||||||||||||||||||||||||||
| 36 | 157 | ▶ | local ($., $@, $!, $^E, $?); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||
| 37 | 157 | ▶ | !in_global_destruction and do { $_[0]->_clear_raw_key; eval { erase \$_[0]->{primitive} } } | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||
| 41 | sub init { | ||||||||||||||||||||||||||||||||||||||
| 42 | 85 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=15 SCAR=41.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 43 | 85 | ▶ | my $primitive = shift // throw 'Missing key primitive'; | ||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
shift() // throw("Missing key primitive")
MC/DC0%0/2
shift() // throw("Missing key primitive")
shift()
throw("Missing key primitive")
Truth table33%1/3
A // B
A= shift()B= throw("Missing key primitive")
| |||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||
| 45 | 85 | my $pkg; | |||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||
| 47 | 85 | ▶ | if (is_arrayref($primitive)) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 8 branches
| |||||||||||||||||||||||||||||||||||||||
| 48 | 1 | $pkg = __PACKAGE__.'::Composite'; | |||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||
| 50 | ▶ | elsif (is_scalarref($primitive) || openhandle($primitive)) { | |||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
Ref::Util::XS::is_scalarref($primitive) or &openhandle($primitive)
MC/DC50%1/2
Ref::Util::XS::is_scalarref($primitive) or &openhandle($primitive)
Ref::Util::XS::is_scalarref($primitive)
&openhandle($primitive)
Truth table66%2/3
A or B
A= Ref::Util::XS::is_scalarref($primitive)B= &openhandle($primitive)
| |||||||||||||||||||||||||||||||||||||||
| 51 | 19 | $pkg = __PACKAGE__.'::File'; | |||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||
| 53 | elsif (is_coderef($primitive)) { | ||||||||||||||||||||||||||||||||||||||
| 54 | 18 | $pkg = __PACKAGE__.'::ChallengeResponse'; | |||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||
| 56 | elsif (!is_ref($primitive)) { | ||||||||||||||||||||||||||||||||||||||
| 57 | 47 | $pkg = __PACKAGE__.'::Password'; | |||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||
| 59 | ▶ | elsif (is_hashref($primitive) && defined $primitive->{composite}) { | |||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
Ref::Util::XS::is_hashref($primitive) and defined $primitive->{"composite"}
MC/DC0%0/2
Ref::Util::XS::is_hashref($primitive) and defined $primitive->{"composite"}
Ref::Util::XS::is_hashref($primitive)
defined $primitive->{"composite"}
Truth table0%0/3
A and B
A= Ref::Util::XS::is_hashref($primitive)B= defined $primitive->{"composite"}
| |||||||||||||||||||||||||||||||||||||||
| 60 | 0 | $pkg = __PACKAGE__.'::Composite'; | |||||||||||||||||||||||||||||||||||||
| 61 | 0 | $primitive = $primitive->{composite}; | |||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||
| 63 | ▶ | elsif (is_hashref($primitive) && defined $primitive->{password}) { | |||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
Ref::Util::XS::is_hashref($primitive) and defined $primitive->{"password"}
MC/DC0%0/2
Ref::Util::XS::is_hashref($primitive) and defined $primitive->{"password"}
Ref::Util::XS::is_hashref($primitive)
defined $primitive->{"password"}
Truth table0%0/3
A and B
A= Ref::Util::XS::is_hashref($primitive)B= defined $primitive->{"password"}
| |||||||||||||||||||||||||||||||||||||||
| 64 | 0 | $pkg = __PACKAGE__.'::Password'; | |||||||||||||||||||||||||||||||||||||
| 65 | 0 | $primitive = $primitive->{password}; | |||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||
| 67 | ▶ | elsif (is_hashref($primitive) && defined $primitive->{file}) { | |||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
Ref::Util::XS::is_hashref($primitive) and defined $primitive->{"file"}
MC/DC0%0/2
Ref::Util::XS::is_hashref($primitive) and defined $primitive->{"file"}
Ref::Util::XS::is_hashref($primitive)
defined $primitive->{"file"}
Truth table0%0/3
A and B
A= Ref::Util::XS::is_hashref($primitive)B= defined $primitive->{"file"}
| |||||||||||||||||||||||||||||||||||||||
| 68 | 0 | $pkg = __PACKAGE__.'::File'; | |||||||||||||||||||||||||||||||||||||
| 69 | 0 | $primitive = $primitive->{file}; | |||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||
| 71 | ▶ | elsif (is_hashref($primitive) && defined $primitive->{responder}) { | |||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
Ref::Util::XS::is_hashref($primitive) and defined $primitive->{"responder"}
MC/DC0%0/2
Ref::Util::XS::is_hashref($primitive) and defined $primitive->{"responder"}
Ref::Util::XS::is_hashref($primitive)
defined $primitive->{"responder"}
Truth table0%0/3
A and B
A= Ref::Util::XS::is_hashref($primitive)B= defined $primitive->{"responder"}
| |||||||||||||||||||||||||||||||||||||||
| 72 | 0 | $pkg = __PACKAGE__.'::ChallengeResponse'; | |||||||||||||||||||||||||||||||||||||
| 73 | 0 | $primitive = $primitive->{responder}; | |||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||
| 75 | else { | ||||||||||||||||||||||||||||||||||||||
| 76 | 0 | throw 'Invalid key primitive', primitive => $primitive; | |||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||
| 79 | 85 | load $pkg; | |||||||||||||||||||||||||||||||||||||
| 80 | 85 | bless $self, $pkg; | |||||||||||||||||||||||||||||||||||||
| 81 | 85 | return $self->init($primitive); | |||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | sub reload { $_[0] } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
reload: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||
| 88 | sub raw_key { | ||||||||||||||||||||||||||||||||||||||
| 89 | 95 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
raw_key: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 90 | 95 | ▶ | return $self->{raw_key} if !$self->is_hidden; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 91 | 86 | return $self->_safe->peek(\$self->{raw_key}); | |||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||
| 94 | sub _set_raw_key { | ||||||||||||||||||||||||||||||||||||||
| 95 | 81 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_raw_key: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 96 | 81 | $self->_clear_raw_key; | |||||||||||||||||||||||||||||||||||||
| 97 | 81 | $self->{raw_key} = shift; # after clear | |||||||||||||||||||||||||||||||||||||
| 98 | 81 | $self->_new_safe->add(\$self->{raw_key}); # auto-hide | |||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||
| 101 | sub _clear_raw_key { | ||||||||||||||||||||||||||||||||||||||
| 102 | 238 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_clear_raw_key: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 103 | 238 | my $safe = $self->_safe; | |||||||||||||||||||||||||||||||||||||
| 104 | 238 | ▶ | $safe->clear if $safe; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 105 | 238 | erase \$self->{raw_key}; | |||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||
| 109 | sub hide { | ||||||||||||||||||||||||||||||||||||||
| 110 | 256 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
hide: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 111 | 256 | ▶ | $self->_new_safe->add(\$self->{raw_key}) if defined $self->{raw_key}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 112 | 256 | return $self; | |||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||
| 116 | sub show { | ||||||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
show: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 118 | 0 | my $safe = $self->_safe; | |||||||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | $safe->unlock if $safe; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 120 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||
| 124 | 95 | ▶ | sub is_hidden { !!$SAFE{$_[0]} } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
is_hidden: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||
| 126 | 324 | ▶ | sub _safe { $SAFE{$_[0]} } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_safe: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 127 | 81 | ▶ | sub _new_safe { $SAFE{$_[0]} = File::KDBX::Safe->new } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_new_safe: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||
| 129 | 14 | 1; | |||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||
| 131 | __END__ | ||||||||||||||||||||||||||||||||||||||