KDBX/Key/File.pm

filter: Statementstmt 95.7% 179 / 187 Branchbran 69.0% 58 / 84 Conditioncond 51.3% 38 / 74 MC/DCmcdc 21.0% 8 / 38 Subroutinesub 100% 21 / 21 Podpod 100% 7 / 7 totaltotal 75.6% 311 / 411 SCAR 47.3
CC
71
Cov
80%
save
66.2
_load_xml
32.1
load
11.0
CRAP 113.1
« KDBX/Loader.pm ↑ Summary KDBX/Loader/V4.pm »
1 package File::KDBX::Key::File;
2 # ABSTRACT: A file key
3  
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 ▶use Crypt::Digest qw(digest_data);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use Crypt::Misc 0.029 qw(decode_b64 encode_b64);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use Crypt::PRNG qw(random_bytes);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use File::KDBX::Constants qw(:key_file);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use File::KDBX::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use File::KDBX::Util qw(:class :erase trim);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use Ref::Util qw(is_ref is_scalarref);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 3 ▶use Scalar::Util qw(openhandle);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 3 ▶use XML::LibXML::Reader;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 3 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 3 extends 'File::KDBX::Key';
19  
20 21 ▶our $VERSION = '0.904'; # VERSION
Subroutine type: called CC=3 SCAR=11.8
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($_[0]) 0 21 21
21 9 ▶ 
Subroutine version: called CC=3 SCAR=11.3
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($_[0]) 0 9 9
22 21 ▶ 
Subroutine filepath: called CC=3 SCAR=11.1
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($_[0]) 0 7 7
Condition50%1/2
$_[0]{"type"} //= undef
l!l
210
MC/DC0%0/1
$_[0]{"type"} //= undef
$_[0]{"type"}
Truth table50%1/2
A
A= $_[0]{"type"}
Aresult
11
00
23 9 ▶has 'type', is => 'ro';
Condition100%2/2
$_[0]{"version"} //= undef
l!l
45
MC/DC100%1/1
$_[0]{"version"} //= undef
$_[0]{"version"}
Truth table100%2/2
A
A= $_[0]{"version"}
Aresult
11
00
24 7 ▶has 'version', is => 'ro';
Condition100%2/2
$_[0]{"filepath"} //= undef
l!l
61
MC/DC100%1/1
$_[0]{"filepath"} //= undef
$_[0]{"filepath"}
Truth table100%2/2
A
A= $_[0]{"filepath"}
Aresult
11
00
25 3 has 'filepath', is => 'ro';
26  
27  
28 37 ▶sub init { shift->load(@_) }
Subroutine init: called CC=1 SCAR=0.0
Pod documented
29  
30 sub load {
31 37 ▶ my $self = shift;
Subroutine load: called CC=11 SCAR=24.0
Pod documented
32 37 ▶ my $primitive = shift // throw 'Missing key primitive';
Condition66%2/3
shift() // throw("Missing key primitive")
l!l&&r!l&&!r
3610
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")
ABresult
1X1
011
000
33  
34 36 my $data;
35 my $cleanup;
36  
37 36 ▶ if (openhandle($primitive)) {
Branch: 3 branches
BranchTrueFalseTotal
if (&openhandle($primitive)) { } 1 35 36
elsif (Ref::Util::XS::is_scalarref($primitive)) { } 20 15 35
elsif (defined $primitive and not Ref::Util::XS::is_ref($primitive)) { } 14 1 15
38 1 seek $primitive, 0, 0; # not using ->seek method so it works on perl 5.10
39 1 my $buf = do { local $/; <$primitive> };
40 1 $data = \$buf;
41 1 $cleanup = erase_scoped $data;
42 }
43 elsif (is_scalarref($primitive)) {
44 20 $data = $primitive;
45 }
46 ▶ elsif (defined $primitive && !is_ref($primitive)) {
Condition66%2/3
defined $primitive and not Ref::Util::XS::is_ref($primitive)
!ll&&!rl&&r
0114
MC/DC50%1/2
defined $primitive and not Ref::Util::XS::is_ref($primitive)
defined $primitive not Ref::Util::XS::is_ref($primitive)
Truth table66%2/3
A and not(B)
A= defined $primitiveB= not Ref::Util::XS::is_ref($primitive)
ABresult
0X0
100
111
47 14 ▶ open(my $fh, '<:raw', $primitive)
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<:raw", $primitive or throw("Failed to open key file ($primitive)", "filepath", $primitive) 1 13 14
48 or throw "Failed to open key file ($primitive)", filepath => $primitive;
49 13 my $buf = do { local $/; <$fh> };
50 13 $data = \$buf;
51 13 $cleanup = erase_scoped $data;
52 13 $self->{filepath} = $primitive;
53 }
54 else {
55 1 throw 'Unexpected primitive type', type => ref $primitive;
56 }
57  
58 34 my $raw_key;
59 34 ▶ if (substr($$data, 0, 120) =~ /<KeyFile>/
Branch: 3 branches
BranchTrueFalseTotal
if (substr($$data, 0, 120) =~ /<KeyFile>/ and () = $self->_load_xml($data, \$raw_key)) { } 6 28 34
elsif (length $$data == 32) { } 4 24 28
elsif ($$data =~ /^[A-Fa-f0-9]{64}$/) { } 2 22 24
Condition66%2/3
substr($$data, 0, 120) =~ /<KeyFile>/ and () = $self->_load_xml($data, \$raw_key)
!ll&&!rl&&r
2806
MC/DC50%1/2
substr($$data, 0, 120) =~ /<KeyFile>/ and () = $self->_load_xml($data, \$raw_key)
substr($$data, 0, 120) =~ /<KeyFile>/ () = $self->_load_xml($data, \$raw_key)
Truth table66%2/3
A and B
A= substr($$data, 0, 120) =~ /<KeyFile>/B= () = $self->_load_xml($data, \$raw_key)
ABresult
0X0
100
111
60 and my ($type, $version) = $self->_load_xml($data, \$raw_key)) {
61 6 $self->{type} = $type;
62 6 $self->{version} = $version;
63 6 $self->_set_raw_key($raw_key);
64 }
65 elsif (length($$data) == 32) {
66 4 $self->{type} = KEY_FILE_TYPE_BINARY;
67 4 $self->_set_raw_key($$data);
68 }
69 elsif ($$data =~ /^[A-Fa-f0-9]{64}$/) {
70 2 $self->{type} = KEY_FILE_TYPE_HEX;
71 2 $self->_set_raw_key(pack('H64', $$data));
72 }
73 else {
74 22 $self->{type} = KEY_FILE_TYPE_HASHED;
75 22 $self->_set_raw_key(digest_data('SHA256', $$data));
76 }
77  
78 34 return $self->hide;
79 }
80  
81  
82 sub reload {
83 2 ▶ my $self = shift;
Subroutine reload: called CC=2 SCAR=7.1
Pod documented
84 2 ▶ $self->init($self->{filepath}) if defined $self->{filepath};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"filepath"} 2 0 2
85 2 return $self;
86 }
87  
88  
89 sub save {
90 7 ▶ my $self = shift;
Subroutine save: called CC=30 SCAR=41.9
Pod documented
91 7 my %args = @_;
92  
93 7 my @cleanup;
94 7 ▶ my $raw_key = $args{raw_key} // $self->raw_key // random_bytes(32);
Condition33%2/6
($args{"raw_key"} // $self->raw_key) // &random_bytes(32)
l!l&&r!l&&!r
700
$args{"raw_key"} // $self->raw_key
l!l&&r!l&&!r
070
MC/DC0%0/3
($args{"raw_key"} // $self->raw_key) // &random_bytes(32)
$args{"raw_key"} $self->raw_key &random_bytes(32)
Truth table25%1/4
A // B // C
A= $args{"raw_key"}B= $self->raw_keyC= &random_bytes(32)
ABCresult
1XX1
01X1
0011
0000
95 7 push @cleanup, erase_scoped $raw_key;
96 7 ▶ length($raw_key) == 32 or throw 'Raw key must be exactly 256 bits (32 bytes)', length => length($raw_key);
Branch: 1 branch
BranchTrueFalseTotal
length $raw_key == 32 or throw("Raw key must be exactly 256 bits (32 bytes)", "length", length $raw_key) 0 7 7
97  
98 7 ▶ my $type = $args{type} // $self->type // KEY_FILE_TYPE_XML;
Condition60%3/5
($args{"type"} // $self->type) // "xml"
l!l
70
$args{"type"} // $self->type
l!l&&r!l&&!r
160
MC/DC0%0/2
($args{"type"} // $self->type) // "xml"
$args{"type"} $self->type
Truth table66%2/3
A // B
A= $args{"type"}B= $self->type
ABresult
1X1
011
000
99 7 ▶ my $version = $args{version} // $self->version // 2;
Condition80%4/5
($args{"version"} // $self->version) // 2
l!l
25
$args{"version"} // $self->version
l!l&&r!l&&!r
025
MC/DC50%1/2
($args{"version"} // $self->version) // 2
$args{"version"} $self->version
Truth table66%2/3
A // B
A= $args{"version"}B= $self->version
ABresult
1X1
011
000
100 7 ▶ my $filepath = $args{filepath} // $self->filepath;
Condition100%3/3
$args{"filepath"} // $self->filepath
l!l&&r!l&&!r
151
MC/DC100%2/2
$args{"filepath"} // $self->filepath
$args{"filepath"} $self->filepath
Truth table100%3/3
A // B
A= $args{"filepath"}B= $self->filepath
ABresult
1X1
011
000
101 7 my $fh = $args{fh};
102 7 ▶ my $atomic = $args{atomic} // 1;
Condition50%1/2
$args{"atomic"} // 1
l!l
07
MC/DC0%0/1
$args{"atomic"} // 1
$args{"atomic"}
Truth table50%1/2
A
A= $args{"atomic"}
Aresult
11
00
103  
104 7 my $filepath_temp;
105 7 ▶ if (!openhandle($fh)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&openhandle($fh)) 6 1 7
106 6 ▶ $filepath or throw 'Must specify where to safe the key file to';
Branch: 1 branch
BranchTrueFalseTotal
$filepath or throw("Must specify where to safe the key file to") 0 6 6
107  
108 6 ▶ if ($atomic) {
Branch: 1 branch
BranchTrueFalseTotal
if ($atomic) { } 6 0 6
109 6 require File::Temp;
110 6 ($fh, $filepath_temp) = eval { File::Temp::tempfile("${filepath}-XXXXXX", UNLINK => 1) };
111 6 ▶ if (!$fh or my $err = $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $fh or my $err = $@) 0 6 6
Condition33%1/3
not $fh or my $err = $@
l!l&&r!l&&!r
006
MC/DC0%0/2
not $fh or my $err = $@
not $fh my $err = $@
Truth table33%1/3
not(A) or B
A= not $fhB= my $err = $@
ABresult
1X1
011
000
112 0 ▶ $err //= 'Unknown error';
Condition0%0/2
$err //= "Unknown error"
l!l
00
MC/DC0%0/1
$err //= "Unknown error"
$err
Truth table0%0/2
A
A= $err
Aresult
11
00
113 0 throw sprintf('Open file failed (%s): %s', $filepath_temp, $err),
114 error => $err,
115 filepath => $filepath_temp;
116 }
117 }
118 else {
119 0 ▶ open($fh, '>:raw', $filepath) or throw "Open file failed ($filepath): $!", filepath => $filepath;
Branch: 1 branch
BranchTrueFalseTotal
open $fh, ">:raw", $filepath or throw("Open file failed ($filepath): $!", "filepath", $filepath) 0 0 0
120 }
121 }
122  
123 7 ▶ if ($type == KEY_FILE_TYPE_XML) {
Branch: 3 branches
BranchTrueFalseTotal
if ($type == 4) { } 3 4 7
elsif ($type == 1) { } 2 2 4
elsif ($type == 2) { } 1 1 2
124 3 $self->_save_xml($fh, $raw_key, $version);
125 }
126 elsif ($type == KEY_FILE_TYPE_BINARY) {
127 2 print $fh $raw_key;
128 }
129 elsif ($type == KEY_FILE_TYPE_HEX) {
130 1 my $hex = uc(unpack('H*', $raw_key));
131 1 push @cleanup, erase_scoped $hex;
132 1 print $fh $hex;
133 }
134 else {
135 1 throw "Cannot save $type key file (invalid type)", type => $type;
136 }
137  
138 6 close($fh);
139  
140 6 ▶ if ($filepath_temp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filepath_temp) 5 1 6
141 5 my ($file_mode, $file_uid, $file_gid) = (stat($filepath))[2, 4, 5];
142  
143 5 ▶ my $mode = $args{mode} // $file_mode // do { my $m = umask; defined $m ? oct(666) &~ $m : undef };
Branch: 1 branch
BranchTrueFalseTotal
defined $m ? : 0 0 0
Condition33%2/6
($args{"mode"} // $file_mode) // do { my $m = umask; defined $m ? 438 & ~$m : undef }
l!l&&r!l&&!r
500
$args{"mode"} // $file_mode
l!l&&r!l&&!r
050
MC/DC0%0/3
($args{"mode"} // $file_mode) // do { my $m = umask; defined $m ? 438 & ~$m : undef }
$args{"mode"} $file_mode do { my $m = umask; defined $m ? 438 & ~$m : undef }
Truth table25%1/4
A // B // C
A= $args{"mode"}B= $file_modeC= do { my $m = umask; defined $m ? 438 & ~$m : undef }
ABCresult
1XX1
01X1
0011
0000
144 5 ▶ my $uid = $args{uid} // $file_uid // -1;
Condition40%2/5
($args{"uid"} // $file_uid) // -1
l!l
50
$args{"uid"} // $file_uid
l!l&&r!l&&!r
050
MC/DC0%0/2
($args{"uid"} // $file_uid) // -1
$args{"uid"} $file_uid
Truth table33%1/3
A // B
A= $args{"uid"}B= $file_uid
ABresult
1X1
011
000
145 5 ▶ my $gid = $args{gid} // $file_gid // -1;
Condition40%2/5
($args{"gid"} // $file_gid) // -1
l!l
50
$args{"gid"} // $file_gid
l!l&&r!l&&!r
050
MC/DC0%0/2
($args{"gid"} // $file_gid) // -1
$args{"gid"} $file_gid
Truth table33%1/3
A // B
A= $args{"gid"}B= $file_gid
ABresult
1X1
011
000
146 5 ▶ chmod($mode, $filepath_temp) if defined $mode;
Branch: 1 branch
BranchTrueFalseTotal
if defined $mode 5 0 5
147 5 chown($uid, $gid, $filepath_temp);
148 5 ▶ rename($filepath_temp, $filepath)
Branch: 1 branch
BranchTrueFalseTotal
rename $filepath_temp, $filepath or throw("Failed to write file ($filepath): $!", "filepath", $filepath) 0 5 5
149 or throw "Failed to write file ($filepath): $!", filepath => $filepath;
150 }
151 }
152  
153 ##############################################################################
154  
155 sub _load_xml {
156 6 ▶ my $self = shift;
Subroutine _load_xml: called CC=22 SCAR=34.7
157 6 my $buf = shift;
158 6 my $out = shift;
159  
160 6 my ($version, $hash, $data);
161  
162 6 my $reader = XML::LibXML::Reader->new(string => $$buf);
163 6 my $pattern = XML::LibXML::Pattern->new('/KeyFile/Meta/Version|/KeyFile/Key/Data');
164  
165 6 ▶ while ($reader->nextPatternMatch($pattern) == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reader->nextPatternMatch($pattern) == 1) 24 6 30
166 24 ▶ next if $reader->nodeType != XML_READER_TYPE_ELEMENT;
Branch: 1 branch
BranchTrueFalseTotal
if $reader->nodeType != 1 12 12 24
167 12 my $name = $reader->localName;
168 12 ▶ if ($name eq 'Version') {
Branch: 2 branches
BranchTrueFalseTotal
if ($name eq 'Version') { } 6 6 12
elsif ($name eq 'Data') { } 6 0 6
169 6 ▶ $reader->read if !$reader->isEmptyElement;
Branch: 1 branch
BranchTrueFalseTotal
unless $reader->isEmptyElement 6 0 6
170 6 ▶ $reader->nodeType == XML_READER_TYPE_TEXT
Branch: 1 branch
BranchTrueFalseTotal
$reader->nodeType == 3 or alert("Expected text node with version", "line", $reader->lineNumber) 0 6 6
171 or alert 'Expected text node with version', line => $reader->lineNumber;
172 6 my $val = trim($reader->value);
173 6 ▶ defined $version
Branch: 1 branch
BranchTrueFalseTotal
defined $version and alert("Overwriting version", "previous", $version, "new", $val, "line", $reader->lineNumber) 0 6 6
174 and alert 'Overwriting version', previous => $version, new => $val, line => $reader->lineNumber;
175 6 $version = $val;
176 }
177 elsif ($name eq 'Data') {
178 6 ▶ $hash = trim($reader->getAttribute('Hash')) if $reader->hasAttributes;
Branch: 1 branch
BranchTrueFalseTotal
if $reader->hasAttributes 4 2 6
179 6 ▶ $reader->read if !$reader->isEmptyElement;
Branch: 1 branch
BranchTrueFalseTotal
unless $reader->isEmptyElement 6 0 6
180 6 ▶ $reader->nodeType == XML_READER_TYPE_TEXT
Branch: 1 branch
BranchTrueFalseTotal
$reader->nodeType == 3 or alert("Expected text node with data", "line", $reader->lineNumber) 0 6 6
181 or alert 'Expected text node with data', line => $reader->lineNumber;
182 6 $data = $reader->value;
183 6 ▶ $data =~ s/\s+//g if defined $data;
Branch: 1 branch
BranchTrueFalseTotal
if defined $data 6 0 6
184 }
185 }
186  
187 6 ▶ return if !defined $version || !defined $data;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $version and defined $data 0 6 6
Condition33%1/3
defined $version and defined $data
!ll&&!rl&&r
006
MC/DC0%0/2
defined $version and defined $data
defined $version defined $data
Truth table33%1/3
A and B
A= defined $versionB= defined $data
ABresult
0X0
100
111
188  
189 6 ▶ if ($version =~ /^1\.0/ && $data =~ /^[A-Za-z0-9+\/=]+$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($version =~ /^1\.0/ and $data =~ m[^[A-Za-z0-9+/=]+$]) { } 2 4 6
elsif ($version =~ /^2\.0/ and $data =~ /^[A-Fa-f0-9]+$/ and defined $hash and $hash =~ /^[A-Fa-f0-9]+$/) { } 4 0 4
Condition66%2/3
$version =~ /^1\.0/ and $data =~ m[^[A-Za-z0-9+/=]+$]
!ll&&!rl&&r
402
MC/DC50%1/2
$version =~ /^1\.0/ and $data =~ m[^[A-Za-z0-9+/=]+$]
$version =~ /^1\.0/ $data =~ m[^[A-Za-z0-9+/=]+$]
Truth table66%2/3
A and B
A= $version =~ /^1\.0/B= $data =~ m[^[A-Za-z0-9+/=]+$]
ABresult
0X0
100
111
190 2 $$out = eval { decode_b64($data) };
191 2 ▶ if (my $err = $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $@) 0 2 2
192 0 throw 'Failed to decode key in key file', version => $version, data => $data, error => $err;
193 }
194 2 return (KEY_FILE_TYPE_XML, $version);
195 }
196 ▶ elsif ($version =~ /^2\.0/ && $data =~ /^[A-Fa-f0-9]+$/ && defined $hash && $hash =~ /^[A-Fa-f0-9]+$/) {
Condition33%3/9
$version =~ /^2\.0/ and $data =~ /^[A-Fa-f0-9]+$/ and defined $hash and $hash =~ /^[A-Fa-f0-9]+$/
!ll&&!rl&&r
004
$version =~ /^2\.0/ and $data =~ /^[A-Fa-f0-9]+$/ and defined $hash
!ll&&!rl&&r
004
$version =~ /^2\.0/ and $data =~ /^[A-Fa-f0-9]+$/
!ll&&!rl&&r
004
MC/DC0%0/4
$version =~ /^2\.0/ and $data =~ /^[A-Fa-f0-9]+$/ and defined $hash and $hash =~ /^[A-Fa-f0-9]+$/
$version =~ /^2\.0/ $data =~ /^[A-Fa-f0-9]+$/ defined $hash $hash =~ /^[A-Fa-f0-9]+$/
Truth table20%1/5
A and B and C and D
A= $version =~ /^2\.0/B= $data =~ /^[A-Fa-f0-9]+$/C= defined $hashD= $hash =~ /^[A-Fa-f0-9]+$/
ABCDresult
0XXX0
10XX0
110X0
11100
11111
197 4 $$out = pack('H*', $data);
198 4 $hash = pack('H*', $hash);
199 4 my $got_hash = digest_data('SHA256', $$out);
200 4 ▶ $hash eq substr($got_hash, 0, length($hash))
Branch: 1 branch
BranchTrueFalseTotal
$hash eq substr($got_hash, 0, length $hash) or throw("Checksum mismatch", "got", $got_hash, "expected", $hash) 0 4 4
201 or throw 'Checksum mismatch', got => $got_hash, expected => $hash;
202 4 return (KEY_FILE_TYPE_XML, $version);
203 }
204  
205 0 throw 'Unexpected data in key file', version => $version, data => $data;
206 }
207  
208 sub _save_xml {
209 3 ▶ my $self = shift;
Subroutine _save_xml: called CC=4 SCAR=13.9
210 3 my $fh = shift;
211 3 my $raw_key = shift;
212 3 ▶ my $version = shift // 2;
Condition50%1/2
shift() // 2
l!l
30
MC/DC0%0/1
shift() // 2
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
213  
214 3 my @cleanup;
215  
216 3 my $dom = XML::LibXML::Document->new('1.0', 'UTF-8');
217 3 my $doc = XML::LibXML::Element->new('KeyFile');
218 3 $dom->setDocumentElement($doc);
219 3 my $meta_node = XML::LibXML::Element->new('Meta');
220 3 $doc->appendChild($meta_node);
221 3 my $version_node = XML::LibXML::Element->new('Version');
222 3 $version_node->appendText(sprintf('%.1f', $version));
223 3 $meta_node->appendChild($version_node);
224 3 my $key_node = XML::LibXML::Element->new('Key');
225 3 $doc->appendChild($key_node);
226 3 my $data_node = XML::LibXML::Element->new('Data');
227 3 $key_node->appendChild($data_node);
228  
229 3 ▶ if (int($version) == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (int $version == 1) { } 1 2 3
elsif (int $version == 2) { } 2 0 2
230 1 my $b64 = encode_b64($raw_key);
231 1 push @cleanup, erase_scoped $b64;
232 1 $data_node->appendText($b64);
233 }
234 elsif (int($version) == 2) {
235 2 my @hex = unpack('(H8)8', $raw_key);
236 2 my $hex = uc(sprintf("\n %s\n %s\n ", join(' ', @hex[0..3]), join(' ', @hex[4..7])));
237 2 push @cleanup, erase_scoped $hex, @hex;
238 2 $data_node->appendText($hex);
239 2 my $hash = digest_data('SHA256', $raw_key);
240 2 substr($hash, 4) = '';
241 2 $hash = uc(unpack('H*', $hash));
242 2 $data_node->setAttribute('Hash', $hash);
243 }
244 else {
245 0 throw 'Failed to save unsupported key file version', version => $version;
246 }
247  
248 3 $dom->toFH($fh, 1);
249 }
250  
251 3 1;
252  
253 __END__
« KDBX/Loader.pm ↑ Summary KDBX/Loader/V4.pm »