| 1 | package File::KDBX::Key::Composite; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: A composite key made up of component keys | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 7 | ▶ | use Crypt::Digest qw(digest_data); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 7 | ▶ | use File::KDBX::Error; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 7 | ▶ | use File::KDBX::Util qw(:class :erase); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 7 | ▶ | use Ref::Util qw(is_arrayref); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 7 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 7 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 7 | extends 'File::KDBX::Key'; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 7 | our $VERSION = '0.904'; # VERSION | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | sub init { | ||||||||||||||||||||||||||||
| 19 | 46 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=6 SCAR=18.3
Pod
documented
| |||||||||||||||||||||||||||||
| 20 | 46 | ▶ | 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")
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 46 | ▶ | my @primitive = grep { defined } is_arrayref($primitive) ? @$primitive : $primitive; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | 46 | ▶ | @primitive or throw 'Composite key must have at least one component key', count => scalar @primitive; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 46 | my @keys = map { blessed $_ && $_->can('raw_key') ? $_ : File::KDBX::Key->new($_, | |||||||||||||||||||||||||||
| 26 | 85 | ▶ | keep_primitive => $self->{keep_primitive}) } @primitive; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($_) and $_->can("raw_key")
MC/DC50%1/2
builtin::blessed($_) and $_->can("raw_key")
builtin::blessed($_)
$_->can("raw_key")
Truth table66%2/3
A and B
A= builtin::blessed($_)B= $_->can("raw_key")
| |||||||||||||||||||||||||||||
| 27 | 46 | $self->{keys} = \@keys; | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 46 | return $self->hide; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | sub raw_key { | ||||||||||||||||||||||||||||
| 34 | 46 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
raw_key: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 35 | 46 | my $challenge = shift; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 46 | ▶ | my @keys = @{$self->keys} or throw 'Cannot generate a raw key from an empty composite key'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 46 | my @basic_keys = map { $_->raw_key } grep { !$_->can('challenge') } @keys; | |||||||||||||||||||||||||||
| 40 | 46 | my $response; | |||||||||||||||||||||||||||
| 41 | 46 | ▶ | $response = $self->challenge($challenge, @_) if defined $challenge; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | 46 | my $cleanup = erase_scoped \@basic_keys, $response; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 46 | ▶ | return digest_data('SHA256', | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | @basic_keys, | ||||||||||||||||||||||||||||
| 46 | defined $response ? $response : (), | ||||||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | sub keys { | ||||||||||||||||||||||||||||
| 52 | 173 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
keys: called CC=3 SCAR=11.7
Pod
documented
| |||||||||||||||||||||||||||||
| 53 | 173 | ▶ | $self->{keys} = shift if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 173 | ▶ | return $self->{keys} ||= []; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"keys"} ||= []
MC/DC0%0/1
$self->{"keys"} ||= []
$self->{"keys"}
Truth table50%1/2
A
A= $self->{"keys"}
| |||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | sub challenge { | ||||||||||||||||||||||||||||
| 59 | 45 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
challenge: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 45 | ▶ | my @chalresp_keys = grep { $_->can('challenge') } @{$self->keys} or return ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 18 | my @responses = map { $_->challenge(@_) } @chalresp_keys; | |||||||||||||||||||||||||||
| 64 | 18 | my $cleanup = erase_scoped \@responses; | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 18 | return digest_data('SHA256', @responses); | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | sub hide { | ||||||||||||||||||||||||||||
| 70 | 82 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
hide: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 71 | 82 | $_->hide for @{$self->keys}; | |||||||||||||||||||||||||||
| 72 | 82 | return $self; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | sub show { | ||||||||||||||||||||||||||||
| 76 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
show: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 77 | 0 | $_->show for @{$self->keys}; | |||||||||||||||||||||||||||
| 78 | 0 | return $self; | |||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 7 | 1; | |||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | __END__ | ||||||||||||||||||||||||||||