| 1 | package File::KDBX::Dumper::V4; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Dump KDBX4 files | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Crypt::Digest qw(digest_data); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Crypt::Mac::HMAC qw(hmac); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Encode qw(encode is_utf8); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use File::KDBX::Constants qw(:header :inner_header :compression :kdf :variant_map); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use File::KDBX::Error; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use File::KDBX::IO::Crypt; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use File::KDBX::IO::HmacBlock; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use File::KDBX::Util qw(:class :empty :int :load erase_scoped); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use IO::Handle; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use Scalar::Util qw(looks_like_number); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 2 | ▶ | use boolean qw(:all); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 2 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 2 | extends 'File::KDBX::Dumper'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 7 | ▶ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_binaries_written: called CC=3 SCAR=11.7
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 2 | our $VERSION = '0.904'; # VERSION | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 7 | ▶ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$_[0]{"_binaries_written"} //= scalar &$default($_[0])
MC/DC0%0/1
$_[0]{"_binaries_written"} //= scalar &$default($_[0])
$_[0]{"_binaries_written"}
Truth table50%1/2
A
A= $_[0]{"_binaries_written"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 2 | has _binaries_written => {}, is => 'ro'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | sub _write_headers { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 7 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_write_headers: called CC=7 SCAR=19.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 7 | my $fh = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 7 | my $kdbx = $self->kdbx; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 7 | my $headers = $kdbx->headers; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 7 | my $buf = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | # Always write the standard AES KDF UUID, for compatibility | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | local $headers->{+HEADER_KDF_PARAMETERS}->{+KDF_PARAM_UUID} = KDF_UUID_AES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 7 | ▶ | if $headers->{+HEADER_KDF_PARAMETERS}->{+KDF_PARAM_UUID} eq KDF_UUID_AES_CHALLENGE_RESPONSE; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 7 | ▶ | if (nonempty (my $comment = $headers->{+HEADER_COMMENT})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | $buf .= $self->_write_header($fh, HEADER_COMMENT, $comment); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 7 | for my $type ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | HEADER_CIPHER_ID, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | HEADER_COMPRESSION_FLAGS, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | HEADER_MASTER_SEED, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | HEADER_ENCRYPTION_IV, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | HEADER_KDF_PARAMETERS, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 35 | ▶ | defined $headers->{$type} or throw "Missing value for required header: $type", type => $type; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 35 | $buf .= $self->_write_header($fh, $type, $headers->{$type}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | $buf .= $self->_write_header($fh, HEADER_PUBLIC_CUSTOM_DATA, $headers->{+HEADER_PUBLIC_CUSTOM_DATA}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 7 | ▶ | if defined $headers->{+HEADER_PUBLIC_CUSTOM_DATA} && keys %{$headers->{+HEADER_PUBLIC_CUSTOM_DATA}}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $headers->{"public_custom_data"} and keys %{$$headers{"public_custom_data"};}
MC/DC50%1/2
defined $headers->{"public_custom_data"} and keys %{$$headers{"public_custom_data"};}
defined $headers->{"public_custom_data"}
keys %{$$headers{"public_custom_data"};}
Truth table66%2/3
A and B
A= defined $headers->{"public_custom_data"}B= keys %{$$headers{"public_custom_data"};}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 7 | $buf .= $self->_write_header($fh, HEADER_END); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 7 | return $buf; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | sub _write_header { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 44 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_write_header: called CC=19 SCAR=37.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 44 | my $fh = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 44 | my $type = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 44 | ▶ | my $val = shift // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
shift() // ""
MC/DC100%1/1
shift() // ""
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 44 | $type = to_header_constant($type); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 44 | ▶ | if ($type == HEADER_END) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 10 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | # nothing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | elsif ($type == HEADER_COMMENT) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | $val = encode('UTF-8', $val); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | elsif ($type == HEADER_CIPHER_ID) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 7 | my $size = length($val); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 7 | ▶ | $size == 16 or throw 'Invalid cipher UUID length', got => $size, expected => $size; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | elsif ($type == HEADER_COMPRESSION_FLAGS) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 7 | $val = pack('L<', $val); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | elsif ($type == HEADER_MASTER_SEED) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 7 | my $size = length($val); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 7 | ▶ | $size == 32 or throw 'Invalid master seed length', got => $size, expected => $size; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | elsif ($type == HEADER_ENCRYPTION_IV) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | # nothing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | elsif ($type == HEADER_KDF_PARAMETERS) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 7 | $val = $self->_write_variant_dictionary($val, { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | KDF_PARAM_UUID() => VMAP_TYPE_BYTEARRAY, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | KDF_PARAM_AES_ROUNDS() => VMAP_TYPE_UINT64, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | KDF_PARAM_AES_SEED() => VMAP_TYPE_BYTEARRAY, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | KDF_PARAM_ARGON2_SALT() => VMAP_TYPE_BYTEARRAY, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | KDF_PARAM_ARGON2_PARALLELISM() => VMAP_TYPE_UINT32, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | KDF_PARAM_ARGON2_MEMORY() => VMAP_TYPE_UINT64, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | KDF_PARAM_ARGON2_ITERATIONS() => VMAP_TYPE_UINT64, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | KDF_PARAM_ARGON2_VERSION() => VMAP_TYPE_UINT32, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | KDF_PARAM_ARGON2_SECRET() => VMAP_TYPE_BYTEARRAY, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | KDF_PARAM_ARGON2_ASSOCDATA() => VMAP_TYPE_BYTEARRAY, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | elsif ($type == HEADER_PUBLIC_CUSTOM_DATA) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 2 | $val = $self->_write_variant_dictionary($val); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | ▶ | elsif ($type == HEADER_INNER_RANDOM_STREAM_ID || | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/12
$type == "inner_random_stream_id" or $type == "inner_random_stream_key" or $type == "transform_seed" or $type == "transform_rounds" or $type == "stream_start_bytes"
$type == "inner_random_stream_id" or $type == "inner_random_stream_key" or $type == "transform_seed" or $type == "transform_rounds"
$type == "inner_random_stream_id" or $type == "inner_random_stream_key" or $type == "transform_seed"
$type == "inner_random_stream_id" or $type == "inner_random_stream_key"
MC/DC0%0/5
$type == "inner_random_stream_id" or $type == "inner_random_stream_key" or $type == "transform_seed" or $type == "transform_rounds" or $type == "stream_start_bytes"
$type == "inner_random_stream_id"
$type == "inner_random_stream_key"
$type == "transform_seed"
$type == "transform_rounds"
$type == "stream_start_bytes"
Truth table0%0/6
A or B or C or D or E
A= $type == "inner_random_stream_id"B= $type == "inner_random_stream_key"C= $type == "transform_seed"D= $type == "transform_rounds"E= $type == "stream_start_bytes"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | $type == HEADER_INNER_RANDOM_STREAM_KEY || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | $type == HEADER_TRANSFORM_SEED || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | $type == HEADER_TRANSFORM_ROUNDS || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | $type == HEADER_STREAM_START_BYTES) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | throw "Unexpected KDBX3 header: $type", type => $type; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | elsif ($type == HEADER_COMMENT) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | throw "Unexpected KDB header: $type", type => $type; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | alert "Unknown header: $type", type => $type; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 44 | my $size = length($val); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 44 | my $buf = pack('C L<', 0+$type, $size); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 44 | ▶ | $fh->print($buf, $val) or throw 'Failed to write header'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 44 | return "$buf$val"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | sub _intuit_variant_type { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 5 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_intuit_variant_type: called CC=9 SCAR=22.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 5 | my $variant = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 5 | ▶ | if (isBoolean($variant)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 1 | return VMAP_TYPE_BOOL; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | ▶ | elsif (looks_like_number($variant) && ($variant + 0) =~ /^\d+$/) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
&looks_like_number($variant) and ($variant + 0) =~ /^\d+$/
MC/DC50%1/2
&looks_like_number($variant) and ($variant + 0) =~ /^\d+$/
&looks_like_number($variant)
($variant + 0) =~ /^\d+$/
Truth table66%2/3
A and B
A= &looks_like_number($variant)B= ($variant + 0) =~ /^\d+$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 1 | my $neg = $variant < 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 1 | my @b = unpack('L>2', scalar reverse pack_Ql($variant)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 1 | ▶ | return VMAP_TYPE_INT64 if $b[0] && $neg; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$b[0] and $neg
MC/DC0%0/2
$b[0] and $neg
$b[0]
$neg
Truth table33%1/3
A and B
A= $b[0]B= $neg
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 1 | ▶ | return VMAP_TYPE_UINT64 if $b[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 1 | ▶ | return VMAP_TYPE_INT32 if $neg; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 1 | return VMAP_TYPE_UINT32; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | elsif (is_utf8($variant)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 1 | return VMAP_TYPE_STRING; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 2 | return VMAP_TYPE_BYTEARRAY; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | sub _write_variant_dictionary { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 9 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_write_variant_dictionary: called CC=12 SCAR=25.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 9 | ▶ | my $dict = shift || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || {}
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 9 | ▶ | my $types = shift || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
shift() || {}
MC/DC100%1/1
shift() || {}
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 9 | my $buf = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 9 | $buf .= pack('S<', VMAP_VERSION); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 9 | for my $key (sort keys %$dict) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 32 | my $val = $dict->{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 32 | ▶ | my $type = $types->{$key} // $self->_intuit_variant_type($val); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$types->{$key} // $self->_intuit_variant_type($val)
MC/DC0%0/2
$types->{$key} // $self->_intuit_variant_type($val)
$types->{$key}
$self->_intuit_variant_type($val)
Truth table66%2/3
A // B
A= $types->{$key}B= $self->_intuit_variant_type($val)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 32 | $buf .= pack('C', $type); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 32 | ▶ | if ($type == VMAP_TYPE_UINT32) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 7 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 5 | $val = pack('L<', $val); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | elsif ($type == VMAP_TYPE_UINT64) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 9 | $val = pack_Ql($val); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | elsif ($type == VMAP_TYPE_BOOL) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 1 | $val = pack('C', $val); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | elsif ($type == VMAP_TYPE_INT32) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | $val = pack('l', $val); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | elsif ($type == VMAP_TYPE_INT64) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | $val = pack_ql($val); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | elsif ($type == VMAP_TYPE_STRING) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 1 | $val = encode('UTF-8', $val); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | elsif ($type == VMAP_TYPE_BYTEARRAY) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | # $val = substr($$buf, $pos, $vlen); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | # $val = [split //, $val]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | throw 'Unknown variant dictionary value type', type => $type; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 32 | my ($klen, $vlen) = (length($key), length($val)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 32 | $buf .= pack("L< a$klen L< a$vlen", $klen, $key, $vlen, $val); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 9 | $buf .= pack('C', VMAP_TYPE_END); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 9 | return $buf; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | sub _write_body { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 7 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_write_body: called CC=8 SCAR=21.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 7 | my $fh = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 7 | my $key = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 7 | my $header_data = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 7 | my $kdbx = $self->kdbx; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | # assert all required headers present | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 7 | for my $field ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | HEADER_CIPHER_ID, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | HEADER_ENCRYPTION_IV, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | HEADER_MASTER_SEED, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 21 | ▶ | defined $kdbx->headers->{$field} or throw "Missing header: $field"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 7 | my @cleanup; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | # write 32-byte checksum | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 7 | my $header_hash = digest_data('SHA256', $header_data); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 7 | ▶ | $fh->print($header_hash) or throw 'Failed to write header hash'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 7 | $key = $kdbx->composite_key($key); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 7 | my $transformed_key = $kdbx->kdf->transform($key); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 7 | push @cleanup, erase_scoped $transformed_key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | # write 32-byte HMAC for header | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 7 | my $hmac_key = digest_data('SHA512', $kdbx->headers->{master_seed}, $transformed_key, "\x01"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 7 | push @cleanup, erase_scoped $hmac_key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 7 | my $header_hmac = hmac('SHA256', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | digest_data('SHA512', "\xff\xff\xff\xff\xff\xff\xff\xff", $hmac_key), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | $header_data, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 7 | ▶ | $fh->print($header_hmac) or throw 'Failed to write header HMAC'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 7 | $kdbx->key($key); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | # HMAC-block the rest of the stream | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 7 | $fh = File::KDBX::IO::HmacBlock->new($fh, key => $hmac_key); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 7 | my $final_key = digest_data('SHA256', $kdbx->headers->{master_seed}, $transformed_key); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 7 | push @cleanup, erase_scoped $final_key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 7 | my $cipher = $kdbx->cipher(key => $final_key); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 7 | $fh = File::KDBX::IO::Crypt->new($fh, cipher => $cipher); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 7 | my $compress = $kdbx->headers->{+HEADER_COMPRESSION_FLAGS}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 7 | ▶ | if ($compress == COMPRESSION_GZIP) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 7 | load_optional('IO::Compress::Gzip'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 7 | ▶ | $fh = IO::Compress::Gzip->new($fh, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | -Level => IO::Compress::Gzip::Z_BEST_COMPRESSION(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | -TextFlag => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | ) or throw "Failed to initialize compression library: $IO::Compress::Gzip::GzipError", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | error => $IO::Compress::Gzip::GzipError; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | elsif ($compress != COMPRESSION_NONE) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | throw "Unsupported compression ($compress)\n", compression_flags => $compress; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 7 | $self->_write_inner_headers($fh); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 7 | local $self->{compress_datetimes} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 7 | $self->_write_inner_body($fh, $header_hash); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | sub _write_inner_headers { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 7 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_write_inner_headers: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 7 | my $fh = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 7 | my $kdbx = $self->kdbx; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 7 | my $headers = $kdbx->inner_headers; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 7 | for my $type ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | INNER_HEADER_INNER_RANDOM_STREAM_ID, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | INNER_HEADER_INNER_RANDOM_STREAM_KEY, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 14 | ▶ | defined $headers->{$type} or throw "Missing inner header: $type"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 14 | $self->_write_inner_header($fh, $type => $headers->{$type}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 7 | $self->_write_binaries($fh); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 7 | $self->_write_inner_header($fh, INNER_HEADER_END); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | sub _write_inner_header { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 21 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_write_inner_header: called CC=9 SCAR=22.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 21 | my $fh = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 21 | my $type = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 21 | ▶ | my $val = shift // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
shift() // ""
MC/DC100%1/1
shift() // ""
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 21 | my $buf = pack('C', $type); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 21 | ▶ | $fh->print($buf) or throw 'Failed to write inner header type'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 21 | $type = to_inner_header_constant($type); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 21 | ▶ | if ($type == INNER_HEADER_END) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | # nothing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | elsif ($type == INNER_HEADER_INNER_RANDOM_STREAM_ID) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 7 | $val = pack('L<', $val); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | elsif ($type == INNER_HEADER_INNER_RANDOM_STREAM_KEY) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | # nothing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | elsif ($type == INNER_HEADER_BINARY) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | # nothing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 21 | $buf = pack('L<', length($val)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 21 | ▶ | $fh->print($buf) or throw 'Failed to write inner header value size'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 21 | ▶ | $fh->print($val) or throw 'Failed to write inner header value'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | sub _write_binaries { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 7 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_write_binaries: called CC=8 SCAR=33.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 7 | my $fh = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 7 | my $kdbx = $self->kdbx; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 7 | my $new_ref = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 7 | my $written = $self->_binaries_written; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 7 | my $entries = $kdbx->entries(history => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 7 | ▶ | while (my $entry = $entries->next) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 2 | for my $key (keys %{$entry->binaries}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | my $binary = $entry->binaries->{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | ▶ | if (defined $binary->{ref} && defined $kdbx->binaries->{$binary->{ref}}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $binary->{"ref"} and defined $kdbx->binaries->{$binary->{"ref"}}
MC/DC0%0/2
defined $binary->{"ref"} and defined $kdbx->binaries->{$binary->{"ref"}}
defined $binary->{"ref"}
defined $kdbx->binaries->{$binary->{"ref"}}
Truth table0%0/3
A and B
A= defined $binary->{"ref"}B= defined $kdbx->binaries->{$binary->{"ref"}}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | $binary = $kdbx->binaries->{$binary->{ref}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | ▶ | if (!defined $binary->{value}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | alert "Skipping binary which has no value: $key", key => $key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | my $hash = digest_data('SHA256', $binary->{value}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | ▶ | if (defined $written->{$hash}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | # nothing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | my $flags = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | ▶ | $flags &= INNER_HEADER_BINARY_FLAG_PROTECT if $binary->{protect}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | $self->_write_binary($fh, \$binary->{value}, $flags); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | $written->{$hash} = $new_ref++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | sub _write_binary { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_write_binary: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | my $fh = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | my $data = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | ▶ | my $flags = shift || 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift() || 0
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | my $buf = pack('C', 0 + INNER_HEADER_BINARY); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | ▶ | $fh->print($buf) or throw 'Failed to write inner header type'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | $buf = pack('L<', 1 + length($$data)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | ▶ | $fh->print($buf) or throw 'Failed to write inner header value size'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | $buf = pack('C', $flags); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | ▶ | $fh->print($buf) or throw 'Failed to write inner header binary flags'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | ▶ | $fh->print($$data) or throw 'Failed to write inner header value'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||