KDBX/KDF.pm

filter: Statementstmt 87.6% 64 / 73 Branchbran 64.2% 9 / 14 Conditioncond 50.0% 7 / 14 MC/DCmcdc 11.1% 1 / 9 Subroutinesub 78.9% 15 / 19 Podpod 100% 8 / 8 totaltotal 75.9% 104 / 137 CC 14 SCAR 14.6
CC
14
Cov
79%
register
10.9
unregister
6.0
new
4.1
CRAP 4.3
« KDBX/IO/HashBlock.pm ↑ Summary KDBX/IO/HmacBlock.pm »
1 package File::KDBX::KDF;
2 # ABSTRACT: A key derivation function
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 Crypt::PRNG qw(random_bytes);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 14 ▶use File::KDBX::Constants qw(:version :kdf);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 14 ▶use File::KDBX::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 14 ▶use File::KDBX::Util qw(format_uuid);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 14 ▶use Module::Load;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 14 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 14 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 14 our $VERSION = '0.905'; # VERSION
16  
17 14 my %KDFS;
18  
19  
20 sub new {
21 177 ▶ my $class = shift;
Subroutine new: called CC=4 SCAR=14.1
Pod documented
22 177 my %args = @_;
23  
24 177 ▶ my $uuid = $args{+KDF_PARAM_UUID} //= delete $args{uuid} or throw 'Missing KDF UUID', args => \%args;
Branch: 1 branch
BranchTrueFalseTotal
my $uuid = ($args{"\$UUID"} //= delete $args{"uuid"}) or throw("Missing KDF UUID", "args", \%args) 0 177 177
Condition66%2/3
$args{"\$UUID"} //= delete $args{"uuid"}
l!l&&r!l&&!r
17340
MC/DC0%0/2
$args{"\$UUID"} //= delete $args{"uuid"}
$args{"\$UUID"} delete $args{"uuid"}
Truth table66%2/3
A //= B
A= $args{"\$UUID"}B= delete $args{"uuid"}
ABresult
1X1
011
000
25 177 my $formatted_uuid = format_uuid($uuid);
26  
27 177 ▶ my $kdf = $KDFS{$uuid} or throw "Unsupported KDF ($formatted_uuid)", uuid => $uuid;
Branch: 1 branch
BranchTrueFalseTotal
my $kdf = $KDFS{$uuid} or throw("Unsupported KDF ($formatted_uuid)", "uuid", $uuid) 0 177 177
28 177 ($class, my %registration_args) = @$kdf;
29  
30 177 load $class;
31 177 my $self = bless {KDF_PARAM_UUID() => $uuid}, $class;
32 177 return $self->init(%args, %registration_args);
33 }
34  
35  
36 sub init {
37 177 ▶ my $self = shift;
Subroutine init: called CC=1 SCAR=0.0
Pod documented
38 177 my %args = @_;
39  
40 177 @$self{keys %args} = values %args;
41  
42 177 return $self;
43 }
44  
45  
46 182 ▶sub uuid { $_[0]->{+KDF_PARAM_UUID} }
Subroutine uuid: called CC=1 SCAR=0.0
Pod documented
47  
48  
49 0 ▶sub seed { die 'Not implemented' }
Subroutine seed: not called CC=1 SCAR=6.9
Pod documented
50  
51  
52 sub transform {
53 51 ▶ my $self = shift;
Subroutine transform: called CC=4 SCAR=13.9
Pod documented
54 51 my $key = shift;
55  
56 51 ▶ if (blessed $key && $key->can('raw_key')) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($key) and $key->can("raw_key")) 45 6 51
Condition66%2/3
builtin::blessed($key) and $key->can("raw_key")
!ll&&!rl&&r
6045
MC/DC50%1/2
builtin::blessed($key) and $key->can("raw_key")
builtin::blessed($key) $key->can("raw_key")
Truth table66%2/3
A and B
A= builtin::blessed($key)B= $key->can("raw_key")
ABresult
0X0
100
111
57 45 ▶ return $self->_transform($key->raw_key) if $self->uuid eq KDF_UUID_AES;
Branch: 1 branch
BranchTrueFalseTotal
if $self->uuid eq "\311\331\363\232b\212D`\277t\r\b\301\212O\352" 24 21 45
58 21 return $self->_transform($key->raw_key($self->seed, @_));
59 }
60  
61 6 return $self->_transform($key);
62 }
63  
64 0 ▶sub _transform { die 'Not implemented' }
Subroutine _transform: not called CC=1 SCAR=6.9
65  
66  
67 sub randomize_seed {
68 0 ▶ my $self = shift;
Subroutine randomize_seed: not called CC=1 SCAR=6.9
Pod documented
69 0 $self->{+KDF_PARAM_AES_SEED} = random_bytes(length($self->seed));
70 }
71  
72  
73 sub register {
74 56 ▶ my $class = shift;
Subroutine register: called CC=7 SCAR=23.8
Pod documented
75 56 my $id = shift;
76 56 my $package = shift;
77 56 my @args = @_;
78  
79 56 my $formatted_id = format_uuid($id);
80 56 ▶ $package = "${class}::${package}" if $package !~ s/^\+// && $package !~ /^\Q${class}::\E/;
Branch: 1 branch
BranchTrueFalseTotal
unless $package =~ s/^\+// or $package =~ /^\Q$class::\E/ 56 0 56
Condition33%1/3
$package =~ s/^\+// or $package =~ /^\Q$class::\E/
l!l&&r!l&&!r
0056
MC/DC0%0/2
$package =~ s/^\+// or $package =~ /^\Q$class::\E/
$package =~ s/^\+// $package =~ /^\Q$class::\E/
Truth table33%1/3
A or B
A= $package =~ s/^\+//B= $package =~ /^\Q$class::\E/
ABresult
1X1
011
000
81  
82 56 ▶ my %blacklist = map { File::KDBX::Util::uuid($_) => 1 } split(/,/, $ENV{FILE_KDBX_KDF_BLACKLIST} // '');
Condition50%1/2
$ENV{"FILE_KDBX_KDF_BLACKLIST"} // ""
l!l
056
MC/DC0%0/1
$ENV{"FILE_KDBX_KDF_BLACKLIST"} // ""
$ENV{"FILE_KDBX_KDF_BLACKLIST"}
Truth table50%1/2
A
A= $ENV{"FILE_KDBX_KDF_BLACKLIST"}
Aresult
11
00
83 56 ▶ if ($blacklist{$id} || $blacklist{$package}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($blacklist{$id} or $blacklist{$package}) 0 56 56
Condition33%1/3
$blacklist{$id} or $blacklist{$package}
l!l&&r!l&&!r
0056
MC/DC0%0/2
$blacklist{$id} or $blacklist{$package}
$blacklist{$id} $blacklist{$package}
Truth table33%1/3
A or B
A= $blacklist{$id}B= $blacklist{$package}
ABresult
1X1
011
000
84 0 alert "Ignoring blacklisted KDF ($formatted_id)", id => $id, package => $package;
85 0 return;
86 }
87  
88 56 ▶ if (defined $KDFS{$id}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $KDFS{$id}) 0 56 56
89 0 alert "Overriding already-registered KDF ($formatted_id) with package $package",
90 id => $id,
91 package => $package;
92 }
93  
94 56 $KDFS{$id} = [$package, @args];
95 }
96  
97  
98 sub unregister {
99 0 ▶ delete $KDFS{$_} for @_;
Subroutine unregister: not called CC=2 SCAR=17.9
Pod documented
100 }
101  
102 BEGIN {
103 14 ▶ __PACKAGE__->register(KDF_UUID_AES, 'AES');
Subroutine BEGIN: called CC=1 SCAR=0.0
104 14 __PACKAGE__->register(KDF_UUID_AES_CHALLENGE_RESPONSE, 'AES');
105 14 __PACKAGE__->register(KDF_UUID_ARGON2D, 'Argon2');
106 14 __PACKAGE__->register(KDF_UUID_ARGON2ID, 'Argon2');
107 }
108  
109 14 1;
110  
111 __END__
« KDBX/IO/HashBlock.pm ↑ Summary KDBX/IO/HmacBlock.pm »