CDS.pm

filter: Statementstmt 1.1% 128 / 10910 Branchbran 0.0% 3 / 3164 Conditioncond 0.1% 3 / 2185 MC/DCmcdc 0.0% 0 / 1343 Subroutinesub 2.5% 39 / 1526 Podpod 0.0% 0 / 36 totaltotal 0.9% 173 / 19164 SCAR 157.6
CC
2677
Cov
1%
run
992.0
discover
600.0
showCompletions
600.0
CRAP 6993276.5
↑ Summary CDS/C.pm »
1 # This is part of the Condensation Perl Module 0.26 (cli) built on 2022-02-08.
2 # See https://condensation.io for information about the Condensation Data System.
3  
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use 5.010000;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use CDS::C;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Digest::SHA;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Fcntl;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use HTTP::Date;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use HTTP::Headers;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use HTTP::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use HTTP::Server::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use Time::Local;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 package CDS;
21  
22 1 our $VERSION = '0.26';
23 1 our $edition = 'cli';
24 1 our $releaseDate = '2022-02-08';
25  
26 0 ▶sub now { time * 1000 }
Subroutine now: not called CC=1 SCAR=6.9
Pod undocumented
27  
28 0 ▶sub SECOND { 1000 }
Subroutine SECOND: not called CC=1 SCAR=6.9
Pod undocumented
29 0 ▶sub MINUTE { 60 * 1000 }
Subroutine MINUTE: not called CC=1 SCAR=6.9
Pod undocumented
30 0 ▶sub HOUR { 60 * 60 * 1000 }
Subroutine HOUR: not called CC=1 SCAR=6.9
Pod undocumented
31 0 ▶sub DAY { 24 * 60 * 60 * 1000 }
Subroutine DAY: not called CC=1 SCAR=6.9
Pod undocumented
32 0 ▶sub WEEK { 7 * 24 * 60 * 60 * 1000 }
Subroutine WEEK: not called CC=1 SCAR=6.9
Pod undocumented
33 0 ▶sub MONTH { 30 * 24 * 60 * 60 * 1000 }
Subroutine MONTH: not called CC=1 SCAR=6.9
Pod undocumented
34 0 ▶sub YEAR { 365 * 24 * 60 * 60 * 1000 }
Subroutine YEAR: not called CC=1 SCAR=6.9
Pod undocumented
35  
36 # File system utility functions.
37  
38 sub readBytesFromFile {
39 0 ▶ my $class = shift;
Subroutine readBytesFromFile: not called CC=2 SCAR=17.9
Pod undocumented
40 0 my $filename = shift;
41  
42 0 ▶ open(my $fh, '<:bytes', $filename) || return;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<:bytes", $filename or return 0 0 0
43 0 local $/;
44 0 my $content = <$fh>;
45 0 close $fh;
46 0 return $content;
47 }
48  
49 sub writeBytesToFile {
50 0 ▶ my $class = shift;
Subroutine writeBytesToFile: not called CC=2 SCAR=17.9
Pod undocumented
51 0 my $filename = shift;
52  
53 0 ▶ open(my $fh, '>:bytes', $filename) || return;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">:bytes", $filename or return 0 0 0
54 0 print $fh @_;
55 0 close $fh;
56 0 return 1;
57 }
58  
59 sub readTextFromFile {
60 0 ▶ my $class = shift;
Subroutine readTextFromFile: not called CC=2 SCAR=17.9
Pod undocumented
61 0 my $filename = shift;
62  
63 0 ▶ open(my $fh, '<:utf8', $filename) || return;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<:utf8", $filename or return 0 0 0
64 0 local $/;
65 0 my $content = <$fh>;
66 0 close $fh;
67 0 return $content;
68 }
69  
70 sub writeTextToFile {
71 0 ▶ my $class = shift;
Subroutine writeTextToFile: not called CC=2 SCAR=17.9
Pod undocumented
72 0 my $filename = shift;
73  
74 0 ▶ open(my $fh, '>:utf8', $filename) || return;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">:utf8", $filename or return 0 0 0
75 0 print $fh @_;
76 0 close $fh;
77 0 return 1;
78 }
79  
80 sub listFolder {
81 0 ▶ my $class = shift;
Subroutine listFolder: not called CC=2 SCAR=17.9
Pod undocumented
82 0 my $folder = shift;
83  
84 0 ▶ opendir(my $dh, $folder) || return;
Branch: 1 branch
BranchTrueFalseTotal
opendir my $dh, $folder or return 0 0 0
85 0 my @files = readdir $dh;
86 0 closedir $dh;
87 0 return @files;
88 }
89  
90 sub intermediateFolders {
91 0 ▶ my $class = shift;
Subroutine intermediateFolders: not called CC=3 SCAR=24.8
Pod undocumented
92 0 my $path = shift;
93  
94 0 my @paths = ($path);
95 0 while (1) {
96 0 ▶ $path =~ /^(.+)\/(.*?)$/ || last;
Branch: 1 branch
BranchTrueFalseTotal
$path =~ m[^(.+)/(.*?)$] or last 0 0 0
97 0 $path = $1;
98 0 ▶ next if ! length $2;
Branch: 1 branch
BranchTrueFalseTotal
unless length $2 0 0 0
99 0 unshift @paths, $path;
100 }
101 0 return @paths;
102 }
103  
104 # This is for debugging purposes only.
105 sub log {
106 0 ▶ my $class = shift;
Subroutine log: not called CC=1 SCAR=6.9
Pod undocumented
107  
108 0 print STDERR @_, "\n";
109 }
110  
111 sub min {
112 0 ▶ my $class = shift;
Subroutine min: not called CC=3 SCAR=24.8
Pod undocumented
113  
114 0 my $min = shift;
115 0 for my $number (@_) {
116 0 ▶ $min = $min < $number ? $min : $number;
Branch: 1 branch
BranchTrueFalseTotal
$min < $number ? : 0 0 0
117 }
118  
119 0 return $min;
120 }
121  
122 sub max {
123 0 ▶ my $class = shift;
Subroutine max: not called CC=3 SCAR=24.8
Pod undocumented
124  
125 0 my $max = shift;
126 0 for my $number (@_) {
127 0 ▶ $max = $max > $number ? $max : $number;
Branch: 1 branch
BranchTrueFalseTotal
$max > $number ? : 0 0 0
128 }
129  
130 0 return $max;
131 }
132  
133 sub booleanCompare {
134 0 ▶ my $class = shift;
Subroutine booleanCompare: not called CC=5 SCAR=34.0
Pod undocumented
135 0 my $a = shift;
136 0 my $b = shift;
137 0 ▶ $a && $b ? 0 : $a ? 1 : $b ? -1 : 0 }
Branch: 3 branches
BranchTrueFalseTotal
$a && $b ? : 0 0 0
$a ? : 0 0 0
$b ? : 0 0 0
Condition0%0/3
$a and $b
!ll&&!rl&&r
000
MC/DC0%0/2
$a and $b
$a $b
Truth table0%0/3
A and B
A= $aB= $b
ABresult
0X0
100
111
138  
139 # Utility functions for random sequences
140  
141 1 srand(time);
142 1 our @hexDigits = ('0'..'9', 'a'..'f');
143  
144 sub randomHex {
145 0 ▶ my $class = shift;
Subroutine randomHex: not called CC=1 SCAR=6.9
Pod undocumented
146 0 my $length = shift;
147  
148 0 return substr(unpack('H*', CDS::C::randomBytes(int(($length + 1) / 2))), 0, $length);
149 }
150  
151 sub randomBytes {
152 0 ▶ my $class = shift;
Subroutine randomBytes: not called CC=1 SCAR=6.9
Pod undocumented
153 0 my $length = shift;
154  
155 0 return CDS::C::randomBytes($length);
156 }
157  
158 sub randomKey {
159 0 ▶ my $class = shift;
Subroutine randomKey: not called CC=1 SCAR=6.9
Pod undocumented
160  
161 0 return CDS::C::randomBytes(32);
162 }
163  
164 0 ▶sub version { 'Condensation, Perl, '.$CDS::VERSION }
Subroutine version: not called CC=1 SCAR=6.9
Pod undocumented
165  
166 # Conversion of numbers and booleans to and from bytes.
167 # To convert text, use Encode::encode_utf8($text) and Encode::decode_utf8($bytes).
168 # To convert hex sequences, use pack('H*', $hex) and unpack('H*', $bytes).
169  
170 sub bytesFromBoolean {
171 0 ▶ my $class = shift;
Subroutine bytesFromBoolean: not called CC=2 SCAR=17.9
Pod undocumented
172 0 my $value = shift;
173 0 ▶ $value ? 'y' : '' }
Branch: 1 branch
BranchTrueFalseTotal
$value ? : 0 0 0
174  
175 sub bytesFromInteger {
176 0 ▶ my $class = shift;
Subroutine bytesFromInteger: not called CC=14 SCAR=53.5
Pod undocumented
177 0 my $value = shift;
178  
179 0 ▶ return '' if $value >= 0 && $value < 1;
Branch: 1 branch
BranchTrueFalseTotal
if $value >= 0 and $value < 1 0 0 0
Condition0%0/3
$value >= 0 and $value < 1
!ll&&!rl&&r
000
MC/DC0%0/2
$value >= 0 and $value < 1
$value >= 0 $value < 1
Truth table0%0/3
A and B
A= $value >= 0B= $value < 1
ABresult
0X0
100
111
180 0 ▶ return pack 'c', $value if $value >= -0x80 && $value < 0x80;
Branch: 1 branch
BranchTrueFalseTotal
if $value >= -128 and $value < 128 0 0 0
Condition0%0/3
$value >= -128 and $value < 128
!ll&&!rl&&r
000
MC/DC0%0/2
$value >= -128 and $value < 128
$value >= -128 $value < 128
Truth table0%0/3
A and B
A= $value >= -128B= $value < 128
ABresult
0X0
100
111
181 0 ▶ return pack 's>', $value if $value >= -0x8000 && $value < 0x8000;
Branch: 1 branch
BranchTrueFalseTotal
if $value >= -32768 and $value < 32768 0 0 0
Condition0%0/3
$value >= -32768 and $value < 32768
!ll&&!rl&&r
000
MC/DC0%0/2
$value >= -32768 and $value < 32768
$value >= -32768 $value < 32768
Truth table0%0/3
A and B
A= $value >= -32768B= $value < 32768
ABresult
0X0
100
111
182  
183 # This works up to 63 bits, plus 1 sign bit
184 0 my $bytes = pack 'q>', $value;
185  
186 0 my $pos = 0;
187 0 my $first = ord(substr($bytes, 0, 1));
188 0 ▶ if ($value > 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($value > 0) { } 0 0 0
elsif ($first == 255) { } 0 0 0
189 # Perl internally uses an unsigned 64-bit integer if the value is positive
190 0 ▶ return "\x7f\xff\xff\xff\xff\xff\xff\xff" if $first >= 128;
Branch: 1 branch
BranchTrueFalseTotal
if $first >= 128 0 0 0
191 0 ▶ while ($first == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($first == 0) 0 0 0
192 0 my $next = ord(substr($bytes, $pos + 1, 1));
193 0 ▶ last if $next >= 128;
Branch: 1 branch
BranchTrueFalseTotal
if $next >= 128 0 0 0
194 0 $first = $next;
195 0 $pos += 1;
196 }
197 } elsif ($first == 255) {
198 0 ▶ while ($first == 255) {
Branch: 1 branch
BranchTrueFalseTotal
if ($first == 255) 0 0 0
199 0 my $next = ord(substr($bytes, $pos + 1, 1));
200 0 ▶ last if $next < 128;
Branch: 1 branch
BranchTrueFalseTotal
if $next < 128 0 0 0
201 0 $first = $next;
202 0 $pos += 1;
203 }
204 }
205  
206 0 return substr($bytes, $pos);
207 }
208  
209 sub bytesFromUnsigned {
210 0 ▶ my $class = shift;
Subroutine bytesFromUnsigned: not called CC=5 SCAR=34.0
Pod undocumented
211 0 my $value = shift;
212  
213 0 ▶ return '' if $value < 1;
Branch: 1 branch
BranchTrueFalseTotal
if $value < 1 0 0 0
214 0 ▶ return pack 'C', $value if $value < 0x100;
Branch: 1 branch
BranchTrueFalseTotal
if $value < 256 0 0 0
215 0 ▶ return pack 'S>', $value if $value < 0x10000;
Branch: 1 branch
BranchTrueFalseTotal
if $value < 65536 0 0 0
216  
217 # This works up to 64 bits
218 0 my $bytes = pack 'Q>', $value;
219 0 my $pos = 0;
220 0 ▶ $pos += 1 while substr($bytes, $pos, 1) eq "\0";
Branch: 1 branch
BranchTrueFalseTotal
substr($bytes, $pos, 1) eq "\0" and do { $pos += 1 } 0 0 0
221 0 return substr($bytes, $pos);
222 }
223  
224 sub bytesFromFloat32 {
225 0 ▶ my $class = shift;
Subroutine bytesFromFloat32: not called CC=1 SCAR=6.9
Pod undocumented
226 0 my $value = shift;
227 0 pack('f', $value) }
228 sub bytesFromFloat64 {
229 0 ▶ my $class = shift;
Subroutine bytesFromFloat64: not called CC=1 SCAR=6.9
Pod undocumented
230 0 my $value = shift;
231 0 pack('d', $value) }
232  
233 sub booleanFromBytes {
234 0 ▶ my $class = shift;
Subroutine booleanFromBytes: not called CC=1 SCAR=6.9
Pod undocumented
235 0 my $bytes = shift;
236  
237 0 return length $bytes > 0;
238 }
239  
240 sub integerFromBytes {
241 0 ▶ my $class = shift;
Subroutine integerFromBytes: not called CC=4 SCAR=30.0
Pod undocumented
242 0 my $bytes = shift;
243  
244 0 ▶ return 0 if ! length $bytes;
Branch: 1 branch
BranchTrueFalseTotal
unless length $bytes 0 0 0
245 0 my $value = unpack('C', substr($bytes, 0, 1));
246 0 ▶ $value -= 0x100 if $value & 0x80;
Branch: 1 branch
BranchTrueFalseTotal
if $value & 128 0 0 0
247 0 for my $i (1 .. length($bytes) - 1) {
248 0 $value *= 256;
249 0 $value += unpack('C', substr($bytes, $i, 1));
250 }
251 0 return $value;
252 }
253  
254 sub unsignedFromBytes {
255 0 ▶ my $class = shift;
Subroutine unsignedFromBytes: not called CC=2 SCAR=17.9
Pod undocumented
256 0 my $bytes = shift;
257  
258 0 my $value = 0;
259 0 for my $i (0 .. length($bytes) - 1) {
260 0 $value *= 256;
261 0 $value += unpack('C', substr($bytes, $i, 1));
262 }
263 0 return $value;
264 }
265  
266 sub floatFromBytes {
267 0 ▶ my $class = shift;
Subroutine floatFromBytes: not called CC=3 SCAR=24.8
Pod undocumented
268 0 my $bytes = shift;
269  
270 0 ▶ return unpack('f', $bytes) if length $bytes == 4;
Branch: 1 branch
BranchTrueFalseTotal
if length $bytes == 4 0 0 0
271 0 ▶ return unpack('d', $bytes) if length $bytes == 8;
Branch: 1 branch
BranchTrueFalseTotal
if length $bytes == 8 0 0 0
272 0 return undef;
273 }
274  
275 # Initial counter value for AES in CTR mode
276 0 ▶sub zeroCTR { "\0" x 16 }
Subroutine zeroCTR: not called CC=1 SCAR=6.9
Pod undocumented
277  
278 1 my $emptyBytesHash = CDS::Hash->fromHex('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855');
279 0 ▶sub emptyBytesHash { $emptyBytesHash }
Subroutine emptyBytesHash: not called CC=1 SCAR=6.9
Pod undocumented
280  
281 # Checks if a box label is valid.
282 sub isValidBoxLabel {
283 0 ▶ my $class = shift;
Subroutine isValidBoxLabel: not called CC=3 SCAR=24.8
Pod undocumented
284 0 my $label = shift;
285 0 ▶ $label eq 'messages' || $label eq 'private' || $label eq 'public' }
Branch: 1 branch
BranchTrueFalseTotal
$label eq "messages" or $label eq "private" or $label eq "public" 0 0 0
Condition0%0/3
$label eq "messages" or $label eq "private"
l!l&&r!l&&!r
000
MC/DC0%0/2
$label eq "messages" or $label eq "private"
$label eq "messages" $label eq "private"
Truth table0%0/3
A or B
A= $label eq "messages"B= $label eq "private"
ABresult
1X1
011
000
286  
287 # Groups box additions or removals by account hash and box label.
288 sub groupedBoxOperations {
289 0 ▶ my $class = shift;
Subroutine groupedBoxOperations: not called CC=4 SCAR=30.0
Pod undocumented
290 0 my $operations = shift;
291  
292 0 my %byAccountHash;
293 0 for my $operation (@$operations) {
294 0 my $accountHashBytes = $operation->{accountHash}->bytes;
295 0 ▶ $byAccountHash{$accountHashBytes} = {accountHash => $operation->{accountHash}, byBoxLabel => {}} if ! exists $byAccountHash{$accountHashBytes};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $byAccountHash{$accountHashBytes} 0 0 0
296 0 my $byBoxLabel = $byAccountHash{$accountHashBytes}->{byBoxLabel};
297 0 my $boxLabel = $operation->{boxLabel};
298 0 ▶ $byBoxLabel->{$boxLabel} = [] if ! exists $byBoxLabel->{$boxLabel};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $byBoxLabel->{$boxLabel} 0 0 0
299 0 push @{$byBoxLabel->{$boxLabel}}, $operation;
300 }
301  
302 0 return values %byAccountHash;
303 }
304  
305 ### Open envelopes ###
306  
307 sub verifyEnvelopeSignature {
308 0 ▶ my $class = shift;
Subroutine verifyEnvelopeSignature: not called CC=9 SCAR=45.0
Pod undocumented
309 0 ▶ my $envelope = shift; die 'wrong type '.ref($envelope).' for $envelope' if defined $envelope && ref $envelope ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $envelope and ref $envelope ne "CDS::Record" 0 0 0
Condition0%0/3
defined $envelope and ref $envelope ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $envelope and ref $envelope ne "CDS::Record"
defined $envelope ref $envelope ne "CDS::Record"
Truth table0%0/3
A and B
A= defined $envelopeB= ref $envelope ne "CDS::Record"
ABresult
0X0
100
111
310 0 ▶ my $publicKey = shift; die 'wrong type '.ref($publicKey).' for $publicKey' if defined $publicKey && ref $publicKey ne 'CDS::PublicKey';
Branch: 1 branch
BranchTrueFalseTotal
if defined $publicKey and ref $publicKey ne "CDS::PublicKey" 0 0 0
Condition0%0/3
defined $publicKey and ref $publicKey ne "CDS::PublicKey"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $publicKey and ref $publicKey ne "CDS::PublicKey"
defined $publicKey ref $publicKey ne "CDS::PublicKey"
Truth table0%0/3
A and B
A= defined $publicKeyB= ref $publicKey ne "CDS::PublicKey"
ABresult
0X0
100
111
311 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
312  
313 # Read the signature
314 0 my $signature = $envelope->child('signature')->bytesValue;
315 0 ▶ return if length $signature < 1;
Branch: 1 branch
BranchTrueFalseTotal
if length $signature < 1 0 0 0
316  
317 # Verify the signature
318 0 ▶ return if ! $publicKey->verifyHash($hash, $signature);
Branch: 1 branch
BranchTrueFalseTotal
unless $publicKey->verifyHash($hash, $signature) 0 0 0
319 0 return 1;
320 }
321  
322 # The result of parsing an ACCOUNT token (see Token.pm).
323 package CDS::AccountToken;
324  
325 sub new {
326 0 ▶ my $class = shift;
Subroutine new: not called CC=3 SCAR=24.8
327 0 my $cliStore = shift;
328 0 ▶ my $actorHash = shift; die 'wrong type '.ref($actorHash).' for $actorHash' if defined $actorHash && ref $actorHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $actorHash and ref $actorHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $actorHash and ref $actorHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $actorHash and ref $actorHash ne "CDS::Hash"
defined $actorHash ref $actorHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $actorHashB= ref $actorHash ne "CDS::Hash"
ABresult
0X0
100
111
329  
330 0 return bless {
331 cliStore => $cliStore,
332 actorHash => $actorHash,
333 };
334 }
335  
336 0 ▶sub cliStore { shift->{cliStore} }
Subroutine cliStore: not called CC=1 SCAR=6.9
337 0 ▶sub actorHash { shift->{actorHash} }
Subroutine actorHash: not called CC=1 SCAR=6.9
338 sub url {
339 0 ▶ my $o = shift;
Subroutine url: not called CC=1 SCAR=6.9
340 0 $o->{cliStore}->url.'/accounts/'.$o->{actorHash}->hex }
341  
342 package CDS::ActorGroup;
343  
344 # Members must be sorted in descending revision order, such that the member with the most recent revision is first. Members must not include any revoked actors.
345 sub new {
346 0 ▶ my $class = shift;
Subroutine new: not called CC=2 SCAR=17.9
347 0 my $members = shift;
348 0 my $entrustedActorsRevision = shift;
349 0 my $entrustedActors = shift;
350  
351 # Create the cache for the "contains" method
352 0 my $containCache = {};
353 0 for my $member (@$members) {
354 0 $containCache->{$member->actorOnStore->publicKey->hash->bytes} = 1;
355 }
356  
357 0 return bless {
358 members => $members,
359 entrustedActorsRevision => $entrustedActorsRevision,
360 entrustedActors => $entrustedActors,
361 containsCache => $containCache,
362 };
363 }
364  
365 sub members {
366 0 ▶ my $o = shift;
Subroutine members: not called CC=1 SCAR=6.9
367 0 @{$o->{members}} }
368 0 ▶sub entrustedActorsRevision { shift->{entrustedActorsRevision} }
Subroutine entrustedActorsRevision: not called CC=1 SCAR=6.9
369 sub entrustedActors {
370 0 ▶ my $o = shift;
Subroutine entrustedActors: not called CC=1 SCAR=6.9
371 0 @{$o->{entrustedActors}} }
372  
373 # Checks whether the actor group contains at least one active member.
374 sub isActive {
375 0 ▶ my $o = shift;
Subroutine isActive: not called CC=3 SCAR=24.8
376  
377 0 for my $member (@{$o->{members}}) {
378 0 ▶ return 1 if $member->isActive;
Branch: 1 branch
BranchTrueFalseTotal
if $member->isActive 0 0 0
379 }
380 0 return;
381 }
382  
383 # Returns the most recent active member, the most recent idle member, or undef if the group is empty.
384 sub leader {
385 0 ▶ my $o = shift;
Subroutine leader: not called CC=3 SCAR=24.8
386  
387 0 for my $member (@{$o->{members}}) {
388 0 ▶ return $member if $member->isActive;
Branch: 1 branch
BranchTrueFalseTotal
if $member->isActive 0 0 0
389 }
390 0 return $o->{members}->[0];
391 }
392  
393 # Returns true if the account belongs to this actor group.
394 # Note that multiple (different) actor groups may claim that the account belongs to them. In practice, an account usually belongs to one actor group.
395 sub contains {
396 0 ▶ my $o = shift;
Subroutine contains: not called CC=3 SCAR=24.8
397 0 ▶ my $actorHash = shift; die 'wrong type '.ref($actorHash).' for $actorHash' if defined $actorHash && ref $actorHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $actorHash and ref $actorHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $actorHash and ref $actorHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $actorHash and ref $actorHash ne "CDS::Hash"
defined $actorHash ref $actorHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $actorHashB= ref $actorHash ne "CDS::Hash"
ABresult
0X0
100
111
398  
399 0 return exists $o->{containsCache}->{$actorHash->bytes};
400 }
401  
402 # Returns true if the account is entrusted by this actor group.
403 sub entrusts {
404 0 ▶ my $o = shift;
Subroutine entrusts: not called CC=5 SCAR=34.0
405 0 ▶ my $actorHash = shift; die 'wrong type '.ref($actorHash).' for $actorHash' if defined $actorHash && ref $actorHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $actorHash and ref $actorHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $actorHash and ref $actorHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $actorHash and ref $actorHash ne "CDS::Hash"
defined $actorHash ref $actorHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $actorHashB= ref $actorHash ne "CDS::Hash"
ABresult
0X0
100
111
406  
407 0 for my $actor (@{$o->{entrustedActors}}) {
408 0 ▶ return 1 if $actorHash->equals($actor->publicKey->hash);
Branch: 1 branch
BranchTrueFalseTotal
if $actorHash->equals($actor->publicKey->hash) 0 0 0
409 }
410 0 return;
411 }
412  
413 # Returns all public keys.
414 sub publicKeys {
415 0 ▶ my $o = shift;
Subroutine publicKeys: not called CC=3 SCAR=24.8
416  
417 0 my @publicKeys;
418 0 for my $member (@{$o->{members}}) {
419 0 push @publicKeys, $member->actorOnStore->publicKey;
420 }
421 0 for my $actor (@{$o->{entrustedActors}}) {
422 0 push @publicKeys, $actor->actorOnStore->publicKey;
423 }
424 0 return @publicKeys;
425 }
426  
427 # Returns an ActorGroupBuilder with all members and entrusted keys of this ActorGroup.
428 sub toBuilder {
429 0 ▶ my $o = shift;
Subroutine toBuilder: not called CC=4 SCAR=30.0
430  
431 0 my $builder = CDS::ActorGroupBuilder->new;
432 0 $builder->mergeEntrustedActors($o->{entrustedActorsRevision});
433 0 for my $member (@{$o->{members}}) {
434 0 my $publicKey = $member->actorOnStore->publicKey;
435 0 $builder->addKnownPublicKey($publicKey);
436 0 ▶ $builder->addMember($publicKey->hash, $member->storeUrl, $member->revision, $member->isActive ? 'active' : 'idle');
Branch: 1 branch
BranchTrueFalseTotal
$member->isActive ? : 0 0 0
437 }
438 0 for my $actor (@{$o->{entrustedActors}}) {
439 0 my $publicKey = $actor->actorOnStore->publicKey;
440 0 $builder->addKnownPublicKey($publicKey);
441 0 $builder->addEntrustedActor($publicKey->hash, $actor->storeUrl);
442 }
443 0 return $builder;
444 }
445  
446 package CDS::ActorGroup::EntrustedActor;
447  
448 sub new {
449 0 ▶ my $class = shift;
Subroutine new: not called CC=3 SCAR=24.8
450 0 ▶ my $actorOnStore = shift; die 'wrong type '.ref($actorOnStore).' for $actorOnStore' if defined $actorOnStore && ref $actorOnStore ne 'CDS::ActorOnStore';
Branch: 1 branch
BranchTrueFalseTotal
if defined $actorOnStore and ref $actorOnStore ne "CDS::ActorOnStore" 0 0 0
Condition0%0/3
defined $actorOnStore and ref $actorOnStore ne "CDS::ActorOnStore"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $actorOnStore and ref $actorOnStore ne "CDS::ActorOnStore"
defined $actorOnStore ref $actorOnStore ne "CDS::ActorOnStore"
Truth table0%0/3
A and B
A= defined $actorOnStoreB= ref $actorOnStore ne "CDS::ActorOnStore"
ABresult
0X0
100
111
451 0 my $storeUrl = shift;
452  
453 0 return bless {
454 actorOnStore => $actorOnStore,
455 storeUrl => $storeUrl,
456 };
457 }
458  
459 0 ▶sub actorOnStore { shift->{actorOnStore} }
Subroutine actorOnStore: not called CC=1 SCAR=6.9
460 0 ▶sub storeUrl { shift->{storeUrl} }
Subroutine storeUrl: not called CC=1 SCAR=6.9
461  
462 package CDS::ActorGroup::Member;
463  
464 sub new {
465 0 ▶ my $class = shift;
Subroutine new: not called CC=3 SCAR=24.8
466 0 ▶ my $actorOnStore = shift; die 'wrong type '.ref($actorOnStore).' for $actorOnStore' if defined $actorOnStore && ref $actorOnStore ne 'CDS::ActorOnStore';
Branch: 1 branch
BranchTrueFalseTotal
if defined $actorOnStore and ref $actorOnStore ne "CDS::ActorOnStore" 0 0 0
Condition0%0/3
defined $actorOnStore and ref $actorOnStore ne "CDS::ActorOnStore"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $actorOnStore and ref $actorOnStore ne "CDS::ActorOnStore"
defined $actorOnStore ref $actorOnStore ne "CDS::ActorOnStore"
Truth table0%0/3
A and B
A= defined $actorOnStoreB= ref $actorOnStore ne "CDS::ActorOnStore"
ABresult
0X0
100
111
467 0 my $storeUrl = shift;
468 0 my $revision = shift;
469 0 my $isActive = shift;
470  
471 0 return bless {
472 actorOnStore => $actorOnStore,
473 storeUrl => $storeUrl,
474 revision => $revision,
475 isActive => $isActive,
476 };
477 }
478  
479 0 ▶sub actorOnStore { shift->{actorOnStore} }
Subroutine actorOnStore: not called CC=1 SCAR=6.9
480 0 ▶sub storeUrl { shift->{storeUrl} }
Subroutine storeUrl: not called CC=1 SCAR=6.9
481 0 ▶sub revision { shift->{revision} }
Subroutine revision: not called CC=1 SCAR=6.9
482 0 ▶sub isActive { shift->{isActive} }
Subroutine isActive: not called CC=1 SCAR=6.9
483  
484 package CDS::ActorGroupBuilder;
485  
486 sub new {
487 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
488  
489 0 return bless {
490 knownPublicKeys => {}, # A hashref of known public keys (e.g. from the existing actor group)
491 members => {}, # Members by URL
492 entrustedActorsRevision => 0, # Revision of the list of entrusted actors
493 entrustedActors => {}, # Entrusted actors by hash
494 };
495 }
496  
497 sub members {
498 0 ▶ my $o = shift;
Subroutine members: not called CC=1 SCAR=6.9
499 0 values %{$o->{members}} }
500 0 ▶sub entrustedActorsRevision { shift->{entrustedActorsRevision} }
Subroutine entrustedActorsRevision: not called CC=1 SCAR=6.9
501 sub entrustedActors {
502 0 ▶ my $o = shift;
Subroutine entrustedActors: not called CC=1 SCAR=6.9
503 0 values %{$o->{entrustedActors}} }
504 0 ▶sub knownPublicKeys { shift->{knownPublicKeys} }
Subroutine knownPublicKeys: not called CC=1 SCAR=6.9
505  
506 sub addKnownPublicKey {
507 0 ▶ my $o = shift;
Subroutine addKnownPublicKey: not called CC=3 SCAR=24.8
508 0 ▶ my $publicKey = shift; die 'wrong type '.ref($publicKey).' for $publicKey' if defined $publicKey && ref $publicKey ne 'CDS::PublicKey';
Branch: 1 branch
BranchTrueFalseTotal
if defined $publicKey and ref $publicKey ne "CDS::PublicKey" 0 0 0
Condition0%0/3
defined $publicKey and ref $publicKey ne "CDS::PublicKey"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $publicKey and ref $publicKey ne "CDS::PublicKey"
defined $publicKey ref $publicKey ne "CDS::PublicKey"
Truth table0%0/3
A and B
A= defined $publicKeyB= ref $publicKey ne "CDS::PublicKey"
ABresult
0X0
100
111
509  
510 0 $o->{publicKeys}->{$publicKey->hash->bytes} = $publicKey;
511 }
512  
513 sub addMember {
514 0 ▶ my $o = shift;
Subroutine addMember: not called CC=7 SCAR=40.3
515 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
516 0 my $storeUrl = shift;
517 0 ▶ my $revision = shift // 0;
Condition0%0/2
shift() // 0
l!l
00
MC/DC0%0/1
shift() // 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
518 0 ▶ my $status = shift // 'active';
Condition0%0/2
shift() // "active"
l!l
00
MC/DC0%0/1
shift() // "active"
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
519  
520 0 my $url = $storeUrl.'/accounts/'.$hash->hex;
521 0 my $member = $o->{members}->{$url};
522 0 ▶ return if $member && $revision <= $member->revision;
Branch: 1 branch
BranchTrueFalseTotal
if $member and $revision <= $member->revision 0 0 0
Condition0%0/3
$member and $revision <= $member->revision
!ll&&!rl&&r
000
MC/DC0%0/2
$member and $revision <= $member->revision
$member $revision <= $member->revision
Truth table0%0/3
A and B
A= $memberB= $revision <= $member->revision
ABresult
0X0
100
111
523 0 $o->{members}->{$url} = CDS::ActorGroupBuilder::Member->new($hash, $storeUrl, $revision, $status);
524 0 return 1;
525 }
526  
527 sub removeMember {
528 0 ▶ my $o = shift;
Subroutine removeMember: not called CC=3 SCAR=24.8
529 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
530 0 my $storeUrl = shift;
531  
532 0 my $url = $storeUrl.'/accounts/'.$hash->hex;
533 0 delete $o->{members}->{$url};
534 }
535  
536 sub parseMembers {
537 0 ▶ my $o = shift;
Subroutine parseMembers: not called CC=9 SCAR=45.0
538 0 ▶ my $record = shift; die 'wrong type '.ref($record).' for $record' if defined $record && ref $record ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $record and ref $record ne "CDS::Record" 0 0 0
Condition0%0/3
defined $record and ref $record ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $record and ref $record ne "CDS::Record"
defined $record ref $record ne "CDS::Record"
Truth table0%0/3
A and B
A= defined $recordB= ref $record ne "CDS::Record"
ABresult
0X0
100
111
539 0 my $linkedPublicKeys = shift;
540  
541 0 ▶ die 'linked public keys?' if ! defined $linkedPublicKeys;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $linkedPublicKeys 0 0 0
542 0 for my $storeRecord ($record->children) {
543 0 my $accountStoreUrl = $storeRecord->asText;
544  
545 0 for my $statusRecord ($storeRecord->children) {
546 0 my $status = $statusRecord->bytes;
547  
548 0 for my $child ($statusRecord->children) {
549 0 ▶ my $hash = $linkedPublicKeys ? $child->hash : CDS::Hash->fromBytes($child->bytes);
Branch: 1 branch
BranchTrueFalseTotal
$linkedPublicKeys ? : 0 0 0
550 0 ▶ $o->addMember($hash // next, $accountStoreUrl, $child->integerValue, $status);
Condition0%0/2
$hash // (next)
l!l
00
MC/DC0%0/1
$hash // (next)
$hash
Truth table0%0/2
A
A= $hash
Aresult
11
00
551 }
552 }
553 }
554 }
555  
556 sub mergeEntrustedActors {
557 0 ▶ my $o = shift;
Subroutine mergeEntrustedActors: not called CC=2 SCAR=17.9
558 0 my $revision = shift;
559  
560 0 ▶ return if $revision <= $o->{entrustedActorsRevision};
Branch: 1 branch
BranchTrueFalseTotal
if $revision <= $o->{"entrustedActorsRevision"} 0 0 0
561 0 $o->{entrustedActorsRevision} = $revision;
562 0 $o->{entrustedActors} = {};
563 0 return 1;
564 }
565  
566 sub addEntrustedActor {
567 0 ▶ my $o = shift;
Subroutine addEntrustedActor: not called CC=3 SCAR=24.8
568 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
569 0 my $storeUrl = shift;
570  
571 0 my $actor = CDS::ActorGroupBuilder::EntrustedActor->new($hash, $storeUrl);
572 0 $o->{entrustedActors}->{$hash->bytes} = $actor;
573 }
574  
575 sub removeEntrustedActor {
576 0 ▶ my $o = shift;
Subroutine removeEntrustedActor: not called CC=3 SCAR=24.8
577 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
578  
579 0 delete $o->{entrustedActors}->{$hash->bytes};
580 }
581  
582 sub parseEntrustedActors {
583 0 ▶ my $o = shift;
Subroutine parseEntrustedActors: not called CC=5 SCAR=34.0
584 0 ▶ my $record = shift; die 'wrong type '.ref($record).' for $record' if defined $record && ref $record ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $record and ref $record ne "CDS::Record" 0 0 0
Condition0%0/3
defined $record and ref $record ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $record and ref $record ne "CDS::Record"
defined $record ref $record ne "CDS::Record"
Truth table0%0/3
A and B
A= defined $recordB= ref $record ne "CDS::Record"
ABresult
0X0
100
111
585 0 my $linkedPublicKeys = shift;
586  
587 0 for my $revisionRecord ($record->children) {
588 0 ▶ next if ! $o->mergeEntrustedActors($revisionRecord->asInteger);
Branch: 1 branch
BranchTrueFalseTotal
unless $o->mergeEntrustedActors($revisionRecord->asInteger) 0 0 0
589 0 $o->parseEntrustedActorList($revisionRecord, $linkedPublicKeys);
590 }
591 }
592  
593 sub parseEntrustedActorList {
594 0 ▶ my $o = shift;
Subroutine parseEntrustedActorList: not called CC=8 SCAR=42.8
595 0 ▶ my $record = shift; die 'wrong type '.ref($record).' for $record' if defined $record && ref $record ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $record and ref $record ne "CDS::Record" 0 0 0
Condition0%0/3
defined $record and ref $record ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $record and ref $record ne "CDS::Record"
defined $record ref $record ne "CDS::Record"
Truth table0%0/3
A and B
A= defined $recordB= ref $record ne "CDS::Record"
ABresult
0X0
100
111
596 0 my $linkedPublicKeys = shift;
597  
598 0 ▶ die 'linked public keys?' if ! defined $linkedPublicKeys;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $linkedPublicKeys 0 0 0
599 0 for my $storeRecord ($record->children) {
600 0 my $storeUrl = $storeRecord->asText;
601  
602 0 for my $child ($storeRecord->children) {
603 0 ▶ my $hash = $linkedPublicKeys ? $child->hash : CDS::Hash->fromBytes($child->bytes);
Branch: 1 branch
BranchTrueFalseTotal
$linkedPublicKeys ? : 0 0 0
604 0 ▶ $o->addEntrustedActor($hash // next, $storeUrl);
Condition0%0/2
$hash // (next)
l!l
00
MC/DC0%0/1
$hash // (next)
$hash
Truth table0%0/2
A
A= $hash
Aresult
11
00
605 }
606 }
607 }
608  
609 sub parse {
610 0 ▶ my $o = shift;
Subroutine parse: not called CC=3 SCAR=24.8
611 0 ▶ my $record = shift; die 'wrong type '.ref($record).' for $record' if defined $record && ref $record ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $record and ref $record ne "CDS::Record" 0 0 0
Condition0%0/3
defined $record and ref $record ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $record and ref $record ne "CDS::Record"
defined $record ref $record ne "CDS::Record"
Truth table0%0/3
A and B
A= defined $recordB= ref $record ne "CDS::Record"
ABresult
0X0
100
111
612 0 my $linkedPublicKeys = shift;
613  
614 0 $o->parseMembers($record->child('actor group'), $linkedPublicKeys);
615 0 $o->parseEntrustedActors($record->child('entrusted actors'), $linkedPublicKeys);
616 }
617  
618 sub load {
619 0 ▶ my $o = shift;
Subroutine load: not called CC=3 SCAR=24.8
620 0 my $store = shift;
621 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
622 0 my $delegate = shift;
623  
624 0 return CDS::LoadActorGroup->load($o, $store, $keyPair, $delegate);
625 }
626  
627 sub discover {
628 0 ▶ my $o = shift;
Subroutine discover: not called CC=3 SCAR=24.8
629 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
630 0 my $delegate = shift;
631  
632 0 return CDS::DiscoverActorGroup->discover($o, $keyPair, $delegate);
633 }
634  
635 # Serializes the actor group to a record that can be passed to parse.
636 sub addToRecord {
637 0 ▶ my $o = shift;
Subroutine addToRecord: not called CC=13 SCAR=52.0
638 0 ▶ my $record = shift; die 'wrong type '.ref($record).' for $record' if defined $record && ref $record ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $record and ref $record ne "CDS::Record" 0 0 0
Condition0%0/3
defined $record and ref $record ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $record and ref $record ne "CDS::Record"
defined $record ref $record ne "CDS::Record"
Truth table0%0/3
A and B
A= defined $recordB= ref $record ne "CDS::Record"
ABresult
0X0
100
111
639 0 my $linkedPublicKeys = shift;
640  
641 0 ▶ die 'linked public keys?' if ! defined $linkedPublicKeys;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $linkedPublicKeys 0 0 0
642  
643 0 my $actorGroupRecord = $record->add('actor group');
644 0 my $currentStoreUrl = undef;
645 0 my $currentStoreRecord = undef;
646 0 my $currentStatus = undef;
647 0 my $currentStatusRecord = undef;
648 0 ▶ for my $member (sort { $a->storeUrl cmp $b->storeUrl || CDS->booleanCompare($b->status, $a->status) } $o->members) {
Branch: 1 branch
BranchTrueFalseTotal
$a->storeUrl cmp $b->storeUrl or "CDS"->booleanCompare($b->status, $a->status) 0 0 0
649 0 ▶ next if ! $member->revision;
Branch: 1 branch
BranchTrueFalseTotal
unless $member->revision 0 0 0
650  
651 0 ▶ if (! defined $currentStoreUrl || $currentStoreUrl ne $member->storeUrl) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $currentStoreUrl or $currentStoreUrl ne $member->storeUrl) 0 0 0
Condition0%0/3
not defined $currentStoreUrl or $currentStoreUrl ne $member->storeUrl
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $currentStoreUrl or $currentStoreUrl ne $member->storeUrl
not defined $currentStoreUrl $currentStoreUrl ne $member->storeUrl
Truth table0%0/3
not(A) or B
A= not defined $currentStoreUrlB= $currentStoreUrl ne $member->storeUrl
ABresult
1X1
011
000
652 0 $currentStoreUrl = $member->storeUrl;
653 0 $currentStoreRecord = $actorGroupRecord->addText($currentStoreUrl);
654 0 $currentStatus = undef;
655 0 $currentStatusRecord = undef;
656 }
657  
658 0 ▶ if (! defined $currentStatus || $currentStatus ne $member->status) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $currentStatus or $currentStatus ne $member->status) 0 0 0
Condition0%0/3
not defined $currentStatus or $currentStatus ne $member->status
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $currentStatus or $currentStatus ne $member->status
not defined $currentStatus $currentStatus ne $member->status
Truth table0%0/3
not(A) or B
A= not defined $currentStatusB= $currentStatus ne $member->status
ABresult
1X1
011
000
659 0 $currentStatus = $member->status;
660 0 $currentStatusRecord = $currentStoreRecord->add($currentStatus);
661 }
662  
663 0 ▶ my $hashRecord = $linkedPublicKeys ? $currentStatusRecord->addHash($member->hash) : $currentStatusRecord->add($member->hash->bytes);
Branch: 1 branch
BranchTrueFalseTotal
$linkedPublicKeys ? : 0 0 0
664 0 $hashRecord->addInteger($member->revision);
665 }
666  
667 0 ▶ if ($o->{entrustedActorsRevision}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"entrustedActorsRevision"}) 0 0 0
668 0 my $listRecord = $o->entrustedActorListToRecord($linkedPublicKeys);
669 0 $record->add('entrusted actors')->addInteger($o->{entrustedActorsRevision})->addRecord($listRecord->children);
670 }
671 }
672  
673 sub toRecord {
674 0 ▶ my $o = shift;
Subroutine toRecord: not called CC=1 SCAR=6.9
675 0 my $linkedPublicKeys = shift;
676  
677 0 my $record = CDS::Record->new;
678 0 $o->addToRecord($record, $linkedPublicKeys);
679 0 return $record;
680 }
681  
682 sub entrustedActorListToRecord {
683 0 ▶ my $o = shift;
Subroutine entrustedActorListToRecord: not called CC=5 SCAR=34.0
684 0 my $linkedPublicKeys = shift;
685  
686 0 my $record = CDS::Record->new;
687 0 my $currentStoreUrl = undef;
688 0 my $currentStoreRecord = undef;
689 0 for my $actor ($o->entrustedActors) {
690 0 ▶ if (! defined $currentStoreUrl || $currentStoreUrl ne $actor->storeUrl) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $currentStoreUrl or $currentStoreUrl ne $actor->storeUrl) 0 0 0
Condition0%0/3
not defined $currentStoreUrl or $currentStoreUrl ne $actor->storeUrl
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $currentStoreUrl or $currentStoreUrl ne $actor->storeUrl
not defined $currentStoreUrl $currentStoreUrl ne $actor->storeUrl
Truth table0%0/3
not(A) or B
A= not defined $currentStoreUrlB= $currentStoreUrl ne $actor->storeUrl
ABresult
1X1
011
000
691 0 $currentStoreUrl = $actor->storeUrl;
692 0 $currentStoreRecord = $record->addText($currentStoreUrl);
693 }
694  
695 0 ▶ $linkedPublicKeys ? $currentStoreRecord->addHash($actor->hash) : $currentStoreRecord->add($actor->hash->bytes);
Branch: 1 branch
BranchTrueFalseTotal
$linkedPublicKeys ? : 0 0 0
696 }
697  
698 0 return $record;
699 }
700  
701 package CDS::ActorGroupBuilder::EntrustedActor;
702  
703 sub new {
704 0 ▶ my $class = shift;
Subroutine new: not called CC=3 SCAR=24.8
705 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
706 0 my $storeUrl = shift;
707  
708 0 return bless {
709 hash => $hash,
710 storeUrl => $storeUrl,
711 };
712 }
713  
714 0 ▶sub hash { shift->{hash} }
Subroutine hash: not called CC=1 SCAR=6.9
715 0 ▶sub storeUrl { shift->{storeUrl} }
Subroutine storeUrl: not called CC=1 SCAR=6.9
716  
717 package CDS::ActorGroupBuilder::Member;
718  
719 sub new {
720 0 ▶ my $class = shift;
Subroutine new: not called CC=3 SCAR=24.8
721 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
722 0 my $storeUrl = shift;
723 0 my $revision = shift;
724 0 my $status = shift;
725  
726 0 return bless {
727 hash => $hash,
728 storeUrl => $storeUrl,
729 revision => $revision,
730 status => $status,
731 };
732 }
733  
734 0 ▶sub hash { shift->{hash} }
Subroutine hash: not called CC=1 SCAR=6.9
735 0 ▶sub storeUrl { shift->{storeUrl} }
Subroutine storeUrl: not called CC=1 SCAR=6.9
736 0 ▶sub revision { shift->{revision} }
Subroutine revision: not called CC=1 SCAR=6.9
737 0 ▶sub status { shift->{status} }
Subroutine status: not called CC=1 SCAR=6.9
738  
739 # The result of parsing an ACTORGROUP token (see Token.pm).
740 package CDS::ActorGroupToken;
741  
742 sub new {
743 0 ▶ my $class = shift;
Subroutine new: not called CC=3 SCAR=24.8
744 0 my $label = shift;
745 0 ▶ my $actorGroup = shift; die 'wrong type '.ref($actorGroup).' for $actorGroup' if defined $actorGroup && ref $actorGroup ne 'CDS::ActorGroup';
Branch: 1 branch
BranchTrueFalseTotal
if defined $actorGroup and ref $actorGroup ne "CDS::ActorGroup" 0 0 0
Condition0%0/3
defined $actorGroup and ref $actorGroup ne "CDS::ActorGroup"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $actorGroup and ref $actorGroup ne "CDS::ActorGroup"
defined $actorGroup ref $actorGroup ne "CDS::ActorGroup"
Truth table0%0/3
A and B
A= defined $actorGroupB= ref $actorGroup ne "CDS::ActorGroup"
ABresult
0X0
100
111
746  
747 0 return bless {
748 label => $label,
749 actorGroup => $actorGroup,
750 };
751 }
752  
753 0 ▶sub label { shift->{label} }
Subroutine label: not called CC=1 SCAR=6.9
754 0 ▶sub actorGroup { shift->{actorGroup} }
Subroutine actorGroup: not called CC=1 SCAR=6.9
755  
756 # A public key and a store.
757 package CDS::ActorOnStore;
758  
759 sub new {
760 0 ▶ my $class = shift;
Subroutine new: not called CC=3 SCAR=24.8
761 0 ▶ my $publicKey = shift; die 'wrong type '.ref($publicKey).' for $publicKey' if defined $publicKey && ref $publicKey ne 'CDS::PublicKey';
Branch: 1 branch
BranchTrueFalseTotal
if defined $publicKey and ref $publicKey ne "CDS::PublicKey" 0 0 0
Condition0%0/3
defined $publicKey and ref $publicKey ne "CDS::PublicKey"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $publicKey and ref $publicKey ne "CDS::PublicKey"
defined $publicKey ref $publicKey ne "CDS::PublicKey"
Truth table0%0/3
A and B
A= defined $publicKeyB= ref $publicKey ne "CDS::PublicKey"
ABresult
0X0
100
111
762 0 my $store = shift;
763  
764 0 return bless {
765 publicKey => $publicKey,
766 store => $store
767 };
768 }
769  
770 0 ▶sub publicKey { shift->{publicKey} }
Subroutine publicKey: not called CC=1 SCAR=6.9
771 0 ▶sub store { shift->{store} }
Subroutine store: not called CC=1 SCAR=6.9
772  
773 sub equals {
774 0 ▶ my $this = shift;
Subroutine equals: not called CC=6 SCAR=37.4
775 0 my $that = shift;
776  
777 0 ▶ return 1 if ! defined $this && ! defined $that;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $this or defined $that 0 0 0
Condition0%0/3
defined $this or defined $that
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $this or defined $that
defined $this defined $that
Truth table0%0/3
A or B
A= defined $thisB= defined $that
ABresult
1X1
011
000
778 0 ▶ return if ! defined $this || ! defined $that;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $this and defined $that 0 0 0
Condition0%0/3
defined $this and defined $that
!ll&&!rl&&r
000
MC/DC0%0/2
defined $this and defined $that
defined $this defined $that
Truth table0%0/3
A and B
A= defined $thisB= defined $that
ABresult
0X0
100
111
779 0 ▶ return $this->{store}->id eq $that->{store}->id && $this->{publicKey}->{hash}->equals($that->{publicKey}->{hash});
Condition0%0/3
$this->{'store'}->id eq $that->{'store'}->id && $this->{'publicKey'}{'hash'}->equals($that->{'publicKey'}{'hash'})
!ll&&!rl&&r
000
MC/DC0%0/2
$this->{'store'}->id eq $that->{'store'}->id && $this->{'publicKey'}{'hash'}->equals($that->{'publicKey'}{'hash'})
$this->{'store'}->id eq $that->{'store'}->id $this->{'publicKey'}{'hash'}->equals($that->{'publicKey'}{'hash'})
Truth table0%0/3
A && B
A= $this->{'store'}->id eq $that->{'store'}->idB= $this->{'publicKey'}{'hash'}->equals($that->{'publicKey'}{'hash'})
ABresult
0X0
100
111
780 }
781  
782 package CDS::ActorWithDocument;
783  
784 sub new {
785 0 ▶ my $class = shift;
Subroutine new: not called CC=4 SCAR=30.0
786 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
787 0 my $storageStore = shift;
788 0 my $messagingStore = shift;
789 0 my $messagingStoreUrl = shift;
790 0 my $publicKeyCache = shift;
791  
792 0 my $o = bless {
793 keyPair => $keyPair,
794 storageStore => $storageStore,
795 messagingStore => $messagingStore,
796 messagingStoreUrl => $messagingStoreUrl,
797 groupDataHandlers => [],
798 }, $class;
799  
800 # Private data on the storage store
801 0 $o->{storagePrivateRoot} = CDS::PrivateRoot->new($keyPair, $storageStore, $o);
802 0 $o->{groupDocument} = CDS::RootDocument->new($o->{storagePrivateRoot}, 'group data');
803 0 $o->{localDocument} = CDS::RootDocument->new($o->{storagePrivateRoot}, 'local data');
804  
805 # Private data on the messaging store
806 0 ▶ $o->{messagingPrivateRoot} = $storageStore->id eq $messagingStore->id ? $o->{storagePrivateRoot} : CDS::PrivateRoot->new($keyPair, $messagingStore, $o);
Branch: 1 branch
BranchTrueFalseTotal
$storageStore->id eq $messagingStore->id ? : 0 0 0
807 0 $o->{sentList} = CDS::SentList->new($o->{messagingPrivateRoot});
808 0 $o->{sentListReady} = 0;
809  
810 # Group data sharing
811 0 $o->{groupDataSharer} = CDS::GroupDataSharer->new($o);
812 0 $o->{groupDataSharer}->addDataHandler($o->{groupDocument}->label, $o->{groupDocument});
813  
814 # Selectors
815 0 $o->{groupRoot} = $o->{groupDocument}->root;
816 0 $o->{localRoot} = $o->{localDocument}->root;
817 0 $o->{publicDataSelector} = $o->{groupRoot}->child('public data');
818 0 $o->{actorGroupSelector} = $o->{groupRoot}->child('actor group');
819 0 $o->{actorSelector} = $o->{actorGroupSelector}->child(substr($keyPair->publicKey->hash->bytes, 0, 16));
820 0 $o->{entrustedActorsSelector} = $o->{groupRoot}->child('entrusted actors');
821  
822 # Message reader
823 0 my $pool = CDS::MessageBoxReaderPool->new($keyPair, $publicKeyCache, $o);
824 0 $o->{messageBoxReader} = CDS::MessageBoxReader->new($pool, CDS::ActorOnStore->new($keyPair->publicKey, $messagingStore), CDS->HOUR);
825  
826 # Active actor group members and entrusted keys
827 0 $o->{cachedGroupDataMembers} = {};
828 0 $o->{cachedEntrustedKeys} = {};
829 0 return $o;
830 }
831  
832 0 ▶sub keyPair { shift->{keyPair} }
Subroutine keyPair: not called CC=1 SCAR=6.9
833 0 ▶sub storageStore { shift->{storageStore} }
Subroutine storageStore: not called CC=1 SCAR=6.9
834 0 ▶sub messagingStore { shift->{messagingStore} }
Subroutine messagingStore: not called CC=1 SCAR=6.9
835 0 ▶sub messagingStoreUrl { shift->{messagingStoreUrl} }
Subroutine messagingStoreUrl: not called CC=1 SCAR=6.9
836  
837 0 ▶sub storagePrivateRoot { shift->{storagePrivateRoot} }
Subroutine storagePrivateRoot: not called CC=1 SCAR=6.9
838 0 ▶sub groupDocument { shift->{groupDocument} }
Subroutine groupDocument: not called CC=1 SCAR=6.9
839 0 ▶sub localDocument { shift->{localDocument} }
Subroutine localDocument: not called CC=1 SCAR=6.9
840  
841 0 ▶sub messagingPrivateRoot { shift->{messagingPrivateRoot} }
Subroutine messagingPrivateRoot: not called CC=1 SCAR=6.9
842 0 ▶sub sentList { shift->{sentList} }
Subroutine sentList: not called CC=1 SCAR=6.9
843 0 ▶sub sentListReady { shift->{sentListReady} }
Subroutine sentListReady: not called CC=1 SCAR=6.9
844  
845 0 ▶sub groupDataSharer { shift->{groupDataSharer} }
Subroutine groupDataSharer: not called CC=1 SCAR=6.9
846  
847 0 ▶sub groupRoot { shift->{groupRoot} }
Subroutine groupRoot: not called CC=1 SCAR=6.9
848 0 ▶sub localRoot { shift->{localRoot} }
Subroutine localRoot: not called CC=1 SCAR=6.9
849 0 ▶sub publicDataSelector { shift->{publicDataSelector} }
Subroutine publicDataSelector: not called CC=1 SCAR=6.9
850 0 ▶sub actorGroupSelector { shift->{actorGroupSelector} }
Subroutine actorGroupSelector: not called CC=1 SCAR=6.9
851 0 ▶sub actorSelector { shift->{actorSelector} }
Subroutine actorSelector: not called CC=1 SCAR=6.9
852 0 ▶sub entrustedActorsSelector { shift->{entrustedActorsSelector} }
Subroutine entrustedActorsSelector: not called CC=1 SCAR=6.9
853  
854 ### Our own actor ###
855  
856 sub isMe {
857 0 ▶ my $o = shift;
Subroutine isMe: not called CC=3 SCAR=24.8
858 0 ▶ my $actorHash = shift; die 'wrong type '.ref($actorHash).' for $actorHash' if defined $actorHash && ref $actorHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $actorHash and ref $actorHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $actorHash and ref $actorHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $actorHash and ref $actorHash ne "CDS::Hash"
defined $actorHash ref $actorHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $actorHashB= ref $actorHash ne "CDS::Hash"
ABresult
0X0
100
111
859  
860 0 return $o->{keyPair}->publicKey->hash->equals($actorHash);
861 }
862  
863 sub setName {
864 0 ▶ my $o = shift;
Subroutine setName: not called CC=1 SCAR=6.9
865 0 my $name = shift;
866  
867 0 $o->{actorSelector}->child('name')->set($name);
868 }
869  
870 sub getName {
871 0 ▶ my $o = shift;
Subroutine getName: not called CC=1 SCAR=6.9
872  
873 0 return $o->{actorSelector}->child('name')->textValue;
874 }
875  
876 sub updateMyRegistration {
877 0 ▶ my $o = shift;
Subroutine updateMyRegistration: not called CC=1 SCAR=6.9
878  
879 0 $o->{actorSelector}->addObject($o->{keyPair}->publicKey->hash, $o->{keyPair}->publicKey->object);
880 0 my $record = CDS::Record->new;
881 0 $record->add('hash')->addHash($o->{keyPair}->publicKey->hash);
882 0 $record->add('store')->addText($o->{messagingStoreUrl});
883 0 $o->{actorSelector}->set($record);
884 }
885  
886 sub setMyActiveFlag {
887 0 ▶ my $o = shift;
Subroutine setMyActiveFlag: not called CC=1 SCAR=6.9
888 0 my $flag = shift;
889  
890 0 $o->{actorSelector}->child('active')->setBoolean($flag);
891 }
892  
893 sub setMyGroupDataFlag {
894 0 ▶ my $o = shift;
Subroutine setMyGroupDataFlag: not called CC=1 SCAR=6.9
895 0 my $flag = shift;
896  
897 0 $o->{actorSelector}->child('group data')->setBoolean($flag);
898 }
899  
900 ### Actor group
901  
902 sub isGroupMember {
903 0 ▶ my $o = shift;
Subroutine isGroupMember: not called CC=5 SCAR=34.0
904 0 ▶ my $actorHash = shift; die 'wrong type '.ref($actorHash).' for $actorHash' if defined $actorHash && ref $actorHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $actorHash and ref $actorHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $actorHash and ref $actorHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $actorHash and ref $actorHash ne "CDS::Hash"
defined $actorHash ref $actorHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $actorHashB= ref $actorHash ne "CDS::Hash"
ABresult
0X0
100
111
905  
906 0 ▶ return 1 if $actorHash->equals($o->{keyPair}->publicKey->hash);
Branch: 1 branch
BranchTrueFalseTotal
if $actorHash->equals($o->{"keyPair"}->publicKey->hash) 0 0 0
907 0 ▶ my $memberSelector = $o->findMember($actorHash) // return;
Condition0%0/2
$o->findMember($actorHash) // (return)
l!l
00
MC/DC0%0/1
$o->findMember($actorHash) // (return)
$o->findMember($actorHash)
Truth table0%0/2
A
A= $o->findMember($actorHash)
Aresult
11
00
908 0 return ! $memberSelector->child('revoked')->isSet;
909 }
910  
911 sub findMember {
912 0 ▶ my $o = shift;
Subroutine findMember: not called CC=6 SCAR=37.4
913 0 ▶ my $memberHash = shift; die 'wrong type '.ref($memberHash).' for $memberHash' if defined $memberHash && ref $memberHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $memberHash and ref $memberHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $memberHash and ref $memberHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $memberHash and ref $memberHash ne "CDS::Hash"
defined $memberHash ref $memberHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $memberHashB= ref $memberHash ne "CDS::Hash"
ABresult
0X0
100
111
914  
915 0 for my $child ($o->{actorGroupSelector}->children) {
916 0 my $record = $child->record;
917 0 ▶ my $hash = $record->child('hash')->hashValue // next;
Condition0%0/2
$record->child("hash")->hashValue // (next)
l!l
00
MC/DC0%0/1
$record->child("hash")->hashValue // (next)
$record->child("hash")->hashValue
Truth table0%0/2
A
A= $record->child("hash")->hashValue
Aresult
11
00
918 0 ▶ next if ! $hash->equals($memberHash);
Branch: 1 branch
BranchTrueFalseTotal
unless $hash->equals($memberHash) 0 0 0
919 0 return $child;
920 }
921  
922 0 return;
923 }
924  
925 sub forgetOldIdleActors {
926 0 ▶ my $o = shift;
Subroutine forgetOldIdleActors: not called CC=5 SCAR=34.0
927 0 my $limit = shift;
928  
929 0 for my $child ($o->{actorGroupSelector}->children) {
930 0 ▶ next if $child->child('active')->booleanValue;
Branch: 1 branch
BranchTrueFalseTotal
if $child->child("active")->booleanValue 0 0 0
931 0 ▶ next if $child->child('group data')->booleanValue;
Branch: 1 branch
BranchTrueFalseTotal
if $child->child("group data")->booleanValue 0 0 0
932 0 ▶ next if $child->revision > $limit;
Branch: 1 branch
BranchTrueFalseTotal
if $child->revision > $limit 0 0 0
933 0 $child->forgetBranch;
934 }
935 }
936  
937 ### Group data members
938  
939 sub getGroupDataMembers {
940 0 ▶ my $o = shift;
Subroutine getGroupDataMembers: not called CC=14 SCAR=53.5
941  
942 # Update the cached list
943 0 for my $child ($o->{actorGroupSelector}->children) {
944 0 my $record = $child->record;
945 0 my $hash = $record->child('hash')->hashValue;
946 0 ▶ $hash = undef if $hash->equals($o->{keyPair}->publicKey->hash);
Branch: 1 branch
BranchTrueFalseTotal
if $hash->equals($o->{"keyPair"}->publicKey->hash) 0 0 0
947 0 ▶ $hash = undef if $child->child('revoked')->isSet;
Branch: 1 branch
BranchTrueFalseTotal
if $child->child("revoked")->isSet 0 0 0
948 0 ▶ $hash = undef if ! $child->child('group data')->isSet;
Branch: 1 branch
BranchTrueFalseTotal
unless $child->child("group data")->isSet 0 0 0
949  
950 # Remove
951 0 ▶ if (! $hash) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($hash) 0 0 0
952 0 delete $o->{cachedGroupDataMembers}->{$child->label};
953 0 next;
954 }
955  
956 # Keep
957 0 my $member = $o->{cachedGroupDataMembers}->{$child->label};
958 0 my $storeUrl = $record->child('store')->textValue;
959 0 ▶ next if $member && $member->storeUrl eq $storeUrl && $member->actorOnStore->publicKey->hash->equals($hash);
Branch: 1 branch
BranchTrueFalseTotal
if $member and $member->storeUrl eq $storeUrl and $member->actorOnStore->publicKey->hash->equals($hash) 0 0 0
Condition0%0/6
$member and $member->storeUrl eq $storeUrl and $member->actorOnStore->publicKey->hash->equals($hash)
!ll&&!rl&&r
000
$member and $member->storeUrl eq $storeUrl
!ll&&!rl&&r
000
MC/DC0%0/3
$member and $member->storeUrl eq $storeUrl and $member->actorOnStore->publicKey->hash->equals($hash)
$member $member->storeUrl eq $storeUrl $member->actorOnStore->publicKey->hash->equals($hash)
Truth table0%0/4
A and B and C
A= $memberB= $member->storeUrl eq $storeUrlC= $member->actorOnStore->publicKey->hash->equals($hash)
ABCresult
0XX0
10X0
1100
1111
960  
961 # Verify the store
962 0 my $store = $o->onVerifyMemberStore($storeUrl, $child);
963 0 ▶ if (! $store) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($store) 0 0 0
964 0 delete $o->{cachedGroupDataMembers}->{$child->label};
965 0 next;
966 }
967  
968 # Reuse the public key and add
969 0 ▶ if ($member && $member->actorOnStore->publicKey->hash->equals($hash)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($member and $member->actorOnStore->publicKey->hash->equals($hash)) 0 0 0
Condition0%0/3
$member and $member->actorOnStore->publicKey->hash->equals($hash)
!ll&&!rl&&r
000
MC/DC0%0/2
$member and $member->actorOnStore->publicKey->hash->equals($hash)
$member $member->actorOnStore->publicKey->hash->equals($hash)
Truth table0%0/3
A and B
A= $memberB= $member->actorOnStore->publicKey->hash->equals($hash)
ABresult
0X0
100
111
970 0 my $actorOnStore = CDS::ActorOnStore->new($member->actorOnStore->publicKey, $store);
971 0 $o->{cachedEntrustedKeys}->{$child->label} = {storeUrl => $storeUrl, actorOnStore => $actorOnStore};
972 }
973  
974 # Get the public key and add
975 0 my ($publicKey, $invalidReason, $storeError) = $o->{keyPair}->getPublicKey($hash, $o->{groupDocument}->unsaved);
976 0 ▶ return if defined $storeError;
Branch: 1 branch
BranchTrueFalseTotal
if defined $storeError 0 0 0
977 0 ▶ if (defined $invalidReason) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $invalidReason) 0 0 0
978 0 delete $o->{cachedGroupDataMembers}->{$child->label};
979 0 next;
980 }
981  
982 0 my $actorOnStore = CDS::ActorOnStore->new($publicKey, $store);
983 0 $o->{cachedGroupDataMembers}->{$child->label} = {storeUrl => $storeUrl, actorOnStore => $actorOnStore};
984 }
985  
986 # Return the current list
987 0 return [map { $_->{actorOnStore} } values %{$o->{cachedGroupDataMembers}}];
988 }
989  
990 ### Entrusted actors
991  
992 sub entrust {
993 0 ▶ my $o = shift;
Subroutine entrust: not called CC=3 SCAR=24.8
994 0 my $storeUrl = shift;
995 0 ▶ my $publicKey = shift; die 'wrong type '.ref($publicKey).' for $publicKey' if defined $publicKey && ref $publicKey ne 'CDS::PublicKey';
Branch: 1 branch
BranchTrueFalseTotal
if defined $publicKey and ref $publicKey ne "CDS::PublicKey" 0 0 0
Condition0%0/3
defined $publicKey and ref $publicKey ne "CDS::PublicKey"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $publicKey and ref $publicKey ne "CDS::PublicKey"
defined $publicKey ref $publicKey ne "CDS::PublicKey"
Truth table0%0/3
A and B
A= defined $publicKeyB= ref $publicKey ne "CDS::PublicKey"
ABresult
0X0
100
111
996  
997 # TODO: this is not compatible with the Java implementation (which uses a record with "hash" and "store")
998 0 my $selector = $o->{entrustedActorsSelector};
999 0 my $builder = CDS::ActorGroupBuilder->new;
1000 0 $builder->parseEntrustedActorList($selector->record, 1);
1001 0 $builder->removeEntrustedActor($publicKey->hash);
1002 0 $builder->addEntrustedActor($storeUrl, $publicKey->hash);
1003 0 $selector->addObject($publicKey->hash, $publicKey->object);
1004 0 $selector->set($builder->entrustedActorListToRecord(1));
1005 0 $o->{cachedEntrustedKeys}->{$publicKey->hash->bytes} = $publicKey;
1006 }
1007  
1008 sub doNotEntrust {
1009 0 ▶ my $o = shift;
Subroutine doNotEntrust: not called CC=3 SCAR=24.8
1010 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
1011  
1012 0 my $selector = $o->{entrustedActorsSelector};
1013 0 my $builder = CDS::ActorGroupBuilder->new;
1014 0 $builder->parseEntrustedActorList($selector->record, 1);
1015 0 $builder->removeEntrustedActor($hash);
1016 0 $selector->set($builder->entrustedActorListToRecord(1));
1017 0 delete $o->{cachedEntrustedKeys}->{$hash->bytes};
1018 }
1019  
1020 sub getEntrustedKeys {
1021 0 ▶ my $o = shift;
Subroutine getEntrustedKeys: not called CC=5 SCAR=34.0
1022  
1023 0 my $entrustedKeys = [];
1024 0 for my $storeRecord ($o->{entrustedActorsSelector}->record->children) {
1025 0 for my $child ($storeRecord->children) {
1026 0 ▶ my $hash = $child->hash // next;
Condition0%0/2
$child->hash // (next)
l!l
00
MC/DC0%0/1
$child->hash // (next)
$child->hash
Truth table0%0/2
A
A= $child->hash
Aresult
11
00
1027 0 ▶ push @$entrustedKeys, $o->getEntrustedKey($hash) // next;
Condition0%0/2
$o->getEntrustedKey($hash) // (next)
l!l
00
MC/DC0%0/1
$o->getEntrustedKey($hash) // (next)
$o->getEntrustedKey($hash)
Truth table0%0/2
A
A= $o->getEntrustedKey($hash)
Aresult
11
00
1028 }
1029 }
1030  
1031 # We could remove unused keys from $o->{cachedEntrustedKeys} here, but since this is
1032 # such a rare event, and doesn't consume a lot of memory, this would be overkill.
1033  
1034 0 return $entrustedKeys;
1035 }
1036  
1037 sub getEntrustedKey {
1038 0 ▶ my $o = shift;
Subroutine getEntrustedKey: not called CC=6 SCAR=37.4
1039 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
1040  
1041 0 my $entrustedKey = $o->{cachedEntrustedKeys}->{$hash->bytes};
1042 0 ▶ return $entrustedKey if $entrustedKey;
Branch: 1 branch
BranchTrueFalseTotal
if $entrustedKey 0 0 0
1043  
1044 0 my ($publicKey, $invalidReason, $storeError) = $o->{keyPair}->getPublicKey($hash, $o->{groupDocument}->unsaved);
1045 0 ▶ return if defined $storeError;
Branch: 1 branch
BranchTrueFalseTotal
if defined $storeError 0 0 0
1046 0 ▶ return if defined $invalidReason;
Branch: 1 branch
BranchTrueFalseTotal
if defined $invalidReason 0 0 0
1047 0 $o->{cachedEntrustedKeys}->{$hash->bytes} = $publicKey;
1048 0 return $publicKey;
1049 }
1050  
1051 ### Private data
1052  
1053 sub procurePrivateData {
1054 0 ▶ my $o = shift;
Subroutine procurePrivateData: not called CC=5 SCAR=34.0
1055 0 ▶ my $interval = shift // CDS->DAY;
Condition0%0/3
shift() // "CDS"->DAY
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() // "CDS"->DAY
shift() "CDS"->DAY
Truth table0%0/3
A // B
A= shift()B= "CDS"->DAY
ABresult
1X1
011
000
1056  
1057 0 ▶ $o->{storagePrivateRoot}->procure($interval) // return;
Condition0%0/2
$o->{"storagePrivateRoot"}->procure($interval) // (return)
l!l
00
MC/DC0%0/1
$o->{"storagePrivateRoot"}->procure($interval) // (return)
$o->{"storagePrivateRoot"}->procure($interval)
Truth table0%0/2
A
A= $o->{"storagePrivateRoot"}->procure($interval)
Aresult
11
00
1058 0 ▶ $o->{groupDocument}->read // return;
Condition0%0/2
$o->{"groupDocument"}->read // (return)
l!l
00
MC/DC0%0/1
$o->{"groupDocument"}->read // (return)
$o->{"groupDocument"}->read
Truth table0%0/2
A
A= $o->{"groupDocument"}->read
Aresult
11
00
1059 0 ▶ $o->{localDocument}->read // return;
Condition0%0/2
$o->{"localDocument"}->read // (return)
l!l
00
MC/DC0%0/1
$o->{"localDocument"}->read // (return)
$o->{"localDocument"}->read
Truth table0%0/2
A
A= $o->{"localDocument"}->read
Aresult
11
00
1060 0 return 1;
1061 }
1062  
1063 sub savePrivateDataAndShareGroupData {
1064 0 ▶ my $o = shift;
Subroutine savePrivateDataAndShareGroupData: not called CC=4 SCAR=30.0
1065  
1066 0 $o->{localDocument}->save;
1067 0 $o->{groupDocument}->save;
1068 0 $o->groupDataSharer->share;
1069 0 ▶ my $entrustedKeys = $o->getEntrustedKeys // return;
Condition0%0/2
$o->getEntrustedKeys // (return)
l!l
00
MC/DC0%0/1
$o->getEntrustedKeys // (return)
$o->getEntrustedKeys
Truth table0%0/2
A
A= $o->getEntrustedKeys
Aresult
11
00
1070 0 my ($ok, $missingHash) = $o->{storagePrivateRoot}->save($entrustedKeys);
1071 0 ▶ return 1 if $ok;
Branch: 1 branch
BranchTrueFalseTotal
if $ok 0 0 0
1072 0 ▶ $o->onMissingObject($missingHash) if $missingHash;
Branch: 1 branch
BranchTrueFalseTotal
if $missingHash 0 0 0
1073 0 return;
1074 }
1075  
1076 # abstract sub onVerifyMemberStore($storeUrl, $selector)
1077 # abstract sub onPrivateRootReadingInvalidEntry($o, $source, $reason)
1078 # abstract sub onMissingObject($missingHash)
1079  
1080 ### Sending messages
1081  
1082 sub procureSentList {
1083 0 ▶ my $o = shift;
Subroutine procureSentList: not called CC=4 SCAR=30.0
1084 0 ▶ my $interval = shift // CDS->DAY;
Condition0%0/3
shift() // "CDS"->DAY
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() // "CDS"->DAY
shift() "CDS"->DAY
Truth table0%0/3
A // B
A= shift()B= "CDS"->DAY
ABresult
1X1
011
000
1085  
1086 0 ▶ $o->{messagingPrivateRoot}->procure($interval) // return;
Condition0%0/2
$o->{"messagingPrivateRoot"}->procure($interval) // (return)
l!l
00
MC/DC0%0/1
$o->{"messagingPrivateRoot"}->procure($interval) // (return)
$o->{"messagingPrivateRoot"}->procure($interval)
Truth table0%0/2
A
A= $o->{"messagingPrivateRoot"}->procure($interval)
Aresult
11
00
1087 0 ▶ $o->{sentList}->read // return;
Condition0%0/2
$o->{"sentList"}->read // (return)
l!l
00
MC/DC0%0/1
$o->{"sentList"}->read // (return)
$o->{"sentList"}->read
Truth table0%0/2
A
A= $o->{"sentList"}->read
Aresult
11
00
1088 0 $o->{sentListReady} = 1;
1089 0 return 1;
1090 }
1091  
1092 sub openMessageChannel {
1093 0 ▶ my $o = shift;
Subroutine openMessageChannel: not called CC=1 SCAR=6.9
1094 0 my $label = shift;
1095 0 my $validity = shift;
1096  
1097 0 return CDS::MessageChannel->new($o, $label, $validity);
1098 }
1099  
1100 sub sendMessages {
1101 0 ▶ my $o = shift;
Subroutine sendMessages: not called CC=5 SCAR=34.0
1102  
1103 0 ▶ return 1 if ! $o->{sentList}->hasChanges;
Branch: 1 branch
BranchTrueFalseTotal
unless $o->{"sentList"}->hasChanges 0 0 0
1104 0 $o->{sentList}->save;
1105 0 ▶ my $entrustedKeys = $o->getEntrustedKeys // return;
Condition0%0/2
$o->getEntrustedKeys // (return)
l!l
00
MC/DC0%0/1
$o->getEntrustedKeys // (return)
$o->getEntrustedKeys
Truth table0%0/2
A
A= $o->getEntrustedKeys
Aresult
11
00
1106 0 my ($ok, $missingHash) = $o->{messagingPrivateRoot}->save($entrustedKeys);
1107 0 ▶ return 1 if $ok;
Branch: 1 branch
BranchTrueFalseTotal
if $ok 0 0 0
1108 0 ▶ $o->onMissingObject($missingHash) if $missingHash;
Branch: 1 branch
BranchTrueFalseTotal
if $missingHash 0 0 0
1109 0 return;
1110 }
1111  
1112 ### Receiving messages
1113  
1114 # abstract sub onMessageBoxVerifyStore($o, $senderStoreUrl, $hash, $envelope, $senderHash)
1115 # abstract sub onMessage($o, $message)
1116 # abstract sub onInvalidMessage($o, $source, $reason)
1117 # abstract sub onMessageBoxEntry($o, $message)
1118 # abstract sub onMessageBoxInvalidEntry($o, $source, $reason)
1119  
1120 ### Announcing ###
1121  
1122 sub announceOnAllStores {
1123 0 ▶ my $o = shift;
Subroutine announceOnAllStores: not called CC=2 SCAR=17.9
1124  
1125 0 $o->announce($o->{storageStore});
1126 0 ▶ $o->announce($o->{messagingStore}) if $o->{messagingStore}->id ne $o->{storageStore}->id;
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"messagingStore"}->id ne $o->{"storageStore"}->id 0 0 0
1127 }
1128  
1129 sub announce {
1130 0 ▶ my $o = shift;
Subroutine announce: not called CC=14 SCAR=53.5
1131 0 my $store = shift;
1132  
1133 0 ▶ die 'probably calling old announce, which should now be announceOnAllStores' if ! defined $store;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $store 0 0 0
1134  
1135 # Prepare the actor group
1136 0 my $builder = CDS::ActorGroupBuilder->new;
1137  
1138 0 my $me = $o->keyPair->publicKey->hash;
1139 0 $builder->addMember($me, $o->messagingStoreUrl, CDS->now, 'active');
1140 0 for my $child ($o->actorGroupSelector->children) {
1141 0 my $record = $child->record;
1142 0 ▶ my $hash = $record->child('hash')->hashValue // next;
Condition0%0/2
$record->child("hash")->hashValue // (next)
l!l
00
MC/DC0%0/1
$record->child("hash")->hashValue // (next)
$record->child("hash")->hashValue
Truth table0%0/2
A
A= $record->child("hash")->hashValue
Aresult
11
00
1143 0 ▶ next if $hash->equals($me);
Branch: 1 branch
BranchTrueFalseTotal
if $hash->equals($me) 0 0 0
1144 0 my $storeUrl = $record->child('store')->textValue;
1145 0 my $revokedSelector = $child->child('revoked');
1146 0 my $activeSelector = $child->child('active');
1147 0 my $revision = CDS->max($child->revision, $revokedSelector->revision, $activeSelector->revision);
1148 0 ▶ my $actorStatus = $revokedSelector->booleanValue ? 'revoked' : $activeSelector->booleanValue ? 'active' : 'idle';
Branch: 2 branches
BranchTrueFalseTotal
$revokedSelector->booleanValue ? : 0 0 0
$activeSelector->booleanValue ? : 0 0 0
1149 0 $builder->addMember($hash, $storeUrl, $revision, $actorStatus);
1150 }
1151  
1152 0 ▶ $builder->parseEntrustedActorList($o->entrustedActorsSelector->record, 1) if $builder->mergeEntrustedActors($o->entrustedActorsSelector->revision);
Branch: 1 branch
BranchTrueFalseTotal
if $builder->mergeEntrustedActors($o->entrustedActorsSelector->revision) 0 0 0
1153  
1154 # Create the card
1155 0 my $card = $builder->toRecord(0);
1156 0 $card->add('public key')->addHash($o->{keyPair}->publicKey->hash);
1157  
1158 # Add the public data
1159 0 for my $child ($o->publicDataSelector->children) {
1160 0 my $childRecord = $child->record;
1161 0 $card->addRecord($childRecord->children);
1162 }
1163  
1164 # Create an unsaved state
1165 0 my $unsaved = CDS::Unsaved->new($o->publicDataSelector->document->unsaved);
1166  
1167 # Add the public card and the public key
1168 0 my $cardObject = $card->toObject;
1169 0 my $cardHash = $cardObject->calculateHash;
1170 0 $unsaved->state->addObject($cardHash, $cardObject);
1171 0 $unsaved->state->addObject($me, $o->keyPair->publicKey->object);
1172  
1173 # Prepare the public envelope
1174 0 my $envelopeObject = $o->keyPair->createPublicEnvelope($cardHash)->toObject;
1175 0 my $envelopeHash = $envelopeObject->calculateHash;
1176  
1177 # Upload the objects
1178 0 my ($missingObject, $transferStore, $transferError) = $o->keyPair->transfer([$cardHash], $unsaved, $store);
1179 0 ▶ return if defined $transferError;
Branch: 1 branch
BranchTrueFalseTotal
if defined $transferError 0 0 0
1180 0 ▶ if ($missingObject) {
Branch: 1 branch
BranchTrueFalseTotal
if ($missingObject) 0 0 0
1181 0 $missingObject->{context} = 'announce on '.$store->id;
1182 0 $o->onMissingObject($missingObject);
1183 0 return;
1184 }
1185  
1186 # Prepare to modify
1187 0 my $modifications = CDS::StoreModifications->new;
1188 0 $modifications->add($me, 'public', $envelopeHash, $envelopeObject);
1189  
1190 # List the current cards to remove them
1191 # Ignore errors, in the worst case, we are going to have multiple entries in the public box
1192 0 my ($hashes, $error) = $store->list($me, 'public', 0, $o->keyPair);
1193 0 ▶ if ($hashes) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hashes) 0 0 0
1194 0 for my $hash (@$hashes) {
1195 0 $modifications->remove($me, 'public', $hash);
1196 }
1197 }
1198  
1199 # Modify the public box
1200 0 my $modifyError = $store->modify($modifications, $o->keyPair);
1201 0 ▶ return if defined $modifyError;
Branch: 1 branch
BranchTrueFalseTotal
if defined $modifyError 0 0 0
1202 0 return $envelopeHash, $cardHash;
1203 }
1204  
1205 # The result of parsing a BOX token (see Token.pm).
1206 package CDS::BoxToken;
1207  
1208 sub new {
1209 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
1210 0 my $accountToken = shift;
1211 0 my $boxLabel = shift;
1212  
1213 0 return bless {
1214 accountToken => $accountToken,
1215 boxLabel => $boxLabel
1216 };
1217 }
1218  
1219 0 ▶sub accountToken { shift->{accountToken} }
Subroutine accountToken: not called CC=1 SCAR=6.9
1220 0 ▶sub boxLabel { shift->{boxLabel} }
Subroutine boxLabel: not called CC=1 SCAR=6.9
1221 sub url {
1222 0 ▶ my $o = shift;
Subroutine url: not called CC=1 SCAR=6.9
1223 0 $o->{accountToken}->url.'/'.$o->{boxLabel} }
1224  
1225 package CDS::CLIActor;
1226  
1227 1 ▶use parent -norequire, 'CDS::ActorWithDocument';
Subroutine BEGIN: called CC=1 SCAR=0.0
1228  
1229 sub openOrCreateDefault {
1230 0 ▶ my $class = shift;
Subroutine openOrCreateDefault: not called CC=1 SCAR=6.9
1231 0 my $ui = shift;
1232  
1233 0 $class->open(CDS::Configuration->getOrCreateDefault($ui));
1234 }
1235  
1236 sub open {
1237 0 ▶ my $class = shift;
Subroutine open: not called CC=5 SCAR=34.0
1238 0 my $configuration = shift;
1239  
1240 # Read the store configuration
1241 0 my $ui = $configuration->ui;
1242 0 my $storeManager = CDS::CLIStoreManager->new($ui);
1243  
1244 0 my $storageStoreUrl = $configuration->storageStoreUrl;
1245 0 ▶ my $storageStore = $storeManager->storeForUrl($storageStoreUrl) // return $ui->error('Your storage store "', $storageStoreUrl, '" cannot be accessed. You can set this store in "', $configuration->file('store'), '".');
Condition0%0/2
$storeManager->storeForUrl($storageStoreUrl) // (return $ui->error("Your storage store \"", $storageStoreUrl, "\" cannot be accessed. You can set this store in \"", $configuration->file("store"), "\"."))
l!l
00
MC/DC0%0/1
$storeManager->storeForUrl($storageStoreUrl) // (return $ui->error("Your storage store \"", $storageStoreUrl, "\" cannot be accessed. You can set this store in \"", $configuration->file("store"), "\"."))
$storeManager->storeForUrl($storageStoreUrl)
Truth table0%0/2
A
A= $storeManager->storeForUrl($storageStoreUrl)
Aresult
11
00
1246  
1247 0 my $messagingStoreUrl = $configuration->messagingStoreUrl;
1248 0 ▶ my $messagingStore = $storeManager->storeForUrl($messagingStoreUrl) // return $ui->error('Your messaging store "', $messagingStoreUrl, '" cannot be accessed. You can set this store in "', $configuration->file('messaging-store'), '".');
Condition0%0/2
$storeManager->storeForUrl($messagingStoreUrl) // (return $ui->error("Your messaging store \"", $messagingStoreUrl, "\" cannot be accessed. You can set this store in \"", $configuration->file("messaging-store"), "\"."))
l!l
00
MC/DC0%0/1
$storeManager->storeForUrl($messagingStoreUrl) // (return $ui->error("Your messaging store \"", $messagingStoreUrl, "\" cannot be accessed. You can set this store in \"", $configuration->file("messaging-store"), "\"."))
$storeManager->storeForUrl($messagingStoreUrl)
Truth table0%0/2
A
A= $storeManager->storeForUrl($messagingStoreUrl)
Aresult
11
00
1249  
1250 # Read the key pair
1251 0 ▶ my $keyPair = $configuration->keyPair // return $ui->error('Your key pair (', $configuration->file('key-pair'), ') is missing.');
Condition0%0/2
$configuration->keyPair // (return $ui->error("Your key pair (", $configuration->file("key-pair"), ") is missing."))
l!l
00
MC/DC0%0/1
$configuration->keyPair // (return $ui->error("Your key pair (", $configuration->file("key-pair"), ") is missing."))
$configuration->keyPair
Truth table0%0/2
A
A= $configuration->keyPair
Aresult
11
00
1252  
1253 # Create the actor
1254 0 my $publicKeyCache = CDS::PublicKeyCache->new(128);
1255 0 my $o = $class->SUPER::new($keyPair, $storageStore, $messagingStore, $messagingStoreUrl, $publicKeyCache);
1256 0 $o->{ui} = $ui;
1257 0 $o->{storeManager} = $storeManager;
1258 0 $o->{configuration} = $configuration;
1259 0 $o->{sessionRoot} = $o->localRoot->child('sessions')->child(''.getppid);
1260 0 $o->{keyPairToken} = CDS::KeyPairToken->new($configuration->file('key-pair'), $keyPair);
1261  
1262 # Message handlers
1263 0 $o->{messageHandlers} = {};
1264 0 $o->setMessageHandler('sender', \&onIgnoreMessage);
1265 0 $o->setMessageHandler('store', \&onIgnoreMessage);
1266 0 $o->setMessageHandler('group data', \&onGroupDataMessage);
1267  
1268 # Read the private data
1269 0 ▶ if (! $o->procurePrivateData) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($o->procurePrivateData) 0 0 0
1270 0 $o->{ui}->space;
1271 0 $ui->pRed('Failed to read the local private data.');
1272 0 $o->{ui}->space;
1273 0 return;
1274 }
1275  
1276 0 return $o;
1277 }
1278  
1279 0 ▶sub ui { shift->{ui} }
Subroutine ui: not called CC=1 SCAR=6.9
1280 0 ▶sub storeManager { shift->{storeManager} }
Subroutine storeManager: not called CC=1 SCAR=6.9
1281 0 ▶sub configuration { shift->{configuration} }
Subroutine configuration: not called CC=1 SCAR=6.9
1282 0 ▶sub sessionRoot { shift->{sessionRoot} }
Subroutine sessionRoot: not called CC=1 SCAR=6.9
1283 0 ▶sub keyPairToken { shift->{keyPairToken} }
Subroutine keyPairToken: not called CC=1 SCAR=6.9
1284  
1285 ### Saving
1286  
1287 sub saveOrShowError {
1288 0 ▶ my $o = shift;
Subroutine saveOrShowError: not called CC=3 SCAR=24.8
1289  
1290 0 $o->forgetOldSessions;
1291 0 my ($ok, $missingHash) = $o->savePrivateDataAndShareGroupData;
1292 0 ▶ return if ! $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 0 0
1293 0 ▶ return $o->onMissingObject($missingHash) if $missingHash;
Branch: 1 branch
BranchTrueFalseTotal
if $missingHash 0 0 0
1294 0 $o->sendMessages;
1295 0 return 1;
1296 }
1297  
1298 sub onMissingObject {
1299 0 ▶ my $o = shift;
Subroutine onMissingObject: not called CC=3 SCAR=24.8
1300 0 ▶ my $missingObject = shift; die 'wrong type '.ref($missingObject).' for $missingObject' if defined $missingObject && ref $missingObject ne 'CDS::Object';
Branch: 1 branch
BranchTrueFalseTotal
if defined $missingObject and ref $missingObject ne "CDS::Object" 0 0 0
Condition0%0/3
defined $missingObject and ref $missingObject ne "CDS::Object"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $missingObject and ref $missingObject ne "CDS::Object"
defined $missingObject ref $missingObject ne "CDS::Object"
Truth table0%0/3
A and B
A= defined $missingObjectB= ref $missingObject ne "CDS::Object"
ABresult
0X0
100
111
1301  
1302 0 $o->{ui}->space;
1303 0 $o->{ui}->pRed('The object ', $missingObject->hash->hex, ' was missing while saving data.');
1304 0 $o->{ui}->space;
1305 0 $o->{ui}->p('This is a fatal error with two possible sources:');
1306 0 $o->{ui}->p('- A store may have lost objects, e.g. due to an error with the underlying storage, misconfiguration, or too aggressive garbage collection.');
1307 0 $o->{ui}->p('- The application is linking objects without properly storing them. This is an error in the application, that must be fixed by a developer.');
1308 0 $o->{ui}->space;
1309 }
1310  
1311 sub onGroupDataSharingStoreError {
1312 0 ▶ my $o = shift;
Subroutine onGroupDataSharingStoreError: not called CC=3 SCAR=24.8
1313 0 ▶ my $recipientActorOnStore = shift; die 'wrong type '.ref($recipientActorOnStore).' for $recipientActorOnStore' if defined $recipientActorOnStore && ref $recipientActorOnStore ne 'CDS::ActorOnStore';
Branch: 1 branch
BranchTrueFalseTotal
if defined $recipientActorOnStore and ref $recipientActorOnStore ne "CDS::ActorOnStore" 0 0 0
Condition0%0/3
defined $recipientActorOnStore and ref $recipientActorOnStore ne "CDS::ActorOnStore"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $recipientActorOnStore and ref $recipientActorOnStore ne "CDS::ActorOnStore"
defined $recipientActorOnStore ref $recipientActorOnStore ne "CDS::ActorOnStore"
Truth table0%0/3
A and B
A= defined $recipientActorOnStoreB= ref $recipientActorOnStore ne "CDS::ActorOnStore"
ABresult
0X0
100
111
1314 0 my $storeError = shift;
1315  
1316 0 $o->{ui}->space;
1317 0 $o->{ui}->pRed('Unable to share the group data with ', $recipientActorOnStore->publicKey->hash->hex, '.');
1318 0 $o->{ui}->space;
1319 }
1320  
1321 ### Reading
1322  
1323 sub onPrivateRootReadingInvalidEntry {
1324 0 ▶ my $o = shift;
Subroutine onPrivateRootReadingInvalidEntry: not called CC=3 SCAR=24.8
1325 0 ▶ my $source = shift; die 'wrong type '.ref($source).' for $source' if defined $source && ref $source ne 'CDS::Source';
Branch: 1 branch
BranchTrueFalseTotal
if defined $source and ref $source ne "CDS::Source" 0 0 0
Condition0%0/3
defined $source and ref $source ne "CDS::Source"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $source and ref $source ne "CDS::Source"
defined $source ref $source ne "CDS::Source"
Truth table0%0/3
A and B
A= defined $sourceB= ref $source ne "CDS::Source"
ABresult
0X0
100
111
1326 0 my $reason = shift;
1327  
1328 0 $o->{ui}->space;
1329 0 $o->{ui}->pRed('The envelope ', $source->hash->shortHex, ' points to invalid private data (', $reason, ').');
1330 0 $o->{ui}->p('This could be due to a storage system failure, a malicious attempt to delete or modify your data, or simply an application error. To investigate what is going on, the following commands may be helpful:');
1331 0 $o->{ui}->line(' cds open envelope ', $source->hash->hex, ' from ', $source->actorOnStore->publicKey->hash->hex, ' on ', $source->actorOnStore->store->url);
1332 0 $o->{ui}->line(' cds show record ', $source->hash->hex, ' on ', $source->actorOnStore->store->url);
1333 0 $o->{ui}->line(' cds list private box of ', $source->actorOnStore->publicKey->hash->hex, ' on ', $source->actorOnStore->store->url);
1334 0 $o->{ui}->p('To remove the invalid entry, type:');
1335 0 $o->{ui}->line(' cds remove ', $source->hash->hex, ' from private box of ', $source->actorOnStore->publicKey->hash->hex, ' on ', $source->actorOnStore->store->url);
1336 0 $o->{ui}->space;
1337 }
1338  
1339 sub onVerifyMemberStore {
1340 0 ▶ my $o = shift;
Subroutine onVerifyMemberStore: not called CC=3 SCAR=24.8
1341 0 my $storeUrl = shift;
1342 0 ▶ my $actorSelector = shift; die 'wrong type '.ref($actorSelector).' for $actorSelector' if defined $actorSelector && ref $actorSelector ne 'CDS::Selector';
Branch: 1 branch
BranchTrueFalseTotal
if defined $actorSelector and ref $actorSelector ne "CDS::Selector" 0 0 0
Condition0%0/3
defined $actorSelector and ref $actorSelector ne "CDS::Selector"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $actorSelector and ref $actorSelector ne "CDS::Selector"
defined $actorSelector ref $actorSelector ne "CDS::Selector"
Truth table0%0/3
A and B
A= defined $actorSelectorB= ref $actorSelector ne "CDS::Selector"
ABresult
0X0
100
111
1343 0 $o->storeForUrl($storeUrl) }
1344  
1345 ### Announcing
1346  
1347 sub registerIfNecessary {
1348 0 ▶ my $o = shift;
Subroutine registerIfNecessary: not called CC=2 SCAR=17.9
1349  
1350 0 my $now = CDS->now;
1351 0 ▶ return if $o->{actorSelector}->revision > $now - CDS->DAY;
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"actorSelector"}->revision > $now - "CDS"->DAY 0 0 0
1352 0 $o->updateMyRegistration;
1353 0 $o->setMyActiveFlag(1);
1354 0 $o->setMyGroupDataFlag(1);
1355 }
1356  
1357 sub announceIfNecessary {
1358 0 ▶ my $o = shift;
Subroutine announceIfNecessary: not called CC=2 SCAR=17.9
1359  
1360 0 my $state = join('', map { CDS->bytesFromUnsigned($_->revision) } sort { $a->label cmp $b->label } $o->{actorGroupSelector}->children);
1361 0 $o->announceOnStoreIfNecessary($o->{storageStore}, $state);
1362 0 ▶ $o->announceOnStoreIfNecessary($o->{messagingStore}, $state) if $o->{messagingStore}->id ne $o->{storageStore}->id;
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"messagingStore"}->id ne $o->{"storageStore"}->id 0 0 0
1363 }
1364  
1365 sub announceOnStoreIfNecessary {
1366 0 ▶ my $o = shift;
Subroutine announceOnStoreIfNecessary: not called CC=3 SCAR=24.8
1367 0 my $store = shift;
1368 0 my $state = shift;
1369  
1370 0 my $stateSelector = $o->{localRoot}->child('announced')->childWithText($store->id);
1371 0 ▶ return if $stateSelector->bytesValue eq $state;
Branch: 1 branch
BranchTrueFalseTotal
if $stateSelector->bytesValue eq $state 0 0 0
1372 0 my ($envelopeHash, $cardHash) = $o->announce($store);
1373 0 ▶ return $o->{ui}->pRed('Updating the card on ', $store->url, ' failed.') if ! $envelopeHash;
Branch: 1 branch
BranchTrueFalseTotal
unless $envelopeHash 0 0 0
1374 0 $stateSelector->setBytes($state);
1375 0 $o->{ui}->pGreen('The card on ', $store->url, ' has been updated.');
1376 0 return 1;
1377 }
1378  
1379 ### Store resolving
1380  
1381 sub storeForUrl {
1382 0 ▶ my $o = shift;
Subroutine storeForUrl: not called CC=1 SCAR=6.9
1383 0 my $url = shift;
1384  
1385 0 $o->{storeManager}->setCacheStoreUrl($o->{sessionRoot}->child('use cache')->textValue);
1386 0 return $o->{storeManager}->storeForUrl($url);
1387 }
1388  
1389 ### Processing messages
1390  
1391 sub setMessageHandler {
1392 0 ▶ my $o = shift;
Subroutine setMessageHandler: not called CC=1 SCAR=6.9
1393 0 my $type = shift;
1394 0 my $handler = shift;
1395  
1396 0 $o->{messageHandlers}->{$type} = $handler;
1397 }
1398  
1399 sub readMessages {
1400 0 ▶ my $o = shift;
Subroutine readMessages: not called CC=2 SCAR=17.9
1401  
1402 0 $o->{ui}->title('Messages');
1403 0 $o->{countMessages} = 0;
1404 0 $o->{messageBoxReader}->read;
1405 0 ▶ $o->{ui}->line($o->{ui}->gray('none')) if ! $o->{countMessages};
Branch: 1 branch
BranchTrueFalseTotal
if not $o->{"countMessages"} 0 0 0
1406 }
1407  
1408 sub onMessageBoxVerifyStore {
1409 0 ▶ my $o = shift;
Subroutine onMessageBoxVerifyStore: not called CC=7 SCAR=40.3
1410 0 my $senderStoreUrl = shift;
1411 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
1412 0 ▶ my $envelope = shift; die 'wrong type '.ref($envelope).' for $envelope' if defined $envelope && ref $envelope ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $envelope and ref $envelope ne "CDS::Record" 0 0 0
Condition0%0/3
defined $envelope and ref $envelope ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $envelope and ref $envelope ne "CDS::Record"
defined $envelope ref $envelope ne "CDS::Record"
Truth table0%0/3
A and B
A= defined $envelopeB= ref $envelope ne "CDS::Record"
ABresult
0X0
100
111
1413 0 ▶ my $senderHash = shift; die 'wrong type '.ref($senderHash).' for $senderHash' if defined $senderHash && ref $senderHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $senderHash and ref $senderHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $senderHash and ref $senderHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $senderHash and ref $senderHash ne "CDS::Hash"
defined $senderHash ref $senderHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $senderHashB= ref $senderHash ne "CDS::Hash"
ABresult
0X0
100
111
1414  
1415 0 return $o->storeForUrl($senderStoreUrl);
1416 }
1417  
1418 sub onMessageBoxEntry {
1419 0 ▶ my $o = shift;
Subroutine onMessageBoxEntry: not called CC=3 SCAR=24.8
1420 0 my $message = shift;
1421  
1422 0 $o->{countMessages} += 1;
1423  
1424 0 for my $section ($message->content->children) {
1425 0 my $type = $section->bytes;
1426 0 ▶ my $handler = $o->{messageHandlers}->{$type} // \&onUnknownMessage;
Condition0%0/2
$o->{"messageHandlers"}{$type} // \&CDS::CLIActor::onUnknownMessage
l!l
00
MC/DC0%0/1
$o->{"messageHandlers"}{$type} // \&CDS::CLIActor::onUnknownMessage
$o->{"messageHandlers"}{$type}
Truth table0%0/2
A
A= $o->{"messageHandlers"}{$type}
Aresult
11
00
1427 0 &$handler($o, $message, $section);
1428 }
1429  
1430 # 1. message processed
1431 # -> source can be deleted immediately (e.g. invalid)
1432 # source.discard()
1433 # -> source has been merged, and will be deleted when changes have been saved
1434 # document.addMergedSource(source)
1435 # 2. wait for sender store
1436 # -> set entry.waitForStore = senderStore
1437 # 3. skip
1438 # -> set entry.processed = false
1439  
1440 0 my $source = $message->source;
1441 0 $message->source->discard;
1442 }
1443  
1444 sub onGroupDataMessage {
1445 0 ▶ my $o = shift;
Subroutine onGroupDataMessage: not called CC=2 SCAR=17.9
1446 0 my $message = shift;
1447 0 my $section = shift;
1448  
1449 0 my $ok = $o->{groupDataSharer}->processGroupDataMessage($message, $section);
1450 0 $o->{groupDocument}->read;
1451 0 ▶ return $o->{ui}->line('Group data from ', $message->sender->publicKey->hash->hex) if $ok;
Branch: 1 branch
BranchTrueFalseTotal
if $ok 0 0 0
1452 0 $o->{ui}->line($o->{ui}->red('Group data from foreign actor ', $message->sender->publicKey->hash->hex, ' (ignored)'));
1453 }
1454  
1455 sub onIgnoreMessage {
1456 0 ▶ my $o = shift;
Subroutine onIgnoreMessage: not called CC=1 SCAR=6.9
1457 0 my $message = shift;
1458 0 my $section = shift;
1459 }
1460  
1461 sub onUnknownMessage {
1462 0 ▶ my $o = shift;
Subroutine onUnknownMessage: not called CC=1 SCAR=6.9
1463 0 my $message = shift;
1464 0 my $section = shift;
1465  
1466 0 $o->{ui}->line($o->{ui}->orange('Unknown message of type "', $section->asText, '" from ', $message->sender->publicKey->hash->hex));
1467 }
1468  
1469 sub onMessageBoxInvalidEntry {
1470 0 ▶ my $o = shift;
Subroutine onMessageBoxInvalidEntry: not called CC=3 SCAR=24.8
1471 0 ▶ my $source = shift; die 'wrong type '.ref($source).' for $source' if defined $source && ref $source ne 'CDS::Source';
Branch: 1 branch
BranchTrueFalseTotal
if defined $source and ref $source ne "CDS::Source" 0 0 0
Condition0%0/3
defined $source and ref $source ne "CDS::Source"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $source and ref $source ne "CDS::Source"
defined $source ref $source ne "CDS::Source"
Truth table0%0/3
A and B
A= defined $sourceB= ref $source ne "CDS::Source"
ABresult
0X0
100
111
1472 0 my $reason = shift;
1473  
1474 0 $o->{ui}->warning('Discarding invalid message ', $source->hash->hex, ' (', $reason, ').');
1475 0 $source->discard;
1476 }
1477  
1478 ### Remembered values
1479  
1480 sub labelSelector {
1481 0 ▶ my $o = shift;
Subroutine labelSelector: not called CC=1 SCAR=6.9
1482 0 my $label = shift;
1483  
1484 0 my $bytes = Encode::encode_utf8($label);
1485 0 return $o->groupRoot->child('labels')->child($bytes);
1486 }
1487  
1488 sub remembered {
1489 0 ▶ my $o = shift;
Subroutine remembered: not called CC=1 SCAR=6.9
1490 0 my $label = shift;
1491  
1492 0 return $o->labelSelector($label)->record;
1493 }
1494  
1495 sub remember {
1496 0 ▶ my $o = shift;
Subroutine remember: not called CC=3 SCAR=24.8
1497 0 my $label = shift;
1498 0 ▶ my $record = shift; die 'wrong type '.ref($record).' for $record' if defined $record && ref $record ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $record and ref $record ne "CDS::Record" 0 0 0
Condition0%0/3
defined $record and ref $record ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $record and ref $record ne "CDS::Record"
defined $record ref $record ne "CDS::Record"
Truth table0%0/3
A and B
A= defined $recordB= ref $record ne "CDS::Record"
ABresult
0X0
100
111
1499  
1500 0 $o->labelSelector($label)->set($record);
1501 }
1502  
1503 sub rememberedRecords {
1504 0 ▶ my $o = shift;
Subroutine rememberedRecords: not called CC=3 SCAR=24.8
1505  
1506 0 my $records = {};
1507 0 for my $child ($o->{groupRoot}->child('labels')->children) {
1508 0 ▶ next if ! $child->isSet;
Branch: 1 branch
BranchTrueFalseTotal
unless $child->isSet 0 0 0
1509 0 my $label = Encode::decode_utf8($child->label);
1510 0 $records->{$label} = $child->record;
1511 }
1512  
1513 0 return $records;
1514 }
1515  
1516 sub storeLabel {
1517 0 ▶ my $o = shift;
Subroutine storeLabel: not called CC=4 SCAR=30.0
1518 0 my $storeUrl = shift;
1519  
1520 0 my $records = $o->rememberedRecords;
1521 0 for my $label (keys %$records) {
1522 0 my $record = $records->{$label};
1523 0 ▶ next if length $record->child('actor')->bytesValue;
Branch: 1 branch
BranchTrueFalseTotal
if length $record->child("actor")->bytesValue 0 0 0
1524 0 ▶ next if $storeUrl ne $record->child('store')->textValue;
Branch: 1 branch
BranchTrueFalseTotal
if $storeUrl ne $record->child("store")->textValue 0 0 0
1525 0 return $label;
1526 }
1527  
1528 0 return;
1529 }
1530  
1531 sub actorLabel {
1532 0 ▶ my $o = shift;
Subroutine actorLabel: not called CC=5 SCAR=34.0
1533 0 ▶ my $actorHash = shift; die 'wrong type '.ref($actorHash).' for $actorHash' if defined $actorHash && ref $actorHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $actorHash and ref $actorHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $actorHash and ref $actorHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $actorHash and ref $actorHash ne "CDS::Hash"
defined $actorHash ref $actorHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $actorHashB= ref $actorHash ne "CDS::Hash"
ABresult
0X0
100
111
1534  
1535 0 my $records = $o->rememberedRecords;
1536 0 for my $label (keys %$records) {
1537 0 my $record = $records->{$label};
1538 0 ▶ next if $actorHash->bytes ne $record->child('actor')->bytesValue;
Branch: 1 branch
BranchTrueFalseTotal
if $actorHash->bytes ne $record->child("actor")->bytesValue 0 0 0
1539 0 return $label;
1540 }
1541  
1542 0 return;
1543 }
1544  
1545 sub actorLabelByHashStartBytes {
1546 0 ▶ my $o = shift;
Subroutine actorLabelByHashStartBytes: not called CC=3 SCAR=24.8
1547 0 my $actorHashStartBytes = shift;
1548  
1549 0 my $length = length $actorHashStartBytes;
1550 0 my $records = $o->rememberedRecords;
1551 0 for my $label (keys %$records) {
1552 0 my $record = $records->{$label};
1553 0 ▶ next if $actorHashStartBytes ne substr($record->child('actor')->bytesValue, 0, $length);
Branch: 1 branch
BranchTrueFalseTotal
if $actorHashStartBytes ne substr($record->child("actor")->bytesValue, 0, $length) 0 0 0
1554 0 return $label;
1555 }
1556  
1557 0 return;
1558 }
1559  
1560 sub accountLabel {
1561 0 ▶ my $o = shift;
Subroutine accountLabel: not called CC=8 SCAR=42.8
1562 0 my $storeUrl = shift;
1563 0 ▶ my $actorHash = shift; die 'wrong type '.ref($actorHash).' for $actorHash' if defined $actorHash && ref $actorHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $actorHash and ref $actorHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $actorHash and ref $actorHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $actorHash and ref $actorHash ne "CDS::Hash"
defined $actorHash ref $actorHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $actorHashB= ref $actorHash ne "CDS::Hash"
ABresult
0X0
100
111
1564  
1565 0 my $storeLabel;
1566 my $actorLabel;
1567  
1568 0 my $records = $o->rememberedRecords;
1569 0 for my $label (keys %$records) {
1570 0 my $record = $records->{$label};
1571 0 my $actorBytes = $record->child('actor')->bytesValue;
1572  
1573 0 my $correctActor = $actorHash->bytes eq $actorBytes;
1574 0 ▶ $actorLabel = $label if $correctActor;
Branch: 1 branch
BranchTrueFalseTotal
if $correctActor 0 0 0
1575  
1576 0 ▶ if ($storeUrl eq $record->child('store')->textValue) {
Branch: 1 branch
BranchTrueFalseTotal
if ($storeUrl eq $record->child("store")->textValue) 0 0 0
1577 0 ▶ return $label if $correctActor;
Branch: 1 branch
BranchTrueFalseTotal
if $correctActor 0 0 0
1578 0 ▶ $storeLabel = $label if ! length $actorBytes;
Branch: 1 branch
BranchTrueFalseTotal
unless length $actorBytes 0 0 0
1579 }
1580 }
1581  
1582 0 return (undef, $storeLabel, $actorLabel);
1583 }
1584  
1585 sub keyPairLabel {
1586 0 ▶ my $o = shift;
Subroutine keyPairLabel: not called CC=3 SCAR=24.8
1587 0 my $file = shift;
1588  
1589 0 my $records = $o->rememberedRecords;
1590 0 for my $label (keys %$records) {
1591 0 my $record = $records->{$label};
1592 0 ▶ next if $file ne $record->child('key pair')->textValue;
Branch: 1 branch
BranchTrueFalseTotal
if $file ne $record->child("key pair")->textValue 0 0 0
1593 0 return $label;
1594 }
1595  
1596 0 return;
1597 }
1598  
1599 ### References that can be used in commands
1600  
1601 sub actorReference {
1602 0 ▶ my $o = shift;
Subroutine actorReference: not called CC=4 SCAR=30.0
1603 0 ▶ my $actorHash = shift; die 'wrong type '.ref($actorHash).' for $actorHash' if defined $actorHash && ref $actorHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $actorHash and ref $actorHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $actorHash and ref $actorHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $actorHash and ref $actorHash ne "CDS::Hash"
defined $actorHash ref $actorHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $actorHashB= ref $actorHash ne "CDS::Hash"
ABresult
0X0
100
111
1604  
1605 0 ▶ return $o->actorLabel($actorHash) // $actorHash->hex;
Condition0%0/3
$o->actorLabel($actorHash) // $actorHash->hex
l!l&&r!l&&!r
000
MC/DC0%0/2
$o->actorLabel($actorHash) // $actorHash->hex
$o->actorLabel($actorHash) $actorHash->hex
Truth table0%0/3
A // B
A= $o->actorLabel($actorHash)B= $actorHash->hex
ABresult
1X1
011
000
1606 }
1607  
1608 sub storeReference {
1609 0 ▶ my $o = shift;
Subroutine storeReference: not called CC=1 SCAR=6.9
1610 0 my $store = shift;
1611 0 $o->storeUrlReference($store->url); }
1612  
1613 sub storeUrlReference {
1614 0 ▶ my $o = shift;
Subroutine storeUrlReference: not called CC=2 SCAR=17.9
1615 0 my $storeUrl = shift;
1616  
1617 0 ▶ return $o->storeLabel($storeUrl) // $storeUrl;
Condition0%0/3
$o->storeLabel($storeUrl) // $storeUrl
l!l&&r!l&&!r
000
MC/DC0%0/2
$o->storeLabel($storeUrl) // $storeUrl
$o->storeLabel($storeUrl) $storeUrl
Truth table0%0/3
A // B
A= $o->storeLabel($storeUrl)B= $storeUrl
ABresult
1X1
011
000
1618 }
1619  
1620 sub accountReference {
1621 0 ▶ my $o = shift;
Subroutine accountReference: not called CC=4 SCAR=30.0
1622 0 my $accountToken = shift;
1623  
1624 0 my ($accountLabel, $storeLabel, $actorLabel) = $o->accountLabel($accountToken->{cliStore}->url, $accountToken->{actorHash});
1625 0 ▶ return $accountLabel if defined $accountLabel;
Branch: 1 branch
BranchTrueFalseTotal
if defined $accountLabel 0 0 0
1626 0 ▶ return defined $actorLabel ? $actorLabel : $accountToken->{actorHash}->hex, ' on ', defined $storeLabel ? $storeLabel : $accountToken->{cliStore}->url;
Branch: 2 branches
BranchTrueFalseTotal
defined $actorLabel ? : 0 0 0
defined $storeLabel ? : 0 0 0
1627 }
1628  
1629 sub boxReference {
1630 0 ▶ my $o = shift;
Subroutine boxReference: not called CC=1 SCAR=6.9
1631 0 my $boxToken = shift;
1632  
1633 0 return $o->boxName($boxToken->{boxLabel}), ' of ', $o->accountReference($boxToken->{accountToken});
1634 }
1635  
1636 sub keyPairReference {
1637 0 ▶ my $o = shift;
Subroutine keyPairReference: not called CC=2 SCAR=17.9
1638 0 my $keyPairToken = shift;
1639  
1640 0 ▶ return $o->keyPairLabel($keyPairToken->file) // $keyPairToken->file;
Condition0%0/3
$o->keyPairLabel($keyPairToken->file) // $keyPairToken->file
l!l&&r!l&&!r
000
MC/DC0%0/2
$o->keyPairLabel($keyPairToken->file) // $keyPairToken->file
$o->keyPairLabel($keyPairToken->file) $keyPairToken->file
Truth table0%0/3
A // B
A= $o->keyPairLabel($keyPairToken->file)B= $keyPairToken->file
ABresult
1X1
011
000
1641 }
1642  
1643 sub blueActorReference {
1644 0 ▶ my $o = shift;
Subroutine blueActorReference: not called CC=4 SCAR=30.0
1645 0 ▶ my $actorHash = shift; die 'wrong type '.ref($actorHash).' for $actorHash' if defined $actorHash && ref $actorHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $actorHash and ref $actorHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $actorHash and ref $actorHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $actorHash and ref $actorHash ne "CDS::Hash"
defined $actorHash ref $actorHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $actorHashB= ref $actorHash ne "CDS::Hash"
ABresult
0X0
100
111
1646  
1647 0 my $label = $o->actorLabel($actorHash);
1648 0 ▶ return defined $label ? $o->{ui}->blue($label) : $actorHash->hex;
Branch: 1 branch
BranchTrueFalseTotal
defined $label ? : 0 0 0
1649 }
1650  
1651 sub blueStoreReference {
1652 0 ▶ my $o = shift;
Subroutine blueStoreReference: not called CC=1 SCAR=6.9
1653 0 my $store = shift;
1654 0 $o->blueStoreUrlReference($store->url); }
1655  
1656 sub blueStoreUrlReference {
1657 0 ▶ my $o = shift;
Subroutine blueStoreUrlReference: not called CC=2 SCAR=17.9
1658 0 my $storeUrl = shift;
1659  
1660 0 my $label = $o->storeLabel($storeUrl);
1661 0 ▶ return defined $label ? $o->{ui}->blue($label) : $storeUrl;
Branch: 1 branch
BranchTrueFalseTotal
defined $label ? : 0 0 0
1662 }
1663  
1664 sub blueAccountReference {
1665 0 ▶ my $o = shift;
Subroutine blueAccountReference: not called CC=4 SCAR=30.0
1666 0 my $accountToken = shift;
1667  
1668 0 my ($accountLabel, $storeLabel, $actorLabel) = $o->accountLabel($accountToken->{cliStore}->url, $accountToken->{actorHash});
1669 0 ▶ return $o->{ui}->blue($accountLabel) if defined $accountLabel;
Branch: 1 branch
BranchTrueFalseTotal
if defined $accountLabel 0 0 0
1670 0 ▶ return defined $actorLabel ? $o->{ui}->blue($actorLabel) : $accountToken->{actorHash}->hex, ' on ', defined $storeLabel ? $o->{ui}->blue($storeLabel) : $accountToken->{cliStore}->url;
Branch: 2 branches
BranchTrueFalseTotal
defined $actorLabel ? : 0 0 0
defined $storeLabel ? : 0 0 0
1671 }
1672  
1673 sub blueBoxReference {
1674 0 ▶ my $o = shift;
Subroutine blueBoxReference: not called CC=1 SCAR=6.9
1675 0 my $boxToken = shift;
1676  
1677 0 return $o->boxName($boxToken->{boxLabel}), ' of ', $o->blueAccountReference($boxToken->{accountToken});
1678 }
1679  
1680 sub blueKeyPairReference {
1681 0 ▶ my $o = shift;
Subroutine blueKeyPairReference: not called CC=2 SCAR=17.9
1682 0 my $keyPairToken = shift;
1683  
1684 0 my $label = $o->keyPairLabel($keyPairToken->file);
1685 0 ▶ return defined $label ? $o->{ui}->blue($label) : $keyPairToken->file;
Branch: 1 branch
BranchTrueFalseTotal
defined $label ? : 0 0 0
1686 }
1687  
1688 sub boxName {
1689 0 ▶ my $o = shift;
Subroutine boxName: not called CC=4 SCAR=30.0
1690 0 my $boxLabel = shift;
1691  
1692 0 ▶ return 'private box' if $boxLabel eq 'private';
Branch: 1 branch
BranchTrueFalseTotal
if $boxLabel eq "private" 0 0 0
1693 0 ▶ return 'public box' if $boxLabel eq 'public';
Branch: 1 branch
BranchTrueFalseTotal
if $boxLabel eq "public" 0 0 0
1694 0 ▶ return 'message box' if $boxLabel eq 'messages';
Branch: 1 branch
BranchTrueFalseTotal
if $boxLabel eq "messages" 0 0 0
1695 0 return $boxLabel;
1696 }
1697  
1698 ### Session
1699  
1700 sub forgetOldSessions {
1701 0 ▶ my $o = shift;
Subroutine forgetOldSessions: not called CC=3 SCAR=24.8
1702  
1703 0 for my $child ($o->{sessionRoot}->parent->children) {
1704 0 my $pid = $child->label;
1705 0 ▶ next if -e '/proc/'.$pid;
Branch: 1 branch
BranchTrueFalseTotal
if -e '/proc/' . $pid 0 0 0
1706 0 $child->forgetBranch;
1707 }
1708 }
1709  
1710 sub selectedKeyPairToken {
1711 0 ▶ my $o = shift;
Subroutine selectedKeyPairToken: not called CC=3 SCAR=24.8
1712  
1713 0 my $file = $o->{sessionRoot}->child('selected key pair')->textValue;
1714 0 ▶ return if ! length $file;
Branch: 1 branch
BranchTrueFalseTotal
unless length $file 0 0 0
1715 0 ▶ my $keyPair = CDS::KeyPair->fromFile($file) // return;
Condition0%0/2
"CDS::KeyPair"->fromFile($file) // (return)
l!l
00
MC/DC0%0/1
"CDS::KeyPair"->fromFile($file) // (return)
"CDS::KeyPair"->fromFile($file)
Truth table0%0/2
A
A= "CDS::KeyPair"->fromFile($file)
Aresult
11
00
1716 0 return CDS::KeyPairToken->new($file, $keyPair);
1717 }
1718  
1719 sub selectedStoreUrl {
1720 0 ▶ my $o = shift;
Subroutine selectedStoreUrl: not called CC=2 SCAR=17.9
1721  
1722 0 my $storeUrl = $o->{sessionRoot}->child('selected store')->textValue;
1723 0 ▶ return if ! length $storeUrl;
Branch: 1 branch
BranchTrueFalseTotal
unless length $storeUrl 0 0 0
1724 0 return $storeUrl;
1725 }
1726  
1727 sub selectedStore {
1728 0 ▶ my $o = shift;
Subroutine selectedStore: not called CC=2 SCAR=17.9
1729  
1730 0 ▶ my $storeUrl = $o->selectedStoreUrl // return;
Condition0%0/2
$o->selectedStoreUrl // (return)
l!l
00
MC/DC0%0/1
$o->selectedStoreUrl // (return)
$o->selectedStoreUrl
Truth table0%0/2
A
A= $o->selectedStoreUrl
Aresult
11
00
1731 0 return $o->storeForUrl($storeUrl);
1732 }
1733  
1734 sub selectedActorHash {
1735 0 ▶ my $o = shift;
Subroutine selectedActorHash: not called CC=1 SCAR=6.9
1736  
1737 0 return CDS::Hash->fromBytes($o->{sessionRoot}->child('selected actor')->bytesValue);
1738 }
1739  
1740 sub preferredKeyPairToken {
1741 0 ▶ my $o = shift;
Subroutine preferredKeyPairToken: not called CC=2 SCAR=17.9
1742 0 ▶ $o->selectedKeyPairToken // $o->keyPairToken }
Condition0%0/3
$o->selectedKeyPairToken // $o->keyPairToken
l!l&&r!l&&!r
000
MC/DC0%0/2
$o->selectedKeyPairToken // $o->keyPairToken
$o->selectedKeyPairToken $o->keyPairToken
Truth table0%0/3
A // B
A= $o->selectedKeyPairTokenB= $o->keyPairToken
ABresult
1X1
011
000
1743 sub preferredStore {
1744 0 ▶ my $o = shift;
Subroutine preferredStore: not called CC=2 SCAR=17.9
1745 0 ▶ $o->selectedStore // $o->storageStore }
Condition0%0/3
$o->selectedStore // $o->storageStore
l!l&&r!l&&!r
000
MC/DC0%0/2
$o->selectedStore // $o->storageStore
$o->selectedStore $o->storageStore
Truth table0%0/3
A // B
A= $o->selectedStoreB= $o->storageStore
ABresult
1X1
011
000
1746 sub preferredStores {
1747 0 ▶ my $o = shift;
Subroutine preferredStores: not called CC=2 SCAR=17.9
1748 0 ▶ $o->selectedStore // ($o->storageStore, $o->messagingStore) }
Condition0%0/3
$o->selectedStore // ($o->storageStore, $o->messagingStore)
l!l&&r!l&&!r
000
MC/DC0%0/2
$o->selectedStore // ($o->storageStore, $o->messagingStore)
$o->selectedStore ($o->storageStore, $o->messagingStore)
Truth table0%0/3
A // B
A= $o->selectedStoreB= ($o->storageStore, $o->messagingStore)
ABresult
1X1
011
000
1749 sub preferredActorHash {
1750 0 ▶ my $o = shift;
Subroutine preferredActorHash: not called CC=2 SCAR=17.9
1751 0 ▶ $o->selectedActorHash // $o->keyPair->publicKey->hash }
Condition0%0/3
$o->selectedActorHash // $o->keyPair->publicKey->hash
l!l&&r!l&&!r
000
MC/DC0%0/2
$o->selectedActorHash // $o->keyPair->publicKey->hash
$o->selectedActorHash $o->keyPair->publicKey->hash
Truth table0%0/3
A // B
A= $o->selectedActorHashB= $o->keyPair->publicKey->hash
ABresult
1X1
011
000
1752  
1753 ### Common functions
1754  
1755 sub uiGetObject {
1756 0 ▶ my $o = shift;
Subroutine uiGetObject: not called CC=5 SCAR=34.0
1757 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
1758 0 my $store = shift;
1759 0 my $keyPairToken = shift;
1760  
1761 0 my ($object, $storeError) = $store->get($hash, $keyPairToken->keyPair);
1762 0 ▶ return if defined $storeError;
Branch: 1 branch
BranchTrueFalseTotal
if defined $storeError 0 0 0
1763 0 ▶ return $o->{ui}->error('The object ', $hash->hex, ' does not exist on "', $store->url, '".') if ! $object;
Branch: 1 branch
BranchTrueFalseTotal
unless $object 0 0 0
1764 0 return $object;
1765 }
1766  
1767 sub uiGetRecord {
1768 0 ▶ my $o = shift;
Subroutine uiGetRecord: not called CC=5 SCAR=34.0
1769 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
1770 0 my $store = shift;
1771 0 my $keyPairToken = shift;
1772  
1773 0 ▶ my $object = $o->uiGetObject($hash, $store, $keyPairToken) // return;
Condition0%0/2
$o->uiGetObject($hash, $store, $keyPairToken) // (return)
l!l
00
MC/DC0%0/1
$o->uiGetObject($hash, $store, $keyPairToken) // (return)
$o->uiGetObject($hash, $store, $keyPairToken)
Truth table0%0/2
A
A= $o->uiGetObject($hash, $store, $keyPairToken)
Aresult
11
00
1774 0 ▶ return CDS::Record->fromObject($object) // return $o->{ui}->error('The object ', $hash->hex, ' is not a record.');
Condition0%0/2
"CDS::Record"->fromObject($object) // (return $o->{"ui"}->error("The object ", $hash->hex, " is not a record."))
l!l
00
MC/DC0%0/1
"CDS::Record"->fromObject($object) // (return $o->{"ui"}->error("The object ", $hash->hex, " is not a record."))
"CDS::Record"->fromObject($object)
Truth table0%0/2
A
A= "CDS::Record"->fromObject($object)
Aresult
11
00
1775 }
1776  
1777 sub uiGetPublicKey {
1778 0 ▶ my $o = shift;
Subroutine uiGetPublicKey: not called CC=5 SCAR=34.0
1779 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
1780 0 my $store = shift;
1781 0 my $keyPairToken = shift;
1782  
1783 0 ▶ my $object = $o->uiGetObject($hash, $store, $keyPairToken) // return;
Condition0%0/2
$o->uiGetObject($hash, $store, $keyPairToken) // (return)
l!l
00
MC/DC0%0/1
$o->uiGetObject($hash, $store, $keyPairToken) // (return)
$o->uiGetObject($hash, $store, $keyPairToken)
Truth table0%0/2
A
A= $o->uiGetObject($hash, $store, $keyPairToken)
Aresult
11
00
1784 0 ▶ return CDS::PublicKey->fromObject($object) // return $o->{ui}->error('The object ', $hash->hex, ' is not a public key.');
Condition0%0/2
"CDS::PublicKey"->fromObject($object) // (return $o->{"ui"}->error("The object ", $hash->hex, " is not a public key."))
l!l
00
MC/DC0%0/1
"CDS::PublicKey"->fromObject($object) // (return $o->{"ui"}->error("The object ", $hash->hex, " is not a public key."))
"CDS::PublicKey"->fromObject($object)
Truth table0%0/2
A
A= "CDS::PublicKey"->fromObject($object)
Aresult
11
00
1785 }
1786  
1787 sub isEnvelope {
1788 0 ▶ my $o = shift;
Subroutine isEnvelope: not called CC=7 SCAR=40.3
1789 0 ▶ my $object = shift; die 'wrong type '.ref($object).' for $object' if defined $object && ref $object ne 'CDS::Object';
Branch: 1 branch
BranchTrueFalseTotal
if defined $object and ref $object ne "CDS::Object" 0 0 0
Condition0%0/3
defined $object and ref $object ne "CDS::Object"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $object and ref $object ne "CDS::Object"
defined $object ref $object ne "CDS::Object"
Truth table0%0/3
A and B
A= defined $objectB= ref $object ne "CDS::Object"
ABresult
0X0
100
111
1790  
1791 0 ▶ my $record = CDS::Record->fromObject($object) // return;
Condition0%0/2
"CDS::Record"->fromObject($object) // (return)
l!l
00
MC/DC0%0/1
"CDS::Record"->fromObject($object) // (return)
"CDS::Record"->fromObject($object)
Truth table0%0/2
A
A= "CDS::Record"->fromObject($object)
Aresult
11
00
1792 0 ▶ return if ! $record->contains('signed');
Branch: 1 branch
BranchTrueFalseTotal
unless $record->contains("signed") 0 0 0
1793 0 my $signatureRecord = $record->child('signature')->firstChild;
1794 0 ▶ return if ! $signatureRecord->hash;
Branch: 1 branch
BranchTrueFalseTotal
unless $signatureRecord->hash 0 0 0
1795 0 ▶ return if ! length $signatureRecord->bytes;
Branch: 1 branch
BranchTrueFalseTotal
unless length $signatureRecord->bytes 0 0 0
1796 0 return 1;
1797 }
1798  
1799 package CDS::CLIStoreManager;
1800  
1801 sub new {
1802 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
1803 0 my $ui = shift;
1804  
1805 0 return bless {ui => $ui, failedStores => {}};
1806 }
1807  
1808 0 ▶sub ui { shift->{ui} }
Subroutine ui: not called CC=1 SCAR=6.9
1809  
1810 sub rawStoreForUrl {
1811 0 ▶ my $o = shift;
Subroutine rawStoreForUrl: not called CC=4 SCAR=30.0
1812 0 my $url = shift;
1813  
1814 0 ▶ return if ! $url;
Branch: 1 branch
BranchTrueFalseTotal
unless $url 0 0 0
1815 return
1816 0 ▶ CDS::FolderStore->forUrl($url) //
Condition0%0/5
("CDS::FolderStore"->forUrl($url) // "CDS::HTTPStore"->forUrl($url)) // undef
l!l
00
"CDS::FolderStore"->forUrl($url) // "CDS::HTTPStore"->forUrl($url)
l!l&&r!l&&!r
000
MC/DC0%0/2
("CDS::FolderStore"->forUrl($url) // "CDS::HTTPStore"->forUrl($url)) // undef
"CDS::FolderStore"->forUrl($url) "CDS::HTTPStore"->forUrl($url)
Truth table0%0/3
A // B
A= "CDS::FolderStore"->forUrl($url)B= "CDS::HTTPStore"->forUrl($url)
ABresult
1X1
011
000
1817 CDS::HTTPStore->forUrl($url) //
1818 undef;
1819 }
1820  
1821 sub storeForUrl {
1822 0 ▶ my $o = shift;
Subroutine storeForUrl: not called CC=2 SCAR=17.9
1823 0 my $url = shift;
1824  
1825 0 my $store = $o->rawStoreForUrl($url);
1826 0 my $progressStore = CDS::UI::ProgressStore->new($store, $url, $o->{ui});
1827 0 ▶ my $cachedStore = defined $o->{cacheStore} ? CDS::ObjectCache->new($progressStore, $o->{cacheStore}) : $progressStore;
Branch: 1 branch
BranchTrueFalseTotal
defined $o->{'cacheStore'} ? : 0 0 0
1828 0 return CDS::ErrorHandlingStore->new($cachedStore, $url, $o);
1829 }
1830  
1831 sub onStoreSuccess {
1832 0 ▶ my $o = shift;
Subroutine onStoreSuccess: not called CC=1 SCAR=6.9
1833 0 my $store = shift;
1834 0 my $function = shift;
1835  
1836 0 delete $o->{failedStores}->{$store->store->id};
1837 }
1838  
1839 sub onStoreError {
1840 0 ▶ my $o = shift;
Subroutine onStoreError: not called CC=1 SCAR=6.9
1841 0 my $store = shift;
1842 0 my $function = shift;
1843 0 my $error = shift;
1844  
1845 0 $o->{failedStores}->{$store->store->id} = 1;
1846 0 $o->{ui}->error('The store "', $store->{url}, '" reports: ', $error);
1847 }
1848  
1849 sub hasStoreError {
1850 0 ▶ my $o = shift;
Subroutine hasStoreError: not called CC=2 SCAR=17.9
1851 0 my $store = shift;
1852 0 my $function = shift;
1853  
1854 0 ▶ return if ! $o->{failedStores}->{$store->store->id};
Branch: 1 branch
BranchTrueFalseTotal
unless $o->{"failedStores"}{$store->store->id} 0 0 0
1855 0 $o->{ui}->error('Ignoring store "', $store->{url}, '", because it previously reported errors.');
1856 0 return 1;
1857 }
1858  
1859 sub setCacheStoreUrl {
1860 0 ▶ my $o = shift;
Subroutine setCacheStoreUrl: not called CC=4 SCAR=30.0
1861 0 my $storeUrl = shift;
1862  
1863 0 ▶ return if ($storeUrl // '') eq ($o->{cacheStoreUrl} // '');
Branch: 1 branch
BranchTrueFalseTotal
if ($storeUrl // "") eq ($o->{"cacheStoreUrl"} // "") 0 0 0
Condition0%0/4
$storeUrl // ""
l!l
00
$o->{"cacheStoreUrl"} // ""
l!l
00
MC/DC0%0/1
$storeUrl // ""
$storeUrl
MC/DC0%0/1
$o->{"cacheStoreUrl"} // ""
$o->{"cacheStoreUrl"}
Truth table0%0/2
A
A= $storeUrl
Aresult
11
00
Truth table0%0/2
A
A= $o->{"cacheStoreUrl"}
Aresult
11
00
1864 0 $o->{cacheStoreUrl} = $storeUrl;
1865 0 $o->{cacheStore} = $o->rawStoreForUrl($storeUrl);
1866 }
1867  
1868 package CDS::CheckSignatureStore;
1869  
1870 sub new {
1871 0 ▶ my $o = shift;
Subroutine new: not called CC=2 SCAR=17.9
1872 0 my $store = shift;
1873 0 my $objects = shift;
1874  
1875 0 ▶ return bless {
Condition0%0/2
$objects // {}
l!l
00
MC/DC0%0/1
$objects // {}
$objects
Truth table0%0/2
A
A= $objects
Aresult
11
00
1876 store => $store,
1877 id => "Check signature store\n".$store->id,
1878 objects => $objects // {},
1879 };
1880 }
1881  
1882 0 ▶sub id { shift->{id} }
Subroutine id: not called CC=1 SCAR=6.9
1883  
1884 sub get {
1885 0 ▶ my $o = shift;
Subroutine get: not called CC=6 SCAR=37.4
1886 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
1887 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
1888  
1889 0 ▶ my $entry = $o->{objects}->{$hash->bytes} // return $o->{store}->get($hash);
Condition0%0/2
$o->{"objects"}{$hash->bytes} // (return $o->{"store"}->get($hash))
l!l
00
MC/DC0%0/1
$o->{"objects"}{$hash->bytes} // (return $o->{"store"}->get($hash))
$o->{"objects"}{$hash->bytes}
Truth table0%0/2
A
A= $o->{"objects"}{$hash->bytes}
Aresult
11
00
1890 0 return $entry->{object};
1891 }
1892  
1893 sub book {
1894 0 ▶ my $o = shift;
Subroutine book: not called CC=5 SCAR=34.0
1895 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
1896 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
1897  
1898 0 return exists $o->{objects}->{$hash->bytes};
1899 }
1900  
1901 sub put {
1902 0 ▶ my $o = shift;
Subroutine put: not called CC=7 SCAR=40.3
1903 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
1904 0 ▶ my $object = shift; die 'wrong type '.ref($object).' for $object' if defined $object && ref $object ne 'CDS::Object';
Branch: 1 branch
BranchTrueFalseTotal
if defined $object and ref $object ne "CDS::Object" 0 0 0
Condition0%0/3
defined $object and ref $object ne "CDS::Object"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $object and ref $object ne "CDS::Object"
defined $object ref $object ne "CDS::Object"
Truth table0%0/3
A and B
A= defined $objectB= ref $object ne "CDS::Object"
ABresult
0X0
100
111
1905 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
1906  
1907 0 $o->{objects}->{$hash->bytes} = {hash => $hash, object => $object};
1908 0 return;
1909 }
1910  
1911 sub list {
1912 0 ▶ my $o = shift;
Subroutine list: not called CC=5 SCAR=34.0
1913 0 ▶ my $accountHash = shift; die 'wrong type '.ref($accountHash).' for $accountHash' if defined $accountHash && ref $accountHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $accountHash and ref $accountHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $accountHash and ref $accountHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $accountHash and ref $accountHash ne "CDS::Hash"
defined $accountHash ref $accountHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $accountHashB= ref $accountHash ne "CDS::Hash"
ABresult
0X0
100
111
1914 0 my $boxLabel = shift;
1915 0 my $timeout = shift;
1916 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
1917  
1918 0 return 'This store only handles objects.';
1919 }
1920  
1921 sub add {
1922 0 ▶ my $o = shift;
Subroutine add: not called CC=7 SCAR=40.3
1923 0 ▶ my $accountHash = shift; die 'wrong type '.ref($accountHash).' for $accountHash' if defined $accountHash && ref $accountHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $accountHash and ref $accountHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $accountHash and ref $accountHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $accountHash and ref $accountHash ne "CDS::Hash"
defined $accountHash ref $accountHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $accountHashB= ref $accountHash ne "CDS::Hash"
ABresult
0X0
100
111
1924 0 my $boxLabel = shift;
1925 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
1926 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
1927  
1928 0 return 'This store only handles objects.';
1929 }
1930  
1931 sub remove {
1932 0 ▶ my $o = shift;
Subroutine remove: not called CC=7 SCAR=40.3
1933 0 ▶ my $accountHash = shift; die 'wrong type '.ref($accountHash).' for $accountHash' if defined $accountHash && ref $accountHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $accountHash and ref $accountHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $accountHash and ref $accountHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $accountHash and ref $accountHash ne "CDS::Hash"
defined $accountHash ref $accountHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $accountHashB= ref $accountHash ne "CDS::Hash"
ABresult
0X0
100
111
1934 0 my $boxLabel = shift;
1935 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
1936 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
1937  
1938 0 return 'This store only handles objects.';
1939 }
1940  
1941 sub modify {
1942 0 ▶ my $o = shift;
Subroutine modify: not called CC=3 SCAR=24.8
1943 0 my $modifications = shift;
1944 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
1945  
1946 0 return $modifications->executeIndividually($o, $keyPair);
1947 }
1948  
1949 # BEGIN AUTOGENERATED
1950 package CDS::Commands::ActorGroup;
1951  
1952 sub register {
1953 0 ▶ my $class = shift;
Subroutine register: not called CC=1 SCAR=6.9
1954 0 my $cds = shift;
1955 0 my $help = shift;
1956  
1957 0 my $node000 = CDS::Parser::Node->new(0);
1958 0 my $node001 = CDS::Parser::Node->new(0);
1959 0 my $node002 = CDS::Parser::Node->new(0);
1960 0 my $node003 = CDS::Parser::Node->new(0);
1961 0 my $node004 = CDS::Parser::Node->new(0);
1962 0 my $node005 = CDS::Parser::Node->new(0);
1963 0 my $node006 = CDS::Parser::Node->new(0);
1964 0 my $node007 = CDS::Parser::Node->new(0);
1965 0 my $node008 = CDS::Parser::Node->new(0);
1966 0 my $node009 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&help});
1967 0 my $node010 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&show});
1968 0 my $node011 = CDS::Parser::Node->new(0);
1969 0 my $node012 = CDS::Parser::Node->new(0);
1970 0 my $node013 = CDS::Parser::Node->new(0);
1971 0 my $node014 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&joinMember});
1972 0 my $node015 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&setMember});
1973 0 my $node016 = CDS::Parser::Node->new(0);
1974 0 $cds->addArrow($node001, 1, 0, 'show');
1975 0 $cds->addArrow($node003, 1, 0, 'join');
1976 0 $cds->addArrow($node004, 1, 0, 'set');
1977 0 $help->addArrow($node000, 1, 0, 'actor');
1978 0 $node000->addArrow($node009, 1, 0, 'group');
1979 0 $node001->addArrow($node002, 1, 0, 'actor');
1980 0 $node002->addArrow($node010, 1, 0, 'group');
1981 0 $node003->addArrow($node005, 1, 0, 'member');
1982 0 $node004->addArrow($node007, 1, 0, 'member');
1983 0 $node005->addDefault($node006);
1984 0 $node005->addArrow($node011, 1, 0, 'ACTOR', \&collectActor);
1985 0 $node006->addArrow($node006, 1, 0, 'ACCOUNT', \&collectAccount);
1986 0 $node006->addArrow($node014, 1, 1, 'ACCOUNT', \&collectAccount);
1987 0 $node007->addDefault($node008);
1988 0 $node008->addArrow($node008, 1, 0, 'ACTOR', \&collectActor1);
1989 0 $node008->addArrow($node013, 1, 0, 'ACTOR', \&collectActor1);
1990 0 $node011->addArrow($node012, 1, 0, 'on');
1991 0 $node012->addArrow($node014, 1, 0, 'STORE', \&collectStore);
1992 0 $node013->addArrow($node015, 1, 0, 'active', \&collectActive);
1993 0 $node013->addArrow($node015, 1, 0, 'backup', \&collectBackup);
1994 0 $node013->addArrow($node015, 1, 0, 'idle', \&collectIdle);
1995 0 $node013->addArrow($node015, 1, 0, 'revoked', \&collectRevoked);
1996 0 $node014->addArrow($node016, 1, 0, 'and');
1997 0 $node016->addDefault($node005);
1998 }
1999  
2000 sub collectAccount {
2001 0 ▶ my $o = shift;
Subroutine collectAccount: not called CC=1 SCAR=6.9
2002 0 my $label = shift;
2003 0 my $value = shift;
2004  
2005 0 push @{$o->{accountTokens}}, $value;
2006 }
2007  
2008 sub collectActive {
2009 0 ▶ my $o = shift;
Subroutine collectActive: not called CC=1 SCAR=6.9
2010 0 my $label = shift;
2011 0 my $value = shift;
2012  
2013 0 $o->{status} = 'active';
2014 }
2015  
2016 sub collectActor {
2017 0 ▶ my $o = shift;
Subroutine collectActor: not called CC=1 SCAR=6.9
2018 0 my $label = shift;
2019 0 my $value = shift;
2020  
2021 0 $o->{actorHash} = $value;
2022 }
2023  
2024 sub collectActor1 {
2025 0 ▶ my $o = shift;
Subroutine collectActor1: not called CC=1 SCAR=6.9
2026 0 my $label = shift;
2027 0 my $value = shift;
2028  
2029 0 push @{$o->{actorHashes}}, $value;
2030 }
2031  
2032 sub collectBackup {
2033 0 ▶ my $o = shift;
Subroutine collectBackup: not called CC=1 SCAR=6.9
2034 0 my $label = shift;
2035 0 my $value = shift;
2036  
2037 0 $o->{status} = 'backup';
2038 }
2039  
2040 sub collectIdle {
2041 0 ▶ my $o = shift;
Subroutine collectIdle: not called CC=1 SCAR=6.9
2042 0 my $label = shift;
2043 0 my $value = shift;
2044  
2045 0 $o->{status} = 'idle';
2046 }
2047  
2048 sub collectRevoked {
2049 0 ▶ my $o = shift;
Subroutine collectRevoked: not called CC=1 SCAR=6.9
2050 0 my $label = shift;
2051 0 my $value = shift;
2052  
2053 0 $o->{status} = 'revoked';
2054 }
2055  
2056 sub collectStore {
2057 0 ▶ my $o = shift;
Subroutine collectStore: not called CC=1 SCAR=6.9
2058 0 my $label = shift;
2059 0 my $value = shift;
2060  
2061 0 push @{$o->{accountTokens}}, CDS::AccountToken->new($value, $o->{actorHash});
2062 0 delete $o->{actorHash};
2063 }
2064  
2065 sub new {
2066 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
2067 0 my $actor = shift;
2068 0 bless {actor => $actor, ui => $actor->ui} }
2069  
2070 # END AUTOGENERATED
2071  
2072 # HTML FOLDER NAME actor-group
2073 # HTML TITLE Actor group
2074 sub help {
2075 0 ▶ my $o = shift;
Subroutine help: not called CC=1 SCAR=6.9
2076 0 my $cmd = shift;
2077  
2078 0 my $ui = $o->{ui};
2079 0 $ui->space;
2080 0 $ui->command('cds show actor group');
2081 0 $ui->p('Shows all members of our actor group and the entrusted keys.');
2082 0 $ui->space;
2083 0 $ui->command('cds join ACCOUNT*');
2084 0 $ui->command('cds join ACTOR on STORE');
2085 0 $ui->p('Adds a member to our actor group. To complete the association, the new member must join us, too.');
2086 0 $ui->space;
2087 0 $ui->command('cds set member ACTOR* active');
2088 0 $ui->command('cds set member ACTOR* backup');
2089 0 $ui->command('cds set member ACTOR* idle');
2090 0 $ui->command('cds set member ACTOR* revoked');
2091 0 $ui->p('Changes the status of a member to one of the following:');
2092 0 $ui->p($ui->bold('Active members'), ' share the group data among themselves, and are advertised to receive messages.');
2093 0 $ui->p($ui->bold('Backup members'), ' share the group data (like active members), but are publicly advertised as not processing messages (like idle members). This is suitable for backup actors.');
2094 0 $ui->p($ui->bold('Idle members'), ' are part of the group, but advertised as not processing messages. They generally do not have the latest group data, and may have no group data at all. Idle members may reactivate themselves, or get reactivated by any active member of the group.');
2095 0 $ui->p($ui->bold('Revoked members'), ' have explicitly been removed from the group, e.g. because their private key (or device) got lost. Revoked members can be reactivated by any active member of the group.');
2096 0 $ui->p('Note that changing the status does not start or stop the corresponding actor, but just change how it is regarded by others. The status of each member should reflect its actual behavior.');
2097 0 $ui->space;
2098 0 $ui->p('After modifying the actor group members, you should "cds announce" yourself to publish the changes.');
2099 0 $ui->space;
2100 }
2101  
2102 sub show {
2103 0 ▶ my $o = shift;
Subroutine show: not called CC=5 SCAR=34.0
2104 0 my $cmd = shift;
2105  
2106 0 my $hasMembers = 0;
2107 0 for my $actorSelector ($o->{actor}->actorGroupSelector->children) {
2108 0 my $record = $actorSelector->record;
2109 0 ▶ my $hash = $record->child('hash')->hashValue // next;
Condition0%0/2
$record->child("hash")->hashValue // (next)
l!l
00
MC/DC0%0/1
$record->child("hash")->hashValue // (next)
$record->child("hash")->hashValue
Truth table0%0/2
A
A= $record->child("hash")->hashValue
Aresult
11
00
2110 0 ▶ next if substr($hash->bytes, 0, length $actorSelector->label) ne $actorSelector->label;
Branch: 1 branch
BranchTrueFalseTotal
if substr($hash->bytes, 0, length $actorSelector->label) ne $actorSelector->label 0 0 0
2111 0 my $storeUrl = $record->child('store')->textValue;
2112 0 my $revisionText = $o->{ui}->niceDateTimeLocal($actorSelector->revision);
2113 0 $o->{ui}->line($o->{ui}->gray($revisionText), ' ', $o->coloredType7($actorSelector), ' ', $hash->hex, ' on ', $storeUrl);
2114 0 $hasMembers = 1;
2115 }
2116  
2117 0 ▶ return if $hasMembers;
Branch: 1 branch
BranchTrueFalseTotal
if $hasMembers 0 0 0
2118 0 $o->{ui}->line($o->{ui}->blue('(just you)'));
2119 }
2120  
2121 sub type {
2122 0 ▶ my $o = shift;
Subroutine type: not called CC=8 SCAR=42.8
2123 0 ▶ my $actorSelector = shift; die 'wrong type '.ref($actorSelector).' for $actorSelector' if defined $actorSelector && ref $actorSelector ne 'CDS::Selector';
Branch: 1 branch
BranchTrueFalseTotal
if defined $actorSelector and ref $actorSelector ne "CDS::Selector" 0 0 0
Condition0%0/3
defined $actorSelector and ref $actorSelector ne "CDS::Selector"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $actorSelector and ref $actorSelector ne "CDS::Selector"
defined $actorSelector ref $actorSelector ne "CDS::Selector"
Truth table0%0/3
A and B
A= defined $actorSelectorB= ref $actorSelector ne "CDS::Selector"
ABresult
0X0
100
111
2124  
2125 0 my $groupData = $actorSelector->child('group data')->isSet;
2126 0 my $active = $actorSelector->child('active')->isSet;
2127 0 my $revoked = $actorSelector->child('revoked')->isSet;
2128 return
2129 0 ▶ $revoked ? 'revoked' :
Branch: 4 branches
BranchTrueFalseTotal
$revoked ? : 0 0 0
$active && $groupData ? : 0 0 0
$groupData ? : 0 0 0
$active ? : 0 0 0
Condition0%0/3
$active and $groupData
!ll&&!rl&&r
000
MC/DC0%0/2
$active and $groupData
$active $groupData
Truth table0%0/3
A and B
A= $activeB= $groupData
ABresult
0X0
100
111
2130 $active && $groupData ? 'active' :
2131 $groupData ? 'backup' :
2132 $active ? 'weird' :
2133 'idle';
2134 }
2135  
2136 sub coloredType7 {
2137 0 ▶ my $o = shift;
Subroutine coloredType7: not called CC=8 SCAR=42.8
2138 0 ▶ my $actorSelector = shift; die 'wrong type '.ref($actorSelector).' for $actorSelector' if defined $actorSelector && ref $actorSelector ne 'CDS::Selector';
Branch: 1 branch
BranchTrueFalseTotal
if defined $actorSelector and ref $actorSelector ne "CDS::Selector" 0 0 0
Condition0%0/3
defined $actorSelector and ref $actorSelector ne "CDS::Selector"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $actorSelector and ref $actorSelector ne "CDS::Selector"
defined $actorSelector ref $actorSelector ne "CDS::Selector"
Truth table0%0/3
A and B
A= defined $actorSelectorB= ref $actorSelector ne "CDS::Selector"
ABresult
0X0
100
111
2139  
2140 0 my $groupData = $actorSelector->child('group data')->isSet;
2141 0 my $active = $actorSelector->child('active')->isSet;
2142 0 my $revoked = $actorSelector->child('revoked')->isSet;
2143 return
2144 $revoked ? $o->{ui}->red('revoked') :
2145 $active && $groupData ? $o->{ui}->green('active ') :
2146 $groupData ? $o->{ui}->blue('backup ') :
2147 $active ? $o->{ui}->orange('weird ') :
2148 0 ▶ $o->{ui}->gray('idle ');
Branch: 4 branches
BranchTrueFalseTotal
$revoked ? : 0 0 0
$active && $groupData ? : 0 0 0
$groupData ? : 0 0 0
$active ? : 0 0 0
Condition0%0/3
$active and $groupData
!ll&&!rl&&r
000
MC/DC0%0/2
$active and $groupData
$active $groupData
Truth table0%0/3
A and B
A= $activeB= $groupData
ABresult
0X0
100
111
2149 }
2150  
2151 sub joinMember {
2152 0 ▶ my $o = shift;
Subroutine joinMember: not called CC=6 SCAR=37.4
2153 0 my $cmd = shift;
2154  
2155 0 $o->{accountTokens} = [];
2156 0 $cmd->collect($o);
2157  
2158 0 my $selector = $o->{actor}->actorGroupSelector;
2159 0 for my $accountToken (@{$o->{accountTokens}}) {
2160 0 my $actorHash = $accountToken->actorHash;
2161  
2162 # Get the public key
2163 0 my ($publicKey, $invalidReason, $storeError) = $o->{actor}->keyPair->getPublicKey($actorHash, $accountToken->cliStore);
2164 0 ▶ if (defined $storeError) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $storeError) 0 0 0
2165 0 $o->{ui}->pRed('Unable to get the public key of ', $actorHash->hex, ' from ', $accountToken->cliStore->url, ': ', $storeError);
2166 0 next;
2167 }
2168  
2169 0 ▶ if (defined $invalidReason) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $invalidReason) 0 0 0
2170 0 $o->{ui}->pRed('Unable to get the public key of ', $actorHash->hex, ' from ', $accountToken->cliStore->url, ': ', $invalidReason);
2171 0 next;
2172 }
2173  
2174 # Add or update this member
2175 0 my $label = substr($actorHash->bytes, 0, 16);
2176 0 my $actorSelector = $selector->child($label);
2177 0 my $wasMember = $actorSelector->isSet;
2178  
2179 0 my $record = CDS::Record->new;
2180 0 $record->add('hash')->addHash($actorHash);
2181 0 $record->add('store')->addText($accountToken->cliStore->url);
2182 0 $actorSelector->set($record);
2183 0 $actorSelector->addObject($publicKey->hash, $publicKey->object);
2184  
2185 0 ▶ $o->{ui}->pGreen('Updated ', $o->type($actorSelector), ' member ', $actorHash->hex, '.') if $wasMember;
Branch: 1 branch
BranchTrueFalseTotal
if $wasMember 0 0 0
2186 0 ▶ $o->{ui}->pGreen('Added ', $actorHash->hex, ' as ', $o->type($actorSelector), ' member of the actor group.') if ! $wasMember;
Branch: 1 branch
BranchTrueFalseTotal
unless $wasMember 0 0 0
2187 }
2188  
2189 # Save
2190 0 $o->{actor}->saveOrShowError;
2191 }
2192  
2193 sub setFlag {
2194 0 ▶ my $o = shift;
Subroutine setFlag: not called CC=4 SCAR=30.0
2195 0 ▶ my $actorSelector = shift; die 'wrong type '.ref($actorSelector).' for $actorSelector' if defined $actorSelector && ref $actorSelector ne 'CDS::Selector';
Branch: 1 branch
BranchTrueFalseTotal
if defined $actorSelector and ref $actorSelector ne "CDS::Selector" 0 0 0
Condition0%0/3
defined $actorSelector and ref $actorSelector ne "CDS::Selector"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $actorSelector and ref $actorSelector ne "CDS::Selector"
defined $actorSelector ref $actorSelector ne "CDS::Selector"
Truth table0%0/3
A and B
A= defined $actorSelectorB= ref $actorSelector ne "CDS::Selector"
ABresult
0X0
100
111
2196 0 my $label = shift;
2197 0 my $value = shift;
2198  
2199 0 my $child = $actorSelector->child($label);
2200 0 ▶ if ($value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value) { } 0 0 0
2201 0 $child->setBoolean(1);
2202 } else {
2203 0 $child->clear;
2204 }
2205 }
2206  
2207 sub setMember {
2208 0 ▶ my $o = shift;
Subroutine setMember: not called CC=4 SCAR=30.0
2209 0 my $cmd = shift;
2210  
2211 0 $o->{actorHashes} = [];
2212 0 $cmd->collect($o);
2213  
2214 0 my $selector = $o->{actor}->actorGroupSelector;
2215 0 for my $actorHash (@{$o->{actorHashes}}) {
2216 0 my $label = substr($actorHash->bytes, 0, 16);
2217 0 my $actorSelector = $selector->child($label);
2218  
2219 0 my $record = $actorSelector->record;
2220 0 my $hash = $record->child('hash')->hashValue;
2221 0 ▶ if (! $hash) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($hash) 0 0 0
2222 0 $o->{ui}->pRed($actorHash->hex, ' is not a member of our actor group.');
2223 0 next;
2224 }
2225  
2226 0 ▶ $o->setFlag($actorSelector, 'group data', $o->{status} eq 'active' || $o->{status} eq 'backup');
Condition0%0/3
$o->{'status'} eq 'active' || $o->{'status'} eq 'backup'
l!l&&r!l&&!r
000
MC/DC0%0/2
$o->{'status'} eq 'active' || $o->{'status'} eq 'backup'
$o->{'status'} eq 'active' $o->{'status'} eq 'backup'
Truth table0%0/3
A || B
A= $o->{'status'} eq 'active'B= $o->{'status'} eq 'backup'
ABresult
1X1
011
000
2227 0 $o->setFlag($actorSelector, 'active', $o->{status} eq 'active');
2228 0 $o->setFlag($actorSelector, 'revoked', $o->{status} eq 'revoked');
2229 0 $o->{ui}->pGreen($actorHash->hex, ' is now ', $o->type($actorSelector), '.');
2230 }
2231  
2232 # Save
2233 0 $o->{actor}->saveOrShowError;
2234 }
2235  
2236 # BEGIN AUTOGENERATED
2237 package CDS::Commands::Announce;
2238  
2239 sub register {
2240 0 ▶ my $class = shift;
Subroutine register: not called CC=1 SCAR=6.9
2241 0 my $cds = shift;
2242 0 my $help = shift;
2243  
2244 0 my $node000 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&help});
2245 0 my $node001 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&announceMe});
2246 0 my $node002 = CDS::Parser::Node->new(1);
2247 0 my $node003 = CDS::Parser::Node->new(0);
2248 0 my $node004 = CDS::Parser::Node->new(0);
2249 0 my $node005 = CDS::Parser::Node->new(0);
2250 0 my $node006 = CDS::Parser::Node->new(0);
2251 0 my $node007 = CDS::Parser::Node->new(0);
2252 0 my $node008 = CDS::Parser::Node->new(0);
2253 0 my $node009 = CDS::Parser::Node->new(0);
2254 0 my $node010 = CDS::Parser::Node->new(0);
2255 0 my $node011 = CDS::Parser::Node->new(0);
2256 0 my $node012 = CDS::Parser::Node->new(0);
2257 0 my $node013 = CDS::Parser::Node->new(1);
2258 0 my $node014 = CDS::Parser::Node->new(0);
2259 0 my $node015 = CDS::Parser::Node->new(0);
2260 0 my $node016 = CDS::Parser::Node->new(0);
2261 0 my $node017 = CDS::Parser::Node->new(0, {constructor => \&new, function => \&announceKeyPair});
2262 0 $cds->addArrow($node001, 1, 0, 'announce');
2263 0 $cds->addArrow($node002, 1, 0, 'announce');
2264 0 $help->addArrow($node000, 1, 0, 'announce');
2265 0 $node002->addArrow($node003, 1, 0, 'KEYPAIR', \&collectKeypair);
2266 0 $node003->addArrow($node004, 1, 0, 'on');
2267 0 $node004->addArrow($node005, 1, 0, 'STORE', \&collectStore);
2268 0 $node005->addArrow($node006, 1, 0, 'without');
2269 0 $node005->addArrow($node007, 1, 0, 'with');
2270 0 $node005->addDefault($node017);
2271 0 $node006->addArrow($node006, 1, 0, 'ACTOR', \&collectActor);
2272 0 $node006->addArrow($node017, 1, 0, 'ACTOR', \&collectActor);
2273 0 $node007->addArrow($node008, 1, 0, 'active', \&collectActive);
2274 0 $node007->addArrow($node008, 1, 0, 'entrusted', \&collectEntrusted);
2275 0 $node007->addArrow($node008, 1, 0, 'idle', \&collectIdle);
2276 0 $node007->addArrow($node008, 1, 0, 'revoked', \&collectRevoked);
2277 0 $node008->addDefault($node009);
2278 0 $node008->addDefault($node010);
2279 0 $node009->addArrow($node009, 1, 0, 'ACCOUNT', \&collectAccount);
2280 0 $node009->addArrow($node013, 1, 1, 'ACCOUNT', \&collectAccount);
2281 0 $node010->addArrow($node010, 1, 0, 'ACTOR', \&collectActor1);
2282 0 $node010->addArrow($node011, 1, 0, 'ACTOR', \&collectActor1);
2283 0 $node011->addArrow($node012, 1, 0, 'on');
2284 0 $node012->addArrow($node013, 1, 0, 'STORE', \&collectStore1);
2285 0 $node013->addArrow($node014, 1, 0, 'but');
2286 0 $node013->addArrow($node016, 1, 0, 'and');
2287 0 $node013->addDefault($node017);
2288 0 $node014->addArrow($node015, 1, 0, 'without');
2289 0 $node015->addArrow($node015, 1, 0, 'ACTOR', \&collectActor);
2290 0 $node015->addArrow($node017, 1, 0, 'ACTOR', \&collectActor);
2291 0 $node016->addDefault($node007);
2292 }
2293  
2294 sub collectAccount {
2295 0 ▶ my $o = shift;
Subroutine collectAccount: not called CC=1 SCAR=6.9
2296 0 my $label = shift;
2297 0 my $value = shift;
2298  
2299 0 push @{$o->{with}}, {status => $o->{status}, accountToken => $value};
2300 }
2301  
2302 sub collectActive {
2303 0 ▶ my $o = shift;
Subroutine collectActive: not called CC=1 SCAR=6.9
2304 0 my $label = shift;
2305 0 my $value = shift;
2306  
2307 0 $o->{status} = 'active';
2308 }
2309  
2310 sub collectActor {
2311 0 ▶ my $o = shift;
Subroutine collectActor: not called CC=1 SCAR=6.9
2312 0 my $label = shift;
2313 0 my $value = shift;
2314  
2315 0 $o->{without}->{$value->bytes} = $value;
2316 }
2317  
2318 sub collectActor1 {
2319 0 ▶ my $o = shift;
Subroutine collectActor1: not called CC=1 SCAR=6.9
2320 0 my $label = shift;
2321 0 my $value = shift;
2322  
2323 0 push @{$o->{actorHashes}}, $value;
2324 }
2325  
2326 sub collectEntrusted {
2327 0 ▶ my $o = shift;
Subroutine collectEntrusted: not called CC=1 SCAR=6.9
2328 0 my $label = shift;
2329 0 my $value = shift;
2330  
2331 0 $o->{status} = 'entrusted';
2332 }
2333  
2334 sub collectIdle {
2335 0 ▶ my $o = shift;
Subroutine collectIdle: not called CC=1 SCAR=6.9
2336 0 my $label = shift;
2337 0 my $value = shift;
2338  
2339 0 $o->{status} = 'idle';
2340 }
2341  
2342 sub collectKeypair {
2343 0 ▶ my $o = shift;
Subroutine collectKeypair: not called CC=1 SCAR=6.9
2344 0 my $label = shift;
2345 0 my $value = shift;
2346  
2347 0 $o->{keyPairToken} = $value;
2348 }
2349  
2350 sub collectRevoked {
2351 0 ▶ my $o = shift;
Subroutine collectRevoked: not called CC=1 SCAR=6.9
2352 0 my $label = shift;
2353 0 my $value = shift;
2354  
2355 0 $o->{status} = 'revoked';
2356 }
2357  
2358 sub collectStore {
2359 0 ▶ my $o = shift;
Subroutine collectStore: not called CC=1 SCAR=6.9
2360 0 my $label = shift;
2361 0 my $value = shift;
2362  
2363 0 $o->{store} = $value;
2364 }
2365  
2366 sub collectStore1 {
2367 0 ▶ my $o = shift;
Subroutine collectStore1: not called CC=2 SCAR=17.9
2368 0 my $label = shift;
2369 0 my $value = shift;
2370  
2371 0 for my $actorHash (@{$o->{actorHashes}}) {
2372 0 my $accountToken = CDS::AccountToken->new($value, $actorHash);
2373 0 push @{$o->{with}}, {status => $o->{status}, accountToken => $accountToken};
2374 }
2375  
2376 0 $o->{actorHashes} = [];
2377 }
2378  
2379 sub new {
2380 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
2381 0 my $actor = shift;
2382 0 bless {actor => $actor, ui => $actor->ui} }
2383  
2384 # END AUTOGENERATED
2385  
2386 # HTML FOLDER NAME announce
2387 # HTML TITLE Announce
2388 sub help {
2389 0 ▶ my $o = shift;
Subroutine help: not called CC=1 SCAR=6.9
2390 0 my $cmd = shift;
2391  
2392 0 my $ui = $o->{ui};
2393 0 $ui->space;
2394 0 $ui->command('cds announce');
2395 0 $ui->p('Announces yourself on your accounts.');
2396 0 $ui->space;
2397 0 $ui->command('cds announce KEYPAIR on STORE');
2398 0 $ui->command('… with (active|idle|revoked|entrusted) ACCOUNT*');
2399 0 $ui->command('… with (active|idle|revoked|entrusted) ACTOR* on STORE');
2400 0 $ui->command('… without ACTOR*');
2401 0 $ui->command('… with … and … and … but without …');
2402 0 $ui->p('Updates the public card of the indicated key pair on the indicated store. The indicated accounts are added or removed from the actor group on the card.');
2403 0 $ui->p('If no card exists, a minimalistic card is created.');
2404 0 $ui->p('Use this with care, as the generated card may not be compliant with the card produced by the actor.');
2405 0 $ui->space;
2406 }
2407  
2408 sub announceMe {
2409 0 ▶ my $o = shift;
Subroutine announceMe: not called CC=2 SCAR=17.9
2410 0 my $cmd = shift;
2411  
2412 0 $o->announceOnStore($o->{actor}->storageStore);
2413 0 ▶ $o->announceOnStore($o->{actor}->messagingStore) if $o->{actor}->messagingStore->id ne $o->{actor}->storageStore->id;
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"actor"}->messagingStore->id ne $o->{"actor"}->storageStore->id 0 0 0
2414 0 $o->{ui}->space;
2415 }
2416  
2417 sub announceOnStore {
2418 0 ▶ my $o = shift;
Subroutine announceOnStore: not called CC=3 SCAR=24.8
2419 0 my $store = shift;
2420  
2421 0 $o->{ui}->space;
2422 0 $o->{ui}->title($store->url);
2423 0 my ($envelopeHash, $cardHash, $invalidReason, $storeError) = $o->{actor}->announce($store);
2424 0 ▶ return if defined $storeError;
Branch: 1 branch
BranchTrueFalseTotal
if defined $storeError 0 0 0
2425 0 ▶ return $o->{ui}->pRed($invalidReason) if defined $invalidReason;
Branch: 1 branch
BranchTrueFalseTotal
if defined $invalidReason 0 0 0
2426 0 $o->{ui}->pGreen('Announced');
2427 }
2428  
2429 sub announceKeyPair {
2430 0 ▶ my $o = shift;
Subroutine announceKeyPair: not called CC=15 SCAR=54.8
2431 0 my $cmd = shift;
2432  
2433 0 $o->{actors} = [];
2434 0 $o->{with} = [];
2435 0 $o->{without} = {};
2436 0 $o->{now} = CDS->now;
2437 0 $cmd->collect($o);
2438  
2439 # List
2440 0 $o->{keyPair} = $o->{keyPairToken}->keyPair;
2441 0 my ($hashes, $listError) = $o->{store}->list($o->{keyPair}->publicKey->hash, 'public', 0, $o->{keyPair});
2442 0 ▶ return if defined $listError;
Branch: 1 branch
BranchTrueFalseTotal
if defined $listError 0 0 0
2443  
2444 # Check if there are more than one cards
2445 0 ▶ if (scalar @$hashes > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$hashes > 1) 0 0 0
2446 0 $o->{ui}->space;
2447 0 $o->{ui}->p('This account contains more than one public card:');
2448 0 $o->{ui}->pushIndent;
2449 0 for my $hash (@$hashes) {
2450 0 $o->{ui}->line($o->{ui}->gold('cds show card ', $hash->hex, ' on ', $o->{storeUrl}));
2451 }
2452 0 $o->{ui}->popIndent;
2453 0 $o->{ui}->p('Remove all but the most recent card. Cards can be removed as follows:');
2454 0 my $keyPairReference = $o->{actor}->blueKeyPairReference($o->{keyPairToken});
2455 0 $o->{ui}->line($o->{ui}->gold('cds remove ', 'HASH', ' on ', $o->{storeUrl}, ' using ', $keyPairReference));
2456 0 $o->{ui}->space;
2457 0 return;
2458 }
2459  
2460 # Read the card
2461 0 ▶ my $cardRecord = scalar @$hashes ? $o->readCard($hashes->[0]) : CDS::Record->new;
Branch: 1 branch
BranchTrueFalseTotal
scalar @$hashes ? : 0 0 0
2462 0 ▶ return if ! $cardRecord;
Branch: 1 branch
BranchTrueFalseTotal
unless $cardRecord 0 0 0
2463  
2464 # Parse
2465 0 my $builder = CDS::ActorGroupBuilder->new;
2466 0 $builder->parse($cardRecord, 0);
2467  
2468 # Apply the changes
2469 0 for my $change (@{$o->{with}}) {
2470 0 ▶ if ($change->{status} eq 'entrusted') {
Branch: 1 branch
BranchTrueFalseTotal
if ($change->{'status'} eq 'entrusted') { } 0 0 0
2471 0 $builder->addEntrustedActor($change->{accountToken}->cliStore->url, $change->{accountToken}->actorHash);
2472 0 $builder->{entrustedActorsRevision} = $o->{now};
2473 } else {
2474 0 $builder->addMember($change->{accountToken}->cliStore->url, $change->{accountToken}->actorHash, $o->{now}, $change->{status});
2475 }
2476 }
2477  
2478 0 for my $hash (values %{$o->{without}}) {
2479 0 $builder->removeEntrustedActor($hash)
2480 }
2481  
2482 0 for my $member ($builder->members) {
2483 0 ▶ next if ! $o->{without}->{$member->hash->bytes};
Branch: 1 branch
BranchTrueFalseTotal
unless $o->{"without"}{$member->hash->bytes} 0 0 0
2484 0 $builder->removeMember($member->storeUrl, $member->hash);
2485 }
2486  
2487 # Write the new card
2488 0 my $newCard = $builder->toRecord(0);
2489 0 $newCard->add('public key')->addHash($o->{keyPair}->publicKey->hash);
2490  
2491 0 for my $child ($cardRecord->children) {
2492 0 ▶ if ($child->bytes eq 'actor group') {
Branch: 3 branches
BranchTrueFalseTotal
if ($child->bytes eq 'actor group') { } 0 0 0
elsif ($child->bytes eq 'entrusted actors') { } 0 0 0
elsif ($child->bytes eq 'public key') { } 0 0 0
2493 } elsif ($child->bytes eq 'entrusted actors') {
2494 } elsif ($child->bytes eq 'public key') {
2495 } else {
2496 0 $newCard->addRecord($child);
2497 }
2498 }
2499  
2500 0 $o->announce($newCard, $hashes);
2501 }
2502  
2503 sub readCard {
2504 0 ▶ my $o = shift;
Subroutine readCard: not called CC=11 SCAR=48.8
2505 0 ▶ my $envelopeHash = shift; die 'wrong type '.ref($envelopeHash).' for $envelopeHash' if defined $envelopeHash && ref $envelopeHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $envelopeHash and ref $envelopeHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $envelopeHash and ref $envelopeHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $envelopeHash and ref $envelopeHash ne "CDS::Hash"
defined $envelopeHash ref $envelopeHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $envelopeHashB= ref $envelopeHash ne "CDS::Hash"
ABresult
0X0
100
111
2506  
2507 # Open the envelope
2508 0 my ($object, $storeError) = $o->{store}->get($envelopeHash, $o->{keyPair});
2509 0 ▶ return if defined $storeError;
Branch: 1 branch
BranchTrueFalseTotal
if defined $storeError 0 0 0
2510 0 ▶ return $o->{ui}->error('Envelope object ', $envelopeHash->hex, ' not found.') if ! $object;
Branch: 1 branch
BranchTrueFalseTotal
unless $object 0 0 0
2511  
2512 0 ▶ my $envelope = CDS::Record->fromObject($object) // return $o->{ui}->error($envelopeHash->hex, ' is not a record.');
Condition0%0/2
"CDS::Record"->fromObject($object) // (return $o->{"ui"}->error($envelopeHash->hex, " is not a record."))
l!l
00
MC/DC0%0/1
"CDS::Record"->fromObject($object) // (return $o->{"ui"}->error($envelopeHash->hex, " is not a record."))
"CDS::Record"->fromObject($object)
Truth table0%0/2
A
A= "CDS::Record"->fromObject($object)
Aresult
11
00
2513 0 ▶ my $cardHash = $envelope->child('content')->hashValue // return $o->{ui}->error($envelopeHash->hex, ' is not a valid envelope, because it has no content hash.');
Condition0%0/2
$envelope->child("content")->hashValue // (return $o->{"ui"}->error($envelopeHash->hex, " is not a valid envelope, because it has no content hash."))
l!l
00
MC/DC0%0/1
$envelope->child("content")->hashValue // (return $o->{"ui"}->error($envelopeHash->hex, " is not a valid envelope, because it has no content hash."))
$envelope->child("content")->hashValue
Truth table0%0/2
A
A= $envelope->child("content")->hashValue
Aresult
11
00
2514 0 ▶ return $o->{ui}->error($envelopeHash->hex, ' has an invalid signature.') if ! CDS->verifyEnvelopeSignature($envelope, $o->{keyPair}->publicKey, $cardHash);
Branch: 1 branch
BranchTrueFalseTotal
unless "CDS"->verifyEnvelopeSignature($envelope, $o->{"keyPair"}->publicKey, $cardHash) 0 0 0
2515  
2516 # Read the card
2517 0 my ($cardObject, $storeError1) = $o->{store}->get($cardHash, $o->{keyPair});
2518 0 ▶ return if defined $storeError1;
Branch: 1 branch
BranchTrueFalseTotal
if defined $storeError1 0 0 0
2519 0 ▶ return $o->{ui}->error('Card object ', $cardHash->hex, ' not found.') if ! $cardObject;
Branch: 1 branch
BranchTrueFalseTotal
unless $cardObject 0 0 0
2520  
2521 0 ▶ return CDS::Record->fromObject($cardObject) // return $o->{ui}->error($cardHash->hex, ' is not a record.');
Condition0%0/2
"CDS::Record"->fromObject($cardObject) // (return $o->{"ui"}->error($cardHash->hex, " is not a record."))
l!l
00
MC/DC0%0/1
"CDS::Record"->fromObject($cardObject) // (return $o->{"ui"}->error($cardHash->hex, " is not a record."))
"CDS::Record"->fromObject($cardObject)
Truth table0%0/2
A
A= "CDS::Record"->fromObject($cardObject)
Aresult
11
00
2522 }
2523  
2524 sub applyChanges {
2525 0 ▶ my $o = shift;
Subroutine applyChanges: not called CC=4 SCAR=30.0
2526 0 ▶ my $actorGroup = shift; die 'wrong type '.ref($actorGroup).' for $actorGroup' if defined $actorGroup && ref $actorGroup ne 'CDS::ActorGroup';
Branch: 1 branch
BranchTrueFalseTotal
if defined $actorGroup and ref $actorGroup ne "CDS::ActorGroup" 0 0 0
Condition0%0/3
defined $actorGroup and ref $actorGroup ne "CDS::ActorGroup"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $actorGroup and ref $actorGroup ne "CDS::ActorGroup"
defined $actorGroup ref $actorGroup ne "CDS::ActorGroup"
Truth table0%0/3
A and B
A= defined $actorGroupB= ref $actorGroup ne "CDS::ActorGroup"
ABresult
0X0
100
111
2527 0 my $status = shift;
2528 0 my $accounts = shift;
2529  
2530 0 for my $account (@$accounts) {
2531 0 $actorGroup->{$account->url} = {storeUrl => $account->cliStore->url, actorHash => $account->actorHash, revision => $o->{now}, status => $status};
2532 }
2533 }
2534  
2535 sub announce {
2536 0 ▶ my $o = shift;
Subroutine announce: not called CC=5 SCAR=34.0
2537 0 my $card = shift;
2538 0 my $sourceHashes = shift;
2539  
2540 0 my $inMemoryStore = CDS::InMemoryStore->create;
2541  
2542 # Serialize the card
2543 0 my $cardObject = $card->toObject;
2544 0 my $cardHash = $cardObject->calculateHash;
2545 0 $inMemoryStore->put($cardHash, $cardObject);
2546 0 $inMemoryStore->put($o->{keyPair}->publicKey->hash, $o->{keyPair}->publicKey->object);
2547  
2548 # Prepare the public envelope
2549 0 my $envelopeObject = $o->{keyPair}->createPublicEnvelope($cardHash)->toObject;
2550 0 my $envelopeHash = $envelopeObject->calculateHash;
2551 0 $inMemoryStore->put($envelopeHash, $envelopeObject);
2552  
2553 # Transfer
2554 0 my ($missingHash, $failedStore, $storeError) = $o->{keyPair}->transfer([$envelopeHash], $inMemoryStore, $o->{store});
2555 0 ▶ return if $storeError;
Branch: 1 branch
BranchTrueFalseTotal
if $storeError 0 0 0
2556 0 ▶ return $o->{ui}->pRed('Object ', $missingHash, ' is missing.') if $missingHash;
Branch: 1 branch
BranchTrueFalseTotal
if $missingHash 0 0 0
2557  
2558 # Modify
2559 0 my $modifications = CDS::StoreModifications->new;
2560 0 $modifications->add($o->{keyPair}->publicKey->hash, 'public', $envelopeHash);
2561 0 for my $hash (@$sourceHashes) {
2562 0 $modifications->remove($o->{keyPair}->publicKey->hash, 'public', $hash);
2563 }
2564  
2565 0 my $modifyError = $o->{store}->modify($modifications, $o->{keyPair});
2566 0 ▶ return if $modifyError;
Branch: 1 branch
BranchTrueFalseTotal
if $modifyError 0 0 0
2567  
2568 0 $o->{ui}->pGreen('Announced on ', $o->{store}->url, '.');
2569 }
2570  
2571 # BEGIN AUTOGENERATED
2572 package CDS::Commands::Book;
2573  
2574 sub register {
2575 0 ▶ my $class = shift;
Subroutine register: not called CC=1 SCAR=6.9
2576 0 my $cds = shift;
2577 0 my $help = shift;
2578  
2579 0 my $node000 = CDS::Parser::Node->new(0);
2580 0 my $node001 = CDS::Parser::Node->new(0);
2581 0 my $node002 = CDS::Parser::Node->new(0);
2582 0 my $node003 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&help});
2583 0 my $node004 = CDS::Parser::Node->new(0);
2584 0 my $node005 = CDS::Parser::Node->new(0);
2585 0 my $node006 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&book});
2586 0 $cds->addArrow($node000, 1, 0, 'book');
2587 0 $cds->addArrow($node001, 1, 0, 'book');
2588 0 $cds->addArrow($node002, 1, 0, 'book');
2589 0 $help->addArrow($node003, 1, 0, 'book');
2590 0 $node000->addArrow($node000, 1, 0, 'HASH', \&collectHash);
2591 0 $node000->addArrow($node004, 1, 0, 'HASH', \&collectHash);
2592 0 $node001->addArrow($node001, 1, 0, 'OBJECT', \&collectObject);
2593 0 $node001->addArrow($node006, 1, 0, 'OBJECT', \&collectObject);
2594 0 $node002->addArrow($node002, 1, 0, 'HASH', \&collectHash);
2595 0 $node002->addArrow($node006, 1, 0, 'HASH', \&collectHash);
2596 0 $node004->addArrow($node005, 1, 0, 'on');
2597 0 $node005->addArrow($node005, 1, 0, 'STORE', \&collectStore);
2598 0 $node005->addArrow($node006, 1, 0, 'STORE', \&collectStore);
2599 }
2600  
2601 sub collectHash {
2602 0 ▶ my $o = shift;
Subroutine collectHash: not called CC=1 SCAR=6.9
2603 0 my $label = shift;
2604 0 my $value = shift;
2605  
2606 0 push @{$o->{hashes}}, $value;
2607 }
2608  
2609 sub collectObject {
2610 0 ▶ my $o = shift;
Subroutine collectObject: not called CC=1 SCAR=6.9
2611 0 my $label = shift;
2612 0 my $value = shift;
2613  
2614 0 push @{$o->{objectTokens}}, $value;
2615 }
2616  
2617 sub collectStore {
2618 0 ▶ my $o = shift;
Subroutine collectStore: not called CC=1 SCAR=6.9
2619 0 my $label = shift;
2620 0 my $value = shift;
2621  
2622 0 push @{$o->{stores}}, $value;
2623 }
2624  
2625 sub new {
2626 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
2627 0 my $actor = shift;
2628 0 bless {actor => $actor, ui => $actor->ui} }
2629  
2630 # END AUTOGENERATED
2631  
2632 # HTML FOLDER NAME store-book
2633 # HTML TITLE Book
2634 sub help {
2635 0 ▶ my $o = shift;
Subroutine help: not called CC=1 SCAR=6.9
2636 0 my $cmd = shift;
2637  
2638 0 my $ui = $o->{ui};
2639 0 $ui->space;
2640 0 $ui->command('cds book OBJECT*');
2641 0 $ui->command('cds book HASH* on STORE*');
2642 0 $ui->p('Books all indicated objects and reports whether booking as successful.');
2643 0 $ui->space;
2644 0 $ui->command('cds book HASH*');
2645 0 $ui->p('As above, but uses the selected store.');
2646 0 $ui->space;
2647 }
2648  
2649 sub book {
2650 0 ▶ my $o = shift;
Subroutine book: not called CC=8 SCAR=42.8
2651 0 my $cmd = shift;
2652  
2653 0 $o->{keyPair} = $o->{actor}->preferredKeyPairToken->keyPair;
2654 0 $o->{hashes} = [];
2655 0 $o->{stores} = [];
2656 0 $o->{objectTokens} = [];
2657 0 $cmd->collect($o);
2658  
2659 # Use the selected store
2660 0 ▶ push @{$o->{stores}}, $o->{actor}->preferredStore if ! scalar @{$o->{stores}};
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @{$o->{"stores"};} 0 0 0
2661  
2662 # Book all hashes on all stores
2663 0 my %triedStores;
2664 0 for my $store (@{$o->{stores}}) {
2665 0 ▶ next if $triedStores{$store->url};
Branch: 1 branch
BranchTrueFalseTotal
if $triedStores{$store->url} 0 0 0
2666 0 $triedStores{$store->url} = 1;
2667 0 for my $hash (@{$o->{hashes}}) {
2668 0 $o->process($store, $hash);
2669 }
2670 }
2671  
2672 # Book the direct object references
2673 0 for my $objectToken (@{$o->{objectTokens}}) {
2674 0 $o->process($objectToken->cliStore, $objectToken->hash);
2675 }
2676  
2677 # Warn the user if no key pair is selected
2678 0 ▶ return if ! $o->{hasErrors};
Branch: 1 branch
BranchTrueFalseTotal
unless $o->{"hasErrors"} 0 0 0
2679 0 ▶ return if $o->{keyPair};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"keyPair"} 0 0 0
2680 0 $o->{ui}->space;
2681 0 $o->{ui}->warning('Since no key pair is selected, the bookings were requested without signature. Stores are more likely to accept signed bookings. To add a signature, select a key pair using "cds use …", or create your key pair using "cds create my key pair".');
2682 }
2683  
2684 sub process {
2685 0 ▶ my $o = shift;
Subroutine process: not called CC=4 SCAR=30.0
2686 0 my $store = shift;
2687 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
2688  
2689 # Upload the object
2690 0 my $success = $store->book($hash, $o->{keyPair});
2691 0 ▶ if ($success) {
Branch: 1 branch
BranchTrueFalseTotal
if ($success) { } 0 0 0
2692 0 $o->{ui}->line($o->{ui}->green('OK '), $hash->hex, ' on ', $store->url);
2693 } else {
2694 0 $o->{ui}->line($o->{ui}->red('not found '), $hash->hex, ' on ', $store->url);
2695 0 $o->{hasErrors} = 1;
2696 }
2697 }
2698  
2699 # BEGIN AUTOGENERATED
2700 package CDS::Commands::CheckKeyPair;
2701  
2702 sub register {
2703 0 ▶ my $class = shift;
Subroutine register: not called CC=1 SCAR=6.9
2704 0 my $cds = shift;
2705 0 my $help = shift;
2706  
2707 0 my $node000 = CDS::Parser::Node->new(0);
2708 0 my $node001 = CDS::Parser::Node->new(0);
2709 0 my $node002 = CDS::Parser::Node->new(0);
2710 0 my $node003 = CDS::Parser::Node->new(0);
2711 0 my $node004 = CDS::Parser::Node->new(0);
2712 0 my $node005 = CDS::Parser::Node->new(0);
2713 0 my $node006 = CDS::Parser::Node->new(0);
2714 0 my $node007 = CDS::Parser::Node->new(0);
2715 0 my $node008 = CDS::Parser::Node->new(0);
2716 0 my $node009 = CDS::Parser::Node->new(0);
2717 0 my $node010 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&help});
2718 0 my $node011 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&checkKeyPair});
2719 0 $cds->addArrow($node004, 1, 0, 'check');
2720 0 $cds->addArrow($node005, 1, 0, 'fix');
2721 0 $help->addArrow($node000, 1, 0, 'check');
2722 0 $help->addArrow($node001, 1, 0, 'fix');
2723 0 $node000->addArrow($node002, 1, 0, 'key');
2724 0 $node001->addArrow($node003, 1, 0, 'key');
2725 0 $node002->addArrow($node010, 1, 0, 'pair');
2726 0 $node003->addArrow($node010, 1, 0, 'pair');
2727 0 $node004->addArrow($node006, 1, 0, 'key');
2728 0 $node005->addArrow($node007, 1, 0, 'key');
2729 0 $node006->addArrow($node008, 1, 0, 'pair');
2730 0 $node007->addArrow($node009, 1, 0, 'pair');
2731 0 $node008->addArrow($node011, 1, 0, 'FILE', \&collectFile);
2732 0 $node009->addArrow($node011, 1, 0, 'FILE', \&collectFile1);
2733 }
2734  
2735 sub collectFile {
2736 0 ▶ my $o = shift;
Subroutine collectFile: not called CC=1 SCAR=6.9
2737 0 my $label = shift;
2738 0 my $value = shift;
2739  
2740 0 $o->{file} = $value;
2741 }
2742  
2743 sub collectFile1 {
2744 0 ▶ my $o = shift;
Subroutine collectFile1: not called CC=1 SCAR=6.9
2745 0 my $label = shift;
2746 0 my $value = shift;
2747  
2748 0 $o->{file} = $value;
2749 0 $o->{fix} = 1;
2750 }
2751  
2752 sub new {
2753 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
2754 0 my $actor = shift;
2755 0 bless {actor => $actor, ui => $actor->ui} }
2756  
2757 # END AUTOGENERATED
2758  
2759 # HTML FOLDER NAME check-key-pair
2760 # HTML TITLE Check key pair
2761 sub help {
2762 0 ▶ my $o = shift;
Subroutine help: not called CC=1 SCAR=6.9
2763 0 my $cmd = shift;
2764  
2765 0 my $ui = $o->{ui};
2766 0 $ui->space;
2767 0 $ui->command('cds check key pair FILE');
2768 0 $ui->p('Checks if the key pair FILE is complete, i.e. that a valid private key and a matching public key exists.');
2769 0 $ui->space;
2770 }
2771  
2772 sub checkKeyPair {
2773 0 ▶ my $o = shift;
Subroutine checkKeyPair: not called CC=14 SCAR=53.5
2774 0 my $cmd = shift;
2775  
2776 0 $cmd->collect($o);
2777  
2778 # Check if we have a complete private key
2779 0 ▶ my $bytes = CDS->readBytesFromFile($o->{file}) // return $o->{ui}->error('The file "', $o->{file}, '" cannot be read.');
Condition0%0/2
"CDS"->readBytesFromFile($o->{"file"}) // (return $o->{"ui"}->error("The file \"", $o->{"file"}, "\" cannot be read."))
l!l
00
MC/DC0%0/1
"CDS"->readBytesFromFile($o->{"file"}) // (return $o->{"ui"}->error("The file \"", $o->{"file"}, "\" cannot be read."))
"CDS"->readBytesFromFile($o->{"file"})
Truth table0%0/2
A
A= "CDS"->readBytesFromFile($o->{"file"})
Aresult
11
00
2780 0 my $record = CDS::Record->fromObject(CDS::Object->fromBytes($bytes));
2781  
2782 0 my $rsaKey = $record->child('rsa key');
2783 0 my $e = $rsaKey->child('e')->bytesValue;
2784 0 ▶ return $o->{ui}->error('The exponent "e" of the private key is missing.') if ! length $e;
Branch: 1 branch
BranchTrueFalseTotal
unless length $e 0 0 0
2785 0 my $p = $rsaKey->child('p')->bytesValue;
2786 0 ▶ return $o->{ui}->error('The prime "p" of the private key is missing.') if ! length $p;
Branch: 1 branch
BranchTrueFalseTotal
unless length $p 0 0 0
2787 0 my $q = $rsaKey->child('q')->bytesValue;
2788 0 ▶ return $o->{ui}->error('The prime "q" of the private key is missing.') if ! length $q;
Branch: 1 branch
BranchTrueFalseTotal
unless length $q 0 0 0
2789 0 $o->{ui}->pGreen('The private key is complete.');
2790  
2791 # Derive the public key
2792 0 my $privateKey = CDS::C::privateKeyNew($e, $p, $q);
2793 0 my $publicKey = CDS::C::publicKeyFromPrivateKey($privateKey);
2794 0 my $n = CDS::C::publicKeyN($publicKey);
2795  
2796 # Check if we have a matching public key
2797 0 my $publicKeyObjectBytes = $record->child('public key object')->bytesValue;
2798 0 ▶ return $o->{ui}->error('The public key is missing.') if ! length $publicKeyObjectBytes;
Branch: 1 branch
BranchTrueFalseTotal
unless length $publicKeyObjectBytes 0 0 0
2799 0 ▶ $o->{publicKeyObject} = CDS::Object->fromBytes($publicKeyObjectBytes) // return $o->{ui}->error('The public key is is not a valid Condensation object.');
Condition0%0/2
"CDS::Object"->fromBytes($publicKeyObjectBytes) // (return $o->{"ui"}->error("The public key is is not a valid Condensation object."))
l!l
00
MC/DC0%0/1
"CDS::Object"->fromBytes($publicKeyObjectBytes) // (return $o->{"ui"}->error("The public key is is not a valid Condensation object."))
"CDS::Object"->fromBytes($publicKeyObjectBytes)
Truth table0%0/2
A
A= "CDS::Object"->fromBytes($publicKeyObjectBytes)
Aresult
11
00
2800 0 $o->{publicKeyHash} = $o->{publicKeyObject}->calculateHash;
2801 0 my $publicKeyRecord = CDS::Record->fromObject($o->{publicKeyObject});
2802 0 ▶ return $o->{ui}->error('The public key is not a valid record.') if ! $publicKeyRecord;
Branch: 1 branch
BranchTrueFalseTotal
unless $publicKeyRecord 0 0 0
2803 0 my $publicN = $publicKeyRecord->child('n')->bytesValue;
2804 0 ▶ return $o->{ui}->error('The modulus "n" of the public key is missing.') if ! length $publicN;
Branch: 1 branch
BranchTrueFalseTotal
unless length $publicN 0 0 0
2805 0 ▶ my $publicE = $publicKeyRecord->child('e')->bytesValue // $o->{ui}->error('The public key is incomplete.');
Condition0%0/3
$publicKeyRecord->child("e")->bytesValue // $o->{"ui"}->error("The public key is incomplete.")
l!l&&r!l&&!r
000
MC/DC0%0/2
$publicKeyRecord->child("e")->bytesValue // $o->{"ui"}->error("The public key is incomplete.")
$publicKeyRecord->child("e")->bytesValue $o->{"ui"}->error("The public key is incomplete.")
Truth table0%0/3
A // B
A= $publicKeyRecord->child("e")->bytesValueB= $o->{"ui"}->error("The public key is incomplete.")
ABresult
1X1
011
000
2806 0 ▶ return $o->{ui}->error('The exponent "e" of the public key is missing.') if ! length $publicE;
Branch: 1 branch
BranchTrueFalseTotal
unless length $publicE 0 0 0
2807 0 ▶ return $o->{ui}->error('The exponent "e" of the public key does not match the exponent "e" of the private key.') if $publicE ne $e;
Branch: 1 branch
BranchTrueFalseTotal
if $publicE ne $e 0 0 0
2808 0 ▶ return $o->{ui}->error('The modulus "n" of the public key does not correspond to the primes "p" and "q" of the private key.') if $publicN ne $n;
Branch: 1 branch
BranchTrueFalseTotal
if $publicN ne $n 0 0 0
2809 0 $o->{ui}->pGreen('The public key ', $o->{publicKeyHash}->hex, ' is complete.');
2810  
2811 # At this point, the configuration looks good, and we can load the key pair
2812 0 ▶ CDS::KeyPair->fromRecord($record) // $o->{ui}->error('Your key pair looks complete, but could not be loaded.');
Condition0%0/3
"CDS::KeyPair"->fromRecord($record) // $o->{"ui"}->error("Your key pair looks complete, but could not be loaded.")
l!l&&r!l&&!r
000
MC/DC0%0/2
"CDS::KeyPair"->fromRecord($record) // $o->{"ui"}->error("Your key pair looks complete, but could not be loaded.")
"CDS::KeyPair"->fromRecord($record) $o->{"ui"}->error("Your key pair looks complete, but could not be loaded.")
Truth table0%0/3
A // B
A= "CDS::KeyPair"->fromRecord($record)B= $o->{"ui"}->error("Your key pair looks complete, but could not be loaded.")
ABresult
1X1
011
000
2813 }
2814  
2815 # BEGIN AUTOGENERATED
2816 package CDS::Commands::CollectGarbage;
2817  
2818 sub register {
2819 0 ▶ my $class = shift;
Subroutine register: not called CC=1 SCAR=6.9
2820 0 my $cds = shift;
2821 0 my $help = shift;
2822  
2823 0 my $node000 = CDS::Parser::Node->new(0);
2824 0 my $node001 = CDS::Parser::Node->new(0);
2825 0 my $node002 = CDS::Parser::Node->new(0);
2826 0 my $node003 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&help});
2827 0 my $node004 = CDS::Parser::Node->new(0, {constructor => \&new, function => \&collectGarbage});
2828 0 my $node005 = CDS::Parser::Node->new(0);
2829 0 my $node006 = CDS::Parser::Node->new(0, {constructor => \&new, function => \&reportGarbage});
2830 0 my $node007 = CDS::Parser::Node->new(0);
2831 0 my $node008 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&collectGarbage});
2832 0 my $node009 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&reportGarbage});
2833 0 $cds->addArrow($node001, 1, 0, 'report');
2834 0 $cds->addArrow($node002, 1, 0, 'collect');
2835 0 $help->addArrow($node000, 1, 0, 'collect');
2836 0 $node000->addArrow($node003, 1, 0, 'garbage');
2837 0 $node001->addArrow($node006, 1, 0, 'garbage');
2838 0 $node002->addArrow($node004, 1, 0, 'garbage');
2839 0 $node004->addArrow($node005, 1, 0, 'of');
2840 0 $node004->addDefault($node008);
2841 0 $node005->addArrow($node008, 1, 0, 'STORE', \&collectStore);
2842 0 $node006->addArrow($node007, 1, 0, 'of');
2843 0 $node006->addDefault($node009);
2844 0 $node007->addArrow($node009, 1, 0, 'STORE', \&collectStore);
2845 }
2846  
2847 sub collectStore {
2848 0 ▶ my $o = shift;
Subroutine collectStore: not called CC=1 SCAR=6.9
2849 0 my $label = shift;
2850 0 my $value = shift;
2851  
2852 0 $o->{store} = $value;
2853 }
2854  
2855 sub new {
2856 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
2857 0 my $actor = shift;
2858 0 bless {actor => $actor, ui => $actor->ui} }
2859  
2860 # END AUTOGENERATED
2861  
2862 # HTML FOLDER NAME collect-garbage
2863 # HTML TITLE Garbage collection
2864 sub help {
2865 0 ▶ my $o = shift;
Subroutine help: not called CC=1 SCAR=6.9
2866 0 my $cmd = shift;
2867  
2868 0 my $ui = $o->{ui};
2869 0 $ui->space;
2870 0 $ui->command('cds collect garbage [of STORE]');
2871 0 $ui->p('Runs garbage collection. STORE must be a folder store. Objects not in use, and older than 1 day are removed from the store.');
2872 0 $ui->p('If no store is provided, garbage collection is run on the selected store, or the actor\'s storage store.');
2873 0 $ui->space;
2874 0 $ui->p('The store must not be written to while garbage collection is running. Objects booked during garbage collection may get deleted, and leave the store in a corrupt state. Reading from the store is fine.');
2875 0 $ui->space;
2876 0 $ui->command('cds report garbage [of STORE]');
2877 0 $ui->p('As above, but reports obsolete objects rather than deleting them. A protocol (shell script) is written to ".garbage" in the store folder.');
2878 0 $ui->space;
2879 }
2880  
2881 sub collectGarbage {
2882 0 ▶ my $o = shift;
Subroutine collectGarbage: not called CC=1 SCAR=6.9
2883 0 my $cmd = shift;
2884  
2885 0 $cmd->collect($o);
2886 0 $o->run(CDS::Commands::CollectGarbage::Delete->new($o->{ui}));
2887 }
2888  
2889 sub wrapUpDeletion {
2890 0 ▶ my $o = shift;
Subroutine wrapUpDeletion: not called CC=1 SCAR=6.9
2891 }
2892  
2893 sub reportGarbage {
2894 0 ▶ my $o = shift;
Subroutine reportGarbage: not called CC=1 SCAR=6.9
2895 0 my $cmd = shift;
2896  
2897 0 $cmd->collect($o);
2898 0 $o->run(CDS::Commands::CollectGarbage::Report->new($o->{ui}));
2899 0 $o->{ui}->space;
2900 }
2901  
2902 # Creates a folder with the selected permissions.
2903 sub run {
2904 0 ▶ my $o = shift;
Subroutine run: not called CC=31 SCAR=69.0
2905 0 my $handler = shift;
2906  
2907 # Prepare
2908 0 ▶ my $store = $o->{store} // $o->{actor}->selectedStore // $o->{actor}->storageStore;
Condition0%0/6
($o->{"store"} // $o->{"actor"}->selectedStore) // $o->{"actor"}->storageStore
l!l&&r!l&&!r
000
$o->{"store"} // $o->{"actor"}->selectedStore
l!l&&r!l&&!r
000
MC/DC0%0/3
($o->{"store"} // $o->{"actor"}->selectedStore) // $o->{"actor"}->storageStore
$o->{"store"} $o->{"actor"}->selectedStore $o->{"actor"}->storageStore
Truth table0%0/4
A // B // C
A= $o->{"store"}B= $o->{"actor"}->selectedStoreC= $o->{"actor"}->storageStore
ABCresult
1XX1
01X1
0011
0000
2909 0 ▶ my $folderStore = CDS::FolderStore->forUrl($store->url) // return $o->{ui}->error('"', $store->url, '" is not a folder store.');
Condition0%0/2
"CDS::FolderStore"->forUrl($store->url) // (return $o->{"ui"}->error("\"", $store->url, "\" is not a folder store."))
l!l
00
MC/DC0%0/1
"CDS::FolderStore"->forUrl($store->url) // (return $o->{"ui"}->error("\"", $store->url, "\" is not a folder store."))
"CDS::FolderStore"->forUrl($store->url)
Truth table0%0/2
A
A= "CDS::FolderStore"->forUrl($store->url)
Aresult
11
00
2910 0 ▶ $handler->initialize($folderStore) // return;
Condition0%0/2
$handler->initialize($folderStore) // (return)
l!l
00
MC/DC0%0/1
$handler->initialize($folderStore) // (return)
$handler->initialize($folderStore)
Truth table0%0/2
A
A= $handler->initialize($folderStore)
Aresult
11
00
2911  
2912 0 $o->{storeFolder} = $folderStore->folder;
2913 0 $o->{accountsFolder} = $folderStore->folder.'/accounts';
2914 0 $o->{objectsFolder} = $folderStore->folder.'/objects';
2915 0 my $dateLimit = time - 86400;
2916 0 my $envelopeExpirationLimit = time * 1000;
2917  
2918 # Read the tree index
2919 0 $o->readIndex;
2920  
2921 # Process all accounts
2922 0 $o->{ui}->space;
2923 0 $o->{ui}->title($o->{ui}->left(64, 'Accounts'), ' ', $o->{ui}->right(10, 'messages'), ' ', $o->{ui}->right(10, 'private'), ' ', $o->{ui}->right(10, 'public'), ' ', 'last modification');
2924 0 $o->startProgress('accounts');
2925 0 $o->{usedHashes} = {};
2926 0 $o->{missingObjects} = {};
2927 0 $o->{brokenOrigins} = {};
2928 0 my $countAccounts = 0;
2929 0 my $countKeptEnvelopes = 0;
2930 0 my $countDeletedEnvelopes = 0;
2931 0 for my $accountHash (sort { $$a cmp $$b } $folderStore->accounts) {
2932 # This would be the private key, but we don't use it right now
2933 0 $o->{usedHashes}->{$accountHash->hex} = 1;
2934  
2935 0 my $newestDate = 0;
2936 0 my %sizeByBox;
2937 0 my $accountFolder = $o->{accountsFolder}.'/'.$accountHash->hex;
2938 0 foreach my $boxLabel (CDS->listFolder($accountFolder)) {
2939 0 ▶ next if $boxLabel =~ /^\./;
Branch: 1 branch
BranchTrueFalseTotal
if $boxLabel =~ /^\./ 0 0 0
2940 0 my $boxFolder = $accountFolder.'/'.$boxLabel;
2941 0 my $date = &lastModified($boxFolder);
2942 0 ▶ $newestDate = $date if $newestDate < $date;
Branch: 1 branch
BranchTrueFalseTotal
if $newestDate < $date 0 0 0
2943 0 my $size = 0;
2944 0 foreach my $filename (CDS->listFolder($boxFolder)) {
2945 0 ▶ next if $filename =~ /^\./;
Branch: 1 branch
BranchTrueFalseTotal
if $filename =~ /^\./ 0 0 0
2946 0 my $hash = pack('H*', $filename);
2947 0 my $file = $boxFolder.'/'.$filename;
2948  
2949 0 my $timestamp = $o->envelopeExpiration($hash, $boxFolder);
2950 0 ▶ if ($timestamp > 0 && $timestamp < $envelopeExpirationLimit) {
Branch: 1 branch
BranchTrueFalseTotal
if ($timestamp > 0 and $timestamp < $envelopeExpirationLimit) 0 0 0
Condition0%0/3
$timestamp > 0 and $timestamp < $envelopeExpirationLimit
!ll&&!rl&&r
000
MC/DC0%0/2
$timestamp > 0 and $timestamp < $envelopeExpirationLimit
$timestamp > 0 $timestamp < $envelopeExpirationLimit
Truth table0%0/3
A and B
A= $timestamp > 0B= $timestamp < $envelopeExpirationLimit
ABresult
0X0
100
111
2951 0 $countDeletedEnvelopes += 1;
2952 0 ▶ $handler->deleteEnvelope($file) // return;
Condition0%0/2
$handler->deleteEnvelope($file) // (return)
l!l
00
MC/DC0%0/1
$handler->deleteEnvelope($file) // (return)
$handler->deleteEnvelope($file)
Truth table0%0/2
A
A= $handler->deleteEnvelope($file)
Aresult
11
00
2953 0 next;
2954 }
2955  
2956 0 $countKeptEnvelopes += 1;
2957 0 my $date = &lastModified($file);
2958 0 ▶ $newestDate = $date if $newestDate < $date;
Branch: 1 branch
BranchTrueFalseTotal
if $newestDate < $date 0 0 0
2959 0 $size += $o->traverse($hash, $boxFolder);
2960 }
2961 0 $sizeByBox{$boxLabel} = $size;
2962 }
2963  
2964 $o->{ui}->line($accountHash->hex, ' ',
2965 $o->{ui}->right(10, $o->{ui}->niceFileSize($sizeByBox{'messages'} || 0)), ' ',
2966 $o->{ui}->right(10, $o->{ui}->niceFileSize($sizeByBox{'private'} || 0)), ' ',
2967 $o->{ui}->right(10, $o->{ui}->niceFileSize($sizeByBox{'public'} || 0)), ' ',
2968 0 ▶ $newestDate == 0 ? 'never' : $o->{ui}->niceDateTime($newestDate * 1000));
Branch: 1 branch
BranchTrueFalseTotal
$newestDate == 0 ? : 0 0 0
Condition0%0/6
$sizeByBox{'messages'} || 0
l!l
00
$sizeByBox{'private'} || 0
l!l
00
$sizeByBox{'public'} || 0
l!l
00
MC/DC0%0/1
$sizeByBox{'messages'} || 0
$sizeByBox{'messages'}
MC/DC0%0/1
$sizeByBox{'private'} || 0
$sizeByBox{'private'}
MC/DC0%0/1
$sizeByBox{'public'} || 0
$sizeByBox{'public'}
Truth table0%0/2
A
A= $sizeByBox{'messages'}
Aresult
11
00
Truth table0%0/2
A
A= $sizeByBox{'private'}
Aresult
11
00
Truth table0%0/2
A
A= $sizeByBox{'public'}
Aresult
11
00
2969  
2970 0 $countAccounts += 1;
2971 }
2972  
2973 0 $o->{ui}->line($countAccounts, ' accounts traversed');
2974 0 $o->{ui}->space;
2975  
2976 # Mark all objects that are younger than 1 day (so that objects being uploaded right now but not linked yet remain)
2977 0 $o->{ui}->title('Objects');
2978 0 $o->startProgress('objects');
2979  
2980 0 my %objects;
2981 0 my @topFolders = sort grep {$_ !~ /^\./} CDS->listFolder($o->{objectsFolder});
2982 0 foreach my $topFolder (@topFolders) {
2983 0 my @files = sort grep {$_ !~ /^\./} CDS->listFolder($o->{objectsFolder}.'/'.$topFolder);
2984 0 foreach my $filename (@files) {
2985 0 $o->incrementProgress;
2986 0 my $hash = pack 'H*', $topFolder.$filename;
2987 0 my @s = stat $o->{objectsFolder}.'/'.$topFolder.'/'.$filename;
2988 0 $objects{$hash} = $s[7];
2989 0 ▶ next if $s[9] < $dateLimit;
Branch: 1 branch
BranchTrueFalseTotal
if $s[9] < $dateLimit 0 0 0
2990 0 $o->traverse($hash, 'recent object');
2991 }
2992 }
2993  
2994 0 $o->{ui}->line(scalar keys %objects, ' objects traversed');
2995 0 $o->{ui}->space;
2996  
2997 # Delete all unmarked objects, and add the marked objects to the new tree index
2998 0 my $index = CDS::Record->new;
2999 0 my $countKeptObjects = 0;
3000 0 my $sizeKeptObjects = 0;
3001 0 my $countDeletedObjects = 0;
3002 0 my $sizeDeletedObjects = 0;
3003  
3004 0 $handler->startDeletion;
3005 0 $o->startProgress('delete-objects');
3006 0 for my $hash (keys %objects) {
3007 0 my $size = $objects{$hash};
3008 0 ▶ if (exists $o->{usedHashes}->{$hash}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $o->{'usedHashes'}{$hash}) { } 0 0 0
3009 0 $countKeptObjects += 1;
3010 0 $sizeKeptObjects += $size;
3011 0 my $entry = $o->{index}->{$hash};
3012 0 ▶ $index->addRecord($entry) if $entry;
Branch: 1 branch
BranchTrueFalseTotal
if $entry 0 0 0
3013 } else {
3014 0 $o->incrementProgress;
3015 0 $countDeletedObjects += 1;
3016 0 $sizeDeletedObjects += $size;
3017 0 my $hashHex = unpack 'H*', $hash;
3018 0 my $file = $o->{objectsFolder}.'/'.substr($hashHex, 0, 2).'/'.substr($hashHex, 2);
3019 0 ▶ $handler->deleteObject($file) // return;
Condition0%0/2
$handler->deleteObject($file) // (return)
l!l
00
MC/DC0%0/1
$handler->deleteObject($file) // (return)
$handler->deleteObject($file)
Truth table0%0/2
A
A= $handler->deleteObject($file)
Aresult
11
00
3020 }
3021 }
3022  
3023 # Write the new tree index
3024 0 CDS->writeBytesToFile($o->{storeFolder}.'/.index-new', $index->toObject->bytes);
3025 0 rename $o->{storeFolder}.'/.index-new', $o->{storeFolder}.'/.index';
3026  
3027 # Show what has been done
3028 0 $o->{ui}->space;
3029 0 $o->{ui}->line($countDeletedEnvelopes, ' ', $handler->{deletedEnvelopesText});
3030 0 $o->{ui}->line($countKeptEnvelopes, ' ', $handler->{keptEnvelopesText});
3031 0 my $line1 = $countDeletedObjects.' '.$handler->{deletedObjectsText};
3032 0 my $line2 = $countKeptObjects.' '.$handler->{keptObjectsText};
3033 0 my $maxLength = CDS->max(length $line1, length $line2);
3034 0 $o->{ui}->line($o->{ui}->left($maxLength, $line1), ' ', $o->{ui}->gray($o->{ui}->niceFileSize($sizeDeletedObjects)));
3035 0 $o->{ui}->line($o->{ui}->left($maxLength, $line2), ' ', $o->{ui}->gray($o->{ui}->niceFileSize($sizeKeptObjects)));
3036 0 $o->{ui}->space;
3037 0 $handler->wrapUp;
3038  
3039 0 my $missing = scalar keys %{$o->{missingObjects}};
3040 0 ▶ if ($missing) {
Branch: 1 branch
BranchTrueFalseTotal
if ($missing) 0 0 0
3041 0 $o->{ui}->warning($missing, ' objects are referenced from other objects, but missing:');
3042  
3043 0 my $count = 0;
3044 0 for my $hashBytes (sort keys %{$o->{missingObjects}}) {
3045 0 $o->{ui}->warning(' ', unpack('H*', $hashBytes));
3046  
3047 0 $count += 1;
3048 0 ▶ if ($missing > 10 && $count > 5) {
Branch: 1 branch
BranchTrueFalseTotal
if ($missing > 10 and $count > 5) 0 0 0
Condition0%0/3
$missing > 10 and $count > 5
!ll&&!rl&&r
000
MC/DC0%0/2
$missing > 10 and $count > 5
$missing > 10 $count > 5
Truth table0%0/3
A and B
A= $missing > 10B= $count > 5
ABresult
0X0
100
111
3049 0 $o->{ui}->warning(' …');
3050 0 last;
3051 }
3052 }
3053  
3054 0 $o->{ui}->space;
3055 0 $o->{ui}->warning('The missing objects are from the following origins:');
3056 0 for my $origin (sort keys %{$o->{brokenOrigins}}) {
3057 0 $o->{ui}->line(' ', $o->{ui}->orange($origin));
3058 }
3059  
3060 0 $o->{ui}->space;
3061 }
3062 }
3063  
3064 sub traverse {
3065 0 ▶ my $o = shift;
Subroutine traverse: not called CC=4 SCAR=30.0
3066 0 my $hashBytes = shift;
3067 0 my $origin = shift;
3068  
3069 0 ▶ return $o->{usedHashes}->{$hashBytes} if exists $o->{usedHashes}->{$hashBytes};
Branch: 1 branch
BranchTrueFalseTotal
if exists $o->{"usedHashes"}{$hashBytes} 0 0 0
3070  
3071 # Get index information about the object
3072 0 ▶ my $record = $o->index($hashBytes, $origin) // return 0;
Condition0%0/2
$o->index($hashBytes, $origin) // (return 0)
l!l
00
MC/DC0%0/1
$o->index($hashBytes, $origin) // (return 0)
$o->index($hashBytes, $origin)
Truth table0%0/2
A
A= $o->index($hashBytes, $origin)
Aresult
11
00
3073 0 my $size = $record->nthChild(0)->asInteger;
3074  
3075 # Process children
3076 0 my $pos = 0;
3077 0 my $hashes = $record->nthChild(1)->bytes;
3078 0 ▶ while ($pos < length $hashes) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos < length $hashes) 0 0 0
3079 0 $size += $o->traverse(substr($hashes, $pos, 32), $origin);
3080 0 $pos += 32;
3081 }
3082  
3083 # Keep the size for future use
3084 0 $o->{usedHashes}->{$hashBytes} = $size;
3085 0 return $size;
3086 }
3087  
3088 sub readIndex {
3089 0 ▶ my $o = shift;
Subroutine readIndex: not called CC=3 SCAR=24.8
3090  
3091 0 $o->{index} = {};
3092 0 my $file = $o->{storeFolder}.'/.index';
3093 0 ▶ my $record = CDS::Record->fromObject(CDS::Object->fromBytes(CDS->readBytesFromFile($file))) // return;
Condition0%0/2
"CDS::Record"->fromObject("CDS::Object"->fromBytes("CDS"->readBytesFromFile($file))) // (return)
l!l
00
MC/DC0%0/1
"CDS::Record"->fromObject("CDS::Object"->fromBytes("CDS"->readBytesFromFile($file))) // (return)
"CDS::Record"->fromObject("CDS::Object"->fromBytes("CDS"->readBytesFromFile($file)))
Truth table0%0/2
A
A= "CDS::Record"->fromObject("CDS::Object"->fromBytes("CDS"->readBytesFromFile($file)))
Aresult
11
00
3094 0 for my $child ($record->children) {
3095 0 $o->{index}->{$child->bytes} = $child;
3096 }
3097 }
3098  
3099 sub index {
3100 0 ▶ my $o = shift;
Subroutine index: not called CC=9 SCAR=45.0
3101 0 my $hashBytes = shift;
3102 0 my $origin = shift;
3103  
3104 0 $o->incrementProgress;
3105  
3106 # Report a known result
3107 0 ▶ if ($o->{missingObjects}->{$hashBytes}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"missingObjects"}{$hashBytes}) 0 0 0
3108 0 $o->{brokenOrigins}->{$origin} = 1;
3109 0 return;
3110 }
3111  
3112 0 ▶ return $o->{index}->{$hashBytes} if exists $o->{index}->{$hashBytes};
Branch: 1 branch
BranchTrueFalseTotal
if exists $o->{"index"}{$hashBytes} 0 0 0
3113  
3114 # Object file
3115 0 my $hashHex = unpack 'H*', $hashBytes;
3116 0 my $file = $o->{objectsFolder}.'/'.substr($hashHex, 0, 2).'/'.substr($hashHex, 2);
3117  
3118 # Size and existence
3119 0 my @s = stat $file;
3120 0 ▶ if (! scalar @s) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @s) 0 0 0
3121 0 $o->{missingObjects}->{$hashBytes} = 1;
3122 0 $o->{brokenOrigins}->{$origin} = 1;
3123 0 return;
3124 }
3125 0 my $size = $s[7];
3126 0 ▶ return $o->{ui}->error('Unexpected: object ', $hashHex, ' has ', $size, ' bytes') if $size < 4;
Branch: 1 branch
BranchTrueFalseTotal
if $size < 4 0 0 0
3127  
3128 # Read header
3129 0 open O, '<', $file;
3130 0 read O, my $buffer, 4;
3131 0 my $links = unpack 'L>', $buffer;
3132 0 ▶ return $o->{ui}->error('Unexpected: object ', $hashHex, ' has ', $links, ' references') if $links > 160000;
Branch: 1 branch
BranchTrueFalseTotal
if $links > 160000 0 0 0
3133 0 ▶ return $o->{ui}->error('Unexpected: object ', $hashHex, ' is too small for ', $links, ' references') if 4 + $links * 32 > $s[7];
Branch: 1 branch
BranchTrueFalseTotal
if 4 + $links * 32 > $s[7] 0 0 0
3134 0 my $hashes = '';
3135 0 ▶ read O, $hashes, $links * 32 if $links > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $links > 0 0 0 0
3136 0 close O;
3137  
3138 0 ▶ return $o->{ui}->error('Incomplete read: ', length $hashes, ' out of ', $links * 32, ' bytes received.') if length $hashes != $links * 32;
Branch: 1 branch
BranchTrueFalseTotal
if length $hashes != $links * 32 0 0 0
3139  
3140 0 my $record = CDS::Record->new($hashBytes);
3141 0 $record->addInteger($size);
3142 0 $record->add($hashes);
3143 0 return $o->{index}->{$hashBytes} = $record;
3144 }
3145  
3146 sub envelopeExpiration {
3147 0 ▶ my $o = shift;
Subroutine envelopeExpiration: not called CC=3 SCAR=24.8
3148 0 my $hashBytes = shift;
3149 0 my $origin = shift;
3150  
3151 0 ▶ my $entry = $o->index($hashBytes, $origin) // return 0;
Condition0%0/2
$o->index($hashBytes, $origin) // (return 0)
l!l
00
MC/DC0%0/1
$o->index($hashBytes, $origin) // (return 0)
$o->index($hashBytes, $origin)
Truth table0%0/2
A
A= $o->index($hashBytes, $origin)
Aresult
11
00
3152 0 ▶ return $entry->nthChild(2)->asInteger if scalar $entry->children > 2;
Branch: 1 branch
BranchTrueFalseTotal
if scalar $entry->children > 2 0 0 0
3153  
3154 # Object file
3155 0 my $hashHex = unpack 'H*', $hashBytes;
3156 0 my $file = $o->{objectsFolder}.'/'.substr($hashHex, 0, 2).'/'.substr($hashHex, 2);
3157 0 my $record = CDS::Record->fromObject(CDS::Object->fromBytes(CDS->readBytesFromFile($file)));
3158 0 my $expires = $record->child('expires')->integerValue;
3159 0 $entry->addInteger($expires);
3160 0 return $expires;
3161 }
3162  
3163 sub startProgress {
3164 0 ▶ my $o = shift;
Subroutine startProgress: not called CC=1 SCAR=6.9
3165 0 my $title = shift;
3166  
3167 0 $o->{progress} = 0;
3168 0 $o->{progressTitle} = $title;
3169 0 $o->{ui}->progress($o->{progress}, ' ', $o->{progressTitle});
3170 }
3171  
3172 sub incrementProgress {
3173 0 ▶ my $o = shift;
Subroutine incrementProgress: not called CC=2 SCAR=17.9
3174  
3175 0 $o->{progress} += 1;
3176 0 ▶ return if $o->{progress} % 100;
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"progress"} % 100 0 0 0
3177 0 $o->{ui}->progress($o->{progress}, ' ', $o->{progressTitle});
3178 }
3179  
3180 sub lastModified {
3181 0 ▶ my $file = shift;
Subroutine lastModified: not called CC=2 SCAR=17.9
3182  
3183 0 my @s = stat $file;
3184 0 ▶ return scalar @s ? $s[9] : 0;
Branch: 1 branch
BranchTrueFalseTotal
scalar @s ? : 0 0 0
3185 }
3186  
3187 package CDS::Commands::CollectGarbage::Delete;
3188  
3189 sub new {
3190 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
3191 0 my $ui = shift;
3192  
3193 0 return bless {
3194 ui => $ui,
3195 deletedEnvelopesText => 'expired envelopes deleted',
3196 keptEnvelopesText => 'envelopes kept',
3197 deletedObjectsText => 'objects deleted',
3198 keptObjectsText => 'objects kept',
3199 };
3200 }
3201  
3202 sub initialize {
3203 0 ▶ my $o = shift;
Subroutine initialize: not called CC=1 SCAR=6.9
3204 0 my $folder = shift;
3205 0 1 }
3206  
3207 sub startDeletion {
3208 0 ▶ my $o = shift;
Subroutine startDeletion: not called CC=1 SCAR=6.9
3209  
3210 0 $o->{ui}->title('Deleting obsolete objects');
3211 }
3212  
3213 sub deleteEnvelope {
3214 0 ▶ my $o = shift;
Subroutine deleteEnvelope: not called CC=1 SCAR=6.9
3215 0 my $file = shift;
3216 0 $o->deleteObject($file) }
3217  
3218 sub deleteObject {
3219 0 ▶ my $o = shift;
Subroutine deleteObject: not called CC=2 SCAR=17.9
3220 0 my $file = shift;
3221  
3222 0 ▶ unlink $file // return $o->{ui}->error('Unable to delete "', $file, '". Giving up …');
Condition0%0/2
$file // (return $o->{"ui"}->error("Unable to delete \"", $file, "\". Giving up \x{2026}"))
l!l
00
MC/DC0%0/1
$file // (return $o->{"ui"}->error("Unable to delete \"", $file, "\". Giving up \x{2026}"))
$file
Truth table0%0/2
A
A= $file
Aresult
11
00
3223 0 return 1;
3224 }
3225  
3226 sub wrapUp {
3227 0 ▶ my $o = shift;
Subroutine wrapUp: not called CC=1 SCAR=6.9
3228 }
3229  
3230 package CDS::Commands::CollectGarbage::Report;
3231  
3232 sub new {
3233 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
3234 0 my $ui = shift;
3235  
3236 0 return bless {
3237 ui => $ui,
3238 countReported => 0,
3239 deletedEnvelopesText => 'envelopes have expired',
3240 keptEnvelopesText => 'envelopes are in use',
3241 deletedObjectsText => 'objects can be deleted',
3242 keptObjectsText => 'objects are in use',
3243 };
3244 }
3245  
3246 sub initialize {
3247 0 ▶ my $o = shift;
Subroutine initialize: not called CC=2 SCAR=17.9
3248 0 my $folderStore = shift;
3249  
3250 0 $o->{file} = $folderStore->folder.'/.garbage';
3251 0 ▶ open($o->{fh}, '>', $o->{file}) || return $o->{ui}->error('Failed to open ', $o->{file}, ' for writing.');
Branch: 1 branch
BranchTrueFalseTotal
open $o->{"fh"}, ">", $o->{"file"} or return $o->{"ui"}->error("Failed to open ", $o->{"file"}, " for writing.") 0 0 0
3252 0 return 1;
3253 }
3254  
3255 sub startDeletion {
3256 0 ▶ my $o = shift;
Subroutine startDeletion: not called CC=1 SCAR=6.9
3257  
3258 0 $o->{ui}->title('Deleting obsolete objects');
3259 }
3260  
3261 sub deleteEnvelope {
3262 0 ▶ my $o = shift;
Subroutine deleteEnvelope: not called CC=1 SCAR=6.9
3263 0 my $file = shift;
3264 0 $o->deleteObject($file) }
3265  
3266 sub deleteObject {
3267 0 ▶ my $o = shift;
Subroutine deleteObject: not called CC=2 SCAR=17.9
3268 0 my $file = shift;
3269  
3270 0 my $fh = $o->{fh};
3271 0 print $fh 'rm ', $file, "\n";
3272 0 $o->{countReported} += 1;
3273 0 ▶ print $fh 'echo ', $o->{countReported}, ' files deleted', "\n" if $o->{countReported} % 100 == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"countReported"} % 100 == 0 0 0 0
3274 0 return 1;
3275 }
3276  
3277 sub wrapUp {
3278 0 ▶ my $o = shift;
Subroutine wrapUp: not called CC=2 SCAR=17.9
3279  
3280 0 close $o->{fh};
3281 0 ▶ if ($o->{countReported} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{'countReported'} == 0) { } 0 0 0
3282 0 unlink $o->{file};
3283 } else {
3284 0 $o->{ui}->space;
3285 0 $o->{ui}->p('The report was written to ', $o->{file}, '.');
3286 0 $o->{ui}->space;
3287 }
3288 }
3289  
3290 # BEGIN AUTOGENERATED
3291 package CDS::Commands::CreateKeyPair;
3292  
3293 sub register {
3294 0 ▶ my $class = shift;
Subroutine register: not called CC=1 SCAR=6.9
3295 0 my $cds = shift;
3296 0 my $help = shift;
3297  
3298 0 my $node000 = CDS::Parser::Node->new(0);
3299 0 my $node001 = CDS::Parser::Node->new(0);
3300 0 my $node002 = CDS::Parser::Node->new(0);
3301 0 my $node003 = CDS::Parser::Node->new(0);
3302 0 my $node004 = CDS::Parser::Node->new(0);
3303 0 my $node005 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&help});
3304 0 my $node006 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&createKeyPair});
3305 0 $cds->addArrow($node002, 1, 0, 'create');
3306 0 $help->addArrow($node000, 1, 0, 'create');
3307 0 $node000->addArrow($node001, 1, 0, 'key');
3308 0 $node001->addArrow($node005, 1, 0, 'pair');
3309 0 $node002->addArrow($node003, 1, 0, 'key');
3310 0 $node003->addArrow($node004, 1, 0, 'pair');
3311 0 $node004->addArrow($node006, 1, 0, 'FILENAME', \&collectFilename);
3312 }
3313  
3314 sub collectFilename {
3315 0 ▶ my $o = shift;
Subroutine collectFilename: not called CC=1 SCAR=6.9
3316 0 my $label = shift;
3317 0 my $value = shift;
3318  
3319 0 $o->{filename} = $value;
3320 }
3321  
3322 sub new {
3323 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
3324 0 my $actor = shift;
3325 0 bless {actor => $actor, ui => $actor->ui} }
3326  
3327 # END AUTOGENERATED
3328  
3329 # HTML FOLDER NAME create-key-pair
3330 # HTML TITLE Create key pair
3331 sub help {
3332 0 ▶ my $o = shift;
Subroutine help: not called CC=1 SCAR=6.9
3333 0 my $cmd = shift;
3334  
3335 0 my $ui = $o->{ui};
3336 0 $ui->space;
3337 0 $ui->command('cds create key pair FILENAME');
3338 0 $ui->p('Generates a key pair, and writes it to FILENAME.');
3339 0 $ui->space;
3340 0 $ui->title('Related commands');
3341 0 $ui->line(' cds select …');
3342 0 $ui->line(' cds use …');
3343 0 $ui->line(' cds entrust …');
3344 0 $ui->line(' cds drop …');
3345 0 $ui->space;
3346 }
3347  
3348 sub createKeyPair {
3349 0 ▶ my $o = shift;
Subroutine createKeyPair: not called CC=3 SCAR=24.8
3350 0 my $cmd = shift;
3351  
3352 0 $cmd->collect($o);
3353 0 ▶ return $o->{ui}->error('The file "', $o->{filename}, '" exists.') if -e $o->{filename};
Branch: 1 branch
BranchTrueFalseTotal
if -e $o->{"filename"} 0 0 0
3354 0 my $keyPair = CDS::KeyPair->generate;
3355 0 ▶ $keyPair->writeToFile($o->{filename}) // return $o->{ui}->error('Failed to write the key pair file "', $o->{filename}, '".');
Condition0%0/2
$keyPair->writeToFile($o->{"filename"}) // (return $o->{"ui"}->error("Failed to write the key pair file \"", $o->{"filename"}, "\"."))
l!l
00
MC/DC0%0/1
$keyPair->writeToFile($o->{"filename"}) // (return $o->{"ui"}->error("Failed to write the key pair file \"", $o->{"filename"}, "\"."))
$keyPair->writeToFile($o->{"filename"})
Truth table0%0/2
A
A= $keyPair->writeToFile($o->{"filename"})
Aresult
11
00
3356 0 $o->{ui}->pGreen('Key pair "', $o->{filename}, '" created.');
3357 }
3358  
3359 # BEGIN AUTOGENERATED
3360 package CDS::Commands::Curl;
3361  
3362 sub register {
3363 0 ▶ my $class = shift;
Subroutine register: not called CC=1 SCAR=6.9
3364 0 my $cds = shift;
3365 0 my $help = shift;
3366  
3367 0 my $node000 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&help});
3368 0 my $node001 = CDS::Parser::Node->new(1);
3369 0 my $node002 = CDS::Parser::Node->new(0);
3370 0 my $node003 = CDS::Parser::Node->new(0);
3371 0 my $node004 = CDS::Parser::Node->new(0);
3372 0 my $node005 = CDS::Parser::Node->new(0);
3373 0 my $node006 = CDS::Parser::Node->new(0);
3374 0 my $node007 = CDS::Parser::Node->new(0);
3375 0 my $node008 = CDS::Parser::Node->new(0);
3376 0 my $node009 = CDS::Parser::Node->new(0);
3377 0 my $node010 = CDS::Parser::Node->new(0);
3378 0 my $node011 = CDS::Parser::Node->new(0);
3379 0 my $node012 = CDS::Parser::Node->new(0);
3380 0 my $node013 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&curlGet});
3381 0 my $node014 = CDS::Parser::Node->new(0);
3382 0 my $node015 = CDS::Parser::Node->new(0);
3383 0 my $node016 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&curlPut});
3384 0 my $node017 = CDS::Parser::Node->new(0);
3385 0 my $node018 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&curlBook});
3386 0 my $node019 = CDS::Parser::Node->new(0);
3387 0 my $node020 = CDS::Parser::Node->new(0);
3388 0 my $node021 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&curlList});
3389 0 my $node022 = CDS::Parser::Node->new(0);
3390 0 my $node023 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&curlGet});
3391 0 my $node024 = CDS::Parser::Node->new(0);
3392 0 my $node025 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&curlPut});
3393 0 my $node026 = CDS::Parser::Node->new(0);
3394 0 my $node027 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&curlBook});
3395 0 my $node028 = CDS::Parser::Node->new(0);
3396 0 my $node029 = CDS::Parser::Node->new(1);
3397 0 my $node030 = CDS::Parser::Node->new(0);
3398 0 my $node031 = CDS::Parser::Node->new(0);
3399 0 my $node032 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&curlList});
3400 0 my $node033 = CDS::Parser::Node->new(0);
3401 0 my $node034 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&curlGet});
3402 0 my $node035 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&curlPut});
3403 0 my $node036 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&curlBook});
3404 0 my $node037 = CDS::Parser::Node->new(1);
3405 0 my $node038 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&curlList});
3406 0 my $node039 = CDS::Parser::Node->new(0);
3407 0 my $node040 = CDS::Parser::Node->new(0);
3408 0 my $node041 = CDS::Parser::Node->new(0);
3409 0 my $node042 = CDS::Parser::Node->new(0);
3410 0 my $node043 = CDS::Parser::Node->new(0);
3411 0 my $node044 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&curlList});
3412 0 my $node045 = CDS::Parser::Node->new(1);
3413 0 my $node046 = CDS::Parser::Node->new(0);
3414 0 my $node047 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&curlModify});
3415 0 my $node048 = CDS::Parser::Node->new(0);
3416 0 my $node049 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&curlModify});
3417 0 my $node050 = CDS::Parser::Node->new(0);
3418 0 my $node051 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&curlModify});
3419 0 $cds->addArrow($node001, 1, 0, 'curl');
3420 0 $help->addArrow($node000, 1, 0, 'curl');
3421 0 $node001->addArrow($node002, 1, 0, 'get');
3422 0 $node001->addArrow($node003, 1, 0, 'put');
3423 0 $node001->addArrow($node004, 1, 0, 'book');
3424 0 $node001->addArrow($node005, 1, 0, 'get');
3425 0 $node001->addArrow($node006, 1, 0, 'book');
3426 0 $node001->addArrow($node007, 1, 0, 'list');
3427 0 $node001->addArrow($node007, 1, 0, 'watch', \&collectWatch);
3428 0 $node001->addDefault($node011);
3429 0 $node002->addArrow($node013, 1, 0, 'HASH', \&collectHash);
3430 0 $node003->addArrow($node016, 1, 0, 'FILE', \&collectFile);
3431 0 $node004->addArrow($node018, 1, 0, 'HASH', \&collectHash);
3432 0 $node005->addArrow($node023, 1, 0, 'OBJECT', \&collectObject);
3433 0 $node006->addArrow($node027, 1, 0, 'OBJECT', \&collectObject);
3434 0 $node007->addArrow($node008, 1, 0, 'message');
3435 0 $node007->addArrow($node009, 1, 0, 'private');
3436 0 $node007->addArrow($node010, 1, 0, 'public');
3437 0 $node007->addArrow($node021, 0, 0, 'messages', \&collectMessages);
3438 0 $node007->addArrow($node021, 0, 0, 'private', \&collectPrivate);
3439 0 $node007->addArrow($node021, 0, 0, 'public', \&collectPublic);
3440 0 $node008->addArrow($node021, 1, 0, 'box', \&collectMessages);
3441 0 $node009->addArrow($node021, 1, 0, 'box', \&collectPrivate);
3442 0 $node010->addArrow($node021, 1, 0, 'box', \&collectPublic);
3443 0 $node011->addArrow($node012, 1, 0, 'remove');
3444 0 $node011->addArrow($node020, 1, 0, 'add');
3445 0 $node012->addArrow($node012, 1, 0, 'HASH', \&collectHash1);
3446 0 $node012->addArrow($node037, 1, 0, 'HASH', \&collectHash1);
3447 0 $node013->addArrow($node014, 1, 0, 'from');
3448 0 $node013->addArrow($node015, 0, 0, 'on');
3449 0 $node013->addDefault($node023);
3450 0 $node014->addArrow($node023, 1, 0, 'STORE', \&collectStore);
3451 0 $node015->addArrow($node023, 0, 0, 'STORE', \&collectStore);
3452 0 $node016->addArrow($node017, 1, 0, 'onto');
3453 0 $node016->addDefault($node025);
3454 0 $node017->addArrow($node025, 1, 0, 'STORE', \&collectStore);
3455 0 $node018->addArrow($node019, 1, 0, 'on');
3456 0 $node018->addDefault($node027);
3457 0 $node019->addArrow($node027, 1, 0, 'STORE', \&collectStore);
3458 0 $node020->addArrow($node029, 1, 0, 'FILE', \&collectFile1);
3459 0 $node020->addArrow($node029, 1, 0, 'HASH', \&collectHash2);
3460 0 $node021->addArrow($node022, 1, 0, 'of');
3461 0 $node022->addArrow($node032, 1, 0, 'ACTOR', \&collectActor);
3462 0 $node023->addArrow($node024, 1, 0, 'using');
3463 0 $node024->addArrow($node034, 1, 0, 'KEYPAIR', \&collectKeypair);
3464 0 $node025->addArrow($node026, 1, 0, 'using');
3465 0 $node026->addArrow($node035, 1, 0, 'KEYPAIR', \&collectKeypair);
3466 0 $node027->addArrow($node028, 1, 0, 'using');
3467 0 $node028->addArrow($node036, 1, 0, 'KEYPAIR', \&collectKeypair);
3468 0 $node029->addDefault($node020);
3469 0 $node029->addArrow($node030, 1, 0, 'and');
3470 0 $node029->addArrow($node040, 1, 0, 'to');
3471 0 $node030->addArrow($node031, 1, 0, 'remove');
3472 0 $node031->addArrow($node031, 1, 0, 'HASH', \&collectHash1);
3473 0 $node031->addArrow($node037, 1, 0, 'HASH', \&collectHash1);
3474 0 $node032->addArrow($node033, 1, 0, 'on');
3475 0 $node033->addArrow($node038, 1, 0, 'STORE', \&collectStore);
3476 0 $node037->addArrow($node040, 1, 0, 'from');
3477 0 $node038->addArrow($node039, 1, 0, 'using');
3478 0 $node039->addArrow($node044, 1, 0, 'KEYPAIR', \&collectKeypair);
3479 0 $node040->addArrow($node041, 1, 0, 'message');
3480 0 $node040->addArrow($node042, 1, 0, 'private');
3481 0 $node040->addArrow($node043, 1, 0, 'public');
3482 0 $node040->addArrow($node045, 0, 0, 'messages', \&collectMessages1);
3483 0 $node040->addArrow($node045, 0, 0, 'private', \&collectPrivate1);
3484 0 $node040->addArrow($node045, 0, 0, 'public', \&collectPublic1);
3485 0 $node041->addArrow($node045, 1, 0, 'box', \&collectMessages1);
3486 0 $node042->addArrow($node045, 1, 0, 'box', \&collectPrivate1);
3487 0 $node043->addArrow($node045, 1, 0, 'box', \&collectPublic1);
3488 0 $node045->addArrow($node046, 1, 0, 'of');
3489 0 $node045->addDefault($node047);
3490 0 $node046->addArrow($node047, 1, 0, 'ACTOR', \&collectActor1);
3491 0 $node047->addArrow($node011, 1, 0, 'and', \&collectAnd);
3492 0 $node047->addArrow($node048, 1, 0, 'on');
3493 0 $node048->addArrow($node049, 1, 0, 'STORE', \&collectStore);
3494 0 $node049->addArrow($node050, 1, 0, 'using');
3495 0 $node050->addArrow($node051, 1, 0, 'KEYPAIR', \&collectKeypair);
3496 }
3497  
3498 sub collectActor {
3499 0 ▶ my $o = shift;
Subroutine collectActor: not called CC=1 SCAR=6.9
3500 0 my $label = shift;
3501 0 my $value = shift;
3502  
3503 0 $o->{actorHash} = $value;
3504 }
3505  
3506 sub collectActor1 {
3507 0 ▶ my $o = shift;
Subroutine collectActor1: not called CC=1 SCAR=6.9
3508 0 my $label = shift;
3509 0 my $value = shift;
3510  
3511 0 $o->{currentBatch}->{actorHash} = $value;
3512 }
3513  
3514 sub collectAnd {
3515 0 ▶ my $o = shift;
Subroutine collectAnd: not called CC=1 SCAR=6.9
3516 0 my $label = shift;
3517 0 my $value = shift;
3518  
3519 0 push @{$o->{batches}}, $o->{currentBatch};
3520 $o->{currentBatch} = {
3521 0 addHashes => [],
3522 addEnvelopes => [],
3523 removeHashes => []
3524 };
3525 }
3526  
3527 sub collectFile {
3528 0 ▶ my $o = shift;
Subroutine collectFile: not called CC=1 SCAR=6.9
3529 0 my $label = shift;
3530 0 my $value = shift;
3531  
3532 0 $o->{file} = $value;
3533 }
3534  
3535 sub collectFile1 {
3536 0 ▶ my $o = shift;
Subroutine collectFile1: not called CC=1 SCAR=6.9
3537 0 my $label = shift;
3538 0 my $value = shift;
3539  
3540 0 push @{$o->{currentBatch}->{addFiles}}, $value;
3541 }
3542  
3543 sub collectHash {
3544 0 ▶ my $o = shift;
Subroutine collectHash: not called CC=1 SCAR=6.9
3545 0 my $label = shift;
3546 0 my $value = shift;
3547  
3548 0 $o->{hash} = $value;
3549 }
3550  
3551 sub collectHash1 {
3552 0 ▶ my $o = shift;
Subroutine collectHash1: not called CC=1 SCAR=6.9
3553 0 my $label = shift;
3554 0 my $value = shift;
3555  
3556 0 push @{$o->{currentBatch}->{removeHashes}}, $value;
3557 }
3558  
3559 sub collectHash2 {
3560 0 ▶ my $o = shift;
Subroutine collectHash2: not called CC=1 SCAR=6.9
3561 0 my $label = shift;
3562 0 my $value = shift;
3563  
3564 0 push @{$o->{currentBatch}->{addHashes}}, $value;
3565 }
3566  
3567 sub collectKeypair {
3568 0 ▶ my $o = shift;
Subroutine collectKeypair: not called CC=1 SCAR=6.9
3569 0 my $label = shift;
3570 0 my $value = shift;
3571  
3572 0 $o->{keyPairToken} = $value;
3573 }
3574  
3575 sub collectMessages {
3576 0 ▶ my $o = shift;
Subroutine collectMessages: not called CC=1 SCAR=6.9
3577 0 my $label = shift;
3578 0 my $value = shift;
3579  
3580 0 $o->{boxLabel} = 'messages';
3581 }
3582  
3583 sub collectMessages1 {
3584 0 ▶ my $o = shift;
Subroutine collectMessages1: not called CC=1 SCAR=6.9
3585 0 my $label = shift;
3586 0 my $value = shift;
3587  
3588 0 $o->{currentBatch}->{boxLabel} = 'messages';
3589 }
3590  
3591 sub collectObject {
3592 0 ▶ my $o = shift;
Subroutine collectObject: not called CC=1 SCAR=6.9
3593 0 my $label = shift;
3594 0 my $value = shift;
3595  
3596 0 $o->{hash} = $value->hash;
3597 0 $o->{store} = $value->cliStore;
3598 }
3599  
3600 sub collectPrivate {
3601 0 ▶ my $o = shift;
Subroutine collectPrivate: not called CC=1 SCAR=6.9
3602 0 my $label = shift;
3603 0 my $value = shift;
3604  
3605 0 $o->{boxLabel} = 'private';
3606 }
3607  
3608 sub collectPrivate1 {
3609 0 ▶ my $o = shift;
Subroutine collectPrivate1: not called CC=1 SCAR=6.9
3610 0 my $label = shift;
3611 0 my $value = shift;
3612  
3613 0 $o->{currentBatch}->{boxLabel} = 'private';
3614 }
3615  
3616 sub collectPublic {
3617 0 ▶ my $o = shift;
Subroutine collectPublic: not called CC=1 SCAR=6.9
3618 0 my $label = shift;
3619 0 my $value = shift;
3620  
3621 0 $o->{boxLabel} = 'public';
3622 }
3623  
3624 sub collectPublic1 {
3625 0 ▶ my $o = shift;
Subroutine collectPublic1: not called CC=1 SCAR=6.9
3626 0 my $label = shift;
3627 0 my $value = shift;
3628  
3629 0 $o->{currentBatch}->{boxLabel} = 'public';
3630 }
3631  
3632 sub collectStore {
3633 0 ▶ my $o = shift;
Subroutine collectStore: not called CC=1 SCAR=6.9
3634 0 my $label = shift;
3635 0 my $value = shift;
3636  
3637 0 $o->{store} = $value;
3638 }
3639  
3640 sub collectWatch {
3641 0 ▶ my $o = shift;
Subroutine collectWatch: not called CC=1 SCAR=6.9
3642 0 my $label = shift;
3643 0 my $value = shift;
3644  
3645 0 $o->{watchTimeout} = 60000;
3646 }
3647  
3648 sub new {
3649 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
3650 0 my $actor = shift;
3651 0 bless {actor => $actor, ui => $actor->ui} }
3652  
3653 # END AUTOGENERATED
3654  
3655 # HTML FOLDER NAME curl
3656 # HTML TITLE Curl
3657 sub help {
3658 0 ▶ my $o = shift;
Subroutine help: not called CC=1 SCAR=6.9
3659 0 my $cmd = shift;
3660  
3661 0 my $ui = $o->{ui};
3662 0 $ui->space;
3663 0 $ui->p($ui->blue('cds curl'), ' prepares and executes a CURL command line for a HTTP store request. This is helpful for debugging a HTTP store implementation. Outside of low-level debugging, it is more convenient to use the "cds get|put|list|add|remove …" commands, which are richer in functionality, and work on all stores.');
3664 0 $ui->space;
3665 0 $ui->command('cds curl get OBJECT');
3666 0 $ui->command('cds curl get HASH [from|on STORE]');
3667 0 $ui->p('Downloads an object with a GET request on an object store.');
3668 0 $ui->space;
3669 0 $ui->command('cds curl put FILE [onto STORE]');
3670 0 $ui->p('Uploads an object with a PUT request on an object store.');
3671 0 $ui->space;
3672 0 $ui->command('cds curl book OBJECT');
3673 0 $ui->command('cds curl book HASH [on STORE]');
3674 0 $ui->p('Books an object with a POST request on an object store.');
3675 0 $ui->space;
3676 0 $ui->command('cds curl list message box of ACTOR [on STORE]');
3677 0 $ui->command('cds curl list private box of ACTOR [on STORE]');
3678 0 $ui->command('cds curl list public box of ACTOR [on STORE]');
3679 0 $ui->p('Lists the indicated box with a GET request on an account store.');
3680 0 $ui->space;
3681 0 $ui->command('cds curl watch message box of ACTOR [on STORE]');
3682 0 $ui->command('cds curl watch private box of ACTOR [on STORE]');
3683 0 $ui->command('cds curl watch public box of ACTOR [on STORE]');
3684 0 $ui->p('As above, but with a watch timeout of 60 second.');
3685 0 $ui->space;
3686 0 $ui->command('cds curl add (FILE|HASH)* to (message|private|public) box of ACTOR [and …] [on STORE]');
3687 0 $ui->command('cds curl remove HASH* from (message|private|public) box of ACTOR [and …] [on STORE]');
3688 0 $ui->p('Modifies the indicated boxes with a POST request on an account store. Multiple modifications to different boxes may be chained using "and". All modifications are submitted using a single request, which is optionally signed (see below).');
3689 0 $ui->space;
3690 0 $ui->command('… using KEYPAIR');
3691 0 $ui->p('Signs the request using KEYPAIR instead of the actor\'s key pair. The store may or may not verify the signature.');
3692 0 $ui->p('For debugging purposes, information about the signature is stored as ".cds-curl-bytes-to-sign", ".cds-curl-hash-to-sign", and ".cds-curl-signature" in the current folder. Note that signatures are valid for 1-2 minutes only. After that, servers will reject them to guard against replay attacks.');
3693 0 $ui->space;
3694 }
3695  
3696 sub curlGet {
3697 0 ▶ my $o = shift;
Subroutine curlGet: not called CC=3 SCAR=24.8
3698 0 my $cmd = shift;
3699  
3700 0 $cmd->collect($o);
3701 0 ▶ $o->{keyPairToken} = $o->{actor}->preferredKeyPairToken if ! $o->{keyPairToken};
Branch: 1 branch
BranchTrueFalseTotal
unless $o->{"keyPairToken"} 0 0 0
3702 0 ▶ $o->{store} = $o->{actor}->preferredStore if ! $o->{store};
Branch: 1 branch
BranchTrueFalseTotal
unless $o->{"store"} 0 0 0
3703  
3704 0 my $objectToken = CDS::ObjectToken->new($o->{store}, $o->{hash});
3705 0 $o->curlRequest('GET', $objectToken->url, ['--output', $o->{hash}->hex]);
3706 }
3707  
3708 sub curlPut {
3709 0 ▶ my $o = shift;
Subroutine curlPut: not called CC=4 SCAR=30.0
3710 0 my $cmd = shift;
3711  
3712 0 $cmd->collect($o);
3713 0 ▶ $o->{keyPairToken} = $o->{actor}->preferredKeyPairToken if ! $o->{keyPairToken};
Branch: 1 branch
BranchTrueFalseTotal
unless $o->{"keyPairToken"} 0 0 0
3714 0 ▶ $o->{store} = $o->{actor}->preferredStore if ! $o->{store};
Branch: 1 branch
BranchTrueFalseTotal
unless $o->{"store"} 0 0 0
3715  
3716 0 ▶ my $bytes = CDS->readBytesFromFile($o->{file}) // return $o->{ui}->error('Unable to read "', $o->{file}, '".');
Condition0%0/2
"CDS"->readBytesFromFile($o->{"file"}) // (return $o->{"ui"}->error("Unable to read \"", $o->{"file"}, "\"."))
l!l
00
MC/DC0%0/1
"CDS"->readBytesFromFile($o->{"file"}) // (return $o->{"ui"}->error("Unable to read \"", $o->{"file"}, "\"."))
"CDS"->readBytesFromFile($o->{"file"})
Truth table0%0/2
A
A= "CDS"->readBytesFromFile($o->{"file"})
Aresult
11
00
3717 0 my $hash = CDS::Hash->calculateFor($bytes);
3718 0 my $objectToken = CDS::ObjectToken->new($o->{store}, $hash);
3719 0 $o->curlRequest('PUT', $objectToken->url, ['--data-binary', '@'.$o->{file}, '-H', 'Content-Type: application/condensation-object']);
3720 }
3721  
3722 sub curlBook {
3723 0 ▶ my $o = shift;
Subroutine curlBook: not called CC=3 SCAR=24.8
3724 0 my $cmd = shift;
3725  
3726 0 $cmd->collect($o);
3727 0 ▶ $o->{keyPairToken} = $o->{actor}->preferredKeyPairToken if ! $o->{keyPairToken};
Branch: 1 branch
BranchTrueFalseTotal
unless $o->{"keyPairToken"} 0 0 0
3728 0 ▶ $o->{store} = $o->{actor}->preferredStore if ! $o->{store};
Branch: 1 branch
BranchTrueFalseTotal
unless $o->{"store"} 0 0 0
3729  
3730 0 my $objectToken = CDS::ObjectToken->new($o->{store}, $o->{hash});
3731 0 $o->curlRequest('POST', $objectToken->url, []);
3732 }
3733  
3734 sub curlList {
3735 0 ▶ my $o = shift;
Subroutine curlList: not called CC=5 SCAR=34.0
3736 0 my $cmd = shift;
3737  
3738 0 $cmd->collect($o);
3739 0 ▶ $o->{keyPairToken} = $o->{actor}->preferredKeyPairToken if ! $o->{keyPairToken};
Branch: 1 branch
BranchTrueFalseTotal
unless $o->{"keyPairToken"} 0 0 0
3740 0 ▶ $o->{store} = $o->{actor}->preferredStore if ! $o->{store};
Branch: 1 branch
BranchTrueFalseTotal
unless $o->{"store"} 0 0 0
3741 0 ▶ $o->{actorHash} = $o->{actor}->preferredActorHash if ! $o->{actorHash};
Branch: 1 branch
BranchTrueFalseTotal
unless $o->{"actorHash"} 0 0 0
3742  
3743 0 my $boxToken = CDS::BoxToken->new(CDS::AccountToken->new($o->{store}, $o->{actorHash}), $o->{boxLabel});
3744 0 my $args = ['--output', '.cds-curl-list'];
3745 0 ▶ push @$args, '-H', 'Condensation-Watch: '.$o->{watchTimeout}.' ms' if $o->{watchTimeout};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"watchTimeout"} 0 0 0
3746 0 $o->curlRequest('GET', $boxToken->url, $args);
3747 }
3748  
3749 sub curlModify {
3750 0 ▶ my $o = shift;
Subroutine curlModify: not called CC=13 SCAR=52.0
3751 0 my $cmd = shift;
3752  
3753 $o->{currentBatch} = {
3754 0 addHashes => [],
3755 addEnvelopes => [],
3756 removeHashes => [],
3757 };
3758 0 $o->{batches} = [];
3759 0 $cmd->collect($o);
3760 0 ▶ $o->{keyPairToken} = $o->{actor}->preferredKeyPairToken if ! $o->{keyPairToken};
Branch: 1 branch
BranchTrueFalseTotal
unless $o->{"keyPairToken"} 0 0 0
3761 0 ▶ $o->{store} = $o->{actor}->preferredStore if ! $o->{store};
Branch: 1 branch
BranchTrueFalseTotal
unless $o->{"store"} 0 0 0
3762  
3763 # Prepare the modifications
3764 0 my $modifications = CDS::StoreModifications->new;
3765  
3766 0 for my $batch (@{$o->{batches}}, $o->{currentBatch}) {
3767 0 ▶ $batch->{actorHash} = $o->{actor}->preferredActorHash if ! $batch->{actorHash};
Branch: 1 branch
BranchTrueFalseTotal
unless $batch->{"actorHash"} 0 0 0
3768  
3769 0 for my $hash (@{$batch->{addHashes}}) {
3770 0 $modifications->add($batch->{actorHash}, $batch->{boxLabel}, $hash);
3771 }
3772  
3773 0 for my $file (@{$batch->{addFiles}}) {
3774 0 ▶ my $bytes = CDS->readBytesFromFile($file) // return $o->{ui}->error('Unable to read "', $file, '".');
Condition0%0/2
"CDS"->readBytesFromFile($file) // (return $o->{"ui"}->error("Unable to read \"", $file, "\"."))
l!l
00
MC/DC0%0/1
"CDS"->readBytesFromFile($file) // (return $o->{"ui"}->error("Unable to read \"", $file, "\"."))
"CDS"->readBytesFromFile($file)
Truth table0%0/2
A
A= "CDS"->readBytesFromFile($file)
Aresult
11
00
3775 0 ▶ my $object = CDS::Object->fromBytes($bytes) // return $o->{ui}->error('"', $file, '" is not a Condensation object.');
Condition0%0/2
"CDS::Object"->fromBytes($bytes) // (return $o->{"ui"}->error("\"", $file, "\" is not a Condensation object."))
l!l
00
MC/DC0%0/1
"CDS::Object"->fromBytes($bytes) // (return $o->{"ui"}->error("\"", $file, "\" is not a Condensation object."))
"CDS::Object"->fromBytes($bytes)
Truth table0%0/2
A
A= "CDS::Object"->fromBytes($bytes)
Aresult
11
00
3776 0 my $hash = $object->calculateHash;
3777 0 ▶ $o->{ui}->warning('"', $file, '" is not a valid envelope. The server may reject it.') if ! $o->{actor}->isEnvelope($object);
Branch: 1 branch
BranchTrueFalseTotal
unless $o->{"actor"}->isEnvelope($object) 0 0 0
3778 0 $modifications->add($batch->{actorHash}, $batch->{boxLabel}, $hash, $object);
3779 }
3780  
3781 0 for my $hash (@{$batch->{removeHashes}}) {
3782 0 $modifications->remove($batch->{actorHash}, $batch->{boxLabel}, $hash);
3783 }
3784 }
3785  
3786 0 ▶ $o->{ui}->warning('You didn\'t specify any changes. The server should accept, but ignore this.') if $modifications->isEmpty;
Branch: 1 branch
BranchTrueFalseTotal
if $modifications->isEmpty 0 0 0
3787  
3788 # Write a new file
3789 0 my $modificationsObject = $modifications->toRecord->toObject;
3790 0 my $modificationsHash = $modificationsObject->calculateHash;
3791 0 my $file = '.cds-curl-modifications-'.substr($modificationsHash->hex, 0, 8);
3792 0 ▶ CDS->writeBytesToFile($file, $modificationsObject->header, $modificationsObject->data) // return $o->{ui}->error('Unable to write modifications to "', $file, '".');
Condition0%0/2
"CDS"->writeBytesToFile($file, $modificationsObject->header, $modificationsObject->data) // (return $o->{"ui"}->error("Unable to write modifications to \"", $file, "\"."))
l!l
00
MC/DC0%0/1
"CDS"->writeBytesToFile($file, $modificationsObject->header, $modificationsObject->data) // (return $o->{"ui"}->error("Unable to write modifications to \"", $file, "\"."))
"CDS"->writeBytesToFile($file, $modificationsObject->header, $modificationsObject->data)
Truth table0%0/2
A
A= "CDS"->writeBytesToFile($file, $modificationsObject->header, $modificationsObject->data)
Aresult
11
00
3793 0 $o->{ui}->line(scalar @{$modifications->additions}, ' addition(s) and ', scalar @{$modifications->removals}, ' removal(s) written to "', $file, '".');
3794  
3795 # Submit
3796 0 $o->curlRequest('POST', $o->{store}->url.'/accounts', ['--data-binary', '@'.$file, '-H', 'Content-Type: application/condensation-modifications'], $modificationsObject);
3797 }
3798  
3799 sub curlRequest {
3800 0 ▶ my $o = shift;
Subroutine curlRequest: not called CC=22 SCAR=62.3
3801 0 my $method = shift;
3802 0 my $url = shift;
3803 0 my $curlArgs = shift;
3804 0 my $contentObjectToSign = shift;
3805  
3806 # Parse the URL
3807 0 ▶ $url =~ /^(https?):\/\/([^\/]+)(\/.*|)$/i || return $o->{ui}->error('"', $url, '" does not look like a valid and complete http://… or https://… URL.');
Branch: 1 branch
BranchTrueFalseTotal
$url =~ m[^(https?)://([^/]+)(/.*|)$]i or return $o->{"ui"}->error("\"", $url, "\" does not look like a valid and complete http://\x{2026} or https://\x{2026} URL.") 0 0 0
3808 0 my $protocol = lc($1);
3809 0 my $host = $2;
3810 0 my $path = $3;
3811  
3812 # Strip off user and password, if any
3813 0 my $credentials;
3814 0 ▶ if ($host =~ /^(.*)\@([^\@]*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($host =~ /^(.*)\@([^\@]*)$/) { } 0 0 0
3815 0 $credentials = $1;
3816 0 $host = lc($2);
3817 } else {
3818 0 $host = lc($host);
3819 }
3820  
3821 # Remove default port
3822 0 ▶ if ($host =~ /^(.*):(\d+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($host =~ /^(.*):(\d+)$/) 0 0 0
3823 0 ▶ $host = $1 if $protocol eq 'http' && $2 == 80;
Branch: 1 branch
BranchTrueFalseTotal
if $protocol eq "http" and $2 == 80 0 0 0
Condition0%0/3
$protocol eq "http" and $2 == 80
!ll&&!rl&&r
000
MC/DC0%0/2
$protocol eq "http" and $2 == 80
$protocol eq "http" $2 == 80
Truth table0%0/3
A and B
A= $protocol eq "http"B= $2 == 80
ABresult
0X0
100
111
3824 0 ▶ $host = $1 if $protocol eq 'https' && $2 == 443;
Branch: 1 branch
BranchTrueFalseTotal
if $protocol eq "https" and $2 == 443 0 0 0
Condition0%0/3
$protocol eq "https" and $2 == 443
!ll&&!rl&&r
000
MC/DC0%0/2
$protocol eq "https" and $2 == 443
$protocol eq "https" $2 == 443
Truth table0%0/3
A and B
A= $protocol eq "https"B= $2 == 443
ABresult
0X0
100
111
3825 }
3826  
3827 # Checks the path and warn the user if obvious things are likely to go wrong
3828 0 ▶ $o->{ui}->warning('Warning: "//" in URL may not work') if $path =~ /\/\//;
Branch: 1 branch
BranchTrueFalseTotal
if $path =~ m[//] 0 0 0
3829 0 ▶ $o->{ui}->warning('Warning: /./ or /../ in URL may not work') if $path =~ /\/\.+\//;
Branch: 1 branch
BranchTrueFalseTotal
if $path =~ m[/\.+/] 0 0 0
3830 0 ▶ $o->{ui}->warning('Warning: /. or /.. at the end of the URL may not work') if $path =~ /\/\.+$/;
Branch: 1 branch
BranchTrueFalseTotal
if $path =~ m[/\.+$] 0 0 0
3831  
3832 # Signature
3833  
3834 # Date
3835 0 my $dateString = CDS::ISODate->millisecondString(CDS->now);
3836  
3837 # Text to sign
3838 0 my $bytesToSign = $dateString."\0".uc($method)."\0".$host.$path;
3839 0 ▶ $bytesToSign .= "\0".$contentObjectToSign->header.$contentObjectToSign->data if defined $contentObjectToSign;
Branch: 1 branch
BranchTrueFalseTotal
if defined $contentObjectToSign 0 0 0
3840  
3841 # Signature
3842 0 my $keyPair = $o->{keyPairToken}->keyPair;
3843 0 my $hashToSign = CDS::Hash->calculateFor($bytesToSign);
3844 0 my $signature = $keyPair->signHash($hashToSign);
3845 0 push @$curlArgs, '-H', 'Condensation-Date: '.$dateString;
3846 0 push @$curlArgs, '-H', 'Condensation-Actor: '.$keyPair->publicKey->hash->hex;
3847 0 push @$curlArgs, '-H', 'Condensation-Signature: '.unpack('H*', $signature);
3848  
3849 # Write signature information to files
3850 0 ▶ CDS->writeBytesToFile('.cds-curl-bytesToSign', $bytesToSign) || $o->{ui}->warning('Unable to write the bytes to sign to ".cds-curl-bytesToSign".');
Branch: 1 branch
BranchTrueFalseTotal
"CDS"->writeBytesToFile(".cds-curl-bytesToSign", $bytesToSign) or $o->{"ui"}->warning("Unable to write the bytes to sign to \".cds-curl-bytesToSign\".") 0 0 0
3851 0 ▶ CDS->writeBytesToFile('.cds-curl-hashToSign', $hashToSign->bytes) || $o->{ui}->warning('Unable to write the hash to sign to ".cds-curl-hashToSign".');
Branch: 1 branch
BranchTrueFalseTotal
"CDS"->writeBytesToFile(".cds-curl-hashToSign", $hashToSign->bytes) or $o->{"ui"}->warning("Unable to write the hash to sign to \".cds-curl-hashToSign\".") 0 0 0
3852 0 ▶ CDS->writeBytesToFile('.cds-curl-signature', $signature) || $o->{ui}->warning('Unable to write signature to ".cds-curl-signature".');
Branch: 1 branch
BranchTrueFalseTotal
"CDS"->writeBytesToFile(".cds-curl-signature", $signature) or $o->{"ui"}->warning("Unable to write signature to \".cds-curl-signature\".") 0 0 0
3853  
3854 # Method
3855 0 ▶ unshift @$curlArgs, '-X', $method if $method ne 'GET';
Branch: 1 branch
BranchTrueFalseTotal
if $method ne "GET" 0 0 0
3856 0 unshift @$curlArgs, '-#', '--dump-header', '-';
3857  
3858 # Print
3859 0 ▶ $o->{ui}->line($o->{ui}->gold('curl', join('', map { ($_ ne '-X' && $_ ne '-' && $_ ne '--dump-header' && $_ ne '-#' && substr($_, 0, 1) eq '-' ? " \\\n " : ' ').&withQuotesIfNecessary($_) } @$curlArgs), scalar @$curlArgs ? " \\\n " : ' ', &withQuotesIfNecessary($url)));
Branch: 2 branches
BranchTrueFalseTotal
$_ ne '-X' && $_ ne '-' && $_ ne '--dump-header' && $_ ne '-#' && substr($_, 0, 1) eq '-' ? : 0 0 0
scalar @$curlArgs ? : 0 0 0
Condition0%0/12
$_ ne "-X" and $_ ne "-" and $_ ne "--dump-header" and $_ ne "-#" and substr($_, 0, 1) eq "-"
!ll&&!rl&&r
000
$_ ne "-X" and $_ ne "-" and $_ ne "--dump-header" and $_ ne "-#"
!ll&&!rl&&r
000
$_ ne "-X" and $_ ne "-" and $_ ne "--dump-header"
!ll&&!rl&&r
000
$_ ne "-X" and $_ ne "-"
!ll&&!rl&&r
000
MC/DC0%0/5
$_ ne "-X" and $_ ne "-" and $_ ne "--dump-header" and $_ ne "-#" and substr($_, 0, 1) eq "-"
$_ ne "-X" $_ ne "-" $_ ne "--dump-header" $_ ne "-#" substr($_, 0, 1) eq "-"
Truth table0%0/6
A and B and C and D and E
A= $_ ne "-X"B= $_ ne "-"C= $_ ne "--dump-header"D= $_ ne "-#"E= substr($_, 0, 1) eq "-"
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
3860  
3861 # Execute
3862 0 system('curl', @$curlArgs, $url);
3863 }
3864  
3865 sub withQuotesIfNecessary {
3866 0 ▶ my $text = shift;
Subroutine withQuotesIfNecessary: not called CC=2 SCAR=17.9
3867  
3868 0 ▶ return $text =~ /[^a-zA-Z0-9\.\/\@:,_-]/ ? '\''.$text.'\'' : $text;
Branch: 1 branch
BranchTrueFalseTotal
$text =~ m[[^a-zA-Z0-9\./\@:,_-]] ? : 0 0 0
3869 }
3870  
3871 # BEGIN AUTOGENERATED
3872 package CDS::Commands::DiscoverActorGroup;
3873  
3874 sub register {
3875 0 ▶ my $class = shift;
Subroutine register: not called CC=1 SCAR=6.9
3876 0 my $cds = shift;
3877 0 my $help = shift;
3878  
3879 0 my $node000 = CDS::Parser::Node->new(0);
3880 0 my $node001 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&help});
3881 0 my $node002 = CDS::Parser::Node->new(1);
3882 0 my $node003 = CDS::Parser::Node->new(0);
3883 0 my $node004 = CDS::Parser::Node->new(0);
3884 0 my $node005 = CDS::Parser::Node->new(0);
3885 0 my $node006 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&showActorGroupCmd});
3886 0 my $node007 = CDS::Parser::Node->new(0);
3887 0 my $node008 = CDS::Parser::Node->new(0);
3888 0 my $node009 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&discover});
3889 0 my $node010 = CDS::Parser::Node->new(0);
3890 0 my $node011 = CDS::Parser::Node->new(0);
3891 0 my $node012 = CDS::Parser::Node->new(0);
3892 0 my $node013 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&discover});
3893 0 $cds->addArrow($node000, 1, 0, 'show');
3894 0 $cds->addArrow($node002, 1, 0, 'discover');
3895 0 $help->addArrow($node001, 1, 0, 'discover');
3896 0 $help->addArrow($node001, 1, 0, 'rediscover');
3897 0 $node000->addArrow($node006, 1, 0, 'ACTORGROUP', \&collectActorgroup);
3898 0 $node002->addDefault($node003);
3899 0 $node002->addDefault($node004);
3900 0 $node002->addDefault($node005);
3901 0 $node002->addArrow($node009, 1, 0, 'me', \&collectMe);
3902 0 $node002->addArrow($node013, 1, 0, 'ACTORGROUP', \&collectActorgroup1);
3903 0 $node003->addArrow($node003, 1, 0, 'ACCOUNT', \&collectAccount);
3904 0 $node003->addArrow($node009, 1, 1, 'ACCOUNT', \&collectAccount);
3905 0 $node004->addArrow($node004, 1, 0, 'KEYPAIR', \&collectKeypair);
3906 0 $node004->addArrow($node007, 1, 0, 'KEYPAIR', \&collectKeypair);
3907 0 $node005->addArrow($node005, 1, 0, 'ACTOR', \&collectActor);
3908 0 $node005->addArrow($node007, 1, 0, 'ACTOR', \&collectActor);
3909 0 $node007->addArrow($node008, 1, 0, 'on');
3910 0 $node007->addDefault($node009);
3911 0 $node008->addArrow($node009, 1, 0, 'STORE', \&collectStore);
3912 0 $node009->addArrow($node010, 1, 0, 'and');
3913 0 $node010->addArrow($node011, 1, 0, 'remember');
3914 0 $node011->addArrow($node012, 1, 0, 'as');
3915 0 $node012->addArrow($node013, 1, 0, 'TEXT', \&collectText);
3916 }
3917  
3918 sub collectAccount {
3919 0 ▶ my $o = shift;
Subroutine collectAccount: not called CC=1 SCAR=6.9
3920 0 my $label = shift;
3921 0 my $value = shift;
3922  
3923 0 push @{$o->{accounts}}, $value;
3924 }
3925  
3926 sub collectActor {
3927 0 ▶ my $o = shift;
Subroutine collectActor: not called CC=1 SCAR=6.9
3928 0 my $label = shift;
3929 0 my $value = shift;
3930  
3931 0 push @{$o->{actorHashes}}, $value;
3932 }
3933  
3934 sub collectActorgroup {
3935 0 ▶ my $o = shift;
Subroutine collectActorgroup: not called CC=1 SCAR=6.9
3936 0 my $label = shift;
3937 0 my $value = shift;
3938  
3939 0 $o->{actorGroupToken} = $value;
3940 }
3941  
3942 sub collectActorgroup1 {
3943 0 ▶ my $o = shift;
Subroutine collectActorgroup1: not called CC=1 SCAR=6.9
3944 0 my $label = shift;
3945 0 my $value = shift;
3946  
3947 0 $o->{actorGroupToken} = $value;
3948 0 $o->{label} = $value->label;
3949 }
3950  
3951 sub collectKeypair {
3952 0 ▶ my $o = shift;
Subroutine collectKeypair: not called CC=1 SCAR=6.9
3953 0 my $label = shift;
3954 0 my $value = shift;
3955  
3956 0 push @{$o->{actorHashes}}, $value->keyPair->publicKey->hash;
3957 }
3958  
3959 sub collectMe {
3960 0 ▶ my $o = shift;
Subroutine collectMe: not called CC=1 SCAR=6.9
3961 0 my $label = shift;
3962 0 my $value = shift;
3963  
3964 0 $o->{me} = 1;
3965 }
3966  
3967 sub collectStore {
3968 0 ▶ my $o = shift;
Subroutine collectStore: not called CC=1 SCAR=6.9
3969 0 my $label = shift;
3970 0 my $value = shift;
3971  
3972 0 $o->{store} = $value;
3973 }
3974  
3975 sub collectText {
3976 0 ▶ my $o = shift;
Subroutine collectText: not called CC=1 SCAR=6.9
3977 0 my $label = shift;
3978 0 my $value = shift;
3979  
3980 0 $o->{label} = $value;
3981 }
3982  
3983 sub new {
3984 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
3985 0 my $actor = shift;
3986 0 bless {actor => $actor, ui => $actor->ui} }
3987  
3988 # END AUTOGENERATED
3989  
3990 # HTML FOLDER NAME discover
3991 # HTML TITLE Discover actor groups
3992 sub help {
3993 0 ▶ my $o = shift;
Subroutine help: not called CC=1 SCAR=6.9
3994 0 my $cmd = shift;
3995  
3996 0 my $ui = $o->{ui};
3997 0 $ui->space;
3998 0 $ui->command('cds discover ACCOUNT');
3999 0 $ui->command('cds discover ACTOR [on STORE]');
4000 0 $ui->p('Discovers the actor group the given account belongs to. Only active group members are discovered.');
4001 0 $ui->space;
4002 0 $ui->command('cds discover ACCOUNT*');
4003 0 $ui->command('cds discover ACTOR* on STORE');
4004 0 $ui->p('Same as above, but starts discovery with multiple accounts. All accounts must belong to the same actor group.');
4005 0 $ui->p('Note that this rarely makes sense. The actor group discovery algorithm reliably discovers an actor group from a single account.');
4006 0 $ui->space;
4007 0 $ui->command('cds discover me');
4008 0 $ui->p('Discovers your own actor group.');
4009 0 $ui->space;
4010 0 $ui->command('… and remember as TEXT');
4011 0 $ui->p('The discovered actor group is remembered as TEXT. See "cds help remember" for details.');
4012 0 $ui->space;
4013 0 $ui->command('cds discover ACTORGROUP');
4014 0 $ui->p('Updates a previously remembered actor group.');
4015 0 $ui->space;
4016 0 $ui->command('cds show ACTORGROUP');
4017 0 $ui->p('Shows a previously discovered and remembered actor group.');
4018 0 $ui->space;
4019 }
4020  
4021 sub discover {
4022 0 ▶ my $o = shift;
Subroutine discover: not called CC=9 SCAR=45.0
4023 0 my $cmd = shift;
4024  
4025 0 $o->{accounts} = [];
4026 0 $o->{actorHashes} = [];
4027 0 $cmd->collect($o);
4028  
4029 # Discover
4030 0 my $builder = $o->prepareBuilder;
4031 0 my ($actorGroup, $cards, $nodes) = $builder->discover($o->{actor}->keyPair, $o);
4032  
4033 # Show the graph
4034 0 $o->{ui}->space;
4035 0 $o->{ui}->title('Graph');
4036 0 for my $node (@$nodes) {
4037 0 ▶ my $status = $node->status eq 'active' ? $o->{ui}->green('active ') : $o->{ui}->gray('idle ');
Branch: 1 branch
BranchTrueFalseTotal
$node->status eq 'active' ? : 0 0 0
4038 0 $o->{ui}->line($o->{ui}->blue($node->actorHash->hex), ' on ', $node->storeUrl, ' ', $status, $o->{ui}->gray($o->{ui}->niceDateTime($node->revision)));
4039 0 $o->{ui}->pushIndent;
4040 0 for my $link ($node->links) {
4041 0 my $isMostRecentInformation = $link->revision == $link->node->revision;
4042 0 ▶ my $color = $isMostRecentInformation ? 246 : 250;
Branch: 1 branch
BranchTrueFalseTotal
$isMostRecentInformation ? : 0 0 0
4043 0 $o->{ui}->line($link->node->actorHash->shortHex, ' on ', $link->node->storeUrl, ' ', $o->{ui}->foreground($color, $o->{ui}->left(8, $link->status), $o->{ui}->niceDateTime($link->revision)));
4044 }
4045 0 $o->{ui}->popIndent;
4046 }
4047  
4048 # Show all accounts
4049 0 $o->showActorGroup($actorGroup);
4050  
4051 # Show all cards
4052 0 $o->{ui}->space;
4053 0 $o->{ui}->title('Cards');
4054 0 for my $card (@$cards) {
4055 0 $o->{ui}->line($o->{ui}->gold('cds show record ', $card->cardHash->hex, ' on ', $card->storeUrl));
4056 }
4057  
4058 # Remember the actor group if desired
4059 0 ▶ if ($o->{label}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"label"}) 0 0 0
4060 0 my $selector = $o->{actor}->labelSelector($o->{label});
4061  
4062 0 my $record = CDS::Record->new;
4063 0 my $actorGroupRecord = $record->add('actor group');
4064 0 $actorGroupRecord->add('discovered')->addInteger(CDS->now);
4065 0 $actorGroupRecord->addRecord($actorGroup->toBuilder->toRecord(1)->children);
4066 0 $selector->set($record);
4067  
4068 0 for my $publicKey ($actorGroup->publicKeys) {
4069 0 $selector->addObject($publicKey->hash, $publicKey->object);
4070 }
4071  
4072 0 ▶ $o->{actor}->saveOrShowError // return;
Condition0%0/2
$o->{"actor"}->saveOrShowError // (return)
l!l
00
MC/DC0%0/1
$o->{"actor"}->saveOrShowError // (return)
$o->{"actor"}->saveOrShowError
Truth table0%0/2
A
A= $o->{"actor"}->saveOrShowError
Aresult
11
00
4073 }
4074  
4075 0 $o->{ui}->space;
4076 }
4077  
4078 sub prepareBuilder {
4079 0 ▶ my $o = shift;
Subroutine prepareBuilder: not called CC=7 SCAR=40.3
4080  
4081 # Actor group
4082 0 ▶ return $o->{actorGroupToken}->actorGroup->toBuilder if $o->{actorGroupToken};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"actorGroupToken"} 0 0 0
4083  
4084 # Other than actor group
4085 0 my $builder = CDS::ActorGroupBuilder->new;
4086 0 $builder->addKnownPublicKey($o->{actor}->keyPair->publicKey);
4087  
4088 # Me
4089 0 ▶ $builder->addMember($o->{actor}->messagingStoreUrl, $o->{actor}->keyPair->publicKey->hash) if $o->{me};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"me"} 0 0 0
4090  
4091 # Accounts
4092 0 for my $account (@{$o->{accounts}}) {
4093 0 $builder->addMember($account->cliStore->url, $account->actorHash);
4094 }
4095  
4096 # Actors on store
4097 0 ▶ if (scalar @{$o->{actorHashes}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$o->{"actorHashes"};}) 0 0 0
4098 0 ▶ my $store = $o->{store} // $o->{actor}->preferredStore;
Condition0%0/3
$o->{"store"} // $o->{"actor"}->preferredStore
l!l&&r!l&&!r
000
MC/DC0%0/2
$o->{"store"} // $o->{"actor"}->preferredStore
$o->{"store"} $o->{"actor"}->preferredStore
Truth table0%0/3
A // B
A= $o->{"store"}B= $o->{"actor"}->preferredStore
ABresult
1X1
011
000
4099 0 for my $actorHash (@{$o->{actorHashes}}) {
4100 0 $builder->addMember($actorHash, $store->url);
4101 }
4102 }
4103  
4104 0 return $builder;
4105 }
4106  
4107 sub showActorGroupCmd {
4108 0 ▶ my $o = shift;
Subroutine showActorGroupCmd: not called CC=1 SCAR=6.9
4109 0 my $cmd = shift;
4110  
4111 0 $cmd->collect($o);
4112 0 $o->showActorGroup($o->{actorGroupToken}->actorGroup);
4113 0 $o->{ui}->space;
4114 }
4115  
4116 sub showActorGroup {
4117 0 ▶ my $o = shift;
Subroutine showActorGroup: not called CC=11 SCAR=48.8
4118 0 ▶ my $actorGroup = shift; die 'wrong type '.ref($actorGroup).' for $actorGroup' if defined $actorGroup && ref $actorGroup ne 'CDS::ActorGroup';
Branch: 1 branch
BranchTrueFalseTotal
if defined $actorGroup and ref $actorGroup ne "CDS::ActorGroup" 0 0 0
Condition0%0/3
defined $actorGroup and ref $actorGroup ne "CDS::ActorGroup"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $actorGroup and ref $actorGroup ne "CDS::ActorGroup"
defined $actorGroup ref $actorGroup ne "CDS::ActorGroup"
Truth table0%0/3
A and B
A= defined $actorGroupB= ref $actorGroup ne "CDS::ActorGroup"
ABresult
0X0
100
111
4119  
4120 0 $o->{ui}->space;
4121 0 ▶ $o->{ui}->title(length $o->{label} ? 'Actors of '.$o->{label} : 'Actor group');
Branch: 1 branch
BranchTrueFalseTotal
length $o->{'label'} ? : 0 0 0
4122 0 for my $member ($actorGroup->members) {
4123 0 ▶ my $date = $member->revision ? $o->{ui}->niceDateTimeLocal($member->revision) : ' ';
Branch: 1 branch
BranchTrueFalseTotal
$member->revision ? : 0 0 0
4124 0 ▶ my $status = $member->isActive ? $o->{ui}->green('active ') : $o->{ui}->gray('idle ');
Branch: 1 branch
BranchTrueFalseTotal
$member->isActive ? : 0 0 0
4125 0 my $storeReference = $o->{actor}->blueStoreUrlReference($member->storeUrl);
4126 0 $o->{ui}->line($o->{ui}->gray($date), ' ', $status, ' ', $member->actorOnStore->publicKey->hash->hex, ' on ', $storeReference);
4127 }
4128  
4129 0 ▶ if ($actorGroup->entrustedActorsRevision) {
Branch: 1 branch
BranchTrueFalseTotal
if ($actorGroup->entrustedActorsRevision) 0 0 0
4130 0 $o->{ui}->space;
4131 0 ▶ $o->{ui}->title(length $o->{label} ? 'Actors entrusted by '.$o->{label} : 'Entrusted actors');
Branch: 1 branch
BranchTrueFalseTotal
length $o->{'label'} ? : 0 0 0
4132 0 $o->{ui}->line($o->{ui}->gray($o->{ui}->niceDateTimeLocal($actorGroup->entrustedActorsRevision)));
4133 0 for my $actor ($actorGroup->entrustedActors) {
4134 0 my $storeReference = $o->{actor}->storeUrlReference($actor->storeUrl);
4135 0 $o->{ui}->line($actor->actorOnStore->publicKey->hash->hex, $o->{ui}->gray(' on ', $storeReference));
4136 }
4137  
4138 0 ▶ $o->{ui}->line($o->{ui}->gray('(none)')) if ! scalar $actorGroup->entrustedActors;
Branch: 1 branch
BranchTrueFalseTotal
if not scalar $actorGroup->entrustedActors 0 0 0
4139 }
4140 }
4141  
4142 sub onDiscoverActorGroupVerifyStore {
4143 0 ▶ my $o = shift;
Subroutine onDiscoverActorGroupVerifyStore: not called CC=3 SCAR=24.8
4144 0 my $storeUrl = shift;
4145 0 ▶ my $actorHash = shift; die 'wrong type '.ref($actorHash).' for $actorHash' if defined $actorHash && ref $actorHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $actorHash and ref $actorHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $actorHash and ref $actorHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $actorHash and ref $actorHash ne "CDS::Hash"
defined $actorHash ref $actorHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $actorHashB= ref $actorHash ne "CDS::Hash"
ABresult
0X0
100
111
4146  
4147 0 return $o->{actor}->storeForUrl($storeUrl);
4148 }
4149  
4150 sub onDiscoverActorGroupInvalidPublicKey {
4151 0 ▶ my $o = shift;
Subroutine onDiscoverActorGroupInvalidPublicKey: not called CC=3 SCAR=24.8
4152 0 ▶ my $actorHash = shift; die 'wrong type '.ref($actorHash).' for $actorHash' if defined $actorHash && ref $actorHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $actorHash and ref $actorHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $actorHash and ref $actorHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $actorHash and ref $actorHash ne "CDS::Hash"
defined $actorHash ref $actorHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $actorHashB= ref $actorHash ne "CDS::Hash"
ABresult
0X0
100
111
4153 0 my $store = shift;
4154 0 my $reason = shift;
4155  
4156 0 $o->{ui}->warning('Public key ', $actorHash->hex, ' on ', $store->url, ' is invalid: ', $reason);
4157 }
4158  
4159 sub onDiscoverActorGroupInvalidCard {
4160 0 ▶ my $o = shift;
Subroutine onDiscoverActorGroupInvalidCard: not called CC=5 SCAR=34.0
4161 0 ▶ my $actorOnStore = shift; die 'wrong type '.ref($actorOnStore).' for $actorOnStore' if defined $actorOnStore && ref $actorOnStore ne 'CDS::ActorOnStore';
Branch: 1 branch
BranchTrueFalseTotal
if defined $actorOnStore and ref $actorOnStore ne "CDS::ActorOnStore" 0 0 0
Condition0%0/3
defined $actorOnStore and ref $actorOnStore ne "CDS::ActorOnStore"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $actorOnStore and ref $actorOnStore ne "CDS::ActorOnStore"
defined $actorOnStore ref $actorOnStore ne "CDS::ActorOnStore"
Truth table0%0/3
A and B
A= defined $actorOnStoreB= ref $actorOnStore ne "CDS::ActorOnStore"
ABresult
0X0
100
111
4162 0 ▶ my $envelopeHash = shift; die 'wrong type '.ref($envelopeHash).' for $envelopeHash' if defined $envelopeHash && ref $envelopeHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $envelopeHash and ref $envelopeHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $envelopeHash and ref $envelopeHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $envelopeHash and ref $envelopeHash ne "CDS::Hash"
defined $envelopeHash ref $envelopeHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $envelopeHashB= ref $envelopeHash ne "CDS::Hash"
ABresult
0X0
100
111
4163 0 my $reason = shift;
4164  
4165 0 $o->{ui}->warning('Card ', $envelopeHash->hex, ' on ', $actorOnStore->store->url, ' is invalid: ', $reason);
4166 }
4167  
4168 sub onDiscoverActorGroupStoreError {
4169 0 ▶ my $o = shift;
Subroutine onDiscoverActorGroupStoreError: not called CC=1 SCAR=6.9
4170 0 my $store = shift;
4171 0 my $error = shift;
4172  
4173 }
4174  
4175 # BEGIN AUTOGENERATED
4176 package CDS::Commands::EntrustedActors;
4177  
4178 sub register {
4179 0 ▶ my $class = shift;
Subroutine register: not called CC=1 SCAR=6.9
4180 0 my $cds = shift;
4181 0 my $help = shift;
4182  
4183 0 my $node000 = CDS::Parser::Node->new(0);
4184 0 my $node001 = CDS::Parser::Node->new(0);
4185 0 my $node002 = CDS::Parser::Node->new(0);
4186 0 my $node003 = CDS::Parser::Node->new(0);
4187 0 my $node004 = CDS::Parser::Node->new(0);
4188 0 my $node005 = CDS::Parser::Node->new(0);
4189 0 my $node006 = CDS::Parser::Node->new(0);
4190 0 my $node007 = CDS::Parser::Node->new(0);
4191 0 my $node008 = CDS::Parser::Node->new(0);
4192 0 my $node009 = CDS::Parser::Node->new(0);
4193 0 my $node010 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&help});
4194 0 my $node011 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&show});
4195 0 my $node012 = CDS::Parser::Node->new(0);
4196 0 my $node013 = CDS::Parser::Node->new(0);
4197 0 my $node014 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&doNotEntrust});
4198 0 my $node015 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&entrust});
4199 0 my $node016 = CDS::Parser::Node->new(0);
4200 0 $cds->addArrow($node001, 1, 0, 'show');
4201 0 $cds->addArrow($node003, 1, 0, 'do');
4202 0 $cds->addArrow($node005, 1, 0, 'entrust');
4203 0 $help->addArrow($node000, 1, 0, 'entrusted');
4204 0 $node000->addArrow($node010, 1, 0, 'actors');
4205 0 $node001->addArrow($node002, 1, 0, 'entrusted');
4206 0 $node002->addArrow($node011, 1, 0, 'actors');
4207 0 $node003->addArrow($node004, 1, 0, 'not');
4208 0 $node004->addArrow($node008, 1, 0, 'entrust');
4209 0 $node005->addDefault($node006);
4210 0 $node005->addDefault($node007);
4211 0 $node005->addArrow($node012, 1, 0, 'ACTOR', \&collectActor);
4212 0 $node006->addArrow($node006, 1, 0, 'ACCOUNT', \&collectAccount);
4213 0 $node006->addArrow($node015, 1, 1, 'ACCOUNT', \&collectAccount);
4214 0 $node007->addArrow($node007, 1, 0, 'ACTOR', \&collectActor1);
4215 0 $node007->addArrow($node015, 1, 0, 'ACTOR', \&collectActor1);
4216 0 $node008->addDefault($node009);
4217 0 $node009->addArrow($node009, 1, 0, 'ACTOR', \&collectActor2);
4218 0 $node009->addArrow($node014, 1, 0, 'ACTOR', \&collectActor2);
4219 0 $node012->addArrow($node013, 1, 0, 'on');
4220 0 $node013->addArrow($node015, 1, 0, 'STORE', \&collectStore);
4221 0 $node015->addArrow($node016, 1, 0, 'and');
4222 0 $node016->addDefault($node005);
4223 }
4224  
4225 sub collectAccount {
4226 0 ▶ my $o = shift;
Subroutine collectAccount: not called CC=1 SCAR=6.9
4227 0 my $label = shift;
4228 0 my $value = shift;
4229  
4230 0 push @{$o->{accountTokens}}, $value;
4231 }
4232  
4233 sub collectActor {
4234 0 ▶ my $o = shift;
Subroutine collectActor: not called CC=1 SCAR=6.9
4235 0 my $label = shift;
4236 0 my $value = shift;
4237  
4238 0 $o->{actorHash} = $value;
4239 }
4240  
4241 sub collectActor1 {
4242 0 ▶ my $o = shift;
Subroutine collectActor1: not called CC=1 SCAR=6.9
4243 0 my $label = shift;
4244 0 my $value = shift;
4245  
4246 0 push @{$o->{accountTokens}}, CDS::AccountToken->new($o->{actor}->preferredStore, $value);
4247 }
4248  
4249 sub collectActor2 {
4250 0 ▶ my $o = shift;
Subroutine collectActor2: not called CC=1 SCAR=6.9
4251 0 my $label = shift;
4252 0 my $value = shift;
4253  
4254 0 push @{$o->{actorHashes}}, $value;
4255 }
4256  
4257 sub collectStore {
4258 0 ▶ my $o = shift;
Subroutine collectStore: not called CC=1 SCAR=6.9
4259 0 my $label = shift;
4260 0 my $value = shift;
4261  
4262 0 push @{$o->{accountTokens}}, CDS::AccountToken->new($value, $o->{actorHash});
4263 0 delete $o->{actorHash};
4264 }
4265  
4266 sub new {
4267 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
4268 0 my $actor = shift;
4269 0 bless {actor => $actor, ui => $actor->ui} }
4270  
4271 # END AUTOGENERATED
4272  
4273 # HTML FOLDER NAME entrusted-actors
4274 # HTML TITLE Entrusted actors
4275 sub help {
4276 0 ▶ my $o = shift;
Subroutine help: not called CC=1 SCAR=6.9
4277 0 my $cmd = shift;
4278  
4279 0 my $ui = $o->{ui};
4280 0 $ui->space;
4281 0 $ui->command('cds show entrusted actors');
4282 0 $ui->p('Shows all entrusted actors.');
4283 0 $ui->space;
4284 0 $ui->command('cds entrust ACCOUNT*');
4285 0 $ui->command('cds entrust ACTOR on STORE');
4286 0 $ui->p('Adds the indicated entrusted actors. Entrusted actors can read our private data and messages. The public key of the entrusted actor must be available on the store.');
4287 0 $ui->space;
4288 0 $ui->command('cds do not entrust ACTOR*');
4289 0 $ui->p('Removes the indicated entrusted actors.');
4290 0 $ui->space;
4291 0 $ui->p('After modifying the entrusted actors, you should "cds announce" yourself to publish the changes.');
4292 0 $ui->space;
4293 }
4294  
4295 sub show {
4296 0 ▶ my $o = shift;
Subroutine show: not called CC=3 SCAR=24.8
4297 0 my $cmd = shift;
4298  
4299 0 my $builder = CDS::ActorGroupBuilder->new;
4300 0 $builder->parseEntrustedActorList($o->{actor}->entrustedActorsSelector->record, 1);
4301  
4302 0 my @actors = $builder->entrustedActors;
4303 0 for my $actor (@actors) {
4304 0 my $storeReference = $o->{actor}->storeUrlReference($actor->storeUrl);
4305 0 $o->{ui}->line($actor->hash->hex, $o->{ui}->gray(' on ', $storeReference));
4306 }
4307  
4308 0 ▶ return if scalar @actors;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @actors 0 0 0
4309 0 $o->{ui}->line($o->{ui}->gray('none'));
4310 }
4311  
4312 sub entrust {
4313 0 ▶ my $o = shift;
Subroutine entrust: not called CC=6 SCAR=37.4
4314 0 my $cmd = shift;
4315  
4316 0 $o->{accountTokens} = [];
4317 0 $cmd->collect($o);
4318  
4319 # Get the list of currently entrusted actors
4320 0 my $entrusted = $o->createEntrustedActorsIndex;
4321  
4322 # Add new actors
4323 0 for my $accountToken (@{$o->{accountTokens}}) {
4324 0 my $actorHash = $accountToken->actorHash;
4325  
4326 # Check if the key is already entrusted
4327 0 ▶ if ($entrusted->{$accountToken->url}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$entrusted{$accountToken->url}) 0 0 0
4328 0 $o->{ui}->pOrange($accountToken->url, ' is already entrusted.');
4329 0 next;
4330 }
4331  
4332 # Get the public key
4333 0 my ($publicKey, $invalidReason, $storeError) = $o->{actor}->keyPair->getPublicKey($actorHash, $accountToken->cliStore);
4334 0 ▶ if (defined $storeError) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $storeError) 0 0 0
4335 0 $o->{ui}->pRed('Unable to get the public key ', $actorHash->hex, ' from ', $accountToken->cliStore->url, ': ', $storeError);
4336 0 next;
4337 }
4338  
4339 0 ▶ if (defined $invalidReason) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $invalidReason) 0 0 0
4340 0 $o->{ui}->pRed('Unable to get the public key ', $actorHash->hex, ' from ', $accountToken->cliStore->url, ': ', $invalidReason);
4341 0 next;
4342 }
4343  
4344 # Add it
4345 0 $o->{actor}->entrust($accountToken->cliStore->url, $publicKey);
4346 0 ▶ $o->{ui}->pGreen($entrusted->{$actorHash->hex} ? 'Updated ' : 'Added ', $actorHash->hex, ' as entrusted actor.');
Branch: 1 branch
BranchTrueFalseTotal
$$entrusted{$actorHash->hex} ? : 0 0 0
4347 }
4348  
4349 # Save
4350 0 $o->{actor}->saveOrShowError;
4351 }
4352  
4353 sub doNotEntrust {
4354 0 ▶ my $o = shift;
Subroutine doNotEntrust: not called CC=3 SCAR=24.8
4355 0 my $cmd = shift;
4356  
4357 0 $o->{actorHashes} = [];
4358 0 $cmd->collect($o);
4359  
4360 # Get the list of currently entrusted actors
4361 0 my $entrusted = $o->createEntrustedActorsIndex;
4362  
4363 # Remove entrusted actors
4364 0 for my $actorHash (@{$o->{actorHashes}}) {
4365 0 ▶ if ($entrusted->{$actorHash->hex}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$entrusted{$actorHash->hex}) { } 0 0 0
4366 0 $o->{actor}->doNotEntrust($actorHash);
4367 0 $o->{ui}->pGreen('Removed ', $actorHash->hex, ' from the list of entrusted actors.');
4368 } else {
4369 0 $o->{ui}->pOrange($actorHash->hex, ' is not entrusted.');
4370 }
4371 }
4372  
4373 # Save
4374 0 $o->{actor}->saveOrShowError;
4375 }
4376  
4377 sub createEntrustedActorsIndex {
4378 0 ▶ my $o = shift;
Subroutine createEntrustedActorsIndex: not called CC=2 SCAR=17.9
4379  
4380 0 my $builder = CDS::ActorGroupBuilder->new;
4381 0 $builder->parseEntrustedActorList($o->{actor}->entrustedActorsSelector->record, 1);
4382  
4383 0 my $index = {};
4384 0 for my $actor ($builder->entrustedActors) {
4385 0 my $url = $actor->storeUrl.'/accounts/'.$actor->hash->hex;
4386 0 $index->{$actor->hash->hex} = 1;
4387 0 $index->{$url} = 1;
4388 }
4389  
4390 0 return $index;
4391 }
4392  
4393 package CDS::Commands::FolderStore;
4394  
4395 # BEGIN AUTOGENERATED
4396  
4397 sub register {
4398 0 ▶ my $class = shift;
Subroutine register: not called CC=1 SCAR=6.9
4399 0 my $cds = shift;
4400 0 my $help = shift;
4401  
4402 0 my $node000 = CDS::Parser::Node->new(0);
4403 0 my $node001 = CDS::Parser::Node->new(0);
4404 0 my $node002 = CDS::Parser::Node->new(0);
4405 0 my $node003 = CDS::Parser::Node->new(0);
4406 0 my $node004 = CDS::Parser::Node->new(0);
4407 0 my $node005 = CDS::Parser::Node->new(0);
4408 0 my $node006 = CDS::Parser::Node->new(0);
4409 0 my $node007 = CDS::Parser::Node->new(0);
4410 0 my $node008 = CDS::Parser::Node->new(0);
4411 0 my $node009 = CDS::Parser::Node->new(0);
4412 0 my $node010 = CDS::Parser::Node->new(0);
4413 0 my $node011 = CDS::Parser::Node->new(0);
4414 0 my $node012 = CDS::Parser::Node->new(0);
4415 0 my $node013 = CDS::Parser::Node->new(0);
4416 0 my $node014 = CDS::Parser::Node->new(0);
4417 0 my $node015 = CDS::Parser::Node->new(0);
4418 0 my $node016 = CDS::Parser::Node->new(0);
4419 0 my $node017 = CDS::Parser::Node->new(0);
4420 0 my $node018 = CDS::Parser::Node->new(0);
4421 0 my $node019 = CDS::Parser::Node->new(0);
4422 0 my $node020 = CDS::Parser::Node->new(0);
4423 0 my $node021 = CDS::Parser::Node->new(0);
4424 0 my $node022 = CDS::Parser::Node->new(0);
4425 0 my $node023 = CDS::Parser::Node->new(0);
4426 0 my $node024 = CDS::Parser::Node->new(0);
4427 0 my $node025 = CDS::Parser::Node->new(1);
4428 0 my $node026 = CDS::Parser::Node->new(0);
4429 0 my $node027 = CDS::Parser::Node->new(0);
4430 0 my $node028 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&help});
4431 0 my $node029 = CDS::Parser::Node->new(1);
4432 0 my $node030 = CDS::Parser::Node->new(0);
4433 0 my $node031 = CDS::Parser::Node->new(0);
4434 0 my $node032 = CDS::Parser::Node->new(0);
4435 0 my $node033 = CDS::Parser::Node->new(0);
4436 0 my $node034 = CDS::Parser::Node->new(0);
4437 0 my $node035 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&checkPermissions});
4438 0 my $node036 = CDS::Parser::Node->new(0);
4439 0 my $node037 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&fixPermissions});
4440 0 my $node038 = CDS::Parser::Node->new(0);
4441 0 my $node039 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&showPermissions});
4442 0 my $node040 = CDS::Parser::Node->new(0);
4443 0 my $node041 = CDS::Parser::Node->new(1);
4444 0 my $node042 = CDS::Parser::Node->new(0);
4445 0 my $node043 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&addAccount});
4446 0 my $node044 = CDS::Parser::Node->new(0);
4447 0 my $node045 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&removeAccount});
4448 0 my $node046 = CDS::Parser::Node->new(0);
4449 0 my $node047 = CDS::Parser::Node->new(1);
4450 0 my $node048 = CDS::Parser::Node->new(0);
4451 0 my $node049 = CDS::Parser::Node->new(0);
4452 0 my $node050 = CDS::Parser::Node->new(0);
4453 0 my $node051 = CDS::Parser::Node->new(0);
4454 0 my $node052 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&checkPermissions});
4455 0 my $node053 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&fixPermissions});
4456 0 my $node054 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&showPermissions});
4457 0 my $node055 = CDS::Parser::Node->new(1);
4458 0 my $node056 = CDS::Parser::Node->new(0);
4459 0 my $node057 = CDS::Parser::Node->new(0);
4460 0 my $node058 = CDS::Parser::Node->new(0);
4461 0 my $node059 = CDS::Parser::Node->new(0);
4462 0 my $node060 = CDS::Parser::Node->new(0);
4463 0 my $node061 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&addAccount});
4464 0 my $node062 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&removeAccount});
4465 0 my $node063 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&setPermissions});
4466 0 my $node064 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&createStore});
4467 0 $cds->addArrow($node001, 1, 0, 'create');
4468 0 $cds->addArrow($node003, 1, 0, 'check');
4469 0 $cds->addArrow($node004, 1, 0, 'fix');
4470 0 $cds->addArrow($node005, 1, 0, 'show');
4471 0 $cds->addArrow($node007, 1, 0, 'set');
4472 0 $cds->addArrow($node009, 1, 0, 'add');
4473 0 $cds->addArrow($node010, 1, 0, 'add');
4474 0 $cds->addArrow($node011, 1, 0, 'add');
4475 0 $cds->addArrow($node012, 1, 0, 'add');
4476 0 $cds->addArrow($node013, 1, 0, 'add');
4477 0 $cds->addArrow($node023, 1, 0, 'remove');
4478 0 $help->addArrow($node000, 1, 0, 'create');
4479 0 $node000->addArrow($node028, 1, 0, 'store');
4480 0 $node001->addArrow($node002, 1, 0, 'store');
4481 0 $node002->addArrow($node029, 1, 0, 'FOLDERNAME', \&collectFoldername);
4482 0 $node003->addArrow($node035, 1, 0, 'permissions');
4483 0 $node004->addArrow($node037, 1, 0, 'permissions');
4484 0 $node005->addArrow($node006, 1, 0, 'permission');
4485 0 $node006->addArrow($node039, 1, 0, 'scheme');
4486 0 $node007->addArrow($node008, 1, 0, 'permission');
4487 0 $node008->addArrow($node041, 1, 0, 'scheme');
4488 0 $node009->addArrow($node014, 1, 0, 'account');
4489 0 $node010->addArrow($node015, 1, 0, 'account');
4490 0 $node011->addArrow($node016, 1, 0, 'account');
4491 0 $node012->addArrow($node017, 1, 0, 'account');
4492 0 $node013->addArrow($node018, 1, 0, 'account');
4493 0 $node014->addArrow($node019, 1, 0, 'for');
4494 0 $node015->addArrow($node020, 1, 0, 'for');
4495 0 $node016->addArrow($node021, 1, 0, 'for');
4496 0 $node017->addArrow($node043, 1, 1, 'ACCOUNT', \&collectAccount);
4497 0 $node018->addArrow($node022, 1, 0, 'for');
4498 0 $node019->addArrow($node043, 1, 0, 'OBJECTFILE', \&collectObjectfile);
4499 0 $node020->addArrow($node043, 1, 0, 'KEYPAIR', \&collectKeypair);
4500 0 $node021->addArrow($node025, 1, 0, 'ACTOR', \&collectActor);
4501 0 $node022->addArrow($node043, 1, 0, 'OBJECT', \&collectObject);
4502 0 $node023->addArrow($node024, 1, 0, 'account');
4503 0 $node024->addArrow($node045, 1, 0, 'HASH', \&collectHash);
4504 0 $node025->addArrow($node026, 1, 0, 'on');
4505 0 $node025->addArrow($node027, 0, 0, 'from');
4506 0 $node026->addArrow($node043, 1, 0, 'STORE', \&collectStore);
4507 0 $node027->addArrow($node043, 0, 0, 'STORE', \&collectStore);
4508 0 $node029->addArrow($node030, 1, 0, 'for');
4509 0 $node029->addArrow($node031, 1, 0, 'for');
4510 0 $node029->addArrow($node032, 1, 0, 'for');
4511 0 $node029->addDefault($node047);
4512 0 $node030->addArrow($node033, 1, 0, 'user');
4513 0 $node031->addArrow($node034, 1, 0, 'group');
4514 0 $node032->addArrow($node047, 1, 0, 'everybody', \&collectEverybody);
4515 0 $node033->addArrow($node047, 1, 0, 'USER', \&collectUser);
4516 0 $node034->addArrow($node047, 1, 0, 'GROUP', \&collectGroup);
4517 0 $node035->addArrow($node036, 1, 0, 'of');
4518 0 $node036->addArrow($node052, 1, 0, 'STORE', \&collectStore1);
4519 0 $node037->addArrow($node038, 1, 0, 'of');
4520 0 $node038->addArrow($node053, 1, 0, 'STORE', \&collectStore1);
4521 0 $node039->addArrow($node040, 1, 0, 'of');
4522 0 $node040->addArrow($node054, 1, 0, 'STORE', \&collectStore1);
4523 0 $node041->addArrow($node042, 1, 0, 'of');
4524 0 $node041->addDefault($node055);
4525 0 $node042->addArrow($node055, 1, 0, 'STORE', \&collectStore1);
4526 0 $node043->addArrow($node044, 1, 0, 'to');
4527 0 $node044->addArrow($node061, 1, 0, 'STORE', \&collectStore1);
4528 0 $node045->addArrow($node046, 1, 0, 'from');
4529 0 $node046->addArrow($node062, 1, 0, 'STORE', \&collectStore1);
4530 0 $node047->addArrow($node048, 1, 0, 'and');
4531 0 $node047->addDefault($node064);
4532 0 $node048->addArrow($node049, 1, 0, 'remember');
4533 0 $node049->addArrow($node050, 1, 0, 'it');
4534 0 $node050->addArrow($node051, 1, 0, 'as');
4535 0 $node051->addArrow($node064, 1, 0, 'TEXT', \&collectText);
4536 0 $node055->addArrow($node056, 1, 0, 'to');
4537 0 $node055->addArrow($node057, 1, 0, 'to');
4538 0 $node055->addArrow($node058, 1, 0, 'to');
4539 0 $node056->addArrow($node059, 1, 0, 'user');
4540 0 $node057->addArrow($node060, 1, 0, 'group');
4541 0 $node058->addArrow($node063, 1, 0, 'everybody', \&collectEverybody);
4542 0 $node059->addArrow($node063, 1, 0, 'USER', \&collectUser);
4543 0 $node060->addArrow($node063, 1, 0, 'GROUP', \&collectGroup);
4544 }
4545  
4546 sub collectAccount {
4547 0 ▶ my $o = shift;
Subroutine collectAccount: not called CC=1 SCAR=6.9
4548 0 my $label = shift;
4549 0 my $value = shift;
4550  
4551 0 $o->{accountToken} = $value;
4552 }
4553  
4554 sub collectActor {
4555 0 ▶ my $o = shift;
Subroutine collectActor: not called CC=1 SCAR=6.9
4556 0 my $label = shift;
4557 0 my $value = shift;
4558  
4559 0 $o->{actorHash} = $value;
4560 }
4561  
4562 sub collectEverybody {
4563 0 ▶ my $o = shift;
Subroutine collectEverybody: not called CC=1 SCAR=6.9
4564 0 my $label = shift;
4565 0 my $value = shift;
4566  
4567 0 $o->{permissions} = CDS::FolderStore::PosixPermissions::World->new;
4568 }
4569  
4570 sub collectFoldername {
4571 0 ▶ my $o = shift;
Subroutine collectFoldername: not called CC=1 SCAR=6.9
4572 0 my $label = shift;
4573 0 my $value = shift;
4574  
4575 0 $o->{foldername} = $value;
4576 }
4577  
4578 sub collectGroup {
4579 0 ▶ my $o = shift;
Subroutine collectGroup: not called CC=1 SCAR=6.9
4580 0 my $label = shift;
4581 0 my $value = shift;
4582  
4583 0 $o->{permissions} = CDS::FolderStore::PosixPermissions::Group->new($o->{group});
4584 }
4585  
4586 sub collectHash {
4587 0 ▶ my $o = shift;
Subroutine collectHash: not called CC=1 SCAR=6.9
4588 0 my $label = shift;
4589 0 my $value = shift;
4590  
4591 0 $o->{hash} = $value;
4592 }
4593  
4594 sub collectKeypair {
4595 0 ▶ my $o = shift;
Subroutine collectKeypair: not called CC=1 SCAR=6.9
4596 0 my $label = shift;
4597 0 my $value = shift;
4598  
4599 0 $o->{keyPairToken} = $value;
4600 }
4601  
4602 sub collectObject {
4603 0 ▶ my $o = shift;
Subroutine collectObject: not called CC=1 SCAR=6.9
4604 0 my $label = shift;
4605 0 my $value = shift;
4606  
4607 0 $o->{accountToken} = CDS::AccountToken->new($value->cliStore, $value->hash);
4608 }
4609  
4610 sub collectObjectfile {
4611 0 ▶ my $o = shift;
Subroutine collectObjectfile: not called CC=1 SCAR=6.9
4612 0 my $label = shift;
4613 0 my $value = shift;
4614  
4615 0 $o->{file} = $value;
4616 }
4617  
4618 sub collectStore {
4619 0 ▶ my $o = shift;
Subroutine collectStore: not called CC=1 SCAR=6.9
4620 0 my $label = shift;
4621 0 my $value = shift;
4622  
4623 0 $o->{accountToken} = CDS::AccountToken->new($value, $o->{actorHash});
4624 }
4625  
4626 sub collectStore1 {
4627 0 ▶ my $o = shift;
Subroutine collectStore1: not called CC=1 SCAR=6.9
4628 0 my $label = shift;
4629 0 my $value = shift;
4630  
4631 0 $o->{store} = $value;
4632 }
4633  
4634 sub collectText {
4635 0 ▶ my $o = shift;
Subroutine collectText: not called CC=1 SCAR=6.9
4636 0 my $label = shift;
4637 0 my $value = shift;
4638  
4639 0 $o->{label} = $value;
4640 }
4641  
4642 sub collectUser {
4643 0 ▶ my $o = shift;
Subroutine collectUser: not called CC=1 SCAR=6.9
4644 0 my $label = shift;
4645 0 my $value = shift;
4646  
4647 0 $o->{permissions} = CDS::FolderStore::PosixPermissions::User->new($value);
4648 }
4649  
4650 sub new {
4651 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
4652 0 my $actor = shift;
4653 0 bless {actor => $actor, ui => $actor->ui} }
4654  
4655 # END AUTOGENERATED
4656  
4657 # HTML FOLDER NAME folder-store
4658 # HTML TITLE Folder store management
4659 sub help {
4660 0 ▶ my $o = shift;
Subroutine help: not called CC=1 SCAR=6.9
4661 0 my $cmd = shift;
4662  
4663 0 my $ui = $o->{ui};
4664 0 $ui->space;
4665 0 $ui->command('cds create store FOLDERNAME');
4666 0 $ui->p('Creates a new store in FOLDERNAME, and adds it to the list of known stores. If the folder does not exist, it is created. If it does exist, it must be empty.');
4667 0 $ui->space;
4668 0 $ui->p('By default, the filesystem permissions of the store are set such that only the current user can post objects and modify boxes. Other users on the system can post to the message box, list boxes, and read objects.');
4669 0 $ui->space;
4670 0 $ui->command('… for user USER');
4671 0 $ui->p('Makes the store accessible to the user USER.');
4672 0 $ui->space;
4673 0 $ui->command('… for group GROUP');
4674 0 $ui->p('Makes the store accessible to the group GROUP.');
4675 0 $ui->space;
4676 0 $ui->command('… for everybody');
4677 0 $ui->p('Makes the store accessible to everybody.');
4678 0 $ui->space;
4679 0 $ui->p('Note that the permissions only affect direct filesystem access. If your store is exposed by a server (e.g. a web server), it may be accessible to others.');
4680 0 $ui->space;
4681 0 $ui->command('… and remember it as TEXT');
4682 0 $ui->p('Remembers the store under the label TEXT. See "cds help remember" for details.');
4683 0 $ui->space;
4684 0 $ui->command('cds check permissions [of STORE]');
4685 0 $ui->p('Checks the permissions (owner, mode) of all accounts, boxes, box entries, and objects of the store, and reports any error. The permission scheme (user, group, or everybody) is derived from the "accounts" and "objects" folders.');
4686 0 $ui->p('If the store is omitted, the selected store is used.');
4687 0 $ui->space;
4688 0 $ui->command('cds fix permissions [of STORE]');
4689 0 $ui->p('Same as above, but tries to fix the permissions (chown, chmod) instead of just reporting them.');
4690 0 $ui->space;
4691 0 $ui->command('cds show permission scheme [of STORE]');
4692 0 $ui->p('Reports the permission scheme of the store.');
4693 0 $ui->space;
4694 0 $ui->command('cds set permission scheme [of STORE] to (user USER|group GROUP|everybody)');
4695 0 $ui->p('Sets the permission scheme of the stores, and changes all permissions accordingly.');
4696 0 $ui->space;
4697 0 $ui->command('cds add account ACCOUNT [to STORE]');
4698 0 $ui->command('cds add account for FILE [to STORE]');
4699 0 $ui->command('cds add account for KEYPAIR [to STORE]');
4700 0 $ui->command('cds add account for OBJECT [to STORE]');
4701 0 $ui->command('cds add account for ACTOR on STORE [to STORE]');
4702 0 $ui->p('Uploads the public key (FILE, KEYPAIR, OBJECT, ACCOUNT, or ACTOR on STORE) onto the store, and adds the corresponding account. This grants the user the right to access this account.');
4703 0 $ui->space;
4704 0 $ui->command('cds remove account HASH [from STORE]');
4705 0 $ui->p('Removes the indicated account from the store. This immediately destroys the user\'s data.');
4706 0 $ui->space;
4707 }
4708  
4709 sub createStore {
4710 0 ▶ my $o = shift;
Subroutine createStore: not called CC=6 SCAR=37.4
4711 0 my $cmd = shift;
4712  
4713 0 $o->{permissions} = CDS::FolderStore::PosixPermissions::User->new;
4714 0 $cmd->collect($o);
4715  
4716 # Give up if the folder is non-empty (but we accept hidden files)
4717 0 for my $file (CDS->listFolder($o->{foldername})) {
4718 0 ▶ next if $file =~ /^\./;
Branch: 1 branch
BranchTrueFalseTotal
if $file =~ /^\./ 0 0 0
4719 0 $o->{ui}->pRed('The folder ', $o->{foldername}, ' is not empty. Giving up …');
4720 0 return;
4721 }
4722  
4723 # Create the object store
4724 0 ▶ $o->create($o->{foldername}.'/objects') // return;
Condition0%0/2
$o->create($o->{"foldername"} . '/objects') // (return)
l!l
00
MC/DC0%0/1
$o->create($o->{"foldername"} . '/objects') // (return)
$o->create($o->{"foldername"} . '/objects')
Truth table0%0/2
A
A= $o->create($o->{"foldername"} . '/objects')
Aresult
11
00
4725 0 $o->{ui}->pGreen('Object store created for ', $o->{permissions}->target, '.');
4726  
4727 # Create the account store
4728 0 ▶ $o->create($o->{foldername}.'/accounts') // return;
Condition0%0/2
$o->create($o->{"foldername"} . '/accounts') // (return)
l!l
00
MC/DC0%0/1
$o->create($o->{"foldername"} . '/accounts') // (return)
$o->create($o->{"foldername"} . '/accounts')
Truth table0%0/2
A
A= $o->create($o->{"foldername"} . '/accounts')
Aresult
11
00
4729 0 $o->{ui}->pGreen('Account store created for ', $o->{permissions}->target, '.');
4730  
4731 # Return if the user does not want us to add the store
4732 0 ▶ return if ! defined $o->{label};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $o->{"label"} 0 0 0
4733  
4734 # Remember the store
4735 0 my $record = CDS::Record->new;
4736 0 $record->addText('store')->addText('file://'.$o->{foldername});
4737 0 $o->{actor}->remember($o->{label}, $record);
4738 0 $o->{actor}->saveOrShowError;
4739 }
4740  
4741 # Creates a folder with the selected permissions.
4742 sub create {
4743 0 ▶ my $o = shift;
Subroutine create: not called CC=11 SCAR=48.8
4744 0 my $folder = shift;
4745  
4746 # Create the folders to here if necessary
4747 0 for my $intermediateFolder (CDS->intermediateFolders($folder)) {
4748 0 mkdir $intermediateFolder, 0755;
4749 }
4750  
4751 # mkdir (if it does not exist yet) and chmod (if it does exist already)
4752 0 mkdir $folder, $o->{permissions}->baseFolderMode;
4753 0 chmod $o->{permissions}->baseFolderMode, $folder;
4754 0 ▶ chown $o->{permissions}->uid // -1, $o->{permissions}->gid // -1, $folder;
Condition0%0/4
$o->{"permissions"}->uid // -1
l!l
00
$o->{"permissions"}->gid // -1
l!l
00
MC/DC0%0/1
$o->{"permissions"}->uid // -1
$o->{"permissions"}->uid
MC/DC0%0/1
$o->{"permissions"}->gid // -1
$o->{"permissions"}->gid
Truth table0%0/2
A
A= $o->{"permissions"}->uid
Aresult
11
00
Truth table0%0/2
A
A= $o->{"permissions"}->gid
Aresult
11
00
4755  
4756 # Check if the result is correct
4757 0 my @s = stat $folder;
4758 0 ▶ return $o->{ui}->error('Unable to create ', $o->{foldername}, '.') if ! scalar @s;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @s 0 0 0
4759 0 my $mode = $s[2];
4760 0 ▶ return $o->{ui}->error($folder, ' exists, but is not a folder') if ! Fcntl::S_ISDIR($mode);
Branch: 1 branch
BranchTrueFalseTotal
unless Fcntl::S_ISDIR($mode) 0 0 0
4761 0 ▶ return $o->{ui}->error('Unable to set the owning user ', $o->{permissions}->user, ' for ', $folder, '.') if defined $o->{permissions}->uid && $s[4] != $o->{permissions}->uid;
Branch: 1 branch
BranchTrueFalseTotal
if defined $o->{"permissions"}->uid and $s[4] != $o->{"permissions"}->uid 0 0 0
Condition0%0/3
defined $o->{"permissions"}->uid and $s[4] != $o->{"permissions"}->uid
!ll&&!rl&&r
000
MC/DC0%0/2
defined $o->{"permissions"}->uid and $s[4] != $o->{"permissions"}->uid
defined $o->{"permissions"}->uid $s[4] != $o->{"permissions"}->uid
Truth table0%0/3
A and B
A= defined $o->{"permissions"}->uidB= $s[4] != $o->{"permissions"}->uid
ABresult
0X0
100
111
4762 0 ▶ return $o->{ui}->error('Unable to set the owning group ', $o->{permissions}->group, ' for ', $folder, '.') if defined $o->{permissions}->gid && $s[5] != $o->{permissions}->gid;
Branch: 1 branch
BranchTrueFalseTotal
if defined $o->{"permissions"}->gid and $s[5] != $o->{"permissions"}->gid 0 0 0
Condition0%0/3
defined $o->{"permissions"}->gid and $s[5] != $o->{"permissions"}->gid
!ll&&!rl&&r
000
MC/DC0%0/2
defined $o->{"permissions"}->gid and $s[5] != $o->{"permissions"}->gid
defined $o->{"permissions"}->gid $s[5] != $o->{"permissions"}->gid
Truth table0%0/3
A and B
A= defined $o->{"permissions"}->gidB= $s[5] != $o->{"permissions"}->gid
ABresult
0X0
100
111
4763 0 ▶ return $o->{ui}->error('Unable to set the mode on ', $folder, '.') if ($mode & 0777) != $o->{permissions}->baseFolderMode;
Branch: 1 branch
BranchTrueFalseTotal
if ($mode & 511) != $o->{"permissions"}->baseFolderMode 0 0 0
4764 0 return 1;
4765 }
4766  
4767 sub existingFolderStoreOrShowError {
4768 0 ▶ my $o = shift;
Subroutine existingFolderStoreOrShowError: not called CC=4 SCAR=30.0
4769  
4770 0 ▶ my $store = $o->{store} // $o->{actor}->preferredStore;
Condition0%0/3
$o->{"store"} // $o->{"actor"}->preferredStore
l!l&&r!l&&!r
000
MC/DC0%0/2
$o->{"store"} // $o->{"actor"}->preferredStore
$o->{"store"} $o->{"actor"}->preferredStore
Truth table0%0/3
A // B
A= $o->{"store"}B= $o->{"actor"}->preferredStore
ABresult
1X1
011
000
4771  
4772 0 my $folderStore = CDS::FolderStore->forUrl($store->url);
4773 0 ▶ if (! $folderStore) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($folderStore) 0 0 0
4774 0 $o->{ui}->error('"', $store->url, '" is not a folder store.');
4775 0 $o->{ui}->space;
4776 0 $o->{ui}->p('Account management and file system permission checks only apply to stores on the local file system. Such stores are referred to by file://… URLs, or file system paths.');
4777 0 $o->{ui}->p('To fix the permissions on a remote store, log onto that server and fix the permissions there. Note that permissions are not part of the Condensation protocol, but a property of some underlying storage systems, such as file systems.');
4778 0 $o->{ui}->space;
4779 0 return;
4780 }
4781  
4782 0 ▶ if (! $folderStore->exists) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($folderStore->exists) 0 0 0
4783 0 $o->{ui}->error('"', $folderStore->folder, '" does not exist.');
4784 0 $o->{ui}->space;
4785 0 $o->{ui}->p('The folder either does not exist, or is not a folder store. You can create this store using:');
4786 0 $o->{ui}->line($o->{ui}->gold(' cds create store ', $folderStore->folder));
4787 0 $o->{ui}->space;
4788 0 return;
4789 }
4790  
4791 0 return $folderStore;
4792 }
4793  
4794 sub showPermissions {
4795 0 ▶ my $o = shift;
Subroutine showPermissions: not called CC=2 SCAR=17.9
4796 0 my $cmd = shift;
4797  
4798 0 $cmd->collect($o);
4799 0 ▶ my $folderStore = $o->existingFolderStoreOrShowError // return;
Condition0%0/2
$o->existingFolderStoreOrShowError // (return)
l!l
00
MC/DC0%0/1
$o->existingFolderStoreOrShowError // (return)
$o->existingFolderStoreOrShowError
Truth table0%0/2
A
A= $o->existingFolderStoreOrShowError
Aresult
11
00
4800 0 $o->showStore($folderStore);
4801 0 $o->{ui}->space;
4802 }
4803  
4804 sub showStore {
4805 0 ▶ my $o = shift;
Subroutine showStore: not called CC=1 SCAR=6.9
4806 0 my $folderStore = shift;
4807  
4808 0 $o->{ui}->space;
4809 0 $o->{ui}->title('Store');
4810 0 $o->{ui}->line($folderStore->folder);
4811 0 $o->{ui}->line('Accessible to ', $folderStore->permissions->target, '.');
4812 }
4813  
4814 sub setPermissions {
4815 0 ▶ my $o = shift;
Subroutine setPermissions: not called CC=3 SCAR=24.8
4816 0 my $cmd = shift;
4817  
4818 0 $cmd->collect($o);
4819  
4820 0 ▶ my $folderStore = $o->existingFolderStoreOrShowError // return;
Condition0%0/2
$o->existingFolderStoreOrShowError // (return)
l!l
00
MC/DC0%0/1
$o->existingFolderStoreOrShowError // (return)
$o->existingFolderStoreOrShowError
Truth table0%0/2
A
A= $o->existingFolderStoreOrShowError
Aresult
11
00
4821 0 $o->showStore($folderStore);
4822  
4823 0 $folderStore->setPermissions($o->{permissions});
4824 0 $o->{ui}->line('Changing permissions …');
4825 0 my $logger = CDS::Commands::FolderStore::SetLogger->new($o, $folderStore->folder);
4826 0 ▶ $folderStore->checkPermissions($logger) || $o->traversalFailed($folderStore);
Branch: 1 branch
BranchTrueFalseTotal
$folderStore->checkPermissions($logger) or $o->traversalFailed($folderStore) 0 0 0
4827 0 $logger->summary;
4828  
4829 0 $o->{ui}->space;
4830 }
4831  
4832 sub checkPermissions {
4833 0 ▶ my $o = shift;
Subroutine checkPermissions: not called CC=3 SCAR=24.8
4834 0 my $cmd = shift;
4835  
4836 0 $cmd->collect($o);
4837  
4838 0 ▶ my $folderStore = $o->existingFolderStoreOrShowError // return;
Condition0%0/2
$o->existingFolderStoreOrShowError // (return)
l!l
00
MC/DC0%0/1
$o->existingFolderStoreOrShowError // (return)
$o->existingFolderStoreOrShowError
Truth table0%0/2
A
A= $o->existingFolderStoreOrShowError
Aresult
11
00
4839 0 $o->showStore($folderStore);
4840  
4841 0 $o->{ui}->line('Checking permissions …');
4842 0 my $logger = CDS::Commands::FolderStore::CheckLogger->new($o, $folderStore->folder);
4843 0 ▶ $folderStore->checkPermissions($logger) || $o->traversalFailed($folderStore);
Branch: 1 branch
BranchTrueFalseTotal
$folderStore->checkPermissions($logger) or $o->traversalFailed($folderStore) 0 0 0
4844 0 $logger->summary;
4845  
4846 0 $o->{ui}->space;
4847 }
4848  
4849 sub fixPermissions {
4850 0 ▶ my $o = shift;
Subroutine fixPermissions: not called CC=3 SCAR=24.8
4851 0 my $cmd = shift;
4852  
4853 0 $cmd->collect($o);
4854  
4855 0 ▶ my $folderStore = $o->existingFolderStoreOrShowError // return;
Condition0%0/2
$o->existingFolderStoreOrShowError // (return)
l!l
00
MC/DC0%0/1
$o->existingFolderStoreOrShowError // (return)
$o->existingFolderStoreOrShowError
Truth table0%0/2
A
A= $o->existingFolderStoreOrShowError
Aresult
11
00
4856 0 $o->showStore($folderStore);
4857  
4858 0 $o->{ui}->line('Fixing permissions …');
4859 0 my $logger = CDS::Commands::FolderStore::FixLogger->new($o, $folderStore->folder);
4860 0 ▶ $folderStore->checkPermissions($logger) || $o->traversalFailed($folderStore);
Branch: 1 branch
BranchTrueFalseTotal
$folderStore->checkPermissions($logger) or $o->traversalFailed($folderStore) 0 0 0
4861 0 $logger->summary;
4862  
4863 0 $o->{ui}->space;
4864 }
4865  
4866 sub traversalFailed {
4867 0 ▶ my $o = shift;
Subroutine traversalFailed: not called CC=1 SCAR=6.9
4868 0 my $folderStore = shift;
4869  
4870 0 $o->{ui}->space;
4871 0 $o->{ui}->p('Traversal failed because a file or folder could not be accessed. You may have to fix the permissions manually, or run this command with other privileges.');
4872 0 $o->{ui}->p('If you have root privileges, you can take over this store using:');
4873 0 my $userName = getpwuid($<);
4874 0 my $groupName = getgrgid($();
4875 0 $o->{ui}->line($o->{ui}->gold(' sudo chown -R ', $userName, ':', $groupName, ' ', $folderStore->folder));
4876 0 $o->{ui}->p('and then set the desired permission scheme:');
4877 0 $o->{ui}->line($o->{ui}->gold(' cds set permissions of ', $folderStore->folder, ' to …'));
4878 0 $o->{ui}->space;
4879 0 exit(1);
4880 }
4881  
4882 sub addAccount {
4883 0 ▶ my $o = shift;
Subroutine addAccount: not called CC=5 SCAR=34.0
4884 0 my $cmd = shift;
4885  
4886 0 $cmd->collect($o);
4887  
4888 # Prepare
4889 0 ▶ my $folderStore = $o->existingFolderStoreOrShowError // return;
Condition0%0/2
$o->existingFolderStoreOrShowError // (return)
l!l
00
MC/DC0%0/1
$o->existingFolderStoreOrShowError // (return)
$o->existingFolderStoreOrShowError
Truth table0%0/2
A
A= $o->existingFolderStoreOrShowError
Aresult
11
00
4890 0 ▶ my $publicKey = $o->publicKey // return;
Condition0%0/2
$o->publicKey // (return)
l!l
00
MC/DC0%0/1
$o->publicKey // (return)
$o->publicKey
Truth table0%0/2
A
A= $o->publicKey
Aresult
11
00
4891  
4892 # Upload the public key onto the store
4893 0 my $error = $folderStore->put($publicKey->hash, $publicKey->object);
4894 0 ▶ return $o->{ui}->error('Unable to upload the public key: ', $error) if $error;
Branch: 1 branch
BranchTrueFalseTotal
if $error 0 0 0
4895  
4896 # Create the account folder
4897 0 my $folder = $folderStore->folder.'/accounts/'.$publicKey->hash->hex;
4898 0 my $permissions = $folderStore->permissions;
4899 0 $permissions->mkdir($folder, $permissions->accountFolderMode);
4900 0 ▶ return $o->{ui}->error('Unable to create folder "', $folder, '".') if ! -d $folder;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $folder 0 0 0
4901 0 $o->{ui}->pGreen('Account ', $publicKey->hash->hex, ' added.');
4902 0 return 1;
4903 }
4904  
4905 sub publicKey {
4906 0 ▶ my $o = shift;
Subroutine publicKey: not called CC=6 SCAR=37.4
4907  
4908 0 ▶ return $o->{keyPairToken}->keyPair->publicKey if $o->{keyPairToken};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"keyPairToken"} 0 0 0
4909  
4910 0 ▶ if ($o->{file}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"file"}) 0 0 0
4911 0 ▶ my $bytes = CDS->readBytesFromFile($o->{file}) // return $o->{ui}->error('Cannot read "', $o->{file}, '".');
Condition0%0/2
"CDS"->readBytesFromFile($o->{"file"}) // (return $o->{"ui"}->error("Cannot read \"", $o->{"file"}, "\"."))
l!l
00
MC/DC0%0/1
"CDS"->readBytesFromFile($o->{"file"}) // (return $o->{"ui"}->error("Cannot read \"", $o->{"file"}, "\"."))
"CDS"->readBytesFromFile($o->{"file"})
Truth table0%0/2
A
A= "CDS"->readBytesFromFile($o->{"file"})
Aresult
11
00
4912 0 ▶ my $object = CDS::Object->fromBytes($bytes) // return $o->{ui}->error('"', $o->{file}, '" is not a public key.');
Condition0%0/2
"CDS::Object"->fromBytes($bytes) // (return $o->{"ui"}->error("\"", $o->{"file"}, "\" is not a public key."))
l!l
00
MC/DC0%0/1
"CDS::Object"->fromBytes($bytes) // (return $o->{"ui"}->error("\"", $o->{"file"}, "\" is not a public key."))
"CDS::Object"->fromBytes($bytes)
Truth table0%0/2
A
A= "CDS::Object"->fromBytes($bytes)
Aresult
11
00
4913 0 ▶ return CDS::PublicKey->fromObject($object) // return $o->{ui}->error('"', $o->{file}, '" is not a public key.');
Condition0%0/2
"CDS::PublicKey"->fromObject($object) // (return $o->{"ui"}->error("\"", $o->{"file"}, "\" is not a public key."))
l!l
00
MC/DC0%0/1
"CDS::PublicKey"->fromObject($object) // (return $o->{"ui"}->error("\"", $o->{"file"}, "\" is not a public key."))
"CDS::PublicKey"->fromObject($object)
Truth table0%0/2
A
A= "CDS::PublicKey"->fromObject($object)
Aresult
11
00
4914 }
4915  
4916 0 return $o->{actor}->uiGetPublicKey($o->{accountToken}->actorHash, $o->{accountToken}->cliStore, $o->{actor}->preferredKeyPairToken);
4917 }
4918  
4919 sub removeAccount {
4920 0 ▶ my $o = shift;
Subroutine removeAccount: not called CC=5 SCAR=34.0
4921 0 my $cmd = shift;
4922  
4923 0 $cmd->collect($o);
4924  
4925 # Prepare the folder
4926 0 ▶ my $folderStore = $o->existingFolderStoreOrShowError // return;
Condition0%0/2
$o->existingFolderStoreOrShowError // (return)
l!l
00
MC/DC0%0/1
$o->existingFolderStoreOrShowError // (return)
$o->existingFolderStoreOrShowError
Truth table0%0/2
A
A= $o->existingFolderStoreOrShowError
Aresult
11
00
4927 0 my $folder = $folderStore->folder.'/accounts/'.$o->{hash}->hex;
4928 0 my $deletedFolder = $folderStore->folder.'/accounts/deleted-'.$o->{hash}->hex;
4929  
4930 # Rename, so that it is not visible any more
4931 0 ▶ $o->recursivelyDelete($deletedFolder) if -e $deletedFolder;
Branch: 1 branch
BranchTrueFalseTotal
if -e $deletedFolder 0 0 0
4932 0 ▶ return $o->{ui}->line('The account ', $o->{hash}->hex, ' does not exist.') if ! -e $folder;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $folder 0 0 0
4933 0 ▶ rename($folder, $deletedFolder) || return $o->{ui}->error('Unable to rename the folder "', $folder, '".');
Branch: 1 branch
BranchTrueFalseTotal
rename $folder, $deletedFolder or return $o->{"ui"}->error("Unable to rename the folder \"", $folder, "\".") 0 0 0
4934  
4935 # Try to delete it entirely
4936 0 $o->recursivelyDelete($deletedFolder);
4937 0 $o->{ui}->pGreen('Account ', $o->{hash}->hex, ' removed.');
4938 0 return 1;
4939 }
4940  
4941 sub recursivelyDelete {
4942 0 ▶ my $o = shift;
Subroutine recursivelyDelete: not called CC=7 SCAR=40.3
4943 0 my $folder = shift;
4944  
4945 0 for my $filename (CDS->listFolder($folder)) {
4946 0 ▶ next if $filename =~ /^\./;
Branch: 1 branch
BranchTrueFalseTotal
if $filename =~ /^\./ 0 0 0
4947 0 my $file = $folder.'/'.$filename;
4948 0 ▶ if (-f $file) {
Branch: 2 branches
BranchTrueFalseTotal
if (-f $file) { } 0 0 0
elsif (-d $file) { } 0 0 0
4949 0 ▶ unlink $file || $o->{ui}->pOrange('Unable to remove the file "', $file, '".');
Condition0%0/3
$file || $o->{'ui'}->pOrange('Unable to remove the file "', $file, '".')
l!l&&r!l&&!r
000
MC/DC0%0/2
$file || $o->{'ui'}->pOrange('Unable to remove the file "', $file, '".')
$file $o->{'ui'}->pOrange('Unable to remove the file "', $file, '".')
Truth table0%0/3
A || B
A= $fileB= $o->{'ui'}->pOrange('Unable to remove the file "', $file, '".')
ABresult
1X1
011
000
4950 } elsif (-d $file) {
4951 0 $o->recursivelyDelete($file);
4952 }
4953 }
4954  
4955 0 ▶ rmdir($folder) || $o->{ui}->pOrange('Unable to remove the folder "', $folder, '".');
Branch: 1 branch
BranchTrueFalseTotal
rmdir $folder or $o->{"ui"}->pOrange("Unable to remove the folder \"", $folder, "\".") 0 0 0
4956 }
4957  
4958 package CDS::Commands::FolderStore::CheckLogger;
4959  
4960 1 ▶use parent -norequire, 'CDS::Commands::FolderStore::Logger';
Subroutine BEGIN: called CC=1 SCAR=0.0
4961  
4962 sub finalizeWrong {
4963 0 ▶ my $o = shift;
Subroutine finalizeWrong: not called CC=1 SCAR=6.9
4964  
4965 0 $o->{ui}->pRed(@_);
4966 0 return 0;
4967 }
4968  
4969 sub summary {
4970 0 ▶ my $o = shift;
Subroutine summary: not called CC=2 SCAR=17.9
4971  
4972 0 $o->{ui}->p(($o->{correct} + $o->{wrong}).' files and folders traversed.');
4973 0 ▶ if ($o->{wrong} > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{'wrong'} > 0) { } 0 0 0
4974 0 $o->{ui}->p($o->{wrong}, ' files and folders have wrong permissions. To fix them, run');
4975 0 $o->{ui}->line($o->{ui}->gold(' cds fix permissions of ', $o->{store}->url));
4976 } else {
4977 0 $o->{ui}->pGreen('All permissions are OK.');
4978 }
4979 }
4980  
4981 package CDS::Commands::FolderStore::FixLogger;
4982  
4983 1 ▶use parent -norequire, 'CDS::Commands::FolderStore::Logger';
Subroutine BEGIN: called CC=1 SCAR=0.0
4984  
4985 sub finalizeWrong {
4986 0 ▶ my $o = shift;
Subroutine finalizeWrong: not called CC=1 SCAR=6.9
4987  
4988 0 $o->{ui}->line(@_);
4989 0 return 1;
4990 }
4991  
4992 sub summary {
4993 0 ▶ my $o = shift;
Subroutine summary: not called CC=2 SCAR=17.9
4994  
4995 0 $o->{ui}->p(($o->{correct} + $o->{wrong}).' files and folders traversed.');
4996 0 ▶ $o->{ui}->p('The permissions of ', $o->{wrong}, ' files and folders have been fixed.') if $o->{wrong} > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"wrong"} > 0 0 0 0
4997 0 $o->{ui}->pGreen('All permissions are OK.');
4998 }
4999  
5000 package CDS::Commands::FolderStore::Logger;
5001  
5002 sub new {
5003 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
5004 0 my $parent = shift;
5005 0 my $baseFolder = shift;
5006  
5007 return bless {
5008 ui => $parent->{ui},
5009 store => $parent->{store},
5010 0 baseFolder => $baseFolder,
5011 correct => 0,
5012 wrong => 0,
5013 }, $class;
5014 }
5015  
5016 sub correct {
5017 0 ▶ my $o = shift;
Subroutine correct: not called CC=1 SCAR=6.9
5018  
5019 0 $o->{correct} += 1;
5020 }
5021  
5022 sub wrong {
5023 0 ▶ my $o = shift;
Subroutine wrong: not called CC=8 SCAR=42.8
5024 0 my $item = shift;
5025 0 my $uid = shift;
5026 0 my $gid = shift;
5027 0 my $mode = shift;
5028 0 my $expectedUid = shift;
5029 0 my $expectedGid = shift;
5030 0 my $expectedMode = shift;
5031  
5032 0 my $len = length $o->{baseFolder};
5033 0 $o->{wrong} += 1;
5034 0 ▶ $item = '…'.substr($item, $len) if length $item > $len && substr($item, 0, $len) eq $o->{baseFolder};
Branch: 1 branch
BranchTrueFalseTotal
if length $item > $len and substr($item, 0, $len) eq $o->{"baseFolder"} 0 0 0
Condition0%0/3
length $item > $len and substr($item, 0, $len) eq $o->{"baseFolder"}
!ll&&!rl&&r
000
MC/DC0%0/2
length $item > $len and substr($item, 0, $len) eq $o->{"baseFolder"}
length $item > $len substr($item, 0, $len) eq $o->{"baseFolder"}
Truth table0%0/3
A and B
A= length $item > $lenB= substr($item, 0, $len) eq $o->{"baseFolder"}
ABresult
0X0
100
111
5035 0 my @changes;
5036 0 ▶ push @changes, 'user '.&username($uid).' -> '.&username($expectedUid) if defined $expectedUid && $uid != $expectedUid;
Branch: 1 branch
BranchTrueFalseTotal
if defined $expectedUid and $uid != $expectedUid 0 0 0
Condition0%0/3
defined $expectedUid and $uid != $expectedUid
!ll&&!rl&&r
000
MC/DC0%0/2
defined $expectedUid and $uid != $expectedUid
defined $expectedUid $uid != $expectedUid
Truth table0%0/3
A and B
A= defined $expectedUidB= $uid != $expectedUid
ABresult
0X0
100
111
5037 0 ▶ push @changes, 'group '.&groupname($gid).' -> '.&groupname($expectedGid) if defined $expectedGid && $gid != $expectedGid;
Branch: 1 branch
BranchTrueFalseTotal
if defined $expectedGid and $gid != $expectedGid 0 0 0
Condition0%0/3
defined $expectedGid and $gid != $expectedGid
!ll&&!rl&&r
000
MC/DC0%0/2
defined $expectedGid and $gid != $expectedGid
defined $expectedGid $gid != $expectedGid
Truth table0%0/3
A and B
A= defined $expectedGidB= $gid != $expectedGid
ABresult
0X0
100
111
5038 0 ▶ push @changes, 'mode '.sprintf('%04o -> %04o', $mode, $expectedMode) if $mode != $expectedMode;
Branch: 1 branch
BranchTrueFalseTotal
if $mode != $expectedMode 0 0 0
5039 0 return $o->finalizeWrong(join(', ', @changes), "\t", $item);
5040 }
5041  
5042 sub username {
5043 0 ▶ my $uid = shift;
Subroutine username: not called CC=2 SCAR=17.9
5044  
5045 0 ▶ return getpwuid($uid) // $uid;
Condition0%0/3
getpwuid $uid // $uid
l!l&&r!l&&!r
000
MC/DC0%0/2
getpwuid $uid // $uid
getpwuid $uid $uid
Truth table0%0/3
A // B
A= getpwuid $uidB= $uid
ABresult
1X1
011
000
5046 }
5047  
5048 sub groupname {
5049 0 ▶ my $gid = shift;
Subroutine groupname: not called CC=2 SCAR=17.9
5050  
5051 0 ▶ return getgrgid($gid) // $gid;
Condition0%0/3
getgrgid $gid // $gid
l!l&&r!l&&!r
000
MC/DC0%0/2
getgrgid $gid // $gid
getgrgid $gid $gid
Truth table0%0/3
A // B
A= getgrgid $gidB= $gid
ABresult
1X1
011
000
5052 }
5053  
5054 sub accessError {
5055 0 ▶ my $o = shift;
Subroutine accessError: not called CC=1 SCAR=6.9
5056 0 my $item = shift;
5057  
5058 0 $o->{ui}->error('Error accessing ', $item, '.');
5059 0 return 0;
5060 }
5061  
5062 sub setError {
5063 0 ▶ my $o = shift;
Subroutine setError: not called CC=1 SCAR=6.9
5064 0 my $item = shift;
5065  
5066 0 $o->{ui}->error('Error setting permissions of ', $item, '.');
5067 0 return 0;
5068 }
5069  
5070 package CDS::Commands::FolderStore::SetLogger;
5071  
5072 1 ▶use parent -norequire, 'CDS::Commands::FolderStore::Logger';
Subroutine BEGIN: called CC=1 SCAR=0.0
5073  
5074 sub finalizeWrong {
5075 0 ▶ my $o = shift;
Subroutine finalizeWrong: not called CC=1 SCAR=6.9
5076  
5077 0 return 1;
5078 }
5079  
5080 sub summary {
5081 0 ▶ my $o = shift;
Subroutine summary: not called CC=2 SCAR=17.9
5082  
5083 0 $o->{ui}->p(($o->{correct} + $o->{wrong}).' files and folders traversed.');
5084 0 ▶ $o->{ui}->p('The permissions of ', $o->{wrong}, ' files and folders have been adjusted.') if $o->{wrong} > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"wrong"} > 0 0 0 0
5085 0 $o->{ui}->pGreen('All permissions are OK.');
5086 }
5087  
5088 # BEGIN AUTOGENERATED
5089 package CDS::Commands::Get;
5090  
5091 sub register {
5092 0 ▶ my $class = shift;
Subroutine register: not called CC=1 SCAR=6.9
5093 0 my $cds = shift;
5094 0 my $help = shift;
5095  
5096 0 my $node000 = CDS::Parser::Node->new(0);
5097 0 my $node001 = CDS::Parser::Node->new(0);
5098 0 my $node002 = CDS::Parser::Node->new(0);
5099 0 my $node003 = CDS::Parser::Node->new(0);
5100 0 my $node004 = CDS::Parser::Node->new(0);
5101 0 my $node005 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&help});
5102 0 my $node006 = CDS::Parser::Node->new(0);
5103 0 my $node007 = CDS::Parser::Node->new(0);
5104 0 my $node008 = CDS::Parser::Node->new(0);
5105 0 my $node009 = CDS::Parser::Node->new(0);
5106 0 my $node010 = CDS::Parser::Node->new(1);
5107 0 my $node011 = CDS::Parser::Node->new(0);
5108 0 my $node012 = CDS::Parser::Node->new(0);
5109 0 my $node013 = CDS::Parser::Node->new(0);
5110 0 my $node014 = CDS::Parser::Node->new(0);
5111 0 my $node015 = CDS::Parser::Node->new(0);
5112 0 my $node016 = CDS::Parser::Node->new(1);
5113 0 my $node017 = CDS::Parser::Node->new(0);
5114 0 my $node018 = CDS::Parser::Node->new(0);
5115 0 my $node019 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&get});
5116 0 my $node020 = CDS::Parser::Node->new(1);
5117 0 my $node021 = CDS::Parser::Node->new(0);
5118 0 my $node022 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&get});
5119 0 $cds->addArrow($node000, 1, 0, 'get');
5120 0 $cds->addArrow($node001, 1, 0, 'save');
5121 0 $cds->addArrow($node002, 1, 0, 'get');
5122 0 $cds->addArrow($node003, 1, 0, 'get');
5123 0 $cds->addArrow($node009, 1, 0, 'save', \&collectSave);
5124 0 $help->addArrow($node005, 1, 0, 'get');
5125 0 $help->addArrow($node005, 1, 0, 'save');
5126 0 $node000->addArrow($node010, 1, 0, 'HASH', \&collectHash);
5127 0 $node001->addArrow($node004, 1, 0, 'data');
5128 0 $node002->addArrow($node006, 1, 0, 'HASH', \&collectHash1);
5129 0 $node003->addArrow($node010, 1, 0, 'OBJECT', \&collectObject);
5130 0 $node004->addArrow($node009, 1, 0, 'of', \&collectOf);
5131 0 $node006->addArrow($node007, 1, 0, 'on');
5132 0 $node006->addArrow($node008, 0, 0, 'from');
5133 0 $node007->addArrow($node010, 1, 0, 'STORE', \&collectStore);
5134 0 $node008->addArrow($node010, 0, 0, 'STORE', \&collectStore);
5135 0 $node009->addArrow($node013, 1, 0, 'HASH', \&collectHash1);
5136 0 $node009->addArrow($node016, 1, 0, 'HASH', \&collectHash);
5137 0 $node009->addArrow($node016, 1, 0, 'OBJECT', \&collectObject1);
5138 0 $node010->addArrow($node011, 1, 0, 'decrypted');
5139 0 $node010->addDefault($node019);
5140 0 $node011->addArrow($node012, 1, 0, 'with');
5141 0 $node012->addArrow($node019, 1, 0, 'AESKEY', \&collectAeskey);
5142 0 $node013->addArrow($node014, 1, 0, 'on');
5143 0 $node013->addArrow($node015, 0, 0, 'from');
5144 0 $node014->addArrow($node016, 1, 0, 'STORE', \&collectStore);
5145 0 $node015->addArrow($node016, 0, 0, 'STORE', \&collectStore);
5146 0 $node016->addArrow($node017, 1, 0, 'decrypted');
5147 0 $node016->addDefault($node020);
5148 0 $node017->addArrow($node018, 1, 0, 'with');
5149 0 $node018->addArrow($node020, 1, 0, 'AESKEY', \&collectAeskey);
5150 0 $node020->addArrow($node021, 1, 0, 'as');
5151 0 $node021->addArrow($node022, 1, 0, 'FILENAME', \&collectFilename);
5152 }
5153  
5154 sub collectAeskey {
5155 0 ▶ my $o = shift;
Subroutine collectAeskey: not called CC=1 SCAR=6.9
5156 0 my $label = shift;
5157 0 my $value = shift;
5158  
5159 0 $o->{aesKey} = $value;
5160 }
5161  
5162 sub collectFilename {
5163 0 ▶ my $o = shift;
Subroutine collectFilename: not called CC=1 SCAR=6.9
5164 0 my $label = shift;
5165 0 my $value = shift;
5166  
5167 0 $o->{filename} = $value;
5168 }
5169  
5170 sub collectHash {
5171 0 ▶ my $o = shift;
Subroutine collectHash: not called CC=1 SCAR=6.9
5172 0 my $label = shift;
5173 0 my $value = shift;
5174  
5175 0 $o->{hash} = $value;
5176 0 $o->{store} = $o->{actor}->preferredStore;
5177 }
5178  
5179 sub collectHash1 {
5180 0 ▶ my $o = shift;
Subroutine collectHash1: not called CC=1 SCAR=6.9
5181 0 my $label = shift;
5182 0 my $value = shift;
5183  
5184 0 $o->{hash} = $value;
5185 }
5186  
5187 sub collectObject {
5188 0 ▶ my $o = shift;
Subroutine collectObject: not called CC=1 SCAR=6.9
5189 0 my $label = shift;
5190 0 my $value = shift;
5191  
5192 0 $o->{hash} = $value->hash;
5193 0 $o->{store} = $value->cliStore;
5194 }
5195  
5196 sub collectObject1 {
5197 0 ▶ my $o = shift;
Subroutine collectObject1: not called CC=1 SCAR=6.9
5198 0 my $label = shift;
5199 0 my $value = shift;
5200  
5201 0 $o->{hash} = $value->hash;
5202 0 push @{$o->{stores}}, $value->store;
5203 }
5204  
5205 sub collectOf {
5206 0 ▶ my $o = shift;
Subroutine collectOf: not called CC=1 SCAR=6.9
5207 0 my $label = shift;
5208 0 my $value = shift;
5209  
5210 0 $o->{saveData} = 1;
5211 }
5212  
5213 sub collectSave {
5214 0 ▶ my $o = shift;
Subroutine collectSave: not called CC=1 SCAR=6.9
5215 0 my $label = shift;
5216 0 my $value = shift;
5217  
5218 0 $o->{saveObject} = 1;
5219 }
5220  
5221 sub collectStore {
5222 0 ▶ my $o = shift;
Subroutine collectStore: not called CC=1 SCAR=6.9
5223 0 my $label = shift;
5224 0 my $value = shift;
5225  
5226 0 $o->{store} = $value;
5227 }
5228  
5229 sub new {
5230 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
5231 0 my $actor = shift;
5232 0 bless {actor => $actor, ui => $actor->ui} }
5233  
5234 # END AUTOGENERATED
5235  
5236 # HTML FOLDER NAME store-get
5237 # HTML TITLE Get
5238 sub help {
5239 0 ▶ my $o = shift;
Subroutine help: not called CC=1 SCAR=6.9
5240 0 my $cmd = shift;
5241  
5242 0 my $ui = $o->{ui};
5243 0 $ui->space;
5244 0 $ui->command('cds get OBJECT');
5245 0 $ui->command('cds get HASH on STORE');
5246 0 $ui->p('Downloads an object and writes it to STDOUT. If the object is not found, the program quits with exit code 1.');
5247 0 $ui->space;
5248 0 $ui->command('cds get HASH');
5249 0 $ui->p('As above, but uses the selected store.');
5250 0 $ui->space;
5251 0 $ui->command('… decrypted with AESKEY');
5252 0 $ui->p('Decrypts the object after retrieval.');
5253 0 $ui->space;
5254 0 $ui->command('cds save … as FILENAME');
5255 0 $ui->p('Saves the object to FILENAME instead of writing it to STDOUT.');
5256 0 $ui->space;
5257 0 $ui->command('cds save data of … as FILENAME');
5258 0 $ui->p('Saves the object\'s data to FILENAME.');
5259 0 $ui->space;
5260 0 $ui->title('Related commands');
5261 0 $ui->line('cds open envelope OBJECT');
5262 0 $ui->line('cds show record OBJECT [decrypted with AESKEY]');
5263 0 $ui->line('cds show hashes of OBJECT');
5264 0 $ui->space;
5265 }
5266  
5267 sub get {
5268 0 ▶ my $o = shift;
Subroutine get: not called CC=7 SCAR=40.3
5269 0 my $cmd = shift;
5270  
5271 0 $cmd->collect($o);
5272  
5273 # Retrieve the object
5274 0 ▶ my $object = $o->{actor}->uiGetObject($o->{hash}, $o->{store}, $o->{actor}->preferredKeyPairToken) // return;
Condition0%0/2
$o->{"actor"}->uiGetObject($o->{"hash"}, $o->{"store"}, $o->{"actor"}->preferredKeyPairToken) // (return)
l!l
00
MC/DC0%0/1
$o->{"actor"}->uiGetObject($o->{"hash"}, $o->{"store"}, $o->{"actor"}->preferredKeyPairToken) // (return)
$o->{"actor"}->uiGetObject($o->{"hash"}, $o->{"store"}, $o->{"actor"}->preferredKeyPairToken)
Truth table0%0/2
A
A= $o->{"actor"}->uiGetObject($o->{"hash"}, $o->{"store"}, $o->{"actor"}->preferredKeyPairToken)
Aresult
11
00
5275  
5276 # Decrypt
5277 0 ▶ $object = $object->crypt($o->{aesKey}) if defined $o->{aesKey};
Branch: 1 branch
BranchTrueFalseTotal
if defined $o->{"aesKey"} 0 0 0
5278  
5279 # Output
5280 0 ▶ if ($o->{saveData}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($o->{'saveData'}) { } 0 0 0
elsif ($o->{'saveObject'}) { } 0 0 0
5281 0 ▶ CDS->writeBytesToFile($o->{filename}, $object->data) // return $o->{ui}->error('Failed to write data to "', $o->{filename}, '".');
Condition0%0/2
"CDS"->writeBytesToFile($o->{"filename"}, $object->data) // (return $o->{"ui"}->error("Failed to write data to \"", $o->{"filename"}, "\"."))
l!l
00
MC/DC0%0/1
"CDS"->writeBytesToFile($o->{"filename"}, $object->data) // (return $o->{"ui"}->error("Failed to write data to \"", $o->{"filename"}, "\"."))
"CDS"->writeBytesToFile($o->{"filename"}, $object->data)
Truth table0%0/2
A
A= "CDS"->writeBytesToFile($o->{"filename"}, $object->data)
Aresult
11
00
5282 0 $o->{ui}->pGreen(length $object->data, ' bytes written to ', $o->{filename}, '.');
5283 } elsif ($o->{saveObject}) {
5284 0 ▶ CDS->writeBytesToFile($o->{filename}, $object->bytes) // return $o->{ui}->error('Failed to write object to "', $o->{filename}, '".');
Condition0%0/2
"CDS"->writeBytesToFile($o->{"filename"}, $object->bytes) // (return $o->{"ui"}->error("Failed to write object to \"", $o->{"filename"}, "\"."))
l!l
00
MC/DC0%0/1
"CDS"->writeBytesToFile($o->{"filename"}, $object->bytes) // (return $o->{"ui"}->error("Failed to write object to \"", $o->{"filename"}, "\"."))
"CDS"->writeBytesToFile($o->{"filename"}, $object->bytes)
Truth table0%0/2
A
A= "CDS"->writeBytesToFile($o->{"filename"}, $object->bytes)
Aresult
11
00
5285 0 $o->{ui}->pGreen(length $object->bytes, ' bytes written to ', $o->{filename}, '.');
5286 } else {
5287 0 $o->{ui}->raw($object->bytes);
5288 }
5289 }
5290  
5291 # BEGIN AUTOGENERATED
5292 package CDS::Commands::Help;
5293  
5294 sub register {
5295 0 ▶ my $class = shift;
Subroutine register: not called CC=1 SCAR=6.9
5296 0 my $cds = shift;
5297 0 my $help = shift;
5298  
5299 0 my $node000 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&help});
5300 0 my $node001 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&version});
5301 0 $cds->addArrow($node000, 0, 0, '--h');
5302 0 $cds->addArrow($node000, 0, 0, '--help');
5303 0 $cds->addArrow($node000, 0, 0, '-?');
5304 0 $cds->addArrow($node000, 0, 0, '-h');
5305 0 $cds->addArrow($node000, 0, 0, '-help');
5306 0 $cds->addArrow($node000, 0, 0, '/?');
5307 0 $cds->addArrow($node000, 0, 0, '/h');
5308 0 $cds->addArrow($node000, 0, 0, '/help');
5309 0 $cds->addArrow($node001, 0, 0, '--version');
5310 0 $cds->addArrow($node001, 0, 0, '-version');
5311 0 $cds->addArrow($node001, 1, 0, 'version');
5312 }
5313  
5314 sub new {
5315 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
5316 0 my $actor = shift;
5317 0 bless {actor => $actor, ui => $actor->ui} }
5318  
5319 # END AUTOGENERATED
5320  
5321 # HTML IGNORE
5322 sub help {
5323 0 ▶ my $o = shift;
Subroutine help: not called CC=1 SCAR=6.9
5324 0 my $cmd = shift;
5325  
5326 0 my $ui = $o->{ui};
5327 0 $ui->space;
5328 0 $ui->title('Condensation CLI');
5329 0 $ui->line('Version ', $CDS::VERSION, ', ', $CDS::releaseDate, ', implementing the Condensation 1 protocol');
5330 0 $ui->space;
5331 0 $ui->p('Condensation is a distributed data system with conflict-free forward merging and end-to-end security. More information is available on ', $ui->a('https://condensation.io'), '.');
5332 0 $ui->space;
5333 0 $ui->p('The command line interface (CLI) understands english-like queries like these:');
5334 0 $ui->pushIndent;
5335 0 $ui->line($ui->blue('cds show key pair'));
5336 0 $ui->line($ui->blue('cds create key pair thomas'));
5337 0 $ui->line($ui->blue('cds get 45db86549d6d2af3a45be834f2cb0e08cdbbd7699624e7bfd947a3505e6b03e5 \\'));
5338 0 $ui->line($ui->blue(' and decrypt with 8b8b091bbe577d5e8d38eae9cd327aa8123fe402a41ea9dd16d86f42fb70cf7e'));
5339 0 $ui->popIndent;
5340 0 $ui->space;
5341 0 $ui->p('If you don\'t know how to continue a command, simply put a ? to see all valid options:');
5342 0 $ui->pushIndent;
5343 0 $ui->line($ui->blue('cds ?'));
5344 0 $ui->line($ui->blue('cds show ?'));
5345 0 $ui->popIndent;
5346 0 $ui->space;
5347 0 $ui->p('To see a list of help topics, type');
5348 0 $ui->pushIndent;
5349 0 $ui->line($ui->blue('cds help ?'));
5350 0 $ui->popIndent;
5351 0 $ui->space;
5352 }
5353  
5354 sub version {
5355 0 ▶ my $o = shift;
Subroutine version: not called CC=1 SCAR=6.9
5356 0 my $cmd = shift;
5357  
5358 0 my $ui = $o->{ui};
5359 0 $ui->line('Condensation CLI ', $CDS::VERSION, ', ', $CDS::releaseDate);
5360 0 $ui->line('implementing the Condensation 1 protocol');
5361 }
5362  
5363 # BEGIN AUTOGENERATED
5364 package CDS::Commands::List;
5365  
5366 sub register {
5367 0 ▶ my $class = shift;
Subroutine register: not called CC=1 SCAR=6.9
5368 0 my $cds = shift;
5369 0 my $help = shift;
5370  
5371 0 my $node000 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&help});
5372 0 my $node001 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&list});
5373 0 my $node002 = CDS::Parser::Node->new(0);
5374 0 my $node003 = CDS::Parser::Node->new(0);
5375 0 my $node004 = CDS::Parser::Node->new(0);
5376 0 my $node005 = CDS::Parser::Node->new(0);
5377 0 my $node006 = CDS::Parser::Node->new(0);
5378 0 my $node007 = CDS::Parser::Node->new(0);
5379 0 my $node008 = CDS::Parser::Node->new(0);
5380 0 my $node009 = CDS::Parser::Node->new(0);
5381 0 my $node010 = CDS::Parser::Node->new(0);
5382 0 my $node011 = CDS::Parser::Node->new(0);
5383 0 my $node012 = CDS::Parser::Node->new(0);
5384 0 my $node013 = CDS::Parser::Node->new(0);
5385 0 my $node014 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&listBoxes});
5386 0 my $node015 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&list});
5387 0 $cds->addArrow($node001, 1, 0, 'list');
5388 0 $cds->addArrow($node001, 1, 0, 'watch', \&collectWatch);
5389 0 $help->addArrow($node000, 1, 0, 'list');
5390 0 $node001->addDefault($node002);
5391 0 $node001->addArrow($node003, 1, 0, 'message');
5392 0 $node001->addArrow($node004, 1, 0, 'private');
5393 0 $node001->addArrow($node005, 1, 0, 'public');
5394 0 $node001->addArrow($node006, 0, 0, 'messages', \&collectMessages);
5395 0 $node001->addArrow($node006, 0, 0, 'private', \&collectPrivate);
5396 0 $node001->addArrow($node006, 0, 0, 'public', \&collectPublic);
5397 0 $node001->addArrow($node007, 1, 0, 'my', \&collectMy);
5398 0 $node001->addDefault($node011);
5399 0 $node002->addArrow($node002, 1, 0, 'BOX', \&collectBox);
5400 0 $node002->addArrow($node014, 1, 0, 'BOX', \&collectBox);
5401 0 $node003->addArrow($node006, 1, 0, 'box', \&collectMessages);
5402 0 $node004->addArrow($node006, 1, 0, 'box', \&collectPrivate);
5403 0 $node005->addArrow($node006, 1, 0, 'box', \&collectPublic);
5404 0 $node006->addArrow($node011, 1, 0, 'of');
5405 0 $node006->addDefault($node012);
5406 0 $node007->addArrow($node008, 1, 0, 'message');
5407 0 $node007->addArrow($node009, 1, 0, 'private');
5408 0 $node007->addArrow($node010, 1, 0, 'public');
5409 0 $node007->addArrow($node015, 1, 0, 'boxes');
5410 0 $node007->addArrow($node015, 0, 0, 'messages', \&collectMessages);
5411 0 $node007->addArrow($node015, 0, 0, 'private', \&collectPrivate);
5412 0 $node007->addArrow($node015, 0, 0, 'public', \&collectPublic);
5413 0 $node008->addArrow($node015, 1, 0, 'box', \&collectMessages);
5414 0 $node009->addArrow($node015, 1, 0, 'box', \&collectPrivate);
5415 0 $node010->addArrow($node015, 1, 0, 'box', \&collectPublic);
5416 0 $node011->addArrow($node012, 1, 0, 'ACTOR', \&collectActor);
5417 0 $node011->addArrow($node012, 1, 0, 'KEYPAIR', \&collectKeypair);
5418 0 $node011->addArrow($node015, 1, 1, 'ACCOUNT', \&collectAccount);
5419 0 $node011->addArrow($node015, 1, 0, 'ACTORGROUP', \&collectActorgroup);
5420 0 $node012->addArrow($node013, 1, 0, 'on');
5421 0 $node012->addDefault($node015);
5422 0 $node013->addArrow($node015, 1, 0, 'STORE', \&collectStore);
5423 }
5424  
5425 sub collectAccount {
5426 0 ▶ my $o = shift;
Subroutine collectAccount: not called CC=1 SCAR=6.9
5427 0 my $label = shift;
5428 0 my $value = shift;
5429  
5430 0 $o->{actorHash} = $value->actorHash;
5431 0 $o->{store} = $value->cliStore;
5432 }
5433  
5434 sub collectActor {
5435 0 ▶ my $o = shift;
Subroutine collectActor: not called CC=1 SCAR=6.9
5436 0 my $label = shift;
5437 0 my $value = shift;
5438  
5439 0 $o->{actorHash} = $value;
5440 }
5441  
5442 sub collectActorgroup {
5443 0 ▶ my $o = shift;
Subroutine collectActorgroup: not called CC=1 SCAR=6.9
5444 0 my $label = shift;
5445 0 my $value = shift;
5446  
5447 0 $o->{actorGroup} = $value;
5448 }
5449  
5450 sub collectBox {
5451 0 ▶ my $o = shift;
Subroutine collectBox: not called CC=1 SCAR=6.9
5452 0 my $label = shift;
5453 0 my $value = shift;
5454  
5455 0 push @{$o->{boxTokens}}, $value;
5456 }
5457  
5458 sub collectKeypair {
5459 0 ▶ my $o = shift;
Subroutine collectKeypair: not called CC=1 SCAR=6.9
5460 0 my $label = shift;
5461 0 my $value = shift;
5462  
5463 0 $o->{actorHash} = $value->keyPair->publicKey->hash;
5464 0 $o->{keyPairToken} = $value;
5465 }
5466  
5467 sub collectMessages {
5468 0 ▶ my $o = shift;
Subroutine collectMessages: not called CC=1 SCAR=6.9
5469 0 my $label = shift;
5470 0 my $value = shift;
5471  
5472 0 $o->{boxLabels} = ['messages'];
5473 }
5474  
5475 sub collectMy {
5476 0 ▶ my $o = shift;
Subroutine collectMy: not called CC=1 SCAR=6.9
5477 0 my $label = shift;
5478 0 my $value = shift;
5479  
5480 0 $o->{my} = 1;
5481 }
5482  
5483 sub collectPrivate {
5484 0 ▶ my $o = shift;
Subroutine collectPrivate: not called CC=1 SCAR=6.9
5485 0 my $label = shift;
5486 0 my $value = shift;
5487  
5488 0 $o->{boxLabels} = ['private'];
5489 }
5490  
5491 sub collectPublic {
5492 0 ▶ my $o = shift;
Subroutine collectPublic: not called CC=1 SCAR=6.9
5493 0 my $label = shift;
5494 0 my $value = shift;
5495  
5496 0 $o->{boxLabels} = ['public'];
5497 }
5498  
5499 sub collectStore {
5500 0 ▶ my $o = shift;
Subroutine collectStore: not called CC=1 SCAR=6.9
5501 0 my $label = shift;
5502 0 my $value = shift;
5503  
5504 0 $o->{store} = $value;
5505 }
5506  
5507 sub collectWatch {
5508 0 ▶ my $o = shift;
Subroutine collectWatch: not called CC=1 SCAR=6.9
5509 0 my $label = shift;
5510 0 my $value = shift;
5511  
5512 0 $o->{watchTimeout} = 60000;
5513 }
5514  
5515 sub new {
5516 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
5517 0 my $actor = shift;
5518 0 bless {actor => $actor, ui => $actor->ui} }
5519  
5520 # END AUTOGENERATED
5521  
5522 # HTML FOLDER NAME store-list
5523 # HTML TITLE List
5524 sub help {
5525 0 ▶ my $o = shift;
Subroutine help: not called CC=1 SCAR=6.9
5526 0 my $cmd = shift;
5527  
5528 0 my $ui = $o->{ui};
5529 0 $ui->space;
5530 0 $ui->command('cds list BOX');
5531 0 $ui->p('Lists the indicated box. The object references are shown as "cds open envelope …" command, which can be executed to display the corresponding envelope. Change the command to "cds get …" to download the raw object, or "cds show record …" to show it as record.');
5532 0 $ui->space;
5533 0 $ui->command('cds list');
5534 0 $ui->p('Lists all boxes of the selected key pair.');
5535 0 $ui->space;
5536 0 $ui->command('cds list BOXLABEL');
5537 0 $ui->p('Lists only the indicated box of the selected key pair. BOXLABEL may be:');
5538 0 $ui->line(' message box');
5539 0 $ui->line(' public box');
5540 0 $ui->line(' private box');
5541 0 $ui->space;
5542 0 $ui->command('cds list my boxes');
5543 0 $ui->command('cds list my BOXLABEL');
5544 0 $ui->p('Lists your own boxes.');
5545 0 $ui->space;
5546 0 $ui->command('cds list [BOXLABEL of] ACTORGROUP|ACCOUNT');
5547 0 $ui->p('Lists boxes of an actor group, or account.');
5548 0 $ui->space;
5549 0 $ui->command('cds list [BOXLABEL of] KEYPAIR|ACTOR [on STORE]');
5550 0 $ui->p('Lists boxes of an actor on the specified or selected store.');
5551 0 $ui->space;
5552 }
5553  
5554 sub listBoxes {
5555 0 ▶ my $o = shift;
Subroutine listBoxes: not called CC=3 SCAR=24.8
5556 0 my $cmd = shift;
5557  
5558 0 $o->{boxTokens} = [];
5559 0 $o->{boxLabels} = ['messages', 'private', 'public'];
5560 0 $cmd->collect($o);
5561  
5562 # Use the selected key pair to sign requests
5563 0 ▶ $o->{keyPairToken} = $o->{actor}->preferredKeyPairToken if ! $o->{keyPairToken};
Branch: 1 branch
BranchTrueFalseTotal
unless $o->{"keyPairToken"} 0 0 0
5564  
5565 0 for my $boxToken (@{$o->{boxTokens}}) {
5566 0 $o->listBox($boxToken);
5567 }
5568  
5569 0 $o->{ui}->space;
5570 }
5571  
5572 sub list {
5573 0 ▶ my $o = shift;
Subroutine list: not called CC=11 SCAR=48.8
5574 0 my $cmd = shift;
5575  
5576 0 $o->{boxLabels} = ['messages', 'private', 'public'];
5577 0 $cmd->collect($o);
5578  
5579 # Actor hashes
5580 0 my @actorHashes;
5581 my @stores;
5582 0 ▶ if ($o->{my}) {
Branch: 3 branches
BranchTrueFalseTotal
if ($o->{'my'}) { } 0 0 0
elsif ($o->{'actorHash'}) { } 0 0 0
elsif ($o->{'actorGroup'}) { } 0 0 0
5583 0 $o->{keyPairToken} = $o->{actor}->keyPairToken;
5584 0 push @actorHashes, $o->{keyPairToken}->keyPair->publicKey->hash;
5585 0 push @stores, $o->{actor}->storageStore, $o->{actor}->messagingStore;
5586 } elsif ($o->{actorHash}) {
5587 0 push @actorHashes, $o->{actorHash};
5588 } elsif ($o->{actorGroup}) {
5589 # TODO
5590 } else {
5591 0 push @actorHashes, $o->{actor}->preferredActorHash;
5592 }
5593  
5594 # Stores
5595 0 ▶ push @stores, $o->{store} if $o->{store};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"store"} 0 0 0
5596 0 ▶ push @stores, $o->{actor}->preferredStore if ! scalar @stores;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @stores 0 0 0
5597  
5598 # Use the selected key pair to sign requests
5599 0 my $preferredKeyPairToken = $o->{actor}->preferredKeyPairToken;
5600 0 ▶ $o->{keyPairToken} = $preferredKeyPairToken if ! $o->{keyPairToken};
Branch: 1 branch
BranchTrueFalseTotal
unless $o->{"keyPairToken"} 0 0 0
5601 0 ▶ $o->{keyPairContext} = $preferredKeyPairToken->keyPair->equals($o->{keyPairToken}->keyPair) ? '' : $o->{ui}->gray(' using ', $o->{actor}->keyPairReference($o->{keyPairToken}));
Branch: 1 branch
BranchTrueFalseTotal
$preferredKeyPairToken->keyPair->equals($o->{'keyPairToken'}->keyPair) ? : 0 0 0
5602  
5603 # List boxes
5604 0 for my $store (@stores) {
5605 0 for my $actorHash (@actorHashes) {
5606 0 for my $boxLabel (@{$o->{boxLabels}}) {
5607 0 $o->listBox(CDS::BoxToken->new(CDS::AccountToken->new($store, $actorHash), $boxLabel));
5608 }
5609 }
5610 }
5611  
5612 0 $o->{ui}->space;
5613 }
5614  
5615 sub listBox {
5616 0 ▶ my $o = shift;
Subroutine listBox: not called CC=9 SCAR=45.0
5617 0 my $boxToken = shift;
5618  
5619 0 $o->{ui}->space;
5620 0 $o->{ui}->title($o->{actor}->blueBoxReference($boxToken));
5621  
5622 # Query the store
5623 0 my $store = $boxToken->accountToken->cliStore;
5624 0 ▶ my ($hashes, $storeError) = $store->list($boxToken->accountToken->actorHash, $boxToken->boxLabel, $o->{watchTimeout} // 0, $o->{keyPairToken}->keyPair);
Condition0%0/2
$o->{"watchTimeout"} // 0
l!l
00
MC/DC0%0/1
$o->{"watchTimeout"} // 0
$o->{"watchTimeout"}
Truth table0%0/2
A
A= $o->{"watchTimeout"}
Aresult
11
00
5625 0 ▶ return if defined $storeError;
Branch: 1 branch
BranchTrueFalseTotal
if defined $storeError 0 0 0
5626  
5627 # Print the result
5628 0 my $count = scalar @$hashes;
5629 0 ▶ return if ! $count;
Branch: 1 branch
BranchTrueFalseTotal
unless $count 0 0 0
5630  
5631 0 ▶ my $context = $boxToken->boxLabel eq 'messages' ? $o->{ui}->gray(' on ', $o->{actor}->storeReference($store)) : $o->{ui}->gray(' from ', $o->{actor}->accountReference($boxToken->accountToken));
Branch: 1 branch
BranchTrueFalseTotal
$boxToken->boxLabel eq 'messages' ? : 0 0 0
5632 0 ▶ my $keyPairContext = $boxToken->boxLabel eq 'public' ? '' : $o->{keyPairContext} // '';
Branch: 1 branch
BranchTrueFalseTotal
$boxToken->boxLabel eq 'public' ? : 0 0 0
Condition0%0/2
$o->{"keyPairContext"} // ""
l!l
00
MC/DC0%0/1
$o->{"keyPairContext"} // ""
$o->{"keyPairContext"}
Truth table0%0/2
A
A= $o->{"keyPairContext"}
Aresult
11
00
5633 0 foreach my $hash (sort { $a->bytes cmp $b->bytes } @$hashes) {
5634 0 $o->{ui}->line($o->{ui}->gold('cds open envelope ', $hash->hex), $context, $keyPairContext);
5635 }
5636 0 ▶ $o->{ui}->line($count.' entries') if $count > 5;
Branch: 1 branch
BranchTrueFalseTotal
if $count > 5 0 0 0
5637 }
5638  
5639 # BEGIN AUTOGENERATED
5640 package CDS::Commands::Modify;
5641  
5642 sub register {
5643 0 ▶ my $class = shift;
Subroutine register: not called CC=1 SCAR=6.9
5644 0 my $cds = shift;
5645 0 my $help = shift;
5646  
5647 0 my $node000 = CDS::Parser::Node->new(0);
5648 0 my $node001 = CDS::Parser::Node->new(0);
5649 0 my $node002 = CDS::Parser::Node->new(0);
5650 0 my $node003 = CDS::Parser::Node->new(0);
5651 0 my $node004 = CDS::Parser::Node->new(0);
5652 0 my $node005 = CDS::Parser::Node->new(0);
5653 0 my $node006 = CDS::Parser::Node->new(0);
5654 0 my $node007 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&help});
5655 0 my $node008 = CDS::Parser::Node->new(1);
5656 0 my $node009 = CDS::Parser::Node->new(0);
5657 0 my $node010 = CDS::Parser::Node->new(0);
5658 0 my $node011 = CDS::Parser::Node->new(0);
5659 0 my $node012 = CDS::Parser::Node->new(0);
5660 0 my $node013 = CDS::Parser::Node->new(0);
5661 0 my $node014 = CDS::Parser::Node->new(0);
5662 0 my $node015 = CDS::Parser::Node->new(0);
5663 0 my $node016 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&modify});
5664 0 $cds->addDefault($node000);
5665 0 $help->addArrow($node007, 1, 0, 'add');
5666 0 $help->addArrow($node007, 1, 0, 'purge');
5667 0 $help->addArrow($node007, 1, 0, 'remove');
5668 0 $node000->addArrow($node001, 1, 0, 'add');
5669 0 $node000->addArrow($node002, 1, 0, 'remove');
5670 0 $node000->addArrow($node003, 1, 0, 'add');
5671 0 $node000->addArrow($node008, 1, 0, 'purge', \&collectPurge);
5672 0 $node001->addArrow($node001, 1, 0, 'HASH', \&collectHash);
5673 0 $node001->addArrow($node004, 1, 0, 'HASH', \&collectHash);
5674 0 $node002->addArrow($node002, 1, 0, 'HASH', \&collectHash1);
5675 0 $node002->addArrow($node005, 1, 0, 'HASH', \&collectHash1);
5676 0 $node003->addArrow($node003, 1, 0, 'FILE', \&collectFile);
5677 0 $node003->addArrow($node006, 1, 0, 'FILE', \&collectFile);
5678 0 $node004->addArrow($node008, 1, 0, 'to');
5679 0 $node005->addArrow($node008, 1, 0, 'from');
5680 0 $node006->addArrow($node008, 1, 0, 'to');
5681 0 $node008->addArrow($node000, 1, 0, 'and');
5682 0 $node008->addArrow($node009, 1, 0, 'message');
5683 0 $node008->addArrow($node010, 1, 0, 'private');
5684 0 $node008->addArrow($node011, 1, 0, 'public');
5685 0 $node008->addArrow($node012, 0, 0, 'messages', \&collectMessages);
5686 0 $node008->addArrow($node012, 0, 0, 'private', \&collectPrivate);
5687 0 $node008->addArrow($node012, 0, 0, 'public', \&collectPublic);
5688 0 $node008->addArrow($node016, 1, 0, 'BOX', \&collectBox);
5689 0 $node009->addArrow($node012, 1, 0, 'box', \&collectMessages);
5690 0 $node010->addArrow($node012, 1, 0, 'box', \&collectPrivate);
5691 0 $node011->addArrow($node012, 1, 0, 'box', \&collectPublic);
5692 0 $node012->addArrow($node013, 1, 0, 'of');
5693 0 $node013->addArrow($node014, 1, 0, 'ACTOR', \&collectActor);
5694 0 $node013->addArrow($node014, 1, 0, 'KEYPAIR', \&collectKeypair);
5695 0 $node013->addArrow($node016, 1, 1, 'ACCOUNT', \&collectAccount);
5696 0 $node014->addArrow($node015, 1, 0, 'on');
5697 0 $node014->addDefault($node016);
5698 0 $node015->addArrow($node016, 1, 0, 'STORE', \&collectStore);
5699 }
5700  
5701 sub collectAccount {
5702 0 ▶ my $o = shift;
Subroutine collectAccount: not called CC=1 SCAR=6.9
5703 0 my $label = shift;
5704 0 my $value = shift;
5705  
5706 0 $o->{boxToken} = CDS::BoxToken->new($value, $o->{boxLabel});
5707 0 delete $o->{boxLabel};
5708 }
5709  
5710 sub collectActor {
5711 0 ▶ my $o = shift;
Subroutine collectActor: not called CC=1 SCAR=6.9
5712 0 my $label = shift;
5713 0 my $value = shift;
5714  
5715 0 $o->{actorHash} = $value;
5716 }
5717  
5718 sub collectBox {
5719 0 ▶ my $o = shift;
Subroutine collectBox: not called CC=1 SCAR=6.9
5720 0 my $label = shift;
5721 0 my $value = shift;
5722  
5723 0 $o->{boxToken} = $value;
5724 }
5725  
5726 sub collectFile {
5727 0 ▶ my $o = shift;
Subroutine collectFile: not called CC=1 SCAR=6.9
5728 0 my $label = shift;
5729 0 my $value = shift;
5730  
5731 0 push @{$o->{fileAdditions}}, $value;
5732 }
5733  
5734 sub collectHash {
5735 0 ▶ my $o = shift;
Subroutine collectHash: not called CC=1 SCAR=6.9
5736 0 my $label = shift;
5737 0 my $value = shift;
5738  
5739 0 push @{$o->{additions}}, $value;
5740 }
5741  
5742 sub collectHash1 {
5743 0 ▶ my $o = shift;
Subroutine collectHash1: not called CC=1 SCAR=6.9
5744 0 my $label = shift;
5745 0 my $value = shift;
5746  
5747 0 push @{$o->{removals}}, $value;
5748 }
5749  
5750 sub collectKeypair {
5751 0 ▶ my $o = shift;
Subroutine collectKeypair: not called CC=1 SCAR=6.9
5752 0 my $label = shift;
5753 0 my $value = shift;
5754  
5755 0 $o->{actorHash} = $value->publicKey->hash;
5756 0 $o->{keyPairToken} = $value;
5757 }
5758  
5759 sub collectMessages {
5760 0 ▶ my $o = shift;
Subroutine collectMessages: not called CC=1 SCAR=6.9
5761 0 my $label = shift;
5762 0 my $value = shift;
5763  
5764 0 $o->{boxLabel} = 'messages';
5765 }
5766  
5767 sub collectPrivate {
5768 0 ▶ my $o = shift;
Subroutine collectPrivate: not called CC=1 SCAR=6.9
5769 0 my $label = shift;
5770 0 my $value = shift;
5771  
5772 0 $o->{boxLabel} = 'private';
5773 }
5774  
5775 sub collectPublic {
5776 0 ▶ my $o = shift;
Subroutine collectPublic: not called CC=1 SCAR=6.9
5777 0 my $label = shift;
5778 0 my $value = shift;
5779  
5780 0 $o->{boxLabel} = 'public';
5781 }
5782  
5783 sub collectPurge {
5784 0 ▶ my $o = shift;
Subroutine collectPurge: not called CC=1 SCAR=6.9
5785 0 my $label = shift;
5786 0 my $value = shift;
5787  
5788 0 $o->{purge} = 1;
5789 }
5790  
5791 sub collectStore {
5792 0 ▶ my $o = shift;
Subroutine collectStore: not called CC=1 SCAR=6.9
5793 0 my $label = shift;
5794 0 my $value = shift;
5795  
5796 0 $o->{boxToken} = CDS::BoxToken->new(CDS::AccountToken->new($value, $o->{actorHash}), $o->{boxLabel});
5797 0 delete $o->{boxLabel};
5798 0 delete $o->{actorHash};
5799 }
5800  
5801 sub new {
5802 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
5803 0 my $actor = shift;
5804 0 bless {actor => $actor, ui => $actor->ui} }
5805  
5806 # END AUTOGENERATED
5807  
5808 # HTML FOLDER NAME store-modify
5809 # HTML TITLE Modify
5810 sub help {
5811 0 ▶ my $o = shift;
Subroutine help: not called CC=1 SCAR=6.9
5812 0 my $cmd = shift;
5813  
5814 0 my $ui = $o->{ui};
5815 0 $ui->space;
5816 0 $ui->command('cds add HASH* to BOX');
5817 0 $ui->p('Adds HASH to BOX.');
5818 0 $ui->space;
5819 0 $ui->command('cds add FILE* to BOX');
5820 0 $ui->p('Adds the envelope FILE to BOX.');
5821 0 $ui->space;
5822 0 $ui->command('cds remove HASH* from BOX');
5823 0 $ui->p('Removes HASH from BOX.');
5824 0 $ui->p('Note that the store may just mark the hash for removal, and defer its actual removal, or even cancel it. Such removals will still be reported as success.');
5825 0 $ui->space;
5826 0 $ui->command('cds purge BOX');
5827 0 $ui->p('Empties BOX, i.e., removes all its hashes.');
5828 0 $ui->space;
5829 0 $ui->command('… BOXLABEL of ACCOUNT');
5830 0 $ui->p('Modifies a box of an actor group, or account.');
5831 0 $ui->space;
5832 0 $ui->command('… BOXLABEL of KEYPAIR on STORE');
5833 0 $ui->command('… BOXLABEL of ACTOR on STORE');
5834 0 $ui->p('Modifies a box of a key pair or an actor on a specific store.');
5835 0 $ui->space;
5836 }
5837  
5838 sub modify {
5839 0 ▶ my $o = shift;
Subroutine modify: not called CC=18 SCAR=58.3
5840 0 my $cmd = shift;
5841  
5842 0 $o->{additions} = [];
5843 0 $o->{removals} = [];
5844 0 $cmd->collect($o);
5845  
5846 # Add a box using the selected store
5847 0 ▶ if ($o->{actorHash} && $o->{boxLabel}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"actorHash"} and $o->{"boxLabel"}) 0 0 0
Condition0%0/3
$o->{"actorHash"} and $o->{"boxLabel"}
!ll&&!rl&&r
000
MC/DC0%0/2
$o->{"actorHash"} and $o->{"boxLabel"}
$o->{"actorHash"} $o->{"boxLabel"}
Truth table0%0/3
A and B
A= $o->{"actorHash"}B= $o->{"boxLabel"}
ABresult
0X0
100
111
5848 0 $o->{boxToken} = CDS::BoxToken->new(CDS::AccountToken->new($o->{actor}->preferredStore, $o->{actorHash}), $o->{boxLabel});
5849 0 delete $o->{actorHash};
5850 0 delete $o->{boxLabel};
5851 }
5852  
5853 0 my $store = $o->{boxToken}->accountToken->cliStore;
5854  
5855 # Prepare additions
5856 0 my $modifications = CDS::StoreModifications->new;
5857 0 for my $hash (@{$o->{additions}}) {
5858 0 $modifications->add($o->{boxToken}->accountToken->actorHash, $o->{boxToken}->boxLabel, $hash);
5859 }
5860  
5861 0 for my $file (@{$o->{fileAdditions}}) {
5862 0 ▶ my $bytes = CDS->readBytesFromFile($file) // return $o->{ui}->error('Unable to read "', $file, '".');
Condition0%0/2
"CDS"->readBytesFromFile($file) // (return $o->{"ui"}->error("Unable to read \"", $file, "\"."))
l!l
00
MC/DC0%0/1
"CDS"->readBytesFromFile($file) // (return $o->{"ui"}->error("Unable to read \"", $file, "\"."))
"CDS"->readBytesFromFile($file)
Truth table0%0/2
A
A= "CDS"->readBytesFromFile($file)
Aresult
11
00
5863 0 ▶ my $object = CDS::Object->fromBytes($bytes) // return $o->{ui}->error('"', $file, '" is not a Condensation object.');
Condition0%0/2
"CDS::Object"->fromBytes($bytes) // (return $o->{"ui"}->error("\"", $file, "\" is not a Condensation object."))
l!l
00
MC/DC0%0/1
"CDS::Object"->fromBytes($bytes) // (return $o->{"ui"}->error("\"", $file, "\" is not a Condensation object."))
"CDS::Object"->fromBytes($bytes)
Truth table0%0/2
A
A= "CDS::Object"->fromBytes($bytes)
Aresult
11
00
5864 0 my $hash = $object->calculateHash;
5865 0 ▶ $o->{ui}->warning('"', $file, '" is not a valid envelope. The server may reject it.') if ! $o->{actor}->isEnvelope($object);
Branch: 1 branch
BranchTrueFalseTotal
unless $o->{"actor"}->isEnvelope($object) 0 0 0
5866 0 $modifications->add($o->{boxToken}->accountToken->actorHash, $o->{boxToken}->boxLabel, $hash, $object);
5867 }
5868  
5869 # Prepare removals
5870 0 my $boxRemovals = [];
5871 0 for my $hash (@{$o->{removals}}) {
5872 0 $modifications->remove($o->{boxToken}->accountToken->actorHash, $o->{boxToken}->boxLabel, $hash);
5873 }
5874  
5875 # If purging is requested, list the box
5876 0 ▶ if ($o->{purge}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"purge"}) 0 0 0
5877 0 my ($hashes, $error) = $store->list($o->{boxToken}->accountToken->actorHash, $o->{boxToken}->boxLabel, 0);
5878 0 ▶ return if defined $error;
Branch: 1 branch
BranchTrueFalseTotal
if defined $error 0 0 0
5879 0 ▶ $o->{ui}->warning('The box is empty.') if ! scalar @$hashes;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @$hashes 0 0 0
5880  
5881 0 for my $hash (@$hashes) {
5882 0 $modifications->remove($o->{boxToken}->accountToken->actorHash, $o->{boxToken}->boxLabel, $hash);
5883 }
5884 }
5885  
5886 # Cancel if there is nothing to do
5887 0 ▶ return if $modifications->isEmpty;
Branch: 1 branch
BranchTrueFalseTotal
if $modifications->isEmpty 0 0 0
5888  
5889 # Modify the box
5890 0 ▶ my $keyPairToken = $o->{keyPairToken} // $o->{actor}->preferredKeyPairToken;
Condition0%0/3
$o->{"keyPairToken"} // $o->{"actor"}->preferredKeyPairToken
l!l&&r!l&&!r
000
MC/DC0%0/2
$o->{"keyPairToken"} // $o->{"actor"}->preferredKeyPairToken
$o->{"keyPairToken"} $o->{"actor"}->preferredKeyPairToken
Truth table0%0/3
A // B
A= $o->{"keyPairToken"}B= $o->{"actor"}->preferredKeyPairToken
ABresult
1X1
011
000
5891 0 my $error = $store->modify($modifications, $keyPairToken->keyPair);
5892 0 ▶ $o->{ui}->pGreen('Box modified.') if ! defined $error;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $error 0 0 0
5893  
5894 # Print undo information
5895 0 ▶ if ($o->{purge} && scalar @$boxRemovals) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"purge"} and scalar @$boxRemovals) 0 0 0
Condition0%0/2
$o->{"purge"} and scalar @$boxRemovals
!ll
00
MC/DC0%0/1
$o->{"purge"} and scalar @$boxRemovals
$o->{"purge"}
Truth table0%0/2
A
A= $o->{"purge"}
Aresult
00
11
5896 0 $o->{ui}->space;
5897 0 $o->{ui}->line($o->{ui}->gray('To undo purging, type:'));
5898 0 $o->{ui}->line($o->{ui}->gray(' cds add ', join(" \\\n ", map { $_->{hash}->hex } @$boxRemovals), " \\\n to ", $o->{actor}->boxReference($o->{boxToken})));
5899 0 $o->{ui}->space;
5900 }
5901 }
5902  
5903 # BEGIN AUTOGENERATED
5904 package CDS::Commands::OpenEnvelope;
5905  
5906 sub register {
5907 0 ▶ my $class = shift;
Subroutine register: not called CC=1 SCAR=6.9
5908 0 my $cds = shift;
5909 0 my $help = shift;
5910  
5911 0 my $node000 = CDS::Parser::Node->new(0);
5912 0 my $node001 = CDS::Parser::Node->new(0);
5913 0 my $node002 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&help});
5914 0 my $node003 = CDS::Parser::Node->new(1);
5915 0 my $node004 = CDS::Parser::Node->new(1);
5916 0 my $node005 = CDS::Parser::Node->new(0);
5917 0 my $node006 = CDS::Parser::Node->new(0);
5918 0 my $node007 = CDS::Parser::Node->new(1);
5919 0 my $node008 = CDS::Parser::Node->new(0);
5920 0 my $node009 = CDS::Parser::Node->new(0);
5921 0 my $node010 = CDS::Parser::Node->new(0);
5922 0 my $node011 = CDS::Parser::Node->new(1);
5923 0 my $node012 = CDS::Parser::Node->new(0);
5924 0 my $node013 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&openEnvelope});
5925 0 $cds->addArrow($node001, 1, 0, 'open');
5926 0 $help->addArrow($node000, 1, 0, 'open');
5927 0 $node000->addArrow($node002, 1, 0, 'envelope');
5928 0 $node001->addArrow($node003, 1, 0, 'envelope');
5929 0 $node003->addArrow($node004, 1, 0, 'HASH', \&collectHash);
5930 0 $node003->addArrow($node007, 1, 0, 'OBJECT', \&collectObject);
5931 0 $node004->addArrow($node005, 1, 0, 'from');
5932 0 $node004->addArrow($node006, 1, 0, 'from');
5933 0 $node004->addDefault($node009);
5934 0 $node005->addArrow($node009, 1, 0, 'ACTOR', \&collectActor);
5935 0 $node006->addArrow($node011, 1, 1, 'ACCOUNT', \&collectAccount);
5936 0 $node007->addArrow($node008, 1, 0, 'from');
5937 0 $node007->addDefault($node011);
5938 0 $node008->addArrow($node011, 1, 0, 'ACTOR', \&collectActor);
5939 0 $node009->addArrow($node010, 1, 0, 'on');
5940 0 $node009->addDefault($node011);
5941 0 $node010->addArrow($node011, 1, 0, 'STORE', \&collectStore);
5942 0 $node011->addArrow($node012, 1, 0, 'using');
5943 0 $node011->addDefault($node013);
5944 0 $node012->addArrow($node013, 1, 0, 'KEYPAIR', \&collectKeypair);
5945 }
5946  
5947 sub collectAccount {
5948 0 ▶ my $o = shift;
Subroutine collectAccount: not called CC=1 SCAR=6.9
5949 0 my $label = shift;
5950 0 my $value = shift;
5951  
5952 0 $o->{senderHash} = $value->actorHash;
5953 0 $o->{store} = $value->cliStore;
5954 }
5955  
5956 sub collectActor {
5957 0 ▶ my $o = shift;
Subroutine collectActor: not called CC=1 SCAR=6.9
5958 0 my $label = shift;
5959 0 my $value = shift;
5960  
5961 0 $o->{senderHash} = $value;
5962 }
5963  
5964 sub collectHash {
5965 0 ▶ my $o = shift;
Subroutine collectHash: not called CC=1 SCAR=6.9
5966 0 my $label = shift;
5967 0 my $value = shift;
5968  
5969 0 $o->{hash} = $value;
5970 0 $o->{store} = $o->{actor}->preferredStore;
5971 }
5972  
5973 sub collectKeypair {
5974 0 ▶ my $o = shift;
Subroutine collectKeypair: not called CC=1 SCAR=6.9
5975 0 my $label = shift;
5976 0 my $value = shift;
5977  
5978 0 $o->{keyPairToken} = $value;
5979 }
5980  
5981 sub collectObject {
5982 0 ▶ my $o = shift;
Subroutine collectObject: not called CC=1 SCAR=6.9
5983 0 my $label = shift;
5984 0 my $value = shift;
5985  
5986 0 $o->{hash} = $value->hash;
5987 0 $o->{store} = $value->cliStore;
5988 }
5989  
5990 sub collectStore {
5991 0 ▶ my $o = shift;
Subroutine collectStore: not called CC=1 SCAR=6.9
5992 0 my $label = shift;
5993 0 my $value = shift;
5994  
5995 0 $o->{store} = $value;
5996 }
5997  
5998 sub new {
5999 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
6000 0 my $actor = shift;
6001 0 bless {actor => $actor, ui => $actor->ui} }
6002  
6003 # END AUTOGENERATED
6004  
6005 # HTML FOLDER NAME open-envelope
6006 # HTML TITLE Open envelope
6007 sub help {
6008 0 ▶ my $o = shift;
Subroutine help: not called CC=1 SCAR=6.9
6009 0 my $cmd = shift;
6010  
6011 0 my $ui = $o->{ui};
6012 0 $ui->space;
6013 0 $ui->command('cds open envelope OBJECT');
6014 0 $ui->command('cds open envelope HASH on STORE');
6015 0 $ui->p('Downloads an envelope, verifies its signatures, and tries to decrypt the AES key using the selected key pair and your own key pair.');
6016 0 $ui->p('In addition to displaying the envelope details, this command also displays the necessary "cds show record …" command to retrieve the content.');
6017 0 $ui->space;
6018 0 $ui->command('cds open envelope HASH');
6019 0 $ui->p('As above, but uses the selected store.');
6020 0 $ui->space;
6021 0 $ui->command('… from ACTOR');
6022 0 $ui->p('Assumes that the envelope was signed by ACTOR, and downloads the corresponding public key. The sender store is assumed to be the envelope\'s store. This is useful to verify public and private envelopes.');
6023 0 $ui->space;
6024 0 $ui->command('… using KEYPAIR');
6025 0 $ui->p('Tries to decrypt the AES key using this key pair, instead of the selected key pair.');
6026 0 $ui->space;
6027 }
6028  
6029 sub openEnvelope {
6030 0 ▶ my $o = shift;
Subroutine openEnvelope: not called CC=7 SCAR=40.3
6031 0 my $cmd = shift;
6032  
6033 0 $o->{keyPairToken} = $o->{actor}->preferredKeyPairToken;
6034 0 $cmd->collect($o);
6035  
6036 # Get the envelope
6037 0 ▶ my $envelope = $o->{actor}->uiGetRecord($o->{hash}, $o->{store}, $o->{keyPairToken}) // return;
Condition0%0/2
$o->{"actor"}->uiGetRecord($o->{"hash"}, $o->{"store"}, $o->{"keyPairToken"}) // (return)
l!l
00
MC/DC0%0/1
$o->{"actor"}->uiGetRecord($o->{"hash"}, $o->{"store"}, $o->{"keyPairToken"}) // (return)
$o->{"actor"}->uiGetRecord($o->{"hash"}, $o->{"store"}, $o->{"keyPairToken"})
Truth table0%0/2
A
A= $o->{"actor"}->uiGetRecord($o->{"hash"}, $o->{"store"}, $o->{"keyPairToken"})
Aresult
11
00
6038  
6039 # Continue by envelope type
6040 0 my $contentRecord = $envelope->child('content');
6041 0 ▶ if ($contentRecord->hashValue) {
Branch: 2 branches
BranchTrueFalseTotal
if ($contentRecord->hashValue) { } 0 0 0
elsif (length $contentRecord->bytesValue) { } 0 0 0
6042 0 ▶ if ($envelope->contains('encrypted for')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($envelope->contains('encrypted for')) { } 0 0 0
6043 0 $o->processPrivateEnvelope($envelope);
6044 } else {
6045 0 $o->processPublicEnvelope($envelope);
6046 }
6047 } elsif (length $contentRecord->bytesValue) {
6048 0 ▶ if ($envelope->contains('head') && $envelope->contains('mac')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($envelope->contains('head') and $envelope->contains('mac')) { } 0 0 0
Condition0%0/3
$envelope->contains("head") and $envelope->contains("mac")
!ll&&!rl&&r
000
MC/DC0%0/2
$envelope->contains("head") and $envelope->contains("mac")
$envelope->contains("head") $envelope->contains("mac")
Truth table0%0/3
A and B
A= $envelope->contains("head")B= $envelope->contains("mac")
ABresult
0X0
100
111
6049 0 $o->processStreamEnvelope($envelope);
6050 } else {
6051 0 $o->processMessageEnvelope($envelope);
6052 }
6053 } else {
6054 0 $o->processOther($envelope);
6055 }
6056 }
6057  
6058 sub processOther {
6059 0 ▶ my $o = shift;
Subroutine processOther: not called CC=3 SCAR=24.8
6060 0 ▶ my $envelope = shift; die 'wrong type '.ref($envelope).' for $envelope' if defined $envelope && ref $envelope ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $envelope and ref $envelope ne "CDS::Record" 0 0 0
Condition0%0/3
defined $envelope and ref $envelope ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $envelope and ref $envelope ne "CDS::Record"
defined $envelope ref $envelope ne "CDS::Record"
Truth table0%0/3
A and B
A= defined $envelopeB= ref $envelope ne "CDS::Record"
ABresult
0X0
100
111
6061  
6062 0 $o->{ui}->space;
6063 0 $o->{ui}->pOrange('This is not an envelope. Envelopes always have a "content" section. The raw record is shown below.');
6064 0 $o->{ui}->space;
6065 0 $o->{ui}->title('Record');
6066 0 $o->{ui}->recordChildren($envelope, $o->{actor}->storeReference($o->{store}));
6067 0 $o->{ui}->space;
6068 }
6069  
6070 sub processPublicEnvelope {
6071 0 ▶ my $o = shift;
Subroutine processPublicEnvelope: not called CC=3 SCAR=24.8
6072 0 ▶ my $envelope = shift; die 'wrong type '.ref($envelope).' for $envelope' if defined $envelope && ref $envelope ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $envelope and ref $envelope ne "CDS::Record" 0 0 0
Condition0%0/3
defined $envelope and ref $envelope ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $envelope and ref $envelope ne "CDS::Record"
defined $envelope ref $envelope ne "CDS::Record"
Truth table0%0/3
A and B
A= defined $envelopeB= ref $envelope ne "CDS::Record"
ABresult
0X0
100
111
6073  
6074 0 $o->{ui}->space;
6075 0 $o->{ui}->title('Public envelope');
6076 0 $o->{ui}->line($o->{ui}->gold('cds show record ', $o->{hash}->hex, ' on ', $o->{actor}->storeReference($o->{store})));
6077  
6078 0 my $contentHash = $envelope->child('content')->hashValue;
6079 0 $o->showPublicPrivateSignature($envelope, $contentHash);
6080  
6081 0 $o->{ui}->space;
6082 0 $o->{ui}->title('Content');
6083 0 $o->{ui}->line($o->{ui}->gold('cds show record ', $contentHash->hex, ' on ', $o->{actor}->storeReference($o->{store})));
6084  
6085 0 $o->{ui}->space;
6086 }
6087  
6088 sub processPrivateEnvelope {
6089 0 ▶ my $o = shift;
Subroutine processPrivateEnvelope: not called CC=4 SCAR=30.0
6090 0 ▶ my $envelope = shift; die 'wrong type '.ref($envelope).' for $envelope' if defined $envelope && ref $envelope ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $envelope and ref $envelope ne "CDS::Record" 0 0 0
Condition0%0/3
defined $envelope and ref $envelope ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $envelope and ref $envelope ne "CDS::Record"
defined $envelope ref $envelope ne "CDS::Record"
Truth table0%0/3
A and B
A= defined $envelopeB= ref $envelope ne "CDS::Record"
ABresult
0X0
100
111
6091  
6092 0 $o->{ui}->space;
6093 0 $o->{ui}->title('Private envelope');
6094 0 $o->{ui}->line($o->{ui}->gold('cds show record ', $o->{hash}->hex, ' on ', $o->{actor}->storeReference($o->{store})));
6095  
6096 0 my $aesKey = $o->decryptAesKey($envelope);
6097 0 my $contentHash = $envelope->child('content')->hashValue;
6098 0 $o->showPublicPrivateSignature($envelope, $contentHash);
6099 0 $o->showEncryptedFor($envelope);
6100  
6101 0 $o->{ui}->space;
6102 0 ▶ if ($aesKey) {
Branch: 1 branch
BranchTrueFalseTotal
if ($aesKey) { } 0 0 0
6103 0 $o->{ui}->title('Content');
6104 0 $o->{ui}->line($o->{ui}->gold('cds show record ', $contentHash->hex, ' on ', $o->{actor}->storeReference($o->{store}), ' decrypted with ', unpack('H*', $aesKey)));
6105 } else {
6106 0 $o->{ui}->title('Encrypted content');
6107 0 $o->{ui}->line($o->{ui}->gold('cds get ', $contentHash->hex, ' on ', $o->{actor}->storeReference($o->{store})));
6108 }
6109  
6110 0 $o->{ui}->space;
6111 }
6112  
6113 sub showPublicPrivateSignature {
6114 0 ▶ my $o = shift;
Subroutine showPublicPrivateSignature: not called CC=6 SCAR=37.4
6115 0 ▶ my $envelope = shift; die 'wrong type '.ref($envelope).' for $envelope' if defined $envelope && ref $envelope ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $envelope and ref $envelope ne "CDS::Record" 0 0 0
Condition0%0/3
defined $envelope and ref $envelope ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $envelope and ref $envelope ne "CDS::Record"
defined $envelope ref $envelope ne "CDS::Record"
Truth table0%0/3
A and B
A= defined $envelopeB= ref $envelope ne "CDS::Record"
ABresult
0X0
100
111
6116 0 ▶ my $contentHash = shift; die 'wrong type '.ref($contentHash).' for $contentHash' if defined $contentHash && ref $contentHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $contentHash and ref $contentHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $contentHash and ref $contentHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $contentHash and ref $contentHash ne "CDS::Hash"
defined $contentHash ref $contentHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $contentHashB= ref $contentHash ne "CDS::Hash"
ABresult
0X0
100
111
6117  
6118 0 $o->{ui}->space;
6119 0 $o->{ui}->title('Signed by');
6120 0 ▶ if ($o->{senderHash}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{'senderHash'}) { } 0 0 0
6121 0 my $accountToken = CDS::AccountToken->new($o->{store}, $o->{senderHash});
6122 0 $o->{ui}->line($o->{actor}->blueAccountReference($accountToken));
6123 0 $o->showSignature($envelope, $o->{senderHash}, $o->{store}, $contentHash);
6124 } else {
6125 0 $o->{ui}->p('The signer is not known. To verify the signature of a public or private envelope, you need to indicate the account on which it was found:');
6126 0 $o->{ui}->line($o->{ui}->gold(' cds show envelope ', $o->{hash}->hex, ' from ', $o->{ui}->underlined('ACTOR'), ' on ', $o->{actor}->storeReference($o->{store})));
6127 }
6128 }
6129  
6130 sub processMessageEnvelope {
6131 0 ▶ my $o = shift;
Subroutine processMessageEnvelope: not called CC=17 SCAR=57.2
6132 0 ▶ my $envelope = shift; die 'wrong type '.ref($envelope).' for $envelope' if defined $envelope && ref $envelope ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $envelope and ref $envelope ne "CDS::Record" 0 0 0
Condition0%0/3
defined $envelope and ref $envelope ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $envelope and ref $envelope ne "CDS::Record"
defined $envelope ref $envelope ne "CDS::Record"
Truth table0%0/3
A and B
A= defined $envelopeB= ref $envelope ne "CDS::Record"
ABresult
0X0
100
111
6133  
6134 0 $o->{ui}->space;
6135 0 $o->{ui}->title('Message envelope');
6136 0 $o->{ui}->line($o->{ui}->gold('cds show record ', $o->{hash}->hex, ' on ', $o->{actor}->storeReference($o->{store})));
6137  
6138 # Decrypt
6139 0 my $encryptedContentBytes = $envelope->child('content')->bytesValue;
6140 0 my $aesKey = $o->decryptAesKey($envelope);
6141 0 ▶ if (! $aesKey) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($aesKey) 0 0 0
6142 0 $o->{ui}->space;
6143 0 $o->{ui}->title('Encrypted content');
6144 0 $o->{ui}->line(length $encryptedContentBytes, ' bytes');
6145 0 return $o->processMessageEnvelope2($envelope);
6146 }
6147  
6148 0 my $contentObject = CDS::Object->fromBytes(CDS::C::aesCrypt($encryptedContentBytes, $aesKey, CDS->zeroCTR));
6149 0 ▶ if (! $contentObject) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($contentObject) 0 0 0
6150 0 $o->{ui}->pRed('The embedded content object is invalid, or the AES key (', unpack('H*', $aesKey), ') is wrong.');
6151 0 return $o->processMessageEnvelope2($envelope);
6152 }
6153  
6154 #my $signedHash = $contentObject->calculateHash; # before 2020-05-05
6155 0 my $signedHash = CDS::Hash->calculateFor($encryptedContentBytes);
6156 0 my $content = CDS::Record->fromObject($contentObject);
6157 0 ▶ if (! $content) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($content) 0 0 0
6158 0 $o->{ui}->pRed('The embedded content object does not contain a record, or the AES key (', unpack('H*', $aesKey), ') is wrong.');
6159 0 return $o->processMessageEnvelope2($envelope);
6160 }
6161  
6162 # Sender hash
6163 0 my $senderHash = $content->child('sender')->hashValue;
6164 0 ▶ $o->{ui}->pRed('The content object is missing the sender.') if ! $senderHash;
Branch: 1 branch
BranchTrueFalseTotal
unless $senderHash 0 0 0
6165  
6166 # Sender store
6167 0 my $senderStoreRecord = $content->child('store');
6168 0 my $senderStoreBytes = $senderStoreRecord->bytesValue;
6169 0 my $mentionsSenderStore = length $senderStoreBytes;
6170 0 ▶ $o->{ui}->pRed('The content object is missing the sender\'s store.') if ! $mentionsSenderStore;
Branch: 1 branch
BranchTrueFalseTotal
unless $mentionsSenderStore 0 0 0
6171 0 ▶ my $senderStore = scalar $mentionsSenderStore ? $o->{actor}->storeForUrl($senderStoreRecord->textValue) : undef;
Branch: 1 branch
BranchTrueFalseTotal
scalar $mentionsSenderStore ? : 0 0 0
6172  
6173 # Sender
6174 0 $o->{ui}->space;
6175 0 $o->{ui}->title('Signed by');
6176 0 ▶ if ($senderHash && $senderStore) {
Branch: 4 branches
BranchTrueFalseTotal
if ($senderHash and $senderStore) { } 0 0 0
elsif ($senderHash) { } 0 0 0
elsif ($senderStore) { } 0 0 0
elsif ($mentionsSenderStore) { } 0 0 0
Condition0%0/3
$senderHash and $senderStore
!ll&&!rl&&r
000
MC/DC0%0/2
$senderHash and $senderStore
$senderHash $senderStore
Truth table0%0/3
A and B
A= $senderHashB= $senderStore
ABresult
0X0
100
111
6177 0 my $senderToken = CDS::AccountToken->new($senderStore, $senderHash);
6178 0 $o->{ui}->line($o->{actor}->blueAccountReference($senderToken));
6179 0 $o->showSignature($envelope, $senderHash, $senderStore, $signedHash);
6180 } elsif ($senderHash) {
6181 0 ▶ my $actorLabel = $o->{actor}->actorLabel($senderHash) // $senderHash->hex;
Condition0%0/3
$o->{"actor"}->actorLabel($senderHash) // $senderHash->hex
l!l&&r!l&&!r
000
MC/DC0%0/2
$o->{"actor"}->actorLabel($senderHash) // $senderHash->hex
$o->{"actor"}->actorLabel($senderHash) $senderHash->hex
Truth table0%0/3
A // B
A= $o->{"actor"}->actorLabel($senderHash)B= $senderHash->hex
ABresult
1X1
011
000
6182 0 ▶ if ($mentionsSenderStore) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mentionsSenderStore) { } 0 0 0
6183 0 $o->{ui}->line($actorLabel, ' on ', $o->{ui}->red($o->{ui}->niceBytes($senderStoreBytes, 64)));
6184 } else {
6185 0 $o->{ui}->line($actorLabel);
6186 }
6187 0 $o->{ui}->pOrange('The signature cannot be verified, because the signer\'s store is not known.');
6188 } elsif ($senderStore) {
6189 0 $o->{ui}->line($o->{ui}->red('?'), ' on ', $o->{actor}->storeReference($senderStore));
6190 0 $o->{ui}->pOrange('The signature cannot be verified, because the signer is not known.');
6191 } elsif ($mentionsSenderStore) {
6192 0 $o->{ui}->line($o->{ui}->red('?'), ' on ', $o->{ui}->red($o->{ui}->niceBytes($senderStoreBytes, 64)));
6193 0 $o->{ui}->pOrange('The signature cannot be verified, because the signer is not known.');
6194 } else {
6195 0 $o->{ui}->pOrange('The signature cannot be verified, because the signer is not known.');
6196 }
6197  
6198 # Content
6199 0 $o->{ui}->space;
6200 0 $o->{ui}->title('Content');
6201 0 ▶ $o->{ui}->recordChildren($content, $senderStore ? $o->{actor}->storeReference($senderStore) : undef);
Branch: 1 branch
BranchTrueFalseTotal
$senderStore ? : 0 0 0
6202  
6203 0 return $o->processMessageEnvelope2($envelope);
6204 }
6205  
6206 sub processMessageEnvelope2 {
6207 0 ▶ my $o = shift;
Subroutine processMessageEnvelope2: not called CC=5 SCAR=34.0
6208 0 ▶ my $envelope = shift; die 'wrong type '.ref($envelope).' for $envelope' if defined $envelope && ref $envelope ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $envelope and ref $envelope ne "CDS::Record" 0 0 0
Condition0%0/3
defined $envelope and ref $envelope ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $envelope and ref $envelope ne "CDS::Record"
defined $envelope ref $envelope ne "CDS::Record"
Truth table0%0/3
A and B
A= defined $envelopeB= ref $envelope ne "CDS::Record"
ABresult
0X0
100
111
6209  
6210 # Encrypted for
6211 0 $o->showEncryptedFor($envelope);
6212  
6213 # Updated by
6214 0 $o->{ui}->space;
6215 0 $o->{ui}->title('May be removed or updated by');
6216  
6217 0 for my $child ($envelope->child('updated by')->children) {
6218 0 $o->showActorHash24($child->bytes);
6219 }
6220  
6221 # Expires
6222 0 $o->{ui}->space;
6223 0 $o->{ui}->title('Expires');
6224 0 my $expires = $envelope->child('expires')->integerValue;
6225 0 ▶ $o->{ui}->line($expires ? $o->{ui}->niceDateTime($expires) : $o->{ui}->gray('never'));
Branch: 1 branch
BranchTrueFalseTotal
$expires ? : 0 0 0
6226 0 $o->{ui}->space;
6227 }
6228  
6229 sub processStreamHead {
6230 0 ▶ my $o = shift;
Subroutine processStreamHead: not called CC=9 SCAR=45.0
6231 0 my $head = shift;
6232  
6233 0 $o->{ui}->space;
6234 0 $o->{ui}->title('Stream head');
6235 0 ▶ return $o->{ui}->pRed('The envelope does not mention a stream head.') if ! $head;
Branch: 1 branch
BranchTrueFalseTotal
unless $head 0 0 0
6236 0 $o->{ui}->line($o->{ui}->gold('cds open envelope ', $head->hex, ' on ', $o->{actor}->storeReference($o->{store})));
6237  
6238 # Get the envelope
6239 0 ▶ my $envelope = $o->{actor}->uiGetRecord($head, $o->{store}, $o->{keyPairToken}) // return;
Condition0%0/2
$o->{"actor"}->uiGetRecord($head, $o->{"store"}, $o->{"keyPairToken"}) // (return)
l!l
00
MC/DC0%0/1
$o->{"actor"}->uiGetRecord($head, $o->{"store"}, $o->{"keyPairToken"}) // (return)
$o->{"actor"}->uiGetRecord($head, $o->{"store"}, $o->{"keyPairToken"})
Truth table0%0/2
A
A= $o->{"actor"}->uiGetRecord($head, $o->{"store"}, $o->{"keyPairToken"})
Aresult
11
00
6240  
6241 # Decrypt the content
6242 0 my $encryptedContentBytes = $envelope->child('content')->bytesValue;
6243 0 ▶ my $aesKey = $o->decryptAesKey($envelope) // return;
Condition0%0/2
$o->decryptAesKey($envelope) // (return)
l!l
00
MC/DC0%0/1
$o->decryptAesKey($envelope) // (return)
$o->decryptAesKey($envelope)
Truth table0%0/2
A
A= $o->decryptAesKey($envelope)
Aresult
11
00
6244 0 ▶ my $contentObject = CDS::Object->fromBytes(CDS::C::aesCrypt($encryptedContentBytes, $aesKey, CDS->zeroCTR)) // return {aesKey => $aesKey};
Condition0%0/2
"CDS::Object"->fromBytes(CDS::C::aesCrypt($encryptedContentBytes, $aesKey, "CDS"->zeroCTR)) // (return {"aesKey", $aesKey})
l!l
00
MC/DC0%0/1
"CDS::Object"->fromBytes(CDS::C::aesCrypt($encryptedContentBytes, $aesKey, "CDS"->zeroCTR)) // (return {"aesKey", $aesKey})
"CDS::Object"->fromBytes(CDS::C::aesCrypt($encryptedContentBytes, $aesKey, "CDS"->zeroCTR))
Truth table0%0/2
A
A= "CDS::Object"->fromBytes(CDS::C::aesCrypt($encryptedContentBytes, $aesKey, "CDS"->zeroCTR))
Aresult
11
00
6245 0 my $signedHash = CDS::Hash->calculateFor($encryptedContentBytes);
6246 0 ▶ my $content = CDS::Record->fromObject($contentObject) // return {aesKey => $aesKey};
Condition0%0/2
"CDS::Record"->fromObject($contentObject) // (return {"aesKey", $aesKey})
l!l
00
MC/DC0%0/1
"CDS::Record"->fromObject($contentObject) // (return {"aesKey", $aesKey})
"CDS::Record"->fromObject($contentObject)
Truth table0%0/2
A
A= "CDS::Record"->fromObject($contentObject)
Aresult
11
00
6247  
6248 # Sender
6249 0 my $senderHash = $content->child('sender')->hashValue;
6250 0 my $senderStoreRecord = $content->child('store');
6251 0 my $senderStore = $o->{actor}->storeForUrl($senderStoreRecord->textValue);
6252 0 ▶ return {aesKey => $aesKey, senderHash => $senderHash, senderStore => $senderStore} if ! $senderHash || ! $senderStore;
Branch: 1 branch
BranchTrueFalseTotal
unless $senderHash and $senderStore 0 0 0
Condition0%0/3
$senderHash and $senderStore
!ll&&!rl&&r
000
MC/DC0%0/2
$senderHash and $senderStore
$senderHash $senderStore
Truth table0%0/3
A and B
A= $senderHashB= $senderStore
ABresult
0X0
100
111
6253  
6254 0 $o->{ui}->pushIndent;
6255 0 $o->{ui}->space;
6256 0 $o->{ui}->title('Signed by');
6257 0 my $senderToken = CDS::AccountToken->new($senderStore, $senderHash);
6258 0 $o->{ui}->line($o->{actor}->blueAccountReference($senderToken));
6259 0 $o->showSignature($envelope, $senderHash, $senderStore, $signedHash);
6260  
6261 # Recipients
6262 0 $o->{ui}->space;
6263 0 $o->{ui}->title('Encrypted for');
6264 0 for my $child ($envelope->child('encrypted for')->children) {
6265 0 $o->showActorHash24($child->bytes);
6266 }
6267  
6268 0 $o->{ui}->popIndent;
6269 0 return {aesKey => $aesKey, senderHash => $senderHash, senderStore => $senderStore, isValid => 1};
6270 }
6271  
6272 sub processStreamEnvelope {
6273 0 ▶ my $o = shift;
Subroutine processStreamEnvelope: not called CC=12 SCAR=50.5
6274 0 ▶ my $envelope = shift; die 'wrong type '.ref($envelope).' for $envelope' if defined $envelope && ref $envelope ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $envelope and ref $envelope ne "CDS::Record" 0 0 0
Condition0%0/3
defined $envelope and ref $envelope ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $envelope and ref $envelope ne "CDS::Record"
defined $envelope ref $envelope ne "CDS::Record"
Truth table0%0/3
A and B
A= defined $envelopeB= ref $envelope ne "CDS::Record"
ABresult
0X0
100
111
6275  
6276 0 $o->{ui}->space;
6277 0 $o->{ui}->title('Stream envelope');
6278 0 $o->{ui}->line($o->{ui}->gold('cds show record ', $o->{hash}->hex, ' on ', $o->{actor}->storeReference($o->{store})));
6279  
6280 # Get the head
6281 0 my $streamHead = $o->processStreamHead($envelope->child('head')->hashValue);
6282 0 ▶ $o->{ui}->pRed('The stream head cannot be opened. Open the stream head envelope for details.') if ! $streamHead || ! $streamHead->{isValid};
Branch: 1 branch
BranchTrueFalseTotal
unless $streamHead and $streamHead->{"isValid"} 0 0 0
Condition0%0/3
$streamHead and $streamHead->{"isValid"}
!ll&&!rl&&r
000
MC/DC0%0/2
$streamHead and $streamHead->{"isValid"}
$streamHead $streamHead->{"isValid"}
Truth table0%0/3
A and B
A= $streamHeadB= $streamHead->{"isValid"}
ABresult
0X0
100
111
6283  
6284 # Get the content
6285 0 my $encryptedBytes = $envelope->child('content')->bytesValue;
6286  
6287 # Get the CTR
6288 0 $o->{ui}->space;
6289 0 $o->{ui}->title('CTR');
6290 0 my $ctr = $envelope->child('ctr')->bytesValue;
6291 0 ▶ if (length $ctr == 16) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $ctr == 16) { } 0 0 0
6292 0 $o->{ui}->line(unpack('H*', $ctr));
6293 } else {
6294 0 $o->{ui}->pRed('The CTR value is invalid.');
6295 }
6296  
6297 0 ▶ return $o->{ui}->space if ! $streamHead;
Branch: 1 branch
BranchTrueFalseTotal
unless $streamHead 0 0 0
6298 0 ▶ return $o->{ui}->space if ! $streamHead->{aesKey};
Branch: 1 branch
BranchTrueFalseTotal
unless $streamHead->{"aesKey"} 0 0 0
6299  
6300 # Get and verify the MAC
6301 0 $o->{ui}->space;
6302 0 $o->{ui}->title('Message authentication (MAC)');
6303 0 my $mac = $envelope->child('mac')->bytesValue;
6304 0 my $signedHash = CDS::Hash->calculateFor($encryptedBytes);
6305 0 my $expectedMac = CDS::C::aesCrypt($signedHash->bytes, $streamHead->{aesKey}, $ctr);
6306 0 ▶ if ($mac eq $expectedMac) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mac eq $expectedMac) { } 0 0 0
6307 0 $o->{ui}->pGreen('The MAC valid.');
6308 } else {
6309 0 $o->{ui}->pRed('The MAC is invalid.');
6310 }
6311  
6312 # Decrypt the content
6313 0 $o->{ui}->space;
6314 0 $o->{ui}->title('Content');
6315 0 my $contentObject = CDS::Object->fromBytes(CDS::C::aesCrypt($encryptedBytes, $streamHead->{aesKey}, CDS::C::counterPlusInt($ctr, 2)));
6316 0 ▶ if (! $contentObject) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($contentObject) 0 0 0
6317 0 $o->{ui}->pRed('The embedded content object is invalid, or the provided AES key (', unpack('H*', $streamHead->{aesKey}), ') is wrong.') ;
6318 0 $o->{ui}->space;
6319 0 return;
6320 }
6321  
6322 0 my $content = CDS::Record->fromObject($contentObject);
6323 0 ▶ return $o->{ui}->pRed('The content is not a record.') if ! $content;
Branch: 1 branch
BranchTrueFalseTotal
unless $content 0 0 0
6324 0 ▶ $o->{ui}->recordChildren($content, $streamHead->{senderStore} ? $o->{actor}->storeReference($streamHead->{senderStore}) : undef);
Branch: 1 branch
BranchTrueFalseTotal
$streamHead->{'senderStore'} ? : 0 0 0
6325 0 $o->{ui}->space;
6326  
6327 # The envelope is valid
6328 #my $source = CDS::Source->new($o->{pool}->{keyPair}, $o->{actorOnStore}, 'messages', $entry->{hash});
6329 #return CDS::ReceivedMessage->new($o, $entry, $source, $envelope, $streamHead->senderStoreUrl, $streamHead->sender, $content, $streamHead);
6330  
6331 }
6332  
6333 sub showActorHash24 {
6334 0 ▶ my $o = shift;
Subroutine showActorHash24: not called CC=4 SCAR=30.0
6335 0 my $actorHashBytes = shift;
6336  
6337 0 my $actorHashHex = unpack('H*', $actorHashBytes);
6338 0 ▶ return $o->{ui}->line($o->{ui}->red($actorHashHex, ' (', length $actorHashBytes, ' instead of 24 bytes)')) if length $actorHashBytes != 24;
Branch: 1 branch
BranchTrueFalseTotal
if length $actorHashBytes != 24 0 0 0
6339  
6340 0 my $actorName = $o->{actor}->actorLabelByHashStartBytes($actorHashBytes);
6341 0 $actorHashHex .= '·' x 16;
6342  
6343 0 my $keyPairHashBytes = $o->{keyPairToken}->keyPair->publicKey->hash->bytes;
6344 0 my $isMe = substr($keyPairHashBytes, 0, 24) eq $actorHashBytes;
6345 0 ▶ $o->{ui}->line($isMe ? $o->{ui}->violet($actorHashHex) : $actorHashHex, (defined $actorName ? $o->{ui}->blue(' '.$actorName) : ''));
Branch: 2 branches
BranchTrueFalseTotal
$isMe ? : 0 0 0
defined $actorName ? : 0 0 0
6346 0 return $isMe;
6347 }
6348  
6349 sub showSignature {
6350 0 ▶ my $o = shift;
Subroutine showSignature: not called CC=9 SCAR=45.0
6351 0 ▶ my $envelope = shift; die 'wrong type '.ref($envelope).' for $envelope' if defined $envelope && ref $envelope ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $envelope and ref $envelope ne "CDS::Record" 0 0 0
Condition0%0/3
defined $envelope and ref $envelope ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $envelope and ref $envelope ne "CDS::Record"
defined $envelope ref $envelope ne "CDS::Record"
Truth table0%0/3
A and B
A= defined $envelopeB= ref $envelope ne "CDS::Record"
ABresult
0X0
100
111
6352 0 ▶ my $senderHash = shift; die 'wrong type '.ref($senderHash).' for $senderHash' if defined $senderHash && ref $senderHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $senderHash and ref $senderHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $senderHash and ref $senderHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $senderHash and ref $senderHash ne "CDS::Hash"
defined $senderHash ref $senderHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $senderHashB= ref $senderHash ne "CDS::Hash"
ABresult
0X0
100
111
6353 0 my $senderStore = shift;
6354 0 ▶ my $signedHash = shift; die 'wrong type '.ref($signedHash).' for $signedHash' if defined $signedHash && ref $signedHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $signedHash and ref $signedHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $signedHash and ref $signedHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $signedHash and ref $signedHash ne "CDS::Hash"
defined $signedHash ref $signedHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $signedHashB= ref $signedHash ne "CDS::Hash"
ABresult
0X0
100
111
6355  
6356 # Get the public key
6357 0 my $publicKey = $o->getPublicKey($senderHash, $senderStore);
6358 0 ▶ return $o->{ui}->line($o->{ui}->orange('The signature cannot be verified, because the signer\'s public key is not available.')) if ! $publicKey;
Branch: 1 branch
BranchTrueFalseTotal
unless $publicKey 0 0 0
6359  
6360 # Verify the signature
6361 0 ▶ if (CDS->verifyEnvelopeSignature($envelope, $publicKey, $signedHash)) {
Branch: 1 branch
BranchTrueFalseTotal
if ('CDS'->verifyEnvelopeSignature($envelope, $publicKey, $signedHash)) { } 0 0 0
6362 0 $o->{ui}->pGreen('The signature is valid.');
6363 } else {
6364 0 $o->{ui}->pRed('The signature is not valid.');
6365 }
6366 }
6367  
6368 sub getPublicKey {
6369 0 ▶ my $o = shift;
Subroutine getPublicKey: not called CC=4 SCAR=30.0
6370 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
6371 0 my $store = shift;
6372  
6373 0 ▶ return $o->{keyPairToken}->keyPair->publicKey if $hash->equals($o->{keyPairToken}->keyPair->publicKey->hash);
Branch: 1 branch
BranchTrueFalseTotal
if $hash->equals($o->{"keyPairToken"}->keyPair->publicKey->hash) 0 0 0
6374 0 return $o->{actor}->uiGetPublicKey($hash, $store, $o->{keyPairToken});
6375 }
6376  
6377 sub showEncryptedFor {
6378 0 ▶ my $o = shift;
Subroutine showEncryptedFor: not called CC=6 SCAR=37.4
6379 0 ▶ my $envelope = shift; die 'wrong type '.ref($envelope).' for $envelope' if defined $envelope && ref $envelope ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $envelope and ref $envelope ne "CDS::Record" 0 0 0
Condition0%0/3
defined $envelope and ref $envelope ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $envelope and ref $envelope ne "CDS::Record"
defined $envelope ref $envelope ne "CDS::Record"
Truth table0%0/3
A and B
A= defined $envelopeB= ref $envelope ne "CDS::Record"
ABresult
0X0
100
111
6380  
6381 0 $o->{ui}->space;
6382 0 $o->{ui}->title('Encrypted for');
6383  
6384 0 my $canDecrypt = 0;
6385 0 for my $child ($envelope->child('encrypted for')->children) {
6386 0 ▶ $canDecrypt = 1 if $o->showActorHash24($child->bytes);
Branch: 1 branch
BranchTrueFalseTotal
if $o->showActorHash24($child->bytes) 0 0 0
6387 }
6388  
6389 0 ▶ return if $canDecrypt;
Branch: 1 branch
BranchTrueFalseTotal
if $canDecrypt 0 0 0
6390 0 $o->{ui}->space;
6391 0 my $keyPairHash = $o->{keyPairToken}->keyPair->publicKey->hash;
6392 0 $o->{ui}->pOrange('This envelope is not encrypted for you (', $keyPairHash->shortHex, '). If you possess one of the keypairs mentioned above, add "… using KEYPAIR" to open this envelope.');
6393 }
6394  
6395 sub decryptAesKey {
6396 0 ▶ my $o = shift;
Subroutine decryptAesKey: not called CC=6 SCAR=37.4
6397 0 ▶ my $envelope = shift; die 'wrong type '.ref($envelope).' for $envelope' if defined $envelope && ref $envelope ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $envelope and ref $envelope ne "CDS::Record" 0 0 0
Condition0%0/3
defined $envelope and ref $envelope ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $envelope and ref $envelope ne "CDS::Record"
defined $envelope ref $envelope ne "CDS::Record"
Truth table0%0/3
A and B
A= defined $envelopeB= ref $envelope ne "CDS::Record"
ABresult
0X0
100
111
6398  
6399 0 my $keyPair = $o->{keyPairToken}->keyPair;
6400 0 my $hashBytes24 = substr($keyPair->publicKey->hash->bytes, 0, 24);
6401 0 my $child = $envelope->child('encrypted for')->child($hashBytes24);
6402  
6403 0 my $encryptedAesKey = $child->bytesValue;
6404 0 ▶ return if ! length $encryptedAesKey;
Branch: 1 branch
BranchTrueFalseTotal
unless length $encryptedAesKey 0 0 0
6405  
6406 0 my $aesKey = $keyPair->decrypt($encryptedAesKey);
6407 0 ▶ return $aesKey if defined $aesKey && length $aesKey == 32;
Branch: 1 branch
BranchTrueFalseTotal
if defined $aesKey and length $aesKey == 32 0 0 0
Condition0%0/3
defined $aesKey and length $aesKey == 32
!ll&&!rl&&r
000
MC/DC0%0/2
defined $aesKey and length $aesKey == 32
defined $aesKey length $aesKey == 32
Truth table0%0/3
A and B
A= defined $aesKeyB= length $aesKey == 32
ABresult
0X0
100
111
6408  
6409 0 $o->{ui}->pRed('The AES key failed to decrypt. It either wasn\'t encrypted properly, or the encryption was performed with the wrong public key.');
6410 0 return;
6411 }
6412  
6413 # BEGIN AUTOGENERATED
6414 package CDS::Commands::Put;
6415  
6416 sub register {
6417 0 ▶ my $class = shift;
Subroutine register: not called CC=1 SCAR=6.9
6418 0 my $cds = shift;
6419 0 my $help = shift;
6420  
6421 0 my $node000 = CDS::Parser::Node->new(0);
6422 0 my $node001 = CDS::Parser::Node->new(0);
6423 0 my $node002 = CDS::Parser::Node->new(0);
6424 0 my $node003 = CDS::Parser::Node->new(0);
6425 0 my $node004 = CDS::Parser::Node->new(0);
6426 0 my $node005 = CDS::Parser::Node->new(0);
6427 0 my $node006 = CDS::Parser::Node->new(0);
6428 0 my $node007 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&help});
6429 0 my $node008 = CDS::Parser::Node->new(0);
6430 0 my $node009 = CDS::Parser::Node->new(0);
6431 0 my $node010 = CDS::Parser::Node->new(0);
6432 0 my $node011 = CDS::Parser::Node->new(0);
6433 0 my $node012 = CDS::Parser::Node->new(1);
6434 0 my $node013 = CDS::Parser::Node->new(0);
6435 0 my $node014 = CDS::Parser::Node->new(0);
6436 0 my $node015 = CDS::Parser::Node->new(0);
6437 0 my $node016 = CDS::Parser::Node->new(0);
6438 0 my $node017 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&put});
6439 0 $cds->addArrow($node000, 1, 0, 'put');
6440 0 $cds->addArrow($node001, 1, 0, 'put');
6441 0 $cds->addArrow($node002, 1, 0, 'put');
6442 0 $help->addArrow($node007, 1, 0, 'put');
6443 0 $node000->addArrow($node012, 1, 0, 'OBJECTFILE', \&collectObjectfile);
6444 0 $node001->addArrow($node003, 1, 0, 'object');
6445 0 $node002->addArrow($node004, 1, 0, 'public');
6446 0 $node003->addArrow($node008, 1, 0, 'with');
6447 0 $node004->addArrow($node005, 1, 0, 'key');
6448 0 $node005->addArrow($node006, 1, 0, 'of');
6449 0 $node006->addArrow($node012, 1, 0, 'KEYPAIR', \&collectKeypair);
6450 0 $node008->addDefault($node009);
6451 0 $node008->addDefault($node011);
6452 0 $node009->addArrow($node009, 1, 0, 'HASH', \&collectHash);
6453 0 $node009->addArrow($node010, 1, 0, 'HASH', \&collectHash);
6454 0 $node010->addArrow($node011, 1, 0, 'and');
6455 0 $node011->addArrow($node012, 1, 0, 'FILE', \&collectFile);
6456 0 $node012->addArrow($node013, 1, 0, 'encrypted');
6457 0 $node012->addDefault($node015);
6458 0 $node013->addArrow($node014, 1, 0, 'with');
6459 0 $node014->addArrow($node015, 1, 0, 'AESKEY', \&collectAeskey);
6460 0 $node015->addArrow($node016, 1, 0, 'onto');
6461 0 $node015->addDefault($node017);
6462 0 $node016->addArrow($node016, 1, 0, 'STORE', \&collectStore);
6463 0 $node016->addArrow($node017, 1, 0, 'STORE', \&collectStore);
6464 }
6465  
6466 sub collectAeskey {
6467 0 ▶ my $o = shift;
Subroutine collectAeskey: not called CC=1 SCAR=6.9
6468 0 my $label = shift;
6469 0 my $value = shift;
6470  
6471 0 $o->{aesKey} = $value;
6472 }
6473  
6474 sub collectFile {
6475 0 ▶ my $o = shift;
Subroutine collectFile: not called CC=1 SCAR=6.9
6476 0 my $label = shift;
6477 0 my $value = shift;
6478  
6479 0 $o->{dataFile} = $value;
6480 }
6481  
6482 sub collectHash {
6483 0 ▶ my $o = shift;
Subroutine collectHash: not called CC=1 SCAR=6.9
6484 0 my $label = shift;
6485 0 my $value = shift;
6486  
6487 0 push @{$o->{hashes}}, $value;
6488 }
6489  
6490 sub collectKeypair {
6491 0 ▶ my $o = shift;
Subroutine collectKeypair: not called CC=1 SCAR=6.9
6492 0 my $label = shift;
6493 0 my $value = shift;
6494  
6495 0 $o->{object} = $value->keyPair->publicKey->object;
6496 }
6497  
6498 sub collectObjectfile {
6499 0 ▶ my $o = shift;
Subroutine collectObjectfile: not called CC=1 SCAR=6.9
6500 0 my $label = shift;
6501 0 my $value = shift;
6502  
6503 0 $o->{objectFile} = $value;
6504 }
6505  
6506 sub collectStore {
6507 0 ▶ my $o = shift;
Subroutine collectStore: not called CC=1 SCAR=6.9
6508 0 my $label = shift;
6509 0 my $value = shift;
6510  
6511 0 push @{$o->{stores}}, $value;
6512 }
6513  
6514 sub new {
6515 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
6516 0 my $actor = shift;
6517 0 bless {actor => $actor, ui => $actor->ui} }
6518  
6519 # END AUTOGENERATED
6520  
6521 # HTML FOLDER NAME store-put
6522 # HTML TITLE Put
6523 sub help {
6524 0 ▶ my $o = shift;
Subroutine help: not called CC=1 SCAR=6.9
6525 0 my $cmd = shift;
6526  
6527 0 my $ui = $o->{ui};
6528 0 $ui->space;
6529 0 $ui->command('cds put FILE* [onto STORE*]');
6530 0 $ui->p('Uploads object files onto object stores. If no stores are provided, the selected store is used. If an upload fails, the program immediately quits with exit code 1.');
6531 0 $ui->space;
6532 0 $ui->command('cds put FILE encrypted with AESKEY [onto STORE*]');
6533 0 $ui->p('Encrypts the object before the upload.');
6534 0 $ui->space;
6535 0 $ui->command('cds put object with [HASH* and] FILE …');
6536 0 $ui->p('Creates an object with the HASHes as hash list and FILE as data.');
6537 0 $ui->space;
6538 0 $ui->command('cds put public key of KEYPAIR …');
6539 0 $ui->p('Uploads the public key of the indicated key pair onto the store.');
6540 0 $ui->space;
6541 }
6542  
6543 sub put {
6544 0 ▶ my $o = shift;
Subroutine put: not called CC=4 SCAR=30.0
6545 0 my $cmd = shift;
6546  
6547 0 $o->{hashes} = [];
6548 0 $o->{stores} = [];
6549 0 $cmd->collect($o);
6550  
6551 # Stores
6552 0 ▶ push @{$o->{stores}}, $o->{actor}->preferredStore if ! scalar @{$o->{stores}};
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @{$o->{"stores"};} 0 0 0
6553  
6554 0 $o->{get} = [];
6555 0 ▶ return $o->putObject($o->{object}) if $o->{object};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"object"} 0 0 0
6556 0 ▶ return $o->putObjectFile if $o->{objectFile};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"objectFile"} 0 0 0
6557 0 $o->putConstructedFile;
6558 }
6559  
6560 sub putObjectFile {
6561 0 ▶ my $o = shift;
Subroutine putObjectFile: not called CC=2 SCAR=17.9
6562  
6563 0 my $object = $o->{objectFile}->object;
6564  
6565 # Display object information
6566 0 $o->{ui}->space;
6567 0 $o->{ui}->title('Uploading ', $o->{objectFile}->file, ' ', $o->{ui}->gray($o->{ui}->niceFileSize($object->byteLength)));
6568 0 ▶ $o->{ui}->line($object->hashesCount == 1 ? '1 hash' : $object->hashesCount.' hashes');
Branch: 1 branch
BranchTrueFalseTotal
$object->hashesCount == 1 ? : 0 0 0
6569 0 $o->{ui}->line($o->{ui}->niceFileSize(length $object->data).' data');
6570 0 $o->{ui}->space;
6571  
6572 # Upload
6573 0 $o->putObject($object);
6574 }
6575  
6576 sub putConstructedFile {
6577 0 ▶ my $o = shift;
Subroutine putConstructedFile: not called CC=3 SCAR=24.8
6578  
6579 # Create the object
6580 0 ▶ my $data = CDS->readBytesFromFile($o->{dataFile}) // return $o->{ui}->error('Unable to read "', $o->{dataFile}, '".');
Condition0%0/2
"CDS"->readBytesFromFile($o->{"dataFile"}) // (return $o->{"ui"}->error("Unable to read \"", $o->{"dataFile"}, "\"."))
l!l
00
MC/DC0%0/1
"CDS"->readBytesFromFile($o->{"dataFile"}) // (return $o->{"ui"}->error("Unable to read \"", $o->{"dataFile"}, "\"."))
"CDS"->readBytesFromFile($o->{"dataFile"})
Truth table0%0/2
A
A= "CDS"->readBytesFromFile($o->{"dataFile"})
Aresult
11
00
6581 0 my $header = pack('L>', scalar @{$o->{hashes}}) . join('', map { $_->bytes } @{$o->{hashes}});
6582 0 my $object = CDS::Object->create($header, $data);
6583  
6584 # Display object information
6585 0 $o->{ui}->space;
6586 0 $o->{ui}->title('Uploading new object ', $o->{ui}->gray($o->{ui}->niceFileSize(length $object->bytes)));
6587 0 ▶ $o->{ui}->line($object->hashesCount == 1 ? '1 hash' : $object->hashesCount.' hashes');
Branch: 1 branch
BranchTrueFalseTotal
$object->hashesCount == 1 ? : 0 0 0
6588 0 $o->{ui}->line($o->{ui}->niceFileSize(length $object->data).' data from ', $o->{dataFile});
6589 0 $o->{ui}->space;
6590  
6591 # Upload
6592 0 $o->putObject($object);
6593 }
6594  
6595 sub putObject {
6596 0 ▶ my $o = shift;
Subroutine putObject: not called CC=7 SCAR=40.3
6597 0 ▶ my $object = shift; die 'wrong type '.ref($object).' for $object' if defined $object && ref $object ne 'CDS::Object';
Branch: 1 branch
BranchTrueFalseTotal
if defined $object and ref $object ne "CDS::Object" 0 0 0
Condition0%0/3
defined $object and ref $object ne "CDS::Object"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $object and ref $object ne "CDS::Object"
defined $object ref $object ne "CDS::Object"
Truth table0%0/3
A and B
A= defined $objectB= ref $object ne "CDS::Object"
ABresult
0X0
100
111
6598  
6599 0 my $keyPair = $o->{actor}->preferredKeyPairToken->keyPair;
6600  
6601 # Encrypt it if desired
6602 0 my $objectBytes;
6603 0 ▶ if (defined $o->{aesKey}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $o->{"aesKey"}) 0 0 0
6604 0 $object = $object->crypt($o->{aesKey});
6605 0 unshift @{$o->{get}}, ' decrypted with ', unpack('H*', $o->{aesKey}), ' ';
6606 }
6607  
6608 # Calculate the hash
6609 0 my $hash = $object->calculateHash;
6610  
6611 # Upload the object
6612 0 my $successfulStore;
6613 0 for my $store (@{$o->{stores}}) {
6614 0 my $error = $store->put($hash, $object, $keyPair);
6615 0 ▶ next if $error;
Branch: 1 branch
BranchTrueFalseTotal
if $error 0 0 0
6616 0 $o->{ui}->pGreen('The object was uploaded onto ', $store->url, '.');
6617 0 $successfulStore = $store;
6618 }
6619  
6620 # Show the corresponding download line
6621 0 ▶ return if ! $successfulStore;
Branch: 1 branch
BranchTrueFalseTotal
unless $successfulStore 0 0 0
6622 0 $o->{ui}->space;
6623 0 $o->{ui}->line('To download the object, type:');
6624 0 $o->{ui}->line($o->{ui}->gold('cds get ', $hash->hex), $o->{ui}->gray(' on ', $successfulStore->url, @{$o->{get}}));
6625 0 $o->{ui}->space;
6626 }
6627  
6628 package CDS::Commands::Remember;
6629  
6630 # BEGIN AUTOGENERATED
6631  
6632 sub register {
6633 0 ▶ my $class = shift;
Subroutine register: not called CC=1 SCAR=6.9
6634 0 my $cds = shift;
6635 0 my $help = shift;
6636  
6637 0 my $node000 = CDS::Parser::Node->new(0, {constructor => \&new, function => \&showLabels});
6638 0 my $node001 = CDS::Parser::Node->new(0);
6639 0 my $node002 = CDS::Parser::Node->new(0);
6640 0 my $node003 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&help});
6641 0 my $node004 = CDS::Parser::Node->new(0);
6642 0 my $node005 = CDS::Parser::Node->new(0);
6643 0 my $node006 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&forget});
6644 0 my $node007 = CDS::Parser::Node->new(1);
6645 0 my $node008 = CDS::Parser::Node->new(0);
6646 0 my $node009 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&remember});
6647 0 $cds->addArrow($node000, 1, 0, 'remember');
6648 0 $cds->addArrow($node001, 1, 0, 'forget');
6649 0 $help->addArrow($node003, 1, 0, 'forget');
6650 0 $help->addArrow($node003, 1, 0, 'remember');
6651 0 $node000->addArrow($node004, 1, 0, 'ACTOR', \&collectActor);
6652 0 $node000->addArrow($node007, 1, 1, 'ACCOUNT', \&collectAccount);
6653 0 $node000->addArrow($node007, 1, 0, 'ACTOR', \&collectActor);
6654 0 $node000->addArrow($node007, 1, 0, 'KEYPAIR', \&collectKeypair);
6655 0 $node000->addArrow($node007, 1, 0, 'STORE', \&collectStore);
6656 0 $node001->addDefault($node002);
6657 0 $node002->addArrow($node002, 1, 0, 'LABEL', \&collectLabel);
6658 0 $node002->addArrow($node006, 1, 0, 'LABEL', \&collectLabel);
6659 0 $node004->addArrow($node005, 1, 0, 'on');
6660 0 $node005->addArrow($node007, 1, 0, 'STORE', \&collectStore);
6661 0 $node007->addArrow($node008, 1, 0, 'as');
6662 0 $node008->addArrow($node009, 1, 0, 'TEXT', \&collectText);
6663 }
6664  
6665 sub collectAccount {
6666 0 ▶ my $o = shift;
Subroutine collectAccount: not called CC=1 SCAR=6.9
6667 0 my $label = shift;
6668 0 my $value = shift;
6669  
6670 0 $o->{store} = $value->cliStore;
6671 0 $o->{actorHash} = $value->actorHash;
6672 }
6673  
6674 sub collectActor {
6675 0 ▶ my $o = shift;
Subroutine collectActor: not called CC=1 SCAR=6.9
6676 0 my $label = shift;
6677 0 my $value = shift;
6678  
6679 0 $o->{actorHash} = $value;
6680 }
6681  
6682 sub collectKeypair {
6683 0 ▶ my $o = shift;
Subroutine collectKeypair: not called CC=1 SCAR=6.9
6684 0 my $label = shift;
6685 0 my $value = shift;
6686  
6687 0 $o->{keyPairToken} = $value;
6688 }
6689  
6690 sub collectLabel {
6691 0 ▶ my $o = shift;
Subroutine collectLabel: not called CC=1 SCAR=6.9
6692 0 my $label = shift;
6693 0 my $value = shift;
6694  
6695 0 push @{$o->{forget}}, $value;
6696 }
6697  
6698 sub collectStore {
6699 0 ▶ my $o = shift;
Subroutine collectStore: not called CC=1 SCAR=6.9
6700 0 my $label = shift;
6701 0 my $value = shift;
6702  
6703 0 $o->{store} = $value;
6704 }
6705  
6706 sub collectText {
6707 0 ▶ my $o = shift;
Subroutine collectText: not called CC=1 SCAR=6.9
6708 0 my $label = shift;
6709 0 my $value = shift;
6710  
6711 0 $o->{label} = $value;
6712 }
6713  
6714 sub new {
6715 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
6716 0 my $actor = shift;
6717 0 bless {actor => $actor, ui => $actor->ui} }
6718  
6719 # END AUTOGENERATED
6720  
6721 # HTML FOLDER NAME remember
6722 # HTML TITLE Remember
6723 sub help {
6724 0 ▶ my $o = shift;
Subroutine help: not called CC=1 SCAR=6.9
6725 0 my $cmd = shift;
6726  
6727 0 my $ui = $o->{ui};
6728 0 $ui->space;
6729 0 $ui->command('cds remember');
6730 0 $ui->p('Shows all remembered values.');
6731 0 $ui->space;
6732 0 $ui->command('cds remember ACCOUNT|ACTOR|STORE|KEYPAIR as TEXT');
6733 0 $ui->command('cds remember ACTOR on STORE as TEXT');
6734 0 $ui->p('Remembers the indicated actor hash, account, store, or key pair as TEXT. This information is stored in the global state, and therefore persists until the name is deleted (cds forget …) or redefined (cds remember …).');
6735 0 $ui->space;
6736 0 $ui->p('Key pairs are stored as link (absolute path) to the key pair file, and specific to the device.');
6737 0 $ui->space;
6738 0 $ui->command('cds forget LABEL');
6739 0 $ui->p('Forgets the corresponding item.');
6740 0 $ui->space;
6741 }
6742  
6743 sub remember {
6744 0 ▶ my $o = shift;
Subroutine remember: not called CC=4 SCAR=30.0
6745 0 my $cmd = shift;
6746  
6747 0 $cmd->collect($o);
6748  
6749 0 my $record = CDS::Record->new;
6750 0 ▶ $record->add('store')->addText($o->{store}->url) if defined $o->{store};
Branch: 1 branch
BranchTrueFalseTotal
if defined $o->{"store"} 0 0 0
6751 0 ▶ $record->add('actor')->add($o->{actorHash}->bytes) if defined $o->{actorHash};
Branch: 1 branch
BranchTrueFalseTotal
if defined $o->{"actorHash"} 0 0 0
6752 0 ▶ $record->add('key pair')->addText($o->{keyPairToken}->file) if defined $o->{keyPairToken};
Branch: 1 branch
BranchTrueFalseTotal
if defined $o->{"keyPairToken"} 0 0 0
6753 0 $o->{actor}->remember($o->{label}, $record);
6754 0 $o->{actor}->saveOrShowError;
6755 }
6756  
6757 sub forget {
6758 0 ▶ my $o = shift;
Subroutine forget: not called CC=2 SCAR=17.9
6759 0 my $cmd = shift;
6760  
6761 0 $o->{forget} = [];
6762 0 $cmd->collect($o);
6763  
6764 0 for my $label (@{$o->{forget}}) {
6765 0 $o->{actor}->groupRoot->child('labels')->child($label)->clear;
6766 }
6767  
6768 0 $o->{actor}->saveOrShowError;
6769 }
6770  
6771 sub showLabels {
6772 0 ▶ my $o = shift;
Subroutine showLabels: not called CC=1 SCAR=6.9
6773 0 my $cmd = shift;
6774  
6775 0 $o->{ui}->space;
6776 0 $o->showRememberedValues;
6777 0 $o->{ui}->space;
6778 }
6779  
6780 sub showRememberedValues {
6781 0 ▶ my $o = shift;
Subroutine showRememberedValues: not called CC=8 SCAR=42.8
6782  
6783 0 my $hasLabel = 0;
6784 0 for my $child (sort { $a->{id} cmp $b->{id} } $o->{actor}->groupRoot->child('labels')->children) {
6785 0 my $record = $child->record;
6786 0 my $label = $o->{ui}->blue($o->{ui}->left(15, Encode::decode_utf8($child->label)));
6787  
6788 0 my $actorHash = CDS::Hash->fromBytes($record->child('actor')->bytesValue);
6789 0 my $storeUrl = $record->child('store')->textValue;
6790 0 my $keyPairFile = $record->child('key pair')->textValue;
6791  
6792 0 ▶ if (length $keyPairFile) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $keyPairFile) 0 0 0
6793 0 $o->{ui}->line($label, ' ', $o->{ui}->gray('key pair'), ' ', $keyPairFile);
6794 0 $hasLabel = 1;
6795 }
6796  
6797 0 ▶ if ($actorHash && length $storeUrl) {
Branch: 3 branches
BranchTrueFalseTotal
if ($actorHash and length $storeUrl) { } 0 0 0
elsif ($actorHash) { } 0 0 0
elsif (length $storeUrl) { } 0 0 0
Condition0%0/3
$actorHash and length $storeUrl
!ll&&!rl&&r
000
MC/DC0%0/2
$actorHash and length $storeUrl
$actorHash length $storeUrl
Truth table0%0/3
A and B
A= $actorHashB= length $storeUrl
ABresult
0X0
100
111
6798 0 my $storeReference = $o->{actor}->blueStoreUrlReference($storeUrl);
6799 0 $o->{ui}->line($label, ' ', $o->{ui}->gray('account'), ' ', $actorHash->hex, ' on ', $storeReference);
6800 0 $hasLabel = 1;
6801 } elsif ($actorHash) {
6802 0 $o->{ui}->line($label, ' ', $o->{ui}->gray('actor'), ' ', $actorHash->hex);
6803 0 $hasLabel = 1;
6804 } elsif (length $storeUrl) {
6805 0 $o->{ui}->line($label, ' ', $o->{ui}->gray('store'), ' ', $storeUrl);
6806 0 $hasLabel = 1;
6807 }
6808  
6809 0 $o->showActorGroupLabel($label, $record->child('actor group'));
6810 }
6811  
6812 0 ▶ return if $hasLabel;
Branch: 1 branch
BranchTrueFalseTotal
if $hasLabel 0 0 0
6813 0 $o->{ui}->line($o->{ui}->gray('none'));
6814 }
6815  
6816 sub showActorGroupLabel {
6817 0 ▶ my $o = shift;
Subroutine showActorGroupLabel: not called CC=13 SCAR=52.0
6818 0 my $label = shift;
6819 0 ▶ my $record = shift; die 'wrong type '.ref($record).' for $record' if defined $record && ref $record ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $record and ref $record ne "CDS::Record" 0 0 0
Condition0%0/3
defined $record and ref $record ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $record and ref $record ne "CDS::Record"
defined $record ref $record ne "CDS::Record"
Truth table0%0/3
A and B
A= defined $recordB= ref $record ne "CDS::Record"
ABresult
0X0
100
111
6820  
6821 0 ▶ return if ! $record->contains('actor group');
Branch: 1 branch
BranchTrueFalseTotal
unless $record->contains("actor group") 0 0 0
6822  
6823 0 my $builder = CDS::ActorGroupBuilder->new;
6824 0 $builder->parse($record, 1);
6825  
6826 0 my $countActive = 0;
6827 0 my $countIdle = 0;
6828 0 my $newestActive = undef;
6829  
6830 0 for my $member ($builder->members) {
6831 0 my $isActive = $member->status eq 'active';
6832 0 ▶ $countActive += 1 if $isActive;
Branch: 1 branch
BranchTrueFalseTotal
if $isActive 0 0 0
6833 0 ▶ $countIdle += 1 if $member->status eq 'idle';
Branch: 1 branch
BranchTrueFalseTotal
if $member->status eq "idle" 0 0 0
6834  
6835 0 ▶ next if ! $isActive;
Branch: 1 branch
BranchTrueFalseTotal
unless $isActive 0 0 0
6836 0 ▶ next if $newestActive && $member->revision <= $newestActive->revision;
Branch: 1 branch
BranchTrueFalseTotal
if $newestActive and $member->revision <= $newestActive->revision 0 0 0
Condition0%0/3
$newestActive and $member->revision <= $newestActive->revision
!ll&&!rl&&r
000
MC/DC0%0/2
$newestActive and $member->revision <= $newestActive->revision
$newestActive $member->revision <= $newestActive->revision
Truth table0%0/3
A and B
A= $newestActiveB= $member->revision <= $newestActive->revision
ABresult
0X0
100
111
6837 0 $newestActive = $member;
6838 }
6839  
6840 0 my @line;
6841 0 push @line, $label, ' ', $o->{ui}->gray('actor group'), ' ';
6842 0 ▶ push @line, $newestActive->hash->hex, ' on ', $o->{actor}->blueStoreUrlReference($newestActive->storeUrl) if $newestActive;
Branch: 1 branch
BranchTrueFalseTotal
if $newestActive 0 0 0
6843 0 ▶ push @line, $o->{ui}->gray('(no active actor)') if ! $newestActive;
Branch: 1 branch
BranchTrueFalseTotal
unless $newestActive 0 0 0
6844 0 push @line, $o->{ui}->green(' ', $countActive, ' active');
6845 0 my $discovered = $record->child('discovered')->integerValue;
6846 0 ▶ push @line, $o->{ui}->gray(' ', $o->{ui}->niceDateTimeLocal($discovered)) if $discovered;
Branch: 1 branch
BranchTrueFalseTotal
if $discovered 0 0 0
6847 0 $o->{ui}->line(@line);
6848 }
6849  
6850 # BEGIN AUTOGENERATED
6851 package CDS::Commands::Select;
6852  
6853 sub register {
6854 0 ▶ my $class = shift;
Subroutine register: not called CC=1 SCAR=6.9
6855 0 my $cds = shift;
6856 0 my $help = shift;
6857  
6858 0 my $node000 = CDS::Parser::Node->new(0);
6859 0 my $node001 = CDS::Parser::Node->new(0);
6860 0 my $node002 = CDS::Parser::Node->new(0);
6861 0 my $node003 = CDS::Parser::Node->new(0);
6862 0 my $node004 = CDS::Parser::Node->new(0);
6863 0 my $node005 = CDS::Parser::Node->new(0);
6864 0 my $node006 = CDS::Parser::Node->new(0);
6865 0 my $node007 = CDS::Parser::Node->new(0);
6866 0 my $node008 = CDS::Parser::Node->new(0);
6867 0 my $node009 = CDS::Parser::Node->new(0);
6868 0 my $node010 = CDS::Parser::Node->new(0);
6869 0 my $node011 = CDS::Parser::Node->new(0);
6870 0 my $node012 = CDS::Parser::Node->new(0);
6871 0 my $node013 = CDS::Parser::Node->new(0);
6872 0 my $node014 = CDS::Parser::Node->new(0);
6873 0 my $node015 = CDS::Parser::Node->new(0);
6874 0 my $node016 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&help});
6875 0 my $node017 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&showSelectionCmd});
6876 0 my $node018 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&unselectKeyPair});
6877 0 my $node019 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&unselectStore});
6878 0 my $node020 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&unselectActor});
6879 0 my $node021 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&unselectAll});
6880 0 my $node022 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&select});
6881 0 $cds->addArrow($node000, 1, 0, 'select');
6882 0 $cds->addArrow($node001, 1, 0, 'select');
6883 0 $cds->addArrow($node002, 1, 0, 'select');
6884 0 $cds->addArrow($node003, 1, 0, 'select');
6885 0 $cds->addArrow($node004, 1, 0, 'select');
6886 0 $cds->addArrow($node005, 1, 0, 'select');
6887 0 $cds->addArrow($node006, 1, 0, 'select');
6888 0 $cds->addArrow($node009, 1, 0, 'unselect');
6889 0 $cds->addArrow($node010, 1, 0, 'unselect');
6890 0 $cds->addArrow($node011, 1, 0, 'unselect');
6891 0 $cds->addArrow($node012, 1, 0, 'unselect');
6892 0 $cds->addArrow($node017, 1, 0, 'select');
6893 0 $help->addArrow($node016, 1, 0, 'select');
6894 0 $node000->addArrow($node022, 1, 0, 'KEYPAIR', \&collectKeypair);
6895 0 $node001->addArrow($node022, 1, 0, 'STORE', \&collectStore);
6896 0 $node002->addArrow($node014, 1, 0, 'ACTOR', \&collectActor);
6897 0 $node003->addArrow($node007, 1, 0, 'storage');
6898 0 $node004->addArrow($node008, 1, 0, 'messaging');
6899 0 $node005->addArrow($node022, 1, 0, 'ACTOR', \&collectActor);
6900 0 $node006->addArrow($node022, 1, 1, 'ACCOUNT', \&collectAccount);
6901 0 $node007->addArrow($node022, 1, 0, 'store', \&collectStore1);
6902 0 $node008->addArrow($node022, 1, 0, 'store', \&collectStore2);
6903 0 $node009->addArrow($node013, 1, 0, 'key');
6904 0 $node010->addArrow($node019, 1, 0, 'store');
6905 0 $node011->addArrow($node020, 1, 0, 'actor');
6906 0 $node012->addArrow($node021, 1, 0, 'all');
6907 0 $node013->addArrow($node018, 1, 0, 'pair');
6908 0 $node014->addArrow($node015, 1, 0, 'on');
6909 0 $node015->addArrow($node022, 1, 0, 'STORE', \&collectStore);
6910 }
6911  
6912 sub collectAccount {
6913 0 ▶ my $o = shift;
Subroutine collectAccount: not called CC=1 SCAR=6.9
6914 0 my $label = shift;
6915 0 my $value = shift;
6916  
6917 0 $o->{store} = $value->cliStore;
6918 0 $o->{actorHash} = $value->actorHash;
6919 }
6920  
6921 sub collectActor {
6922 0 ▶ my $o = shift;
Subroutine collectActor: not called CC=1 SCAR=6.9
6923 0 my $label = shift;
6924 0 my $value = shift;
6925  
6926 0 $o->{actorHash} = $value;
6927 }
6928  
6929 sub collectKeypair {
6930 0 ▶ my $o = shift;
Subroutine collectKeypair: not called CC=1 SCAR=6.9
6931 0 my $label = shift;
6932 0 my $value = shift;
6933  
6934 0 $o->{keyPairToken} = $value;
6935 0 $o->{actorHash} = $value->keyPair->publicKey->hash;
6936 }
6937  
6938 sub collectStore {
6939 0 ▶ my $o = shift;
Subroutine collectStore: not called CC=1 SCAR=6.9
6940 0 my $label = shift;
6941 0 my $value = shift;
6942  
6943 0 $o->{store} = $value;
6944 }
6945  
6946 sub collectStore1 {
6947 0 ▶ my $o = shift;
Subroutine collectStore1: not called CC=1 SCAR=6.9
6948 0 my $label = shift;
6949 0 my $value = shift;
6950  
6951 0 $o->{store} = $o->{actor}->storageStore;
6952 }
6953  
6954 sub collectStore2 {
6955 0 ▶ my $o = shift;
Subroutine collectStore2: not called CC=1 SCAR=6.9
6956 0 my $label = shift;
6957 0 my $value = shift;
6958  
6959 0 $o->{store} = $o->{actor}->messagingStore;
6960 }
6961  
6962 sub new {
6963 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
6964 0 my $actor = shift;
6965 0 bless {actor => $actor, ui => $actor->ui} }
6966  
6967 # END AUTOGENERATED
6968  
6969 # HTML FOLDER NAME select
6970 # HTML TITLE Select
6971 sub help {
6972 0 ▶ my $o = shift;
Subroutine help: not called CC=1 SCAR=6.9
6973 0 my $cmd = shift;
6974  
6975 0 my $ui = $o->{ui};
6976 0 $ui->space;
6977 0 $ui->command('cds select');
6978 0 $ui->p('Shows the current selection.');
6979 0 $ui->space;
6980 0 $ui->command('cds select KEYPAIR');
6981 0 $ui->p('Selects KEYPAIR on this terminal. Some commands will use this key pair by default.');
6982 0 $ui->space;
6983 0 $ui->command('cds unselect key pair');
6984 0 $ui->p('Removes the key pair selection.');
6985 0 $ui->space;
6986 0 $ui->command('cds select STORE');
6987 0 $ui->p('Selects STORE on this terminal. Some commands will use this store by default.');
6988 0 $ui->space;
6989 0 $ui->command('cds unselect store');
6990 0 $ui->p('Removes the store selection.');
6991 0 $ui->space;
6992 0 $ui->command('cds select ACTOR');
6993 0 $ui->p('Selects ACTOR on this terminal. Some commands will use this store by default.');
6994 0 $ui->space;
6995 0 $ui->command('cds unselect actor');
6996 0 $ui->p('Removes the actor selection.');
6997 0 $ui->space;
6998 0 $ui->command('cds unselect');
6999 0 $ui->p('Removes any selection.');
7000 0 $ui->space;
7001 }
7002  
7003 sub select {
7004 0 ▶ my $o = shift;
Subroutine select: not called CC=4 SCAR=30.0
7005 0 my $cmd = shift;
7006  
7007 0 $cmd->collect($o);
7008  
7009 0 ▶ if ($o->{keyPairToken}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"keyPairToken"}) 0 0 0
7010 0 $o->{actor}->sessionRoot->child('selected key pair')->setText($o->{keyPairToken}->file);
7011 0 $o->{ui}->pGreen('Key pair ', $o->{keyPairToken}->file, ' selected.');
7012 }
7013  
7014 0 ▶ if ($o->{store}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"store"}) 0 0 0
7015 0 $o->{actor}->sessionRoot->child('selected store')->setText($o->{store}->url);
7016 0 $o->{ui}->pGreen('Store ', $o->{store}->url, ' selected.');
7017 }
7018  
7019 0 ▶ if ($o->{actorHash}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"actorHash"}) 0 0 0
7020 0 $o->{actor}->sessionRoot->child('selected actor')->setBytes($o->{actorHash}->bytes);
7021 0 $o->{ui}->pGreen('Actor ', $o->{actorHash}->hex, ' selected.');
7022 }
7023  
7024 0 $o->{actor}->saveOrShowError;
7025 }
7026  
7027 sub unselectKeyPair {
7028 0 ▶ my $o = shift;
Subroutine unselectKeyPair: not called CC=1 SCAR=6.9
7029 0 my $cmd = shift;
7030  
7031 0 $o->{actor}->sessionRoot->child('selected key pair')->clear;
7032 0 $o->{ui}->pGreen('Key pair selection cleared.');
7033 0 $o->{actor}->saveOrShowError;
7034 }
7035  
7036 sub unselectStore {
7037 0 ▶ my $o = shift;
Subroutine unselectStore: not called CC=1 SCAR=6.9
7038 0 my $cmd = shift;
7039  
7040 0 $o->{actor}->sessionRoot->child('selected store')->clear;
7041 0 $o->{ui}->pGreen('Store selection cleared.');
7042 0 $o->{actor}->saveOrShowError;
7043 }
7044  
7045 sub unselectActor {
7046 0 ▶ my $o = shift;
Subroutine unselectActor: not called CC=1 SCAR=6.9
7047 0 my $cmd = shift;
7048  
7049 0 $o->{actor}->sessionRoot->child('selected actor')->clear;
7050 0 $o->{ui}->pGreen('Actor selection cleared.');
7051 0 $o->{actor}->saveOrShowError;
7052 }
7053  
7054 sub unselectAll {
7055 0 ▶ my $o = shift;
Subroutine unselectAll: not called CC=2 SCAR=17.9
7056 0 my $cmd = shift;
7057  
7058 0 $o->{actor}->sessionRoot->child('selected key pair')->clear;
7059 0 $o->{actor}->sessionRoot->child('selected store')->clear;
7060 0 $o->{actor}->sessionRoot->child('selected actor')->clear;
7061 0 ▶ $o->{actor}->saveOrShowError // return;
Condition0%0/2
$o->{"actor"}->saveOrShowError // (return)
l!l
00
MC/DC0%0/1
$o->{"actor"}->saveOrShowError // (return)
$o->{"actor"}->saveOrShowError
Truth table0%0/2
A
A= $o->{"actor"}->saveOrShowError
Aresult
11
00
7062 0 $o->showSelection;
7063 }
7064  
7065 sub showSelectionCmd {
7066 0 ▶ my $o = shift;
Subroutine showSelectionCmd: not called CC=1 SCAR=6.9
7067 0 my $cmd = shift;
7068  
7069 0 $o->{ui}->space;
7070 0 $o->showSelection;
7071 0 $o->{ui}->space;
7072 }
7073  
7074 sub showSelection {
7075 0 ▶ my $o = shift;
Subroutine showSelection: not called CC=4 SCAR=30.0
7076  
7077 0 my $keyPairFile = $o->{actor}->sessionRoot->child('selected key pair')->textValue;
7078 0 my $storeUrl = $o->{actor}->sessionRoot->child('selected store')->textValue;
7079 0 my $actorBytes = $o->{actor}->sessionRoot->child('selected actor')->bytesValue;
7080  
7081 0 ▶ $o->{ui}->line($o->{ui}->darkBold('Selected key pair '), length $keyPairFile ? $keyPairFile : $o->{ui}->gray('none'));
Branch: 1 branch
BranchTrueFalseTotal
length $keyPairFile ? : 0 0 0
7082 0 ▶ $o->{ui}->line($o->{ui}->darkBold('Selected store '), length $storeUrl ? $storeUrl : $o->{ui}->gray('none'));
Branch: 1 branch
BranchTrueFalseTotal
length $storeUrl ? : 0 0 0
7083 0 ▶ $o->{ui}->line($o->{ui}->darkBold('Selected actor '), length $actorBytes == 32 ? unpack('H*', $actorBytes) : $o->{ui}->gray('none'));
Branch: 1 branch
BranchTrueFalseTotal
length $actorBytes == 32 ? : 0 0 0
7084 }
7085  
7086 # BEGIN AUTOGENERATED
7087 package CDS::Commands::ShowCard;
7088  
7089 sub register {
7090 0 ▶ my $class = shift;
Subroutine register: not called CC=1 SCAR=6.9
7091 0 my $cds = shift;
7092 0 my $help = shift;
7093  
7094 0 my $node000 = CDS::Parser::Node->new(0);
7095 0 my $node001 = CDS::Parser::Node->new(0);
7096 0 my $node002 = CDS::Parser::Node->new(0);
7097 0 my $node003 = CDS::Parser::Node->new(0);
7098 0 my $node004 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&help});
7099 0 my $node005 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&showMyCard});
7100 0 my $node006 = CDS::Parser::Node->new(1);
7101 0 my $node007 = CDS::Parser::Node->new(0);
7102 0 my $node008 = CDS::Parser::Node->new(0);
7103 0 my $node009 = CDS::Parser::Node->new(0);
7104 0 my $node010 = CDS::Parser::Node->new(0);
7105 0 my $node011 = CDS::Parser::Node->new(0);
7106 0 my $node012 = CDS::Parser::Node->new(0);
7107 0 my $node013 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&showCard});
7108 0 $cds->addArrow($node001, 1, 0, 'show');
7109 0 $cds->addArrow($node002, 1, 0, 'show');
7110 0 $help->addArrow($node000, 1, 0, 'show');
7111 0 $node000->addArrow($node004, 1, 0, 'card');
7112 0 $node001->addArrow($node006, 1, 0, 'card');
7113 0 $node002->addArrow($node003, 1, 0, 'my');
7114 0 $node003->addArrow($node005, 1, 0, 'card');
7115 0 $node006->addArrow($node007, 1, 0, 'of');
7116 0 $node006->addArrow($node008, 1, 0, 'of');
7117 0 $node006->addArrow($node009, 1, 0, 'of');
7118 0 $node006->addArrow($node010, 1, 0, 'of');
7119 0 $node006->addDefault($node011);
7120 0 $node007->addArrow($node007, 1, 0, 'ACCOUNT', \&collectAccount);
7121 0 $node007->addArrow($node013, 1, 1, 'ACCOUNT', \&collectAccount);
7122 0 $node008->addArrow($node013, 1, 0, 'ACTORGROUP', \&collectActorgroup);
7123 0 $node009->addArrow($node011, 1, 0, 'KEYPAIR', \&collectKeypair);
7124 0 $node010->addArrow($node011, 1, 0, 'ACTOR', \&collectActor);
7125 0 $node011->addArrow($node012, 1, 0, 'on');
7126 0 $node011->addDefault($node013);
7127 0 $node012->addArrow($node012, 1, 0, 'STORE', \&collectStore);
7128 0 $node012->addArrow($node013, 1, 0, 'STORE', \&collectStore);
7129 }
7130  
7131 sub collectAccount {
7132 0 ▶ my $o = shift;
Subroutine collectAccount: not called CC=1 SCAR=6.9
7133 0 my $label = shift;
7134 0 my $value = shift;
7135  
7136 0 push @{$o->{accountTokens}}, $value;
7137 }
7138  
7139 sub collectActor {
7140 0 ▶ my $o = shift;
Subroutine collectActor: not called CC=1 SCAR=6.9
7141 0 my $label = shift;
7142 0 my $value = shift;
7143  
7144 0 $o->{actorHash} = $value;
7145 }
7146  
7147 sub collectActorgroup {
7148 0 ▶ my $o = shift;
Subroutine collectActorgroup: not called CC=2 SCAR=17.9
7149 0 my $label = shift;
7150 0 my $value = shift;
7151  
7152 0 for my $member ($value->actorGroup->members) {
7153 0 my $actorOnStore = $member->actorOnStore;
7154 0 $o->addKnownPublicKey($actorOnStore->publicKey);
7155 0 push @{$o->{accountTokens}}, CDS::AccountToken->new($actorOnStore->store, $actorOnStore->publicKey->hash);
7156 }
7157 }
7158  
7159 sub collectKeypair {
7160 0 ▶ my $o = shift;
Subroutine collectKeypair: not called CC=1 SCAR=6.9
7161 0 my $label = shift;
7162 0 my $value = shift;
7163  
7164 0 $o->{keyPairToken} = $value;
7165 0 $o->{actorHash} = $value->keyPair->publicKey->hash;
7166 }
7167  
7168 sub collectStore {
7169 0 ▶ my $o = shift;
Subroutine collectStore: not called CC=1 SCAR=6.9
7170 0 my $label = shift;
7171 0 my $value = shift;
7172  
7173 0 push @{$o->{stores}}, $value;
7174 }
7175  
7176 sub new {
7177 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
7178 0 my $actor = shift;
7179 0 bless {actor => $actor, ui => $actor->ui} }
7180  
7181 # END AUTOGENERATED
7182  
7183 # HTML FOLDER NAME show-card
7184 # HTML TITLE Show an actor's public card
7185 sub help {
7186 0 ▶ my $o = shift;
Subroutine help: not called CC=1 SCAR=6.9
7187 0 my $cmd = shift;
7188  
7189 0 my $ui = $o->{ui};
7190 0 $ui->space;
7191 0 $ui->command('cds show card of ACCOUNT');
7192 0 $ui->command('cds show card of ACTOR [on STORE]');
7193 0 $ui->command('cds show card of KEYPAIR [on STORE]');
7194 0 $ui->p('Shows the card(s) of an actor.');
7195 0 $ui->space;
7196 0 $ui->command('cds show card of ACTORGROUP');
7197 0 $ui->p('Shows all cards of an actor group.');
7198 0 $ui->space;
7199 0 $ui->command('cds show card');
7200 0 $ui->p('Shows the card of the selected actor on the selected store.');
7201 0 $ui->space;
7202 0 $ui->command('cds show my card');
7203 0 $ui->p('Shows your own card.');
7204 0 $ui->space;
7205 0 $ui->p('An actor usually has one card. If no cards are shown, the corresponding actor does not exist, is not using that store, or has not properly announced itself. Two cards may exist while the actor is updating its card. Such a state is temporary, but may exist for hours or days if the actor has intermittent network access. Three or more cards may point to an error in the way the actor updates his card, an error in the synchronization code (if the account is synchronized). Two or more cards may also occur naturally when stores are merged.');
7206 0 $ui->space;
7207 0 $ui->p('A peer consists of one or more actors, which all publish their own card. The cards are usually different, but should contain consistent information.');
7208 0 $ui->space;
7209 0 $ui->p('You can publish your own card (i.e. the card of your main key pair) using');
7210 0 $ui->p(' cds announce');
7211 0 $ui->space;
7212 }
7213  
7214 sub showCard {
7215 0 ▶ my $o = shift;
Subroutine showCard: not called CC=6 SCAR=37.4
7216 0 my $cmd = shift;
7217  
7218 0 $o->{keyPairToken} = $o->{actor}->preferredKeyPairToken;
7219 0 $o->{stores} = [];
7220 0 $o->{accountTokens} = [];
7221 0 $o->{knownPublicKeys} = {};
7222 0 $cmd->collect($o);
7223  
7224 # Use actorHash/store
7225 0 ▶ if (! scalar @{$o->{accountTokens}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @{$o->{"accountTokens"};}) 0 0 0
7226 0 ▶ $o->{actorHash} = $o->{actor}->preferredActorHash if ! $o->{actorHash};
Branch: 1 branch
BranchTrueFalseTotal
unless $o->{"actorHash"} 0 0 0
7227 0 ▶ push @{$o->{stores}}, $o->{actor}->preferredStores if ! scalar @{$o->{stores}};
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @{$o->{"stores"};} 0 0 0
7228 0 for my $store (@{$o->{stores}}) {
7229 0 push @{$o->{accountTokens}}, CDS::AccountToken->new($store, $o->{actorHash});
7230 }
7231 }
7232  
7233 # Show the cards
7234 0 $o->addKnownPublicKey($o->{keyPairToken}->keyPair->publicKey);
7235 0 $o->addKnownPublicKey($o->{actor}->keyPair->publicKey);
7236 0 for my $accountToken (@{$o->{accountTokens}}) {
7237 0 $o->processAccount($accountToken);
7238 }
7239  
7240 0 $o->{ui}->space;
7241 }
7242  
7243 sub showMyCard {
7244 0 ▶ my $o = shift;
Subroutine showMyCard: not called CC=2 SCAR=17.9
7245 0 my $cmd = shift;
7246  
7247 0 $o->{keyPairToken} = $o->{actor}->preferredKeyPairToken;
7248 0 $o->processAccount(CDS::AccountToken->new($o->{actor}->messagingStore, $o->{actor}->keyPair->publicKey->hash));
7249 0 ▶ $o->processAccount(CDS::AccountToken->new($o->{actor}->storageStore, $o->{actor}->keyPair->publicKey->hash)) if $o->{actor}->storageStore->url ne $o->{actor}->messagingStore->url;
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"actor"}->storageStore->url ne $o->{"actor"}->messagingStore->url 0 0 0
7250 0 $o->{ui}->space;
7251 }
7252  
7253 sub processAccount {
7254 0 ▶ my $o = shift;
Subroutine processAccount: not called CC=6 SCAR=37.4
7255 0 my $accountToken = shift;
7256  
7257 0 $o->{ui}->space;
7258  
7259 # Query the store
7260 0 my $store = $accountToken->cliStore;
7261 0 my ($hashes, $storeError) = $store->list($accountToken->actorHash, 'public', 0);
7262 0 ▶ if (defined $storeError) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $storeError) 0 0 0
7263 0 $o->{ui}->title('public box of ', $o->{actor}->blueAccountReference($accountToken));
7264 0 return;
7265 }
7266  
7267 # Print the result
7268 0 my $count = scalar @$hashes;
7269 0 ▶ $o->{ui}->title('public box of ', $o->{actor}->blueAccountReference($accountToken), ' ', $o->{ui}->blue($count == 0 ? 'no cards' : $count == 1 ? '1 card' : $count.' cards'));
Branch: 2 branches
BranchTrueFalseTotal
$count == 0 ? : 0 0 0
$count == 1 ? : 0 0 0
7270 0 ▶ return if ! $count;
Branch: 1 branch
BranchTrueFalseTotal
unless $count 0 0 0
7271  
7272 0 foreach my $hash (sort { $a->bytes cmp $b->bytes } @$hashes) {
7273 0 $o->processEntry($accountToken, $hash);
7274 }
7275 }
7276  
7277 sub processEntry {
7278 0 ▶ my $o = shift;
Subroutine processEntry: not called CC=11 SCAR=48.8
7279 0 my $accountToken = shift;
7280 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
7281  
7282 0 my $keyPair = $o->{keyPairToken}->keyPair;
7283 0 my $store = $accountToken->cliStore;
7284 0 my $storeReference = $o->{actor}->storeReference($store);
7285  
7286 # Open the envelope
7287 0 $o->{ui}->line($o->{ui}->gold('cds open envelope ', $hash->hex), $o->{ui}->gray(' from ', $accountToken->actorHash->hex, ' on ', $storeReference));
7288  
7289 0 ▶ my $envelope = $o->{actor}->uiGetRecord($hash, $accountToken->cliStore, $o->{keyPairToken}) // return;
Condition0%0/2
$o->{"actor"}->uiGetRecord($hash, $accountToken->cliStore, $o->{"keyPairToken"}) // (return)
l!l
00
MC/DC0%0/1
$o->{"actor"}->uiGetRecord($hash, $accountToken->cliStore, $o->{"keyPairToken"}) // (return)
$o->{"actor"}->uiGetRecord($hash, $accountToken->cliStore, $o->{"keyPairToken"})
Truth table0%0/2
A
A= $o->{"actor"}->uiGetRecord($hash, $accountToken->cliStore, $o->{"keyPairToken"})
Aresult
11
00
7290 0 ▶ my $publicKey = $o->getPublicKey($accountToken) // $o->{ui}->pRed('The owner\'s public key is missing. Skipping signature verification.');
Condition0%0/3
$o->getPublicKey($accountToken) // $o->{"ui"}->pRed("The owner's public key is missing. Skipping signature verification.")
l!l&&r!l&&!r
000
MC/DC0%0/2
$o->getPublicKey($accountToken) // $o->{"ui"}->pRed("The owner's public key is missing. Skipping signature verification.")
$o->getPublicKey($accountToken) $o->{"ui"}->pRed("The owner's public key is missing. Skipping signature verification.")
Truth table0%0/3
A // B
A= $o->getPublicKey($accountToken)B= $o->{"ui"}->pRed("The owner's public key is missing. Skipping signature verification.")
ABresult
1X1
011
000
7291 0 ▶ my $cardHash = $envelope->child('content')->hashValue // $o->{ui}->pRed('Missing content hash.');
Condition0%0/3
$envelope->child("content")->hashValue // $o->{"ui"}->pRed("Missing content hash.")
l!l&&r!l&&!r
000
MC/DC0%0/2
$envelope->child("content")->hashValue // $o->{"ui"}->pRed("Missing content hash.")
$envelope->child("content")->hashValue $o->{"ui"}->pRed("Missing content hash.")
Truth table0%0/3
A // B
A= $envelope->child("content")->hashValueB= $o->{"ui"}->pRed("Missing content hash.")
ABresult
1X1
011
000
7292 0 ▶ return $o->{ui}->pRed('Invalid signature.') if $publicKey && $cardHash && ! CDS->verifyEnvelopeSignature($envelope, $publicKey, $cardHash);
Branch: 1 branch
BranchTrueFalseTotal
if $publicKey and $cardHash and not "CDS"->verifyEnvelopeSignature($envelope, $publicKey, $cardHash) 0 0 0
Condition0%0/6
$publicKey and $cardHash and not "CDS"->verifyEnvelopeSignature($envelope, $publicKey, $cardHash)
!ll&&!rl&&r
000
$publicKey and $cardHash
!ll&&!rl&&r
000
MC/DC0%0/3
$publicKey and $cardHash and not "CDS"->verifyEnvelopeSignature($envelope, $publicKey, $cardHash)
$publicKey $cardHash not "CDS"->verifyEnvelopeSignature($envelope, $publicKey, $cardHash)
Truth table0%0/4
A and B and not(C)
A= $publicKeyB= $cardHashC= not "CDS"->verifyEnvelopeSignature($envelope, $publicKey, $cardHash)
ABCresult
0XX0
10X0
1100
1111
7293  
7294 # Read and show the card
7295 0 ▶ return if ! $cardHash;
Branch: 1 branch
BranchTrueFalseTotal
unless $cardHash 0 0 0
7296 0 $o->{ui}->line($o->{ui}->gold('cds show record ', $cardHash->hex), $o->{ui}->gray(' on ', $storeReference));
7297 0 ▶ my $card = $o->{actor}->uiGetRecord($cardHash, $accountToken->cliStore, $o->{keyPairToken}) // return;
Condition0%0/2
$o->{"actor"}->uiGetRecord($cardHash, $accountToken->cliStore, $o->{"keyPairToken"}) // (return)
l!l
00
MC/DC0%0/1
$o->{"actor"}->uiGetRecord($cardHash, $accountToken->cliStore, $o->{"keyPairToken"}) // (return)
$o->{"actor"}->uiGetRecord($cardHash, $accountToken->cliStore, $o->{"keyPairToken"})
Truth table0%0/2
A
A= $o->{"actor"}->uiGetRecord($cardHash, $accountToken->cliStore, $o->{"keyPairToken"})
Aresult
11
00
7298  
7299 0 $o->{ui}->pushIndent;
7300 0 $o->{ui}->recordChildren($card, $storeReference);
7301 0 $o->{ui}->popIndent;
7302 0 return;
7303 }
7304  
7305 sub getPublicKey {
7306 0 ▶ my $o = shift;
Subroutine getPublicKey: not called CC=3 SCAR=24.8
7307 0 my $accountToken = shift;
7308  
7309 0 my $hash = $accountToken->actorHash;
7310 0 my $knownPublicKey = $o->{knownPublicKeys}->{$hash->bytes};
7311 0 ▶ return $knownPublicKey if $knownPublicKey;
Branch: 1 branch
BranchTrueFalseTotal
if $knownPublicKey 0 0 0
7312 0 ▶ my $publicKey = $o->{actor}->uiGetPublicKey($hash, $accountToken->cliStore, $o->{keyPairToken}) // return;
Condition0%0/2
$o->{"actor"}->uiGetPublicKey($hash, $accountToken->cliStore, $o->{"keyPairToken"}) // (return)
l!l
00
MC/DC0%0/1
$o->{"actor"}->uiGetPublicKey($hash, $accountToken->cliStore, $o->{"keyPairToken"}) // (return)
$o->{"actor"}->uiGetPublicKey($hash, $accountToken->cliStore, $o->{"keyPairToken"})
Truth table0%0/2
A
A= $o->{"actor"}->uiGetPublicKey($hash, $accountToken->cliStore, $o->{"keyPairToken"})
Aresult
11
00
7313 0 $o->addKnownPublicKey($publicKey);
7314 0 return $publicKey;
7315 }
7316  
7317 sub addKnownPublicKey {
7318 0 ▶ my $o = shift;
Subroutine addKnownPublicKey: not called CC=3 SCAR=24.8
7319 0 ▶ my $publicKey = shift; die 'wrong type '.ref($publicKey).' for $publicKey' if defined $publicKey && ref $publicKey ne 'CDS::PublicKey';
Branch: 1 branch
BranchTrueFalseTotal
if defined $publicKey and ref $publicKey ne "CDS::PublicKey" 0 0 0
Condition0%0/3
defined $publicKey and ref $publicKey ne "CDS::PublicKey"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $publicKey and ref $publicKey ne "CDS::PublicKey"
defined $publicKey ref $publicKey ne "CDS::PublicKey"
Truth table0%0/3
A and B
A= defined $publicKeyB= ref $publicKey ne "CDS::PublicKey"
ABresult
0X0
100
111
7320  
7321 0 $o->{knownPublicKeys}->{$publicKey->hash->bytes} = $publicKey;
7322 }
7323  
7324 # BEGIN AUTOGENERATED
7325 package CDS::Commands::ShowKeyPair;
7326  
7327 sub register {
7328 0 ▶ my $class = shift;
Subroutine register: not called CC=1 SCAR=6.9
7329 0 my $cds = shift;
7330 0 my $help = shift;
7331  
7332 0 my $node000 = CDS::Parser::Node->new(0);
7333 0 my $node001 = CDS::Parser::Node->new(0);
7334 0 my $node002 = CDS::Parser::Node->new(0);
7335 0 my $node003 = CDS::Parser::Node->new(0);
7336 0 my $node004 = CDS::Parser::Node->new(0);
7337 0 my $node005 = CDS::Parser::Node->new(0);
7338 0 my $node006 = CDS::Parser::Node->new(0);
7339 0 my $node007 = CDS::Parser::Node->new(0);
7340 0 my $node008 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&help});
7341 0 my $node009 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&showKeyPair});
7342 0 my $node010 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&showMyKeyPair});
7343 0 my $node011 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&showSelectedKeyPair});
7344 0 $cds->addArrow($node002, 1, 0, 'show');
7345 0 $cds->addArrow($node003, 1, 0, 'show');
7346 0 $cds->addArrow($node004, 1, 0, 'show');
7347 0 $help->addArrow($node000, 1, 0, 'show');
7348 0 $node000->addArrow($node001, 1, 0, 'key');
7349 0 $node001->addArrow($node008, 1, 0, 'pair');
7350 0 $node002->addArrow($node009, 1, 0, 'KEYPAIR', \&collectKeypair);
7351 0 $node003->addArrow($node005, 1, 0, 'my');
7352 0 $node004->addArrow($node006, 1, 0, 'key');
7353 0 $node005->addArrow($node007, 1, 0, 'key');
7354 0 $node006->addArrow($node011, 1, 0, 'pair');
7355 0 $node007->addArrow($node010, 1, 0, 'pair');
7356 }
7357  
7358 sub collectKeypair {
7359 0 ▶ my $o = shift;
Subroutine collectKeypair: not called CC=1 SCAR=6.9
7360 0 my $label = shift;
7361 0 my $value = shift;
7362  
7363 0 $o->{keyPairToken} = $value;
7364 }
7365  
7366 sub new {
7367 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
7368 0 my $actor = shift;
7369 0 bless {actor => $actor, ui => $actor->ui} }
7370  
7371 # END AUTOGENERATED
7372  
7373 # HTML FOLDER NAME show-key-pair
7374 # HTML TITLE Show key pair
7375 sub help {
7376 0 ▶ my $o = shift;
Subroutine help: not called CC=1 SCAR=6.9
7377 0 my $cmd = shift;
7378  
7379 0 my $ui = $o->{ui};
7380 0 $ui->space;
7381 0 $ui->command('cds show KEYPAIR');
7382 0 $ui->command('cds show my key pair');
7383 0 $ui->command('cds show key pair');
7384 0 $ui->p('Shows information about KEYPAIR, your key pair, or the currently selected key pair (see "cds use …").');
7385 0 $ui->space;
7386 }
7387  
7388 sub showKeyPair {
7389 0 ▶ my $o = shift;
Subroutine showKeyPair: not called CC=1 SCAR=6.9
7390 0 my $cmd = shift;
7391  
7392 0 $cmd->collect($o);
7393 0 $o->showAll($o->{keyPairToken});
7394 }
7395  
7396 sub showMyKeyPair {
7397 0 ▶ my $o = shift;
Subroutine showMyKeyPair: not called CC=1 SCAR=6.9
7398 0 my $cmd = shift;
7399  
7400 0 $cmd->collect($o);
7401 0 $o->showAll($o->{actor}->keyPairToken);
7402 }
7403  
7404 sub showSelectedKeyPair {
7405 0 ▶ my $o = shift;
Subroutine showSelectedKeyPair: not called CC=1 SCAR=6.9
7406 0 my $cmd = shift;
7407  
7408 0 $cmd->collect($o);
7409 0 $o->showAll($o->{actor}->preferredKeyPairToken);
7410 }
7411  
7412 sub show {
7413 0 ▶ my $o = shift;
Subroutine show: not called CC=2 SCAR=17.9
7414 0 my $keyPairToken = shift;
7415  
7416 0 ▶ $o->{ui}->line($o->{ui}->darkBold('File '), $keyPairToken->file) if defined $keyPairToken->file;
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPairToken->file 0 0 0
7417 0 $o->{ui}->line($o->{ui}->darkBold('Hash '), $keyPairToken->keyPair->publicKey->hash->hex);
7418 }
7419  
7420 sub showAll {
7421 0 ▶ my $o = shift;
Subroutine showAll: not called CC=1 SCAR=6.9
7422 0 my $keyPairToken = shift;
7423  
7424 0 $o->{ui}->space;
7425 0 $o->{ui}->title('Key pair');
7426 0 $o->show($keyPairToken);
7427 0 $o->showPublicKeyObject($keyPairToken);
7428 0 $o->showPublicKey($keyPairToken);
7429 0 $o->showPrivateKey($keyPairToken);
7430 0 $o->{ui}->space;
7431 }
7432  
7433 sub showPublicKeyObject {
7434 0 ▶ my $o = shift;
Subroutine showPublicKeyObject: not called CC=1 SCAR=6.9
7435 0 my $keyPairToken = shift;
7436  
7437 0 my $object = $keyPairToken->keyPair->publicKey->object;
7438 0 $o->{ui}->space;
7439 0 $o->{ui}->title('Public key object');
7440 0 $o->byteData(' ', $object->bytes);
7441 }
7442  
7443 sub showPublicKey {
7444 0 ▶ my $o = shift;
Subroutine showPublicKey: not called CC=1 SCAR=6.9
7445 0 my $keyPairToken = shift;
7446  
7447 0 my $rsaPublicKey = $keyPairToken->keyPair->publicKey->{rsaPublicKey};
7448 0 $o->{ui}->space;
7449 0 $o->{ui}->title('Public key');
7450 0 $o->byteData('e ', CDS::C::publicKeyE($rsaPublicKey));
7451 0 $o->byteData('n ', CDS::C::publicKeyN($rsaPublicKey));
7452 }
7453  
7454 sub showPrivateKey {
7455 0 ▶ my $o = shift;
Subroutine showPrivateKey: not called CC=1 SCAR=6.9
7456 0 my $keyPairToken = shift;
7457  
7458 0 my $rsaPrivateKey = $keyPairToken->keyPair->{rsaPrivateKey};
7459 0 $o->{ui}->space;
7460 0 $o->{ui}->title('Private key');
7461 0 $o->byteData('e ', CDS::C::privateKeyE($rsaPrivateKey));
7462 0 $o->byteData('p ', CDS::C::privateKeyP($rsaPrivateKey));
7463 0 $o->byteData('q ', CDS::C::privateKeyQ($rsaPrivateKey));
7464 }
7465  
7466 sub byteData {
7467 0 ▶ my $o = shift;
Subroutine byteData: not called CC=2 SCAR=17.9
7468 0 my $label = shift;
7469 0 my $bytes = shift;
7470  
7471 0 my $hex = unpack('H*', $bytes);
7472 0 $o->{ui}->line($o->{ui}->darkBold($label), substr($hex, 0, 64));
7473  
7474 0 my $start = 64;
7475 0 my $spaces = ' ' x length $label;
7476 0 ▶ while ($start < length $hex) {
Branch: 1 branch
BranchTrueFalseTotal
if ($start < length $hex) 0 0 0
7477 0 $o->{ui}->line($spaces, substr($hex, $start, 64));
7478 0 $start += 64;
7479 }
7480 }
7481  
7482 # BEGIN AUTOGENERATED
7483 package CDS::Commands::ShowMessages;
7484  
7485 sub register {
7486 0 ▶ my $class = shift;
Subroutine register: not called CC=1 SCAR=6.9
7487 0 my $cds = shift;
7488 0 my $help = shift;
7489  
7490 0 my $node000 = CDS::Parser::Node->new(0);
7491 0 my $node001 = CDS::Parser::Node->new(0);
7492 0 my $node002 = CDS::Parser::Node->new(0);
7493 0 my $node003 = CDS::Parser::Node->new(0);
7494 0 my $node004 = CDS::Parser::Node->new(0);
7495 0 my $node005 = CDS::Parser::Node->new(0);
7496 0 my $node006 = CDS::Parser::Node->new(0);
7497 0 my $node007 = CDS::Parser::Node->new(0);
7498 0 my $node008 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&help});
7499 0 my $node009 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&showMessagesOfSelected});
7500 0 my $node010 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&showMyMessages});
7501 0 my $node011 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&showOurMessages});
7502 0 my $node012 = CDS::Parser::Node->new(1);
7503 0 my $node013 = CDS::Parser::Node->new(0);
7504 0 my $node014 = CDS::Parser::Node->new(0);
7505 0 my $node015 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&showMessages});
7506 0 $cds->addArrow($node001, 1, 0, 'show');
7507 0 $cds->addArrow($node002, 1, 0, 'show');
7508 0 $cds->addArrow($node003, 1, 0, 'show');
7509 0 $cds->addArrow($node004, 1, 0, 'show');
7510 0 $help->addArrow($node000, 1, 0, 'show');
7511 0 $node000->addArrow($node008, 1, 0, 'messages');
7512 0 $node001->addArrow($node005, 1, 0, 'messages');
7513 0 $node002->addArrow($node006, 1, 0, 'my');
7514 0 $node003->addArrow($node009, 1, 0, 'messages');
7515 0 $node004->addArrow($node007, 1, 0, 'our');
7516 0 $node005->addArrow($node012, 1, 0, 'of');
7517 0 $node006->addArrow($node010, 1, 0, 'messages');
7518 0 $node007->addArrow($node011, 1, 0, 'messages');
7519 0 $node012->addArrow($node013, 1, 0, 'ACTOR', \&collectActor);
7520 0 $node012->addArrow($node013, 1, 0, 'KEYPAIR', \&collectKeypair);
7521 0 $node012->addArrow($node015, 1, 1, 'ACCOUNT', \&collectAccount);
7522 0 $node012->addArrow($node015, 1, 0, 'ACTOR', \&collectActor1);
7523 0 $node012->addArrow($node015, 1, 0, 'ACTORGROUP', \&collectActorgroup);
7524 0 $node012->addArrow($node015, 1, 0, 'KEYPAIR', \&collectKeypair1);
7525 0 $node013->addArrow($node014, 1, 0, 'on');
7526 0 $node014->addArrow($node015, 1, 0, 'STORE', \&collectStore);
7527 }
7528  
7529 sub collectAccount {
7530 0 ▶ my $o = shift;
Subroutine collectAccount: not called CC=1 SCAR=6.9
7531 0 my $label = shift;
7532 0 my $value = shift;
7533  
7534 0 push @{$o->{accountTokens}}, $value;
7535 }
7536  
7537 sub collectActor {
7538 0 ▶ my $o = shift;
Subroutine collectActor: not called CC=1 SCAR=6.9
7539 0 my $label = shift;
7540 0 my $value = shift;
7541  
7542 0 $o->{actorHash} = $value;
7543 }
7544  
7545 sub collectActor1 {
7546 0 ▶ my $o = shift;
Subroutine collectActor1: not called CC=1 SCAR=6.9
7547 0 my $label = shift;
7548 0 my $value = shift;
7549  
7550 0 push @{$o->{accountTokens}}, CDS::AccountToken->new($o->{actor}->preferredStore, $value);
7551 }
7552  
7553 sub collectActorgroup {
7554 0 ▶ my $o = shift;
Subroutine collectActorgroup: not called CC=2 SCAR=17.9
7555 0 my $label = shift;
7556 0 my $value = shift;
7557  
7558 0 for my $member ($value->actorGroup->members) {
7559 0 push @{$o->{accountTokens}}, CDS::AccountToken->new($member->actorOnStore->store, $member->actorOnStore->publicKey->hash);
7560 }
7561 }
7562  
7563 sub collectKeypair {
7564 0 ▶ my $o = shift;
Subroutine collectKeypair: not called CC=1 SCAR=6.9
7565 0 my $label = shift;
7566 0 my $value = shift;
7567  
7568 0 $o->{keyPairToken} = $value;
7569 0 $o->{actorHash} = $value->keyPair->publicKey->hash;
7570 }
7571  
7572 sub collectKeypair1 {
7573 0 ▶ my $o = shift;
Subroutine collectKeypair1: not called CC=1 SCAR=6.9
7574 0 my $label = shift;
7575 0 my $value = shift;
7576  
7577 0 $o->{keyPairToken} = $value;
7578 0 push @{$o->{accountTokens}}, CDS::AccountToken->new($o->{actor}->preferredStore, $value->publicKey->hash);
7579 }
7580  
7581 sub collectStore {
7582 0 ▶ my $o = shift;
Subroutine collectStore: not called CC=1 SCAR=6.9
7583 0 my $label = shift;
7584 0 my $value = shift;
7585  
7586 0 push @{$o->{accountTokens}}, CDS::AccountToken->new($value, $o->{actorHash});
7587 0 delete $o->{actorHash};
7588 }
7589  
7590 sub new {
7591 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
7592 0 my $actor = shift;
7593 0 bless {actor => $actor, ui => $actor->ui} }
7594  
7595 # END AUTOGENERATED
7596  
7597 # HTML FOLDER NAME show-messages
7598 # HTML TITLE Show messages
7599 sub help {
7600 0 ▶ my $o = shift;
Subroutine help: not called CC=1 SCAR=6.9
7601 0 my $cmd = shift;
7602  
7603 0 my $ui = $o->{ui};
7604 0 $ui->space;
7605 0 $ui->command('cds show messages of ACCOUNT');
7606 0 $ui->command('cds show messages of ACTOR|KEYPAIR [on STORE]');
7607 0 $ui->p('Shows all (unprocessed) messages of an actor ordered by their envelope hash. If store is omitted, the selected store is used.');
7608 0 $ui->space;
7609 0 $ui->command('cds show messages of ACTORGROUP');
7610 0 $ui->p('Shows all messages of all actors of that group.');
7611 0 $ui->space;
7612 0 $ui->command('cds show messages');
7613 0 $ui->p('Shows the messages of the selected key pair on the selected store.');
7614 0 $ui->space;
7615 0 $ui->command('cds show my messages');
7616 0 $ui->p('Shows your messages.');
7617 0 $ui->space;
7618 0 $ui->command('cds show our messages');
7619 0 $ui->p('Shows all messages of your actor group.');
7620 0 $ui->space;
7621 0 $ui->p('Unprocessed messages are stored in the message box of an actor. Each entry points to an envelope, which in turn points to a record object. The envelope is signed by the sender, but does not hold any date. If the application relies on dates, it must include this date in the message.');
7622 0 $ui->space;
7623 0 $ui->p('While the envelope hash is stored on the actor\'s store, the envelope and the message are stored on the sender\'s store, and are downloaded from there. Depending on the reachability and responsiveness of that store, messages may not always be accessible.');
7624 0 $ui->space;
7625 0 $ui->p('Senders typically keep sent messages for about 10 days on their store. After that, the envelope hash may still be in the message box, but the actual message may have vanished.');
7626 0 $ui->space;
7627 }
7628  
7629 sub showMessagesOfSelected {
7630 0 ▶ my $o = shift;
Subroutine showMessagesOfSelected: not called CC=1 SCAR=6.9
7631 0 my $cmd = shift;
7632  
7633 0 $o->{keyPairToken} = $o->{actor}->preferredKeyPairToken;
7634 0 $o->processAccounts(CDS::AccountToken->new($o->{actor}->preferredStore, $o->{actor}->preferredActorHash));
7635 }
7636  
7637 sub showMyMessages {
7638 0 ▶ my $o = shift;
Subroutine showMyMessages: not called CC=1 SCAR=6.9
7639 0 my $cmd = shift;
7640  
7641 0 $o->{keyPairToken} = $o->{actor}->keyPairToken;
7642 0 my $actorHash = $o->{actor}->keyPair->publicKey->hash;
7643 0 my $store = $o->{actor}->messagingStore;
7644 0 $o->processAccounts(CDS::AccountToken->new($store, $actorHash));
7645 }
7646  
7647 sub showOurMessages {
7648 0 ▶ my $o = shift;
Subroutine showOurMessages: not called CC=6 SCAR=37.4
7649 0 my $cmd = shift;
7650  
7651 0 $o->{keyPairToken} = $o->{actor}->keyPairToken;
7652  
7653 0 my @accountTokens;
7654 0 for my $child ($o->{actor}->actorGroupSelector->children) {
7655 0 ▶ next if $child->child('revoked')->isSet;
Branch: 1 branch
BranchTrueFalseTotal
if $child->child("revoked")->isSet 0 0 0
7656 0 ▶ next if ! $child->child('active')->isSet;
Branch: 1 branch
BranchTrueFalseTotal
unless $child->child("active")->isSet 0 0 0
7657  
7658 0 my $record = $child->record;
7659 0 ▶ my $actorHash = $record->child('hash')->hashValue // next;
Condition0%0/2
$record->child("hash")->hashValue // (next)
l!l
00
MC/DC0%0/1
$record->child("hash")->hashValue // (next)
$record->child("hash")->hashValue
Truth table0%0/2
A
A= $record->child("hash")->hashValue
Aresult
11
00
7660 0 my $storeUrl = $record->child('store')->textValue;
7661 0 ▶ my $store = $o->{actor}->storeForUrl($storeUrl) // next;
Condition0%0/2
$o->{"actor"}->storeForUrl($storeUrl) // (next)
l!l
00
MC/DC0%0/1
$o->{"actor"}->storeForUrl($storeUrl) // (next)
$o->{"actor"}->storeForUrl($storeUrl)
Truth table0%0/2
A
A= $o->{"actor"}->storeForUrl($storeUrl)
Aresult
11
00
7662 0 push @accountTokens, CDS::AccountToken->new($store, $actorHash);
7663 }
7664  
7665 0 $o->processAccounts(@accountTokens);
7666 }
7667  
7668 sub showMessages {
7669 0 ▶ my $o = shift;
Subroutine showMessages: not called CC=2 SCAR=17.9
7670 0 my $cmd = shift;
7671  
7672 0 $o->{accountTokens} = [];
7673 0 $cmd->collect($o);
7674  
7675 # Unless a key pair was provided, use the selected key pair
7676 0 ▶ $o->{keyPairToken} = $o->{actor}->keyPairToken if ! $o->{keyPairToken};
Branch: 1 branch
BranchTrueFalseTotal
unless $o->{"keyPairToken"} 0 0 0
7677  
7678 0 $o->processAccounts(@{$o->{accountTokens}});
7679 }
7680  
7681 sub processAccounts {
7682 0 ▶ my $o = shift;
Subroutine processAccounts: not called CC=6 SCAR=37.4
7683  
7684 # Initialize the statistics
7685 0 $o->{countValid} = 0;
7686 0 $o->{countInvalid} = 0;
7687  
7688 # Show the messages of all selected accounts
7689 0 for my $accountToken (@_) {
7690 0 CDS::Commands::ShowMessages::ProcessAccount->new($o, $accountToken);
7691 }
7692  
7693 # Show the statistics
7694 0 $o->{ui}->space;
7695 0 $o->{ui}->title('Total');
7696 0 ▶ $o->{ui}->line(scalar @_, ' account', scalar @_ == 1 ? '' : 's');
Branch: 1 branch
BranchTrueFalseTotal
scalar @_ == 1 ? : 0 0 0
7697 0 ▶ $o->{ui}->line($o->{countValid}, ' message', $o->{countValid} == 1 ? '' : 's');
Branch: 1 branch
BranchTrueFalseTotal
$o->{'countValid'} == 1 ? : 0 0 0
7698 0 ▶ $o->{ui}->line($o->{countInvalid}, ' invalid message', $o->{countInvalid} == 1 ? '' : 's') if $o->{countInvalid};
Branch: 2 branches
BranchTrueFalseTotal
if $o->{"countInvalid"} 0 0 0
$o->{'countInvalid'} == 1 ? : 0 0 0
7699 0 $o->{ui}->space;
7700 }
7701  
7702 package CDS::Commands::ShowMessages::ProcessAccount;
7703  
7704 sub new {
7705 0 ▶ my $class = shift;
Subroutine new: not called CC=3 SCAR=24.8
7706 0 my $cmd = shift;
7707 0 my $accountToken = shift;
7708  
7709 0 my $o = bless {
7710 cmd => $cmd,
7711 accountToken => $accountToken,
7712 countValid => 0,
7713 countInvalid => 0,
7714 };
7715  
7716 0 $cmd->{ui}->space;
7717 0 $cmd->{ui}->title('Messages of ', $cmd->{actor}->blueAccountReference($accountToken));
7718  
7719 # Get the public key
7720 0 ▶ my $publicKey = $o->getPublicKey // return;
Condition0%0/2
$o->getPublicKey // (return)
l!l
00
MC/DC0%0/1
$o->getPublicKey // (return)
$o->getPublicKey
Truth table0%0/2
A
A= $o->getPublicKey
Aresult
11
00
7721  
7722 # Read all messages
7723 0 my $publicKeyCache = CDS::PublicKeyCache->new(128);
7724 0 my $pool = CDS::MessageBoxReaderPool->new($cmd->{keyPairToken}->keyPair, $publicKeyCache, $o);
7725 0 my $reader = CDS::MessageBoxReader->new($pool, CDS::ActorOnStore->new($publicKey, $accountToken->cliStore));
7726 0 $reader->read;
7727  
7728 0 ▶ $cmd->{ui}->line($cmd->{ui}->gray('No messages.')) if $o->{countValid} + $o->{countInvalid} == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"countValid"} + $o->{"countInvalid"} == 0 0 0 0
7729 }
7730  
7731 sub getPublicKey {
7732 0 ▶ my $o = shift;
Subroutine getPublicKey: not called CC=2 SCAR=17.9
7733  
7734 # Use the keypair's public key if possible
7735 0 ▶ return $o->{cmd}->{keyPairToken}->keyPair->publicKey if $o->{accountToken}->actorHash->equals($o->{cmd}->{keyPairToken}->keyPair->publicKey->hash);
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"accountToken"}->actorHash->equals($o->{"cmd"}{"keyPairToken"}->keyPair->publicKey->hash) 0 0 0
7736  
7737 # Retrieve the public key
7738 0 return $o->{cmd}->{actor}->uiGetPublicKey($o->{accountToken}->actorHash, $o->{accountToken}->cliStore, $o->{cmd}->{keyPairToken});
7739 }
7740  
7741 sub onMessageBoxVerifyStore {
7742 0 ▶ my $o = shift;
Subroutine onMessageBoxVerifyStore: not called CC=7 SCAR=40.3
7743 0 my $senderStoreUrl = shift;
7744 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
7745 0 ▶ my $envelope = shift; die 'wrong type '.ref($envelope).' for $envelope' if defined $envelope && ref $envelope ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $envelope and ref $envelope ne "CDS::Record" 0 0 0
Condition0%0/3
defined $envelope and ref $envelope ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $envelope and ref $envelope ne "CDS::Record"
defined $envelope ref $envelope ne "CDS::Record"
Truth table0%0/3
A and B
A= defined $envelopeB= ref $envelope ne "CDS::Record"
ABresult
0X0
100
111
7746 0 ▶ my $senderHash = shift; die 'wrong type '.ref($senderHash).' for $senderHash' if defined $senderHash && ref $senderHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $senderHash and ref $senderHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $senderHash and ref $senderHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $senderHash and ref $senderHash ne "CDS::Hash"
defined $senderHash ref $senderHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $senderHashB= ref $senderHash ne "CDS::Hash"
ABresult
0X0
100
111
7747  
7748 0 return $o->{cmd}->{actor}->storeForUrl($senderStoreUrl);
7749 }
7750  
7751 sub onMessageBoxEntry {
7752 0 ▶ my $o = shift;
Subroutine onMessageBoxEntry: not called CC=1 SCAR=6.9
7753 0 my $message = shift;
7754  
7755 0 $o->{countValid} += 1;
7756 0 $o->{cmd}->{countValid} += 1;
7757  
7758 0 my $ui = $o->{cmd}->{ui};
7759 0 my $sender = CDS::AccountToken->new($message->sender->store, $message->sender->publicKey->hash);
7760  
7761 0 $ui->space;
7762 0 $ui->title($message->source->hash->hex);
7763 0 $ui->line('from ', $o->{cmd}->{actor}->blueAccountReference($sender));
7764 0 $ui->line('for ', $o->{cmd}->{actor}->blueAccountReference($o->{accountToken}));
7765 0 $ui->space;
7766 0 $ui->recordChildren($message->content);
7767 }
7768  
7769 sub onMessageBoxInvalidEntry {
7770 0 ▶ my $o = shift;
Subroutine onMessageBoxInvalidEntry: not called CC=3 SCAR=24.8
7771 0 ▶ my $source = shift; die 'wrong type '.ref($source).' for $source' if defined $source && ref $source ne 'CDS::Source';
Branch: 1 branch
BranchTrueFalseTotal
if defined $source and ref $source ne "CDS::Source" 0 0 0
Condition0%0/3
defined $source and ref $source ne "CDS::Source"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $source and ref $source ne "CDS::Source"
defined $source ref $source ne "CDS::Source"
Truth table0%0/3
A and B
A= defined $sourceB= ref $source ne "CDS::Source"
ABresult
0X0
100
111
7772 0 my $reason = shift;
7773  
7774 0 $o->{countInvalid} += 1;
7775 0 $o->{cmd}->{countInvalid} += 1;
7776  
7777 0 my $ui = $o->{cmd}->{ui};
7778 0 my $hashHex = $source->hash->hex;
7779 0 my $storeReference = $o->{cmd}->{actor}->storeReference($o->{accountToken}->cliStore);
7780  
7781 0 $ui->space;
7782 0 $ui->title($hashHex);
7783 0 $ui->pOrange($reason);
7784 0 $ui->space;
7785 0 $ui->p('You may use the following commands to check out the envelope:');
7786 0 $ui->line($ui->gold(' cds open envelope ', $hashHex, ' on ', $storeReference));
7787 0 $ui->line($ui->gold(' cds show record ', $hashHex, ' on ', $storeReference));
7788 0 $ui->line($ui->gold(' cds show hashes and data of ', $hashHex, ' on ', $storeReference));
7789 }
7790  
7791 # BEGIN AUTOGENERATED
7792 package CDS::Commands::ShowObject;
7793  
7794 sub register {
7795 0 ▶ my $class = shift;
Subroutine register: not called CC=1 SCAR=6.9
7796 0 my $cds = shift;
7797 0 my $help = shift;
7798  
7799 0 my $node000 = CDS::Parser::Node->new(0);
7800 0 my $node001 = CDS::Parser::Node->new(0);
7801 0 my $node002 = CDS::Parser::Node->new(0);
7802 0 my $node003 = CDS::Parser::Node->new(0);
7803 0 my $node004 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&help});
7804 0 my $node005 = CDS::Parser::Node->new(1);
7805 0 my $node006 = CDS::Parser::Node->new(0);
7806 0 my $node007 = CDS::Parser::Node->new(0);
7807 0 my $node008 = CDS::Parser::Node->new(0);
7808 0 my $node009 = CDS::Parser::Node->new(0);
7809 0 my $node010 = CDS::Parser::Node->new(1);
7810 0 my $node011 = CDS::Parser::Node->new(0);
7811 0 my $node012 = CDS::Parser::Node->new(0);
7812 0 my $node013 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&show});
7813 0 $cds->addArrow($node000, 1, 0, 'show');
7814 0 $cds->addArrow($node001, 1, 0, 'show');
7815 0 $cds->addArrow($node003, 1, 0, 'show');
7816 0 $help->addArrow($node002, 1, 0, 'show');
7817 0 $node000->addArrow($node006, 1, 0, 'object', \&collectObject);
7818 0 $node001->addArrow($node006, 1, 0, 'record', \&collectRecord);
7819 0 $node002->addArrow($node004, 1, 0, 'bytes');
7820 0 $node002->addArrow($node004, 1, 0, 'data');
7821 0 $node002->addArrow($node004, 1, 0, 'hash');
7822 0 $node002->addArrow($node004, 1, 0, 'hashes');
7823 0 $node002->addArrow($node004, 1, 0, 'object');
7824 0 $node002->addArrow($node004, 1, 0, 'record');
7825 0 $node002->addArrow($node004, 1, 0, 'size');
7826 0 $node003->addArrow($node005, 1, 0, 'bytes', \&collectBytes);
7827 0 $node003->addArrow($node005, 1, 0, 'data', \&collectData);
7828 0 $node003->addArrow($node005, 1, 0, 'hash', \&collectHash);
7829 0 $node003->addArrow($node005, 1, 0, 'hashes', \&collectHashes);
7830 0 $node003->addArrow($node005, 1, 0, 'record', \&collectRecord);
7831 0 $node003->addArrow($node005, 1, 0, 'size', \&collectSize);
7832 0 $node005->addArrow($node003, 1, 0, 'and');
7833 0 $node005->addArrow($node006, 1, 0, 'of');
7834 0 $node006->addArrow($node007, 1, 0, 'HASH', \&collectHash1);
7835 0 $node006->addArrow($node010, 1, 1, 'FILE', \&collectFile);
7836 0 $node006->addArrow($node010, 1, 0, 'HASH', \&collectHash2);
7837 0 $node006->addArrow($node010, 1, 0, 'OBJECT', \&collectObject1);
7838 0 $node007->addArrow($node008, 1, 0, 'on');
7839 0 $node007->addArrow($node009, 0, 0, 'from');
7840 0 $node008->addArrow($node010, 1, 0, 'STORE', \&collectStore);
7841 0 $node009->addArrow($node010, 0, 0, 'STORE', \&collectStore);
7842 0 $node010->addArrow($node011, 1, 0, 'decrypted');
7843 0 $node010->addDefault($node013);
7844 0 $node011->addArrow($node012, 1, 0, 'with');
7845 0 $node012->addArrow($node013, 1, 0, 'AESKEY', \&collectAeskey);
7846 }
7847  
7848 sub collectAeskey {
7849 0 ▶ my $o = shift;
Subroutine collectAeskey: not called CC=1 SCAR=6.9
7850 0 my $label = shift;
7851 0 my $value = shift;
7852  
7853 0 $o->{aesKey} = $value;
7854 }
7855  
7856 sub collectBytes {
7857 0 ▶ my $o = shift;
Subroutine collectBytes: not called CC=1 SCAR=6.9
7858 0 my $label = shift;
7859 0 my $value = shift;
7860  
7861 0 $o->{showBytes} = 1;
7862 }
7863  
7864 sub collectData {
7865 0 ▶ my $o = shift;
Subroutine collectData: not called CC=1 SCAR=6.9
7866 0 my $label = shift;
7867 0 my $value = shift;
7868  
7869 0 $o->{showData} = 1;
7870 }
7871  
7872 sub collectFile {
7873 0 ▶ my $o = shift;
Subroutine collectFile: not called CC=1 SCAR=6.9
7874 0 my $label = shift;
7875 0 my $value = shift;
7876  
7877 0 $o->{file} = $value;
7878 }
7879  
7880 sub collectHash {
7881 0 ▶ my $o = shift;
Subroutine collectHash: not called CC=1 SCAR=6.9
7882 0 my $label = shift;
7883 0 my $value = shift;
7884  
7885 0 $o->{showHash} = 1;
7886 }
7887  
7888 sub collectHash1 {
7889 0 ▶ my $o = shift;
Subroutine collectHash1: not called CC=1 SCAR=6.9
7890 0 my $label = shift;
7891 0 my $value = shift;
7892  
7893 0 $o->{hash} = $value;
7894 }
7895  
7896 sub collectHash2 {
7897 0 ▶ my $o = shift;
Subroutine collectHash2: not called CC=1 SCAR=6.9
7898 0 my $label = shift;
7899 0 my $value = shift;
7900  
7901 0 $o->{hash} = $value;
7902 0 $o->{store} = $o->{actor}->preferredStore;
7903 }
7904  
7905 sub collectHashes {
7906 0 ▶ my $o = shift;
Subroutine collectHashes: not called CC=1 SCAR=6.9
7907 0 my $label = shift;
7908 0 my $value = shift;
7909  
7910 0 $o->{showHashes} = 1;
7911 }
7912  
7913 sub collectObject {
7914 0 ▶ my $o = shift;
Subroutine collectObject: not called CC=1 SCAR=6.9
7915 0 my $label = shift;
7916 0 my $value = shift;
7917  
7918 0 $o->{showHashes} = 1;
7919 0 $o->{showData} = 1;
7920 }
7921  
7922 sub collectObject1 {
7923 0 ▶ my $o = shift;
Subroutine collectObject1: not called CC=1 SCAR=6.9
7924 0 my $label = shift;
7925 0 my $value = shift;
7926  
7927 0 $o->{hash} = $value->hash;
7928 0 $o->{store} = $value->cliStore;
7929 }
7930  
7931 sub collectRecord {
7932 0 ▶ my $o = shift;
Subroutine collectRecord: not called CC=1 SCAR=6.9
7933 0 my $label = shift;
7934 0 my $value = shift;
7935  
7936 0 $o->{showRecord} = 1;
7937 }
7938  
7939 sub collectSize {
7940 0 ▶ my $o = shift;
Subroutine collectSize: not called CC=1 SCAR=6.9
7941 0 my $label = shift;
7942 0 my $value = shift;
7943  
7944 0 $o->{showSize} = 1;
7945 }
7946  
7947 sub collectStore {
7948 0 ▶ my $o = shift;
Subroutine collectStore: not called CC=1 SCAR=6.9
7949 0 my $label = shift;
7950 0 my $value = shift;
7951  
7952 0 $o->{store} = $value;
7953 }
7954  
7955 sub new {
7956 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
7957 0 my $actor = shift;
7958 0 bless {actor => $actor, ui => $actor->ui} }
7959  
7960 # END AUTOGENERATED
7961  
7962 # HTML FOLDER NAME show-object
7963 # HTML TITLE Show objects
7964 sub help {
7965 0 ▶ my $o = shift;
Subroutine help: not called CC=1 SCAR=6.9
7966 0 my $cmd = shift;
7967  
7968 0 my $ui = $o->{ui};
7969 0 $ui->space;
7970 0 $ui->command('cds show record OBJECT');
7971 0 $ui->command('cds show record HASH on STORE');
7972 0 $ui->p('Downloads an object, and shows the containing record. The stores are tried in the order they are indicated, until one succeeds. If the object is not found, or not a valid Condensation object, the program quits with exit code 1.');
7973 0 $ui->space;
7974 0 $ui->line('The following object properties can be displayed:');
7975 0 $ui->line(' cds show hash of …');
7976 0 $ui->line(' cds show size of …');
7977 0 $ui->line(' cds show bytes of …');
7978 0 $ui->line(' cds show hashes of …');
7979 0 $ui->line(' cds show data of …');
7980 0 $ui->line(' cds show record …');
7981 0 $ui->space;
7982 0 $ui->p('Multiple properties may be combined with "and", e.g.:');
7983 0 $ui->line(' cds show size and hashes and record of …');
7984 0 $ui->space;
7985 0 $ui->command('cds show record HASH');
7986 0 $ui->p('As above, but uses the selected store.');
7987 0 $ui->space;
7988 0 $ui->command('cds show record FILE');
7989 0 $ui->p('As above, but loads the object from FILE rather than from an object store.');
7990 0 $ui->space;
7991 0 $ui->command('… decrypted with AESKEY');
7992 0 $ui->p('Decrypts the object after retrieval.');
7993 0 $ui->space;
7994 0 $ui->command('cds show object …');
7995 0 $ui->p('A shortcut for "cds show hashes and data of …".');
7996 0 $ui->space;
7997 0 $ui->title('Related commands');
7998 0 $ui->line('cds get OBJECT [decrypted with AESKEY]');
7999 0 $ui->line('cds save [data of] OBJECT [decrypted with AESKEY] as FILE');
8000 0 $ui->line('cds open envelope OBJECT [on STORE] [using KEYPAIR]');
8001 0 $ui->line('cds show document OBJECT [on STORE]');
8002 0 $ui->space;
8003 }
8004  
8005 sub show {
8006 0 ▶ my $o = shift;
Subroutine show: not called CC=10 SCAR=47.0
8007 0 my $cmd = shift;
8008  
8009 0 $cmd->collect($o);
8010  
8011 # Get and decrypt the object
8012 0 ▶ $o->{object} = defined $o->{file} ? $o->loadObjectFromFile : $o->loadObjectFromStore;
Branch: 1 branch
BranchTrueFalseTotal
defined $o->{'file'} ? : 0 0 0
8013 0 ▶ return if ! $o->{object};
Branch: 1 branch
BranchTrueFalseTotal
unless $o->{"object"} 0 0 0
8014 0 ▶ $o->{object} = $o->{object}->crypt($o->{aesKey}) if defined $o->{aesKey};
Branch: 1 branch
BranchTrueFalseTotal
if defined $o->{"aesKey"} 0 0 0
8015  
8016 # Show the desired information
8017 0 ▶ $o->showHash if $o->{showHash};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"showHash"} 0 0 0
8018 0 ▶ $o->showSize if $o->{showSize};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"showSize"} 0 0 0
8019 0 ▶ $o->showBytes if $o->{showBytes};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"showBytes"} 0 0 0
8020 0 ▶ $o->showHashes if $o->{showHashes};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"showHashes"} 0 0 0
8021 0 ▶ $o->showData if $o->{showData};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"showData"} 0 0 0
8022 0 ▶ $o->showRecord if $o->{showRecord};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"showRecord"} 0 0 0
8023 0 $o->{ui}->space;
8024 }
8025  
8026 sub loadObjectFromFile {
8027 0 ▶ my $o = shift;
Subroutine loadObjectFromFile: not called CC=3 SCAR=24.8
8028  
8029 0 ▶ my $bytes = CDS->readBytesFromFile($o->{file}) // return $o->{ui}->error('Unable to read "', $o->{file}, '".');
Condition0%0/2
"CDS"->readBytesFromFile($o->{"file"}) // (return $o->{"ui"}->error("Unable to read \"", $o->{"file"}, "\"."))
l!l
00
MC/DC0%0/1
"CDS"->readBytesFromFile($o->{"file"}) // (return $o->{"ui"}->error("Unable to read \"", $o->{"file"}, "\"."))
"CDS"->readBytesFromFile($o->{"file"})
Truth table0%0/2
A
A= "CDS"->readBytesFromFile($o->{"file"})
Aresult
11
00
8030 0 ▶ return CDS::Object->fromBytes($bytes) // return $o->{ui}->error('"', $o->{file}, '" does not contain a valid Condensation object.');
Condition0%0/2
"CDS::Object"->fromBytes($bytes) // (return $o->{"ui"}->error("\"", $o->{"file"}, "\" does not contain a valid Condensation object."))
l!l
00
MC/DC0%0/1
"CDS::Object"->fromBytes($bytes) // (return $o->{"ui"}->error("\"", $o->{"file"}, "\" does not contain a valid Condensation object."))
"CDS::Object"->fromBytes($bytes)
Truth table0%0/2
A
A= "CDS::Object"->fromBytes($bytes)
Aresult
11
00
8031 }
8032  
8033 sub loadObjectFromStore {
8034 0 ▶ my $o = shift;
Subroutine loadObjectFromStore: not called CC=1 SCAR=6.9
8035  
8036 0 return $o->{actor}->uiGetObject($o->{hash}, $o->{store}, $o->{actor}->preferredKeyPairToken);
8037 }
8038  
8039 sub loadCommand {
8040 0 ▶ my $o = shift;
Subroutine loadCommand: not called CC=3 SCAR=24.8
8041  
8042 0 ▶ my $decryption = defined $o->{aesKey} ? ' decrypted with '.unpack('H*', $o->{aesKey}) : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $o->{'aesKey'} ? : 0 0 0
8043 0 ▶ return $o->{file}.$decryption if defined $o->{file};
Branch: 1 branch
BranchTrueFalseTotal
if defined $o->{"file"} 0 0 0
8044 0 return $o->{hash}->hex.' on '.$o->{actor}->storeReference($o->{store}).$decryption;
8045 }
8046  
8047 sub showHash {
8048 0 ▶ my $o = shift;
Subroutine showHash: not called CC=1 SCAR=6.9
8049  
8050 0 $o->{ui}->space;
8051 0 $o->{ui}->title('Object hash');
8052 0 $o->{ui}->line($o->{object}->calculateHash->hex);
8053 }
8054  
8055 sub showSize {
8056 0 ▶ my $o = shift;
Subroutine showSize: not called CC=1 SCAR=6.9
8057  
8058 0 $o->{ui}->space;
8059 0 $o->{ui}->title('Object size');
8060 0 $o->{ui}->line($o->{ui}->niceFileSize(length $o->{object}->bytes), ' total (', length $o->{object}->bytes, ' bytes)');
8061 0 $o->{ui}->line($o->{object}->hashesCount, ' hashes (', length $o->{object}->header, ' bytes)');
8062 0 $o->{ui}->line($o->{ui}->niceFileSize(length $o->{object}->data), ' data (', length $o->{object}->data, ' bytes)');
8063 }
8064  
8065 sub showBytes {
8066 0 ▶ my $o = shift;
Subroutine showBytes: not called CC=3 SCAR=24.8
8067  
8068 0 $o->{ui}->space;
8069 0 my $bytes = $o->{object}->bytes;
8070 0 $o->{ui}->title('Object bytes (', $o->{ui}->niceFileSize(length $bytes), ')');
8071 0 ▶ return if ! length $bytes;
Branch: 1 branch
BranchTrueFalseTotal
unless length $bytes 0 0 0
8072  
8073 0 my $hexDump = $o->{ui}->hexDump($bytes);
8074 0 my $dataStart = $hexDump->styleHashList(0);
8075 0 ▶ my $end = $dataStart ? $hexDump->styleRecord($dataStart) : 0;
Branch: 1 branch
BranchTrueFalseTotal
$dataStart ? : 0 0 0
8076 0 $hexDump->changeStyle({at => $end, style => $hexDump->reset});
8077 0 $hexDump->display;
8078 }
8079  
8080 sub showHashes {
8081 0 ▶ my $o = shift;
Subroutine showHashes: not called CC=3 SCAR=24.8
8082  
8083 0 $o->{ui}->space;
8084 0 my $hashesCount = $o->{object}->hashesCount;
8085 0 ▶ $o->{ui}->title($hashesCount == 1 ? '1 hash' : $hashesCount.' hashes');
Branch: 1 branch
BranchTrueFalseTotal
$hashesCount == 1 ? : 0 0 0
8086 0 my $count = 0;
8087 0 for my $hash ($o->{object}->hashes) {
8088 0 $o->{ui}->line($o->{ui}->violet(unpack('H4', pack('S>', $count))), ' ', $hash->hex);
8089 0 $count += 1;
8090 }
8091 }
8092  
8093 sub showData {
8094 0 ▶ my $o = shift;
Subroutine showData: not called CC=2 SCAR=17.9
8095  
8096 0 $o->{ui}->space;
8097 0 my $data = $o->{object}->data;
8098 0 $o->{ui}->title('Data (', $o->{ui}->niceFileSize(length $data), ')');
8099 0 ▶ return if ! length $data;
Branch: 1 branch
BranchTrueFalseTotal
unless length $data 0 0 0
8100  
8101 0 my $hexDump = $o->{ui}->hexDump($data);
8102 0 my $end = $hexDump->styleRecord(0);
8103 0 $hexDump->changeStyle({at => $end, style => $hexDump->reset});
8104 0 $hexDump->display;
8105 }
8106  
8107 sub showRecord {
8108 0 ▶ my $o = shift;
Subroutine showRecord: not called CC=5 SCAR=34.0
8109  
8110 # Title
8111 0 $o->{ui}->space;
8112 0 $o->{ui}->title('Data interpreted as record');
8113  
8114 # Empty object (empty record)
8115 0 ▶ return $o->{ui}->line($o->{ui}->gray('(empty record)')) if ! length $o->{object}->data;
Branch: 1 branch
BranchTrueFalseTotal
unless length $o->{"object"}->data 0 0 0
8116  
8117 # Record
8118 0 my $record = CDS::Record->new;
8119 0 my $reader = CDS::RecordReader->new($o->{object});
8120 0 $reader->readChildren($record);
8121 0 ▶ if ($reader->hasError) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reader->hasError) 0 0 0
8122 0 $o->{ui}->pRed('This is not a record.');
8123 0 $o->{ui}->space;
8124 0 $o->{ui}->p('You may use one of the following commands to check out the content:');
8125 0 $o->{ui}->line($o->{ui}->gold(' cds show object ', $o->loadCommand));
8126 0 $o->{ui}->line($o->{ui}->gold(' cds show data of ', $o->loadCommand));
8127 0 $o->{ui}->line($o->{ui}->gold(' cds save data of ', $o->loadCommand, ' as FILENAME'));
8128 0 return;
8129 }
8130  
8131 0 ▶ $o->{ui}->recordChildren($record, $o->{store} ? $o->{actor}->blueStoreReference($o->{store}) : '');
Branch: 1 branch
BranchTrueFalseTotal
$o->{'store'} ? : 0 0 0
8132  
8133 # Trailer
8134 0 my $trailer = $reader->trailer;
8135 0 ▶ if (length $trailer) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $trailer) 0 0 0
8136 0 $o->{ui}->space;
8137 0 $o->{ui}->pRed('This is probably not a record, because ', length $trailer, ' bytes remain behind the record. Use "cds show data of …" to investigate the raw object content. If this object is encrypted, provide the decryption key using "… and decrypted with KEY".');
8138 0 $o->{ui}->space;
8139 }
8140 }
8141  
8142 # BEGIN AUTOGENERATED
8143 package CDS::Commands::ShowPrivateData;
8144  
8145 sub register {
8146 0 ▶ my $class = shift;
Subroutine register: not called CC=1 SCAR=6.9
8147 0 my $cds = shift;
8148 0 my $help = shift;
8149  
8150 0 my $node000 = CDS::Parser::Node->new(0);
8151 0 my $node001 = CDS::Parser::Node->new(0);
8152 0 my $node002 = CDS::Parser::Node->new(0);
8153 0 my $node003 = CDS::Parser::Node->new(0);
8154 0 my $node004 = CDS::Parser::Node->new(0);
8155 0 my $node005 = CDS::Parser::Node->new(0);
8156 0 my $node006 = CDS::Parser::Node->new(0);
8157 0 my $node007 = CDS::Parser::Node->new(0);
8158 0 my $node008 = CDS::Parser::Node->new(0);
8159 0 my $node009 = CDS::Parser::Node->new(0);
8160 0 my $node010 = CDS::Parser::Node->new(0);
8161 0 my $node011 = CDS::Parser::Node->new(0);
8162 0 my $node012 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&help});
8163 0 my $node013 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&showGroupData});
8164 0 my $node014 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&showLocalData});
8165 0 my $node015 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&showSentList});
8166 0 my $node016 = CDS::Parser::Node->new(0);
8167 0 my $node017 = CDS::Parser::Node->new(0);
8168 0 my $node018 = CDS::Parser::Node->new(0);
8169 0 my $node019 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&showSentList});
8170 0 $cds->addArrow($node006, 1, 0, 'show');
8171 0 $cds->addArrow($node007, 1, 0, 'show');
8172 0 $cds->addArrow($node008, 1, 0, 'show');
8173 0 $help->addArrow($node000, 1, 0, 'show');
8174 0 $help->addArrow($node001, 1, 0, 'show');
8175 0 $help->addArrow($node002, 1, 0, 'show');
8176 0 $node000->addArrow($node003, 1, 0, 'group');
8177 0 $node001->addArrow($node004, 1, 0, 'local');
8178 0 $node002->addArrow($node005, 1, 0, 'sent');
8179 0 $node003->addArrow($node012, 1, 0, 'data');
8180 0 $node004->addArrow($node012, 1, 0, 'data');
8181 0 $node005->addArrow($node012, 1, 0, 'list');
8182 0 $node006->addArrow($node009, 1, 0, 'group');
8183 0 $node007->addArrow($node010, 1, 0, 'local');
8184 0 $node008->addArrow($node011, 1, 0, 'sent');
8185 0 $node009->addArrow($node013, 1, 0, 'data');
8186 0 $node010->addArrow($node014, 1, 0, 'data');
8187 0 $node011->addArrow($node015, 1, 0, 'list');
8188 0 $node015->addArrow($node016, 1, 0, 'ordered');
8189 0 $node016->addArrow($node017, 1, 0, 'by');
8190 0 $node017->addArrow($node018, 1, 0, 'envelope');
8191 0 $node017->addArrow($node019, 1, 0, 'date', \&collectDate);
8192 0 $node017->addArrow($node019, 1, 0, 'id', \&collectId);
8193 0 $node018->addArrow($node019, 1, 0, 'hash', \&collectHash);
8194 }
8195  
8196 sub collectDate {
8197 0 ▶ my $o = shift;
Subroutine collectDate: not called CC=1 SCAR=6.9
8198 0 my $label = shift;
8199 0 my $value = shift;
8200  
8201 0 $o->{orderedBy} = 'date';
8202 }
8203  
8204 sub collectHash {
8205 0 ▶ my $o = shift;
Subroutine collectHash: not called CC=1 SCAR=6.9
8206 0 my $label = shift;
8207 0 my $value = shift;
8208  
8209 0 $o->{orderedBy} = 'envelope hash';
8210 }
8211  
8212 sub collectId {
8213 0 ▶ my $o = shift;
Subroutine collectId: not called CC=1 SCAR=6.9
8214 0 my $label = shift;
8215 0 my $value = shift;
8216  
8217 0 $o->{orderedBy} = 'id';
8218 }
8219  
8220 sub new {
8221 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
8222 0 my $actor = shift;
8223 0 bless {actor => $actor, ui => $actor->ui} }
8224  
8225 # END AUTOGENERATED
8226  
8227 # HTML FOLDER NAME show-private-data
8228 # HTML TITLE Show the private data
8229 sub help {
8230 0 ▶ my $o = shift;
Subroutine help: not called CC=1 SCAR=6.9
8231 0 my $cmd = shift;
8232  
8233 0 my $ui = $o->{ui};
8234 0 $ui->space;
8235 0 $ui->command('cds show group data');
8236 0 $ui->p('Shows the group document. This document is shared among all group members.');
8237 0 $ui->space;
8238 0 $ui->command('cds show local data');
8239 0 $ui->p('Shows the local document. This document is stored locally, and private to this actor.');
8240 0 $ui->space;
8241 0 $ui->command('cds show sent list');
8242 0 $ui->p('Shows the list of sent messages with their expiry date, envelope hash, and content hash.');
8243 0 $ui->space;
8244 0 $ui->command('… ordered by id');
8245 0 $ui->command('… ordered by date');
8246 0 $ui->command('… ordered by envelope hash');
8247 0 $ui->p('Sorts the list accordingly. By default, the list is sorted by id.');
8248 0 $ui->space;
8249 }
8250  
8251 sub showGroupData {
8252 0 ▶ my $o = shift;
Subroutine showGroupData: not called CC=1 SCAR=6.9
8253 0 my $cmd = shift;
8254  
8255 0 $o->{ui}->space;
8256 0 $o->{ui}->selector($o->{actor}->groupRoot, 'Group data');
8257 0 $o->{ui}->space;
8258 }
8259  
8260 sub showLocalData {
8261 0 ▶ my $o = shift;
Subroutine showLocalData: not called CC=1 SCAR=6.9
8262 0 my $cmd = shift;
8263  
8264 0 $o->{ui}->space;
8265 0 $o->{ui}->selector($o->{actor}->localRoot, 'Local data');
8266 0 $o->{ui}->space;
8267 }
8268  
8269 sub showSentList {
8270 0 ▶ my $o = shift;
Subroutine showSentList: not called CC=6 SCAR=37.4
8271 0 my $cmd = shift;
8272  
8273 0 $o->{orderedBy} = 'id';
8274 0 $cmd->collect($o);
8275  
8276 0 $o->{ui}->space;
8277 0 $o->{ui}->title('Sent list');
8278  
8279 0 ▶ $o->{actor}->procureSentList // return;
Condition0%0/2
$o->{"actor"}->procureSentList // (return)
l!l
00
MC/DC0%0/1
$o->{"actor"}->procureSentList // (return)
$o->{"actor"}->procureSentList
Truth table0%0/2
A
A= $o->{"actor"}->procureSentList
Aresult
11
00
8280 0 my $sentList = $o->{actor}->sentList;
8281 0 my @items = sort { $a->id cmp $b->id } values %{$sentList->{items}};
8282 0 ▶ @items = sort { $a->envelopeHashBytes cmp $b->envelopeHashBytes } @items if $o->{orderedBy} eq 'envelope hash';
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"orderedBy"} eq "envelope hash" 0 0 0
8283 0 ▶ @items = sort { $a->validUntil <=> $b->validUntil } @items if $o->{orderedBy} eq 'date';
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"orderedBy"} eq "date" 0 0 0
8284 0 my $noHash = '-' x 64;
8285 0 for my $item (@items) {
8286 0 my $id = $item->id;
8287 0 my $envelopeHash = $item->envelopeHash;
8288 0 my $message = $item->message;
8289 0 my $label = $o->{ui}->niceBytes($id, 32);
8290 0 ▶ $o->{ui}->line($o->{ui}->gray($o->{ui}->niceDateTimeLocal($item->validUntil)), ' ', $envelopeHash ? $envelopeHash->hex : $noHash, ' ', $o->{ui}->blue($label));
Branch: 1 branch
BranchTrueFalseTotal
$envelopeHash ? : 0 0 0
8291 0 $o->{ui}->recordChildren($message);
8292 }
8293  
8294 0 $o->{ui}->space;
8295 }
8296  
8297 # BEGIN AUTOGENERATED
8298 package CDS::Commands::ShowTree;
8299  
8300 sub register {
8301 0 ▶ my $class = shift;
Subroutine register: not called CC=1 SCAR=6.9
8302 0 my $cds = shift;
8303 0 my $help = shift;
8304  
8305 0 my $node000 = CDS::Parser::Node->new(0);
8306 0 my $node001 = CDS::Parser::Node->new(0);
8307 0 my $node002 = CDS::Parser::Node->new(0);
8308 0 my $node003 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&help});
8309 0 my $node004 = CDS::Parser::Node->new(0);
8310 0 my $node005 = CDS::Parser::Node->new(0);
8311 0 my $node006 = CDS::Parser::Node->new(0);
8312 0 my $node007 = CDS::Parser::Node->new(0);
8313 0 my $node008 = CDS::Parser::Node->new(0);
8314 0 my $node009 = CDS::Parser::Node->new(0);
8315 0 my $node010 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&showTree});
8316 0 $cds->addArrow($node001, 1, 0, 'show');
8317 0 $cds->addArrow($node002, 0, 0, 'show');
8318 0 $help->addArrow($node000, 1, 0, 'show');
8319 0 $node000->addArrow($node003, 1, 0, 'tree');
8320 0 $node001->addArrow($node004, 1, 0, 'tree');
8321 0 $node002->addArrow($node004, 0, 0, 'trees');
8322 0 $node004->addDefault($node005);
8323 0 $node004->addDefault($node006);
8324 0 $node004->addDefault($node007);
8325 0 $node005->addArrow($node005, 1, 0, 'HASH', \&collectHash);
8326 0 $node005->addArrow($node010, 1, 0, 'HASH', \&collectHash);
8327 0 $node006->addArrow($node006, 1, 0, 'HASH', \&collectHash);
8328 0 $node006->addArrow($node008, 1, 0, 'HASH', \&collectHash);
8329 0 $node007->addArrow($node007, 1, 0, 'OBJECT', \&collectObject);
8330 0 $node007->addArrow($node010, 1, 0, 'OBJECT', \&collectObject);
8331 0 $node008->addArrow($node009, 1, 0, 'on');
8332 0 $node009->addArrow($node010, 1, 0, 'STORE', \&collectStore);
8333 }
8334  
8335 sub collectHash {
8336 0 ▶ my $o = shift;
Subroutine collectHash: not called CC=1 SCAR=6.9
8337 0 my $label = shift;
8338 0 my $value = shift;
8339  
8340 0 push @{$o->{hashes}}, $value;
8341 }
8342  
8343 sub collectObject {
8344 0 ▶ my $o = shift;
Subroutine collectObject: not called CC=1 SCAR=6.9
8345 0 my $label = shift;
8346 0 my $value = shift;
8347  
8348 0 push @{$o->{objectTokens}}, $value;
8349 }
8350  
8351 sub collectStore {
8352 0 ▶ my $o = shift;
Subroutine collectStore: not called CC=1 SCAR=6.9
8353 0 my $label = shift;
8354 0 my $value = shift;
8355  
8356 0 $o->{store} = $value;
8357 }
8358  
8359 sub new {
8360 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
8361 0 my $actor = shift;
8362 0 bless {actor => $actor, ui => $actor->ui} }
8363  
8364 # END AUTOGENERATED
8365  
8366 # HTML FOLDER NAME show-tree
8367 # HTML TITLE Show trees
8368 sub help {
8369 0 ▶ my $o = shift;
Subroutine help: not called CC=1 SCAR=6.9
8370 0 my $cmd = shift;
8371  
8372 0 my $ui = $o->{ui};
8373 0 $ui->space;
8374 0 $ui->command('cds show tree OBJECT*');
8375 0 $ui->command('cds show tree HASH* on STORE');
8376 0 $ui->p('Downloads a tree, and shows the tree hierarchy. If an object has been traversed before, it is listed as "reported above".');
8377 0 $ui->space;
8378 0 $ui->command('cds show tree HASH*');
8379 0 $ui->p('As above, but uses the selected store.');
8380 0 $ui->space;
8381 }
8382  
8383 sub showTree {
8384 0 ▶ my $o = shift;
Subroutine showTree: not called CC=6 SCAR=37.4
8385 0 my $cmd = shift;
8386  
8387 0 $o->{keyPairToken} = $o->{actor}->preferredKeyPairToken;
8388 0 $o->{objectTokens} = [];
8389 0 $o->{hashes} = [];
8390 0 $cmd->collect($o);
8391  
8392 # Process all trees
8393 0 for my $objectToken (@{$o->{objectTokens}}) {
8394 0 $o->{ui}->space;
8395 0 $o->process($objectToken->hash, $objectToken->cliStore);
8396 }
8397  
8398 0 ▶ if (scalar @{$o->{hashes}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$o->{"hashes"};}) 0 0 0
8399 0 ▶ my $store = $o->{store} // $o->{actor}->preferredStore;
Condition0%0/3
$o->{"store"} // $o->{"actor"}->preferredStore
l!l&&r!l&&!r
000
MC/DC0%0/2
$o->{"store"} // $o->{"actor"}->preferredStore
$o->{"store"} $o->{"actor"}->preferredStore
Truth table0%0/3
A // B
A= $o->{"store"}B= $o->{"actor"}->preferredStore
ABresult
1X1
011
000
8400 0 for my $hash (@{$o->{hashes}}) {
8401 0 $o->{ui}->space;
8402 0 $o->process($hash, $store);
8403 }
8404 }
8405  
8406 # Report the total size
8407 0 my $totalSize = 0;
8408 0 my $totalDataSize = 0;
8409 0 map { $totalSize += $_->{size} ; $totalDataSize += $_->{dataSize} } values %{$o->{objects}};
8410 0 $o->{ui}->space;
8411 0 $o->{ui}->p(scalar keys %{$o->{objects}}, ' unique objects ', $o->{ui}->bold($o->{ui}->niceFileSize($totalSize)), $o->{ui}->gray(' (', $o->{ui}->niceFileSize($totalSize - $totalDataSize), ' header and ', $o->{ui}->niceFileSize($totalDataSize), ' data)'));
8412 0 ▶ $o->{ui}->pRed(scalar keys %{$o->{missingObjects}}, ' or more objects are missing') if scalar keys %{$o->{missingObjects}};
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %{$$o{"missingObjects"};} 0 0 0
8413 0 $o->{ui}->space;
8414 }
8415  
8416 sub process {
8417 0 ▶ my $o = shift;
Subroutine process: not called CC=8 SCAR=42.8
8418 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
8419 0 my $store = shift;
8420  
8421 0 my $hashHex = $hash->hex;
8422  
8423 # Check if we retrieved this object before
8424 0 ▶ if (exists $o->{objects}->{$hashHex}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $o->{"objects"}{$hashHex}) 0 0 0
8425 0 $o->{ui}->line($hash->hex, ' reported above') ;
8426 0 return 1;
8427 }
8428  
8429 # Retrieve the object
8430 0 my ($object, $storeError) = $store->get($hash, $o->{keyPairToken}->keyPair);
8431 0 ▶ return if defined $storeError;
Branch: 1 branch
BranchTrueFalseTotal
if defined $storeError 0 0 0
8432  
8433 0 ▶ if (! $object) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($object) 0 0 0
8434 0 $o->{missingObjects}->{$hashHex} = 1;
8435 0 return $o->{ui}->line($hashHex, ' ', $o->{ui}->red('is missing'));
8436 }
8437  
8438 # Display
8439 0 my $size = $object->byteLength;
8440 0 $o->{objects}->{$hashHex} = {size => $size, dataSize => length $object->data};
8441 0 $o->{ui}->line($hashHex, ' ', $o->{ui}->bold($o->{ui}->niceFileSize($size)), ' ', $o->{ui}->gray($object->hashesCount, ' hashes'));
8442  
8443 # Process all children
8444 0 $o->{ui}->pushIndent;
8445 0 foreach my $hash ($object->hashes) {
8446 0 ▶ $o->process($hash, $store) // return;
Condition0%0/2
$o->process($hash, $store) // (return)
l!l
00
MC/DC0%0/1
$o->process($hash, $store) // (return)
$o->process($hash, $store)
Truth table0%0/2
A
A= $o->process($hash, $store)
Aresult
11
00
8447 }
8448 0 $o->{ui}->popIndent;
8449 0 return 1;
8450 }
8451  
8452 # BEGIN AUTOGENERATED
8453 package CDS::Commands::StartHTTPServer;
8454  
8455 sub register {
8456 0 ▶ my $class = shift;
Subroutine register: not called CC=1 SCAR=6.9
8457 0 my $cds = shift;
8458 0 my $help = shift;
8459  
8460 0 my $node000 = CDS::Parser::Node->new(0);
8461 0 my $node001 = CDS::Parser::Node->new(0);
8462 0 my $node002 = CDS::Parser::Node->new(0);
8463 0 my $node003 = CDS::Parser::Node->new(0);
8464 0 my $node004 = CDS::Parser::Node->new(0);
8465 0 my $node005 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&help});
8466 0 my $node006 = CDS::Parser::Node->new(0);
8467 0 my $node007 = CDS::Parser::Node->new(0);
8468 0 my $node008 = CDS::Parser::Node->new(0);
8469 0 my $node009 = CDS::Parser::Node->new(1);
8470 0 my $node010 = CDS::Parser::Node->new(0);
8471 0 my $node011 = CDS::Parser::Node->new(1);
8472 0 my $node012 = CDS::Parser::Node->new(0);
8473 0 my $node013 = CDS::Parser::Node->new(0);
8474 0 my $node014 = CDS::Parser::Node->new(0);
8475 0 my $node015 = CDS::Parser::Node->new(0);
8476 0 my $node016 = CDS::Parser::Node->new(1);
8477 0 my $node017 = CDS::Parser::Node->new(0);
8478 0 my $node018 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&startHttpServer});
8479 0 $cds->addArrow($node001, 1, 0, 'start');
8480 0 $help->addArrow($node000, 1, 0, 'http');
8481 0 $node000->addArrow($node005, 1, 0, 'server');
8482 0 $node001->addArrow($node002, 1, 0, 'http');
8483 0 $node002->addArrow($node003, 1, 0, 'server');
8484 0 $node003->addArrow($node004, 1, 0, 'for');
8485 0 $node004->addArrow($node006, 1, 0, 'STORE', \&collectStore);
8486 0 $node006->addArrow($node007, 1, 0, 'on');
8487 0 $node007->addArrow($node008, 1, 0, 'port');
8488 0 $node008->addArrow($node009, 1, 0, 'PORT', \&collectPort);
8489 0 $node009->addArrow($node010, 1, 0, 'at');
8490 0 $node009->addDefault($node011);
8491 0 $node010->addArrow($node011, 1, 0, 'TEXT', \&collectText);
8492 0 $node011->addArrow($node012, 1, 0, 'with');
8493 0 $node011->addDefault($node016);
8494 0 $node012->addArrow($node013, 1, 0, 'static');
8495 0 $node013->addArrow($node014, 1, 0, 'files');
8496 0 $node014->addArrow($node015, 1, 0, 'from');
8497 0 $node015->addArrow($node016, 1, 0, 'FOLDER', \&collectFolder);
8498 0 $node016->addArrow($node017, 1, 0, 'for');
8499 0 $node016->addDefault($node018);
8500 0 $node017->addArrow($node018, 1, 0, 'everybody', \&collectEverybody);
8501 }
8502  
8503 sub collectEverybody {
8504 0 ▶ my $o = shift;
Subroutine collectEverybody: not called CC=1 SCAR=6.9
8505 0 my $label = shift;
8506 0 my $value = shift;
8507  
8508 0 $o->{corsAllowEverybody} = 1;
8509 }
8510  
8511 sub collectFolder {
8512 0 ▶ my $o = shift;
Subroutine collectFolder: not called CC=1 SCAR=6.9
8513 0 my $label = shift;
8514 0 my $value = shift;
8515  
8516 0 $o->{staticFolder} = $value;
8517 }
8518  
8519 sub collectPort {
8520 0 ▶ my $o = shift;
Subroutine collectPort: not called CC=1 SCAR=6.9
8521 0 my $label = shift;
8522 0 my $value = shift;
8523  
8524 0 $o->{port} = $value;
8525 }
8526  
8527 sub collectStore {
8528 0 ▶ my $o = shift;
Subroutine collectStore: not called CC=1 SCAR=6.9
8529 0 my $label = shift;
8530 0 my $value = shift;
8531  
8532 0 $o->{store} = $value;
8533 }
8534  
8535 sub collectText {
8536 0 ▶ my $o = shift;
Subroutine collectText: not called CC=1 SCAR=6.9
8537 0 my $label = shift;
8538 0 my $value = shift;
8539  
8540 0 $o->{root} = $value;
8541 }
8542  
8543 sub new {
8544 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
8545 0 my $actor = shift;
8546 0 bless {actor => $actor, ui => $actor->ui} }
8547  
8548 # END AUTOGENERATED
8549  
8550 # HTML FOLDER NAME start-http-server
8551 # HTML TITLE HTTP store server
8552 sub help {
8553 0 ▶ my $o = shift;
Subroutine help: not called CC=1 SCAR=6.9
8554 0 my $cmd = shift;
8555  
8556 0 my $ui = $o->{ui};
8557 0 $ui->space;
8558 0 $ui->command('cds start http server for STORE on port PORT');
8559 0 $ui->p('Starts a simple HTTP server listening on port PORT. The server handles requests within /objects and /accounts, and uses STORE as backend. Requests on the root URL (/) deliver a short message.');
8560 0 $ui->p('You may need superuser (root) privileges to use the default HTTP port 80.');
8561 0 $ui->p('This server is very useful for small to medium-size projects, but not particularly efficient for large-scale applications. It makes no effort to use DMA or similar features to speed up delivery, and handles only one request at a time (single-threaded). However, when using a front-end web server with load-balancing capabilities, multiple HTTP servers for the same store may be started to handle multiple requests in parallel.');
8562 0 $ui->space;
8563 0 $ui->command('… at TEXT');
8564 0 $ui->p('As above, but makes the store accessible at /TEXT/objects and /TEXT/accounts.');
8565 0 $ui->space;
8566 0 $ui->command('… with static files from FOLDER');
8567 0 $ui->p('Delivers static files from FOLDER for URLs outside of /objects and /accounts. This is useful for self-contained web apps.');
8568 0 $ui->space;
8569 0 $ui->command('… for everybody');
8570 0 $ui->p('Sets CORS headers to allow everybody to access the store from within a web browser.');
8571 0 $ui->space;
8572 0 $ui->p('For more options, write a Perl script instantiating and configuring a CDS::HTTPServer.');
8573 0 $ui->space;
8574 }
8575  
8576 sub startHttpServer {
8577 0 ▶ my $o = shift;
Subroutine startHttpServer: not called CC=7 SCAR=40.3
8578 0 my $cmd = shift;
8579  
8580 0 $cmd->collect($o);
8581  
8582 0 my $httpServer = CDS::HTTPServer->new($o->{port});
8583 0 $httpServer->setLogger(CDS::Commands::StartHTTPServer::Logger->new($o->{ui}));
8584 0 $httpServer->setCorsAllowEverybody($o->{corsAllowEverybody});
8585 0 ▶ $httpServer->addHandler(CDS::HTTPServer::StoreHandler->new($o->{root} // '/', $o->{store}));
Condition0%0/2
$o->{"root"} // "/"
l!l
00
MC/DC0%0/1
$o->{"root"} // "/"
$o->{"root"}
Truth table0%0/2
A
A= $o->{"root"}
Aresult
11
00
8586 0 ▶ $httpServer->addHandler(CDS::HTTPServer::IdentificationHandler->new($o->{root} // '/')) if ! defined $o->{staticFolder};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $o->{"staticFolder"} 0 0 0
Condition0%0/2
$o->{"root"} // "/"
l!l
00
MC/DC0%0/1
$o->{"root"} // "/"
$o->{"root"}
Truth table0%0/2
A
A= $o->{"root"}
Aresult
11
00
8587 0 ▶ $httpServer->addHandler(CDS::HTTPServer::StaticFilesHandler->new('/', $o->{staticFolder}, 'index.html')) if defined $o->{staticFolder};
Branch: 1 branch
BranchTrueFalseTotal
if defined $o->{"staticFolder"} 0 0 0
8588 0 eval { $httpServer->run; };
8589 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
8590 0 my $error = $@;
8591 0 ▶ $error = $1 if $error =~ /^(.*?)( at |\n)/;
Branch: 1 branch
BranchTrueFalseTotal
if $error =~ /^(.*?)( at |\n)/ 0 0 0
8592 0 $o->{ui}->space;
8593 0 $o->{ui}->p('Failed to run server on port '.$o->{port}.': '.$error);
8594 0 $o->{ui}->space;
8595 }
8596 }
8597  
8598 package CDS::Commands::StartHTTPServer::Logger;
8599  
8600 sub new {
8601 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
8602 0 my $ui = shift;
8603  
8604 0 return bless {ui => $ui};
8605 }
8606  
8607 sub onServerStarts {
8608 0 ▶ my $o = shift;
Subroutine onServerStarts: not called CC=1 SCAR=6.9
8609 0 my $port = shift;
8610  
8611 0 my $ui = $o->{ui};
8612 0 $ui->space;
8613 0 $ui->line($o->{ui}->gray($ui->niceDateTimeLocal), ' ', $ui->green('Server ready at http://localhost:', $port));
8614 }
8615  
8616 sub onRequestStarts {
8617 0 ▶ my $o = shift;
Subroutine onRequestStarts: not called CC=1 SCAR=6.9
8618 0 my $request = shift;
8619 }
8620  
8621 sub onRequestError {
8622 0 ▶ my $o = shift;
Subroutine onRequestError: not called CC=1 SCAR=6.9
8623 0 my $request = shift;
8624  
8625 0 my $ui = $o->{ui};
8626 0 $ui->line($o->{ui}->gray($ui->niceDateTimeLocal), ' ', $ui->blue($ui->left(15, $request->peerAddress)), ' ', $request->method, ' ', $request->path, ' ', $ui->red(@_));
8627 }
8628  
8629 sub onRequestDone {
8630 0 ▶ my $o = shift;
Subroutine onRequestDone: not called CC=1 SCAR=6.9
8631 0 my $request = shift;
8632 0 my $responseCode = shift;
8633  
8634 0 my $ui = $o->{ui};
8635 0 $ui->line($o->{ui}->gray($ui->niceDateTimeLocal), ' ', $ui->blue($ui->left(15, $request->peerAddress)), ' ', $request->method, ' ', $request->path, ' ', $ui->bold($responseCode));
8636 }
8637  
8638 # BEGIN AUTOGENERATED
8639 package CDS::Commands::Transfer;
8640  
8641 sub register {
8642 0 ▶ my $class = shift;
Subroutine register: not called CC=1 SCAR=6.9
8643 0 my $cds = shift;
8644 0 my $help = shift;
8645  
8646 0 my $node000 = CDS::Parser::Node->new(0);
8647 0 my $node001 = CDS::Parser::Node->new(0);
8648 0 my $node002 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&help});
8649 0 my $node003 = CDS::Parser::Node->new(0);
8650 0 my $node004 = CDS::Parser::Node->new(0);
8651 0 my $node005 = CDS::Parser::Node->new(0);
8652 0 my $node006 = CDS::Parser::Node->new(0);
8653 0 my $node007 = CDS::Parser::Node->new(0);
8654 0 my $node008 = CDS::Parser::Node->new(0);
8655 0 my $node009 = CDS::Parser::Node->new(0);
8656 0 my $node010 = CDS::Parser::Node->new(1);
8657 0 my $node011 = CDS::Parser::Node->new(0);
8658 0 my $node012 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&transfer});
8659 0 $cds->addArrow($node000, 1, 0, 'thoroughly');
8660 0 $cds->addArrow($node001, 0, 0, 'leniently');
8661 0 $cds->addDefault($node003);
8662 0 $cds->addArrow($node003, 1, 0, 'leniently', \&collectLeniently);
8663 0 $cds->addArrow($node003, 1, 0, 'thoroughly', \&collectThoroughly);
8664 0 $help->addArrow($node002, 1, 0, 'transfer');
8665 0 $node000->addArrow($node003, 1, 0, 'leniently', \&collectLeniently1);
8666 0 $node001->addArrow($node003, 0, 0, 'thoroughly', \&collectLeniently1);
8667 0 $node003->addArrow($node004, 1, 0, 'transfer');
8668 0 $node004->addDefault($node005);
8669 0 $node004->addDefault($node006);
8670 0 $node004->addDefault($node007);
8671 0 $node005->addArrow($node005, 1, 0, 'HASH', \&collectHash);
8672 0 $node005->addArrow($node010, 1, 0, 'HASH', \&collectHash);
8673 0 $node006->addArrow($node006, 1, 0, 'OBJECT', \&collectObject);
8674 0 $node006->addArrow($node010, 1, 0, 'OBJECT', \&collectObject);
8675 0 $node007->addArrow($node007, 1, 0, 'HASH', \&collectHash);
8676 0 $node007->addArrow($node008, 1, 0, 'HASH', \&collectHash);
8677 0 $node008->addArrow($node009, 1, 0, 'from');
8678 0 $node009->addArrow($node010, 1, 0, 'STORE', \&collectStore);
8679 0 $node010->addArrow($node011, 1, 0, 'to');
8680 0 $node011->addArrow($node011, 1, 0, 'STORE', \&collectStore1);
8681 0 $node011->addArrow($node012, 1, 0, 'STORE', \&collectStore1);
8682 }
8683  
8684 sub collectHash {
8685 0 ▶ my $o = shift;
Subroutine collectHash: not called CC=1 SCAR=6.9
8686 0 my $label = shift;
8687 0 my $value = shift;
8688  
8689 0 push @{$o->{hashes}}, $value;
8690 }
8691  
8692 sub collectLeniently {
8693 0 ▶ my $o = shift;
Subroutine collectLeniently: not called CC=1 SCAR=6.9
8694 0 my $label = shift;
8695 0 my $value = shift;
8696  
8697 0 $o->{leniently} = 1;
8698 }
8699  
8700 sub collectLeniently1 {
8701 0 ▶ my $o = shift;
Subroutine collectLeniently1: not called CC=1 SCAR=6.9
8702 0 my $label = shift;
8703 0 my $value = shift;
8704  
8705 0 $o->{leniently} = 1;
8706 0 $o->{thoroughly} = 1;
8707 }
8708  
8709 sub collectObject {
8710 0 ▶ my $o = shift;
Subroutine collectObject: not called CC=1 SCAR=6.9
8711 0 my $label = shift;
8712 0 my $value = shift;
8713  
8714 0 push @{$o->{objectTokens}}, $value;
8715 }
8716  
8717 sub collectStore {
8718 0 ▶ my $o = shift;
Subroutine collectStore: not called CC=1 SCAR=6.9
8719 0 my $label = shift;
8720 0 my $value = shift;
8721  
8722 0 $o->{fromStore} = $value;
8723 }
8724  
8725 sub collectStore1 {
8726 0 ▶ my $o = shift;
Subroutine collectStore1: not called CC=1 SCAR=6.9
8727 0 my $label = shift;
8728 0 my $value = shift;
8729  
8730 0 push @{$o->{toStores}}, $value;
8731 }
8732  
8733 sub collectThoroughly {
8734 0 ▶ my $o = shift;
Subroutine collectThoroughly: not called CC=1 SCAR=6.9
8735 0 my $label = shift;
8736 0 my $value = shift;
8737  
8738 0 $o->{thoroughly} = 1;
8739 }
8740  
8741 sub new {
8742 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
8743 0 my $actor = shift;
8744 0 bless {actor => $actor, ui => $actor->ui} }
8745  
8746 # END AUTOGENERATED
8747  
8748 # HTML FOLDER NAME transfer
8749 # HTML TITLE Transfer
8750 sub help {
8751 0 ▶ my $o = shift;
Subroutine help: not called CC=1 SCAR=6.9
8752 0 my $cmd = shift;
8753  
8754 0 my $ui = $o->{ui};
8755 0 $ui->space;
8756 0 $ui->command('cds transfer OBJECT* to STORE*');
8757 0 $ui->command('cds transfer HASH* from STORE to STORE*');
8758 0 $ui->p('Copies a tree from one store to another.');
8759 0 $ui->space;
8760 0 $ui->command('cds transfer HASH* to STORE*');
8761 0 $ui->p('As above, but uses the selected store as source store.');
8762 0 $ui->space;
8763 0 $ui->command('cds ', $ui->underlined('leniently'), ' transfer …');
8764 0 $ui->p('Warns about missing objects, but ignores them and proceeds with the rest.');
8765 0 $ui->space;
8766 0 $ui->command('cds ', $ui->underlined('thoroughly'), ' transfer …');
8767 0 $ui->p('Check subtrees of objects existing at the destination. This may be used to fix missing objects on the destination store.');
8768 0 $ui->space;
8769 }
8770  
8771 sub transfer {
8772 0 ▶ my $o = shift;
Subroutine transfer: not called CC=10 SCAR=47.0
8773 0 my $cmd = shift;
8774  
8775 0 $o->{keyPairToken} = $o->{actor}->preferredKeyPairToken;
8776 0 $o->{objectTokens} = [];
8777 0 $o->{hashes} = [];
8778 0 $o->{toStores} = [];
8779 0 $cmd->collect($o);
8780  
8781 # Use the selected store
8782 0 ▶ $o->{fromStore} = $o->{actor}->preferredStore if scalar @{$o->{hashes}} && ! $o->{fromStore};
Branch: 1 branch
BranchTrueFalseTotal
if scalar @{$o->{"hashes"};} and not $o->{"fromStore"} 0 0 0
Condition0%0/3
scalar @{$o->{"hashes"};} and not $o->{"fromStore"}
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @{$o->{"hashes"};} and not $o->{"fromStore"}
scalar @{$o->{"hashes"};} not $o->{"fromStore"}
Truth table0%0/3
A and not(B)
A= scalar @{$o->{"hashes"};}B= not $o->{"fromStore"}
ABresult
0X0
100
111
8783  
8784 # Prepare the destination stores
8785 0 my $toStores = [];
8786 0 for my $toStore (@{$o->{toStores}}) {
8787 0 push @$toStores, {store => $toStore, storeError => undef, needed => [1]};
8788 }
8789  
8790 # Print the stores
8791 0 $o->{ui}->space;
8792 0 my $n = scalar @$toStores;
8793 0 for my $i (0 .. $n - 1) {
8794 0 my $toStore = $toStores->[$i];
8795 0 $o->{ui}->line($o->{ui}->gray(' │' x $i, ' ┌', '──' x ($n - $i), ' ', $toStore->{store}->url));
8796 }
8797  
8798 # Process all trees
8799 0 $o->{objects} = {};
8800 0 $o->{missingObjects} = {};
8801 0 for my $objectToken (@{$o->{objectTokens}}) {
8802 0 $o->{ui}->line($o->{ui}->gray(' │' x $n));
8803 0 $o->process($objectToken->hash, $objectToken->cliStore, $toStores, 1);
8804 }
8805 0 for my $hash (@{$o->{hashes}}) {
8806 0 $o->{ui}->line($o->{ui}->gray(' │' x $n));
8807 0 $o->process($hash, $o->{fromStore}, $toStores, 1);
8808 }
8809  
8810 # Print the stores again, with their errors
8811 0 $o->{ui}->line($o->{ui}->gray(' │' x $n));
8812 0 for my $i (reverse 0 .. $n - 1) {
8813 0 my $toStore = $toStores->[$i];
8814 0 ▶ $o->{ui}->line($o->{ui}->gray(' │' x $i, ' â””', '──' x ($n - $i), ' ', $toStore->{store}->url), ' ', defined $toStore->{storeError} ? $o->{ui}->red($toStore->{storeError}) : '');
Branch: 1 branch
BranchTrueFalseTotal
defined $toStore->{'storeError'} ? : 0 0 0
8815 }
8816  
8817 # Report the total size
8818 0 my $totalSize = 0;
8819 0 my $totalDataSize = 0;
8820 0 map { $totalSize += $_->{size} ; $totalDataSize += $_->{dataSize} } values %{$o->{objects}};
8821 0 $o->{ui}->space;
8822 0 $o->{ui}->p(scalar keys %{$o->{objects}}, ' unique objects ', $o->{ui}->bold($o->{ui}->niceFileSize($totalSize)), ' ', $o->{ui}->gray($o->{ui}->niceFileSize($totalDataSize), ' data'));
8823 0 ▶ $o->{ui}->pOrange(scalar keys %{$o->{missingObjects}}, ' or more objects are missing') if scalar keys %{$o->{missingObjects}};
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %{$$o{"missingObjects"};} 0 0 0
8824 0 $o->{ui}->space;
8825 }
8826  
8827 sub process {
8828 0 ▶ my $o = shift;
Subroutine process: not called CC=22 SCAR=62.3
8829 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
8830 0 my $fromStore = shift;
8831 0 my $toStores = shift;
8832 0 my $depth = shift;
8833  
8834 0 my $hashHex = $hash->hex;
8835 0 my $keyPair = $o->{keyPairToken}->keyPair;
8836  
8837 # Check if we retrieved this object before
8838 0 ▶ if (exists $o->{objects}->{$hashHex}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $o->{"objects"}{$hashHex}) 0 0 0
8839 0 $o->report($hash->hex, $toStores, $depth, $o->{ui}->green('copied before'));
8840 0 return 1;
8841 }
8842  
8843 # Try to book the object on all active stores
8844 0 my $countNeeded = 0;
8845 0 my $hasActiveStore = 0;
8846 0 for my $toStore (@$toStores) {
8847 0 ▶ next if defined $toStore->{storeError};
Branch: 1 branch
BranchTrueFalseTotal
if defined $toStore->{"storeError"} 0 0 0
8848 0 $hasActiveStore = 1;
8849 0 ▶ next if ! $o->{thoroughly} && ! $toStore->{needed}->[$depth - 1];
Branch: 1 branch
BranchTrueFalseTotal
unless $o->{"thoroughly"} or $toStore->{"needed"}[$depth - 1] 0 0 0
Condition0%0/3
$o->{"thoroughly"} or $toStore->{"needed"}[$depth - 1]
l!l&&r!l&&!r
000
MC/DC0%0/2
$o->{"thoroughly"} or $toStore->{"needed"}[$depth - 1]
$o->{"thoroughly"} $toStore->{"needed"}[$depth - 1]
Truth table0%0/3
A or B
A= $o->{"thoroughly"}B= $toStore->{"needed"}[$depth - 1]
ABresult
1X1
011
000
8850  
8851 0 my ($found, $bookError) = $toStore->{store}->book($hash);
8852 0 ▶ if (defined $bookError) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $bookError) 0 0 0
8853 0 $toStore->{storeError} = $bookError;
8854 0 next;
8855 }
8856  
8857 0 ▶ next if $found;
Branch: 1 branch
BranchTrueFalseTotal
if $found 0 0 0
8858 0 $toStore->{needed}->[$depth] = 1;
8859 0 $countNeeded += 1;
8860 }
8861  
8862 # Return if all stores reported an error
8863 0 ▶ return if ! $hasActiveStore;
Branch: 1 branch
BranchTrueFalseTotal
unless $hasActiveStore 0 0 0
8864  
8865 # Ignore existing subtrees at the destination unless "thoroughly" is set
8866 0 ▶ if (! $o->{thoroughly} && ! $countNeeded) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($o->{"thoroughly"} or $countNeeded) 0 0 0
Condition0%0/3
$o->{"thoroughly"} or $countNeeded
l!l&&r!l&&!r
000
MC/DC0%0/2
$o->{"thoroughly"} or $countNeeded
$o->{"thoroughly"} $countNeeded
Truth table0%0/3
A or B
A= $o->{"thoroughly"}B= $countNeeded
ABresult
1X1
011
000
8867 0 $o->report($hashHex, $toStores, $depth, $o->{ui}->gray('skipping subtree'));
8868 0 return 1;
8869 }
8870  
8871 # Retrieve the object
8872 0 my ($object, $getError) = $fromStore->get($hash, $keyPair);
8873 0 ▶ return if defined $getError;
Branch: 1 branch
BranchTrueFalseTotal
if defined $getError 0 0 0
8874  
8875 0 ▶ if (! defined $object) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $object) 0 0 0
8876 0 $o->{missingObjects}->{$hashHex} = 1;
8877 0 $o->report($hashHex, $toStores, $depth, $o->{ui}->orange('is missing'));
8878 0 ▶ return if ! $o->{leniently};
Branch: 1 branch
BranchTrueFalseTotal
unless $o->{"leniently"} 0 0 0
8879 }
8880  
8881 # Display
8882 0 my $size = $object->byteLength;
8883 0 $o->{objects}->{$hashHex} = {needed => $countNeeded, size => $size, dataSize => length $object->data};
8884 0 $o->report($hashHex, $toStores, $depth, $o->{ui}->bold($o->{ui}->niceFileSize($size)), ' ', $o->{ui}->gray($object->hashesCount, ' hashes'));
8885  
8886 # Process all children
8887 0 foreach my $hash ($object->hashes) {
8888 0 ▶ $o->process($hash, $fromStore, $toStores, $depth + 1) // return;
Condition0%0/2
$o->process($hash, $fromStore, $toStores, $depth + 1) // (return)
l!l
00
MC/DC0%0/1
$o->process($hash, $fromStore, $toStores, $depth + 1) // (return)
$o->process($hash, $fromStore, $toStores, $depth + 1)
Truth table0%0/2
A
A= $o->process($hash, $fromStore, $toStores, $depth + 1)
Aresult
11
00
8889 }
8890  
8891 # Write the object to all active stores
8892 0 for my $toStore (@$toStores) {
8893 0 ▶ next if defined $toStore->{storeError};
Branch: 1 branch
BranchTrueFalseTotal
if defined $toStore->{"storeError"} 0 0 0
8894 0 ▶ next if ! $toStore->{needed}->[$depth];
Branch: 1 branch
BranchTrueFalseTotal
unless $toStore->{"needed"}[$depth] 0 0 0
8895 0 my $putError = $toStore->{store}->put($hash, $object, $keyPair);
8896 0 ▶ $toStore->{storeError} = $putError if $putError;
Branch: 1 branch
BranchTrueFalseTotal
if $putError 0 0 0
8897 }
8898  
8899 0 return 1;
8900 }
8901  
8902 sub report {
8903 0 ▶ my $o = shift;
Subroutine report: not called CC=4 SCAR=30.0
8904 0 my $hashHex = shift;
8905 0 my $toStores = shift;
8906 0 my $depth = shift;
8907  
8908 0 my @text;
8909 0 for my $toStore (@$toStores) {
8910 0 ▶ if ($toStore->{storeError}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($toStore->{'storeError'}) { } 0 0 0
elsif ($toStore->{'needed'}[$depth]) { } 0 0 0
8911 0 push @text, $o->{ui}->red(' ⨯');
8912 } elsif ($toStore->{needed}->[$depth]) {
8913 0 push @text, $o->{ui}->green(' +');
8914 } else {
8915 0 push @text, $o->{ui}->green(' ‒');
8916 }
8917 }
8918  
8919 0 push @text, ' ', ' ' x ($depth - 1), $hashHex;
8920 0 push @text, ' ', @_;
8921 0 $o->{ui}->line(@text);
8922 }
8923  
8924 # BEGIN AUTOGENERATED
8925 package CDS::Commands::UseCache;
8926  
8927 sub register {
8928 0 ▶ my $class = shift;
Subroutine register: not called CC=1 SCAR=6.9
8929 0 my $cds = shift;
8930 0 my $help = shift;
8931  
8932 0 my $node000 = CDS::Parser::Node->new(0);
8933 0 my $node001 = CDS::Parser::Node->new(0);
8934 0 my $node002 = CDS::Parser::Node->new(0);
8935 0 my $node003 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&help});
8936 0 my $node004 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&useCache});
8937 0 my $node005 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&dropCache});
8938 0 my $node006 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&cache});
8939 0 $cds->addArrow($node000, 1, 0, 'use');
8940 0 $cds->addArrow($node002, 1, 0, 'drop');
8941 0 $cds->addArrow($node006, 1, 0, 'cache');
8942 0 $help->addArrow($node003, 1, 0, 'cache');
8943 0 $node000->addArrow($node001, 1, 0, 'cache');
8944 0 $node001->addArrow($node004, 1, 0, 'STORE', \&collectStore);
8945 0 $node002->addArrow($node005, 1, 0, 'cache');
8946 }
8947  
8948 sub collectStore {
8949 0 ▶ my $o = shift;
Subroutine collectStore: not called CC=1 SCAR=6.9
8950 0 my $label = shift;
8951 0 my $value = shift;
8952  
8953 0 $o->{store} = $value;
8954 }
8955  
8956 sub new {
8957 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
8958 0 my $actor = shift;
8959 0 bless {actor => $actor, ui => $actor->ui} }
8960  
8961 # END AUTOGENERATED
8962  
8963 # HTML FOLDER NAME use-cache
8964 # HTML TITLE Using a cache store
8965 sub help {
8966 0 ▶ my $o = shift;
Subroutine help: not called CC=1 SCAR=6.9
8967 0 my $cmd = shift;
8968  
8969 0 my $ui = $o->{ui};
8970 0 $ui->space;
8971 0 $ui->command('cds use cache STORE');
8972 0 $ui->p('Uses STORE to cache objects, and speed up subsequent requests of the same object. This is particularly useful when working with (slow) remote stores. The cache store should be a fast store, such as a local folder store or an in-memory store.');
8973 0 $ui->p('Cached objects are not linked to any account, and may disappear with the next garbage collection. Most stores however keep objects for a least a few hours after their last use.');
8974 0 $ui->space;
8975 0 $ui->command('cds drop cache');
8976 0 $ui->p('Stops using the cache.');
8977 0 $ui->space;
8978 0 $ui->command('cds cache');
8979 0 $ui->p('Shows which cache store is used (if any).');
8980 0 $ui->space;
8981 }
8982  
8983 sub useCache {
8984 0 ▶ my $o = shift;
Subroutine useCache: not called CC=2 SCAR=17.9
8985 0 my $cmd = shift;
8986  
8987 0 $cmd->collect($o);
8988  
8989 0 $o->{actor}->sessionRoot->child('use cache')->setText($o->{store}->url);
8990 0 ▶ $o->{actor}->saveOrShowError // return;
Condition0%0/2
$o->{"actor"}->saveOrShowError // (return)
l!l
00
MC/DC0%0/1
$o->{"actor"}->saveOrShowError // (return)
$o->{"actor"}->saveOrShowError
Truth table0%0/2
A
A= $o->{"actor"}->saveOrShowError
Aresult
11
00
8991 0 $o->{ui}->pGreen('Using store "', $o->{store}->url, '" to cache objects.');
8992 }
8993  
8994 sub dropCache {
8995 0 ▶ my $o = shift;
Subroutine dropCache: not called CC=2 SCAR=17.9
8996 0 my $cmd = shift;
8997  
8998 0 $o->{actor}->sessionRoot->child('use cache')->clear;
8999 0 ▶ $o->{actor}->saveOrShowError // return;
Condition0%0/2
$o->{"actor"}->saveOrShowError // (return)
l!l
00
MC/DC0%0/1
$o->{"actor"}->saveOrShowError // (return)
$o->{"actor"}->saveOrShowError
Truth table0%0/2
A
A= $o->{"actor"}->saveOrShowError
Aresult
11
00
9000 0 $o->{ui}->pGreen('Not using any cache any more.');
9001 }
9002  
9003 sub cache {
9004 0 ▶ my $o = shift;
Subroutine cache: not called CC=2 SCAR=17.9
9005 0 my $cmd = shift;
9006  
9007 0 my $storeUrl = $o->{actor}->sessionRoot->child('use cache')->textValue;
9008 0 ▶ return $o->{ui}->line('Not using any cache.') if ! length $storeUrl;
Branch: 1 branch
BranchTrueFalseTotal
unless length $storeUrl 0 0 0
9009 0 return $o->{ui}->line('Using store "', $storeUrl, '" to cache objects.');
9010 }
9011  
9012 # BEGIN AUTOGENERATED
9013 package CDS::Commands::UseStore;
9014  
9015 sub register {
9016 0 ▶ my $class = shift;
Subroutine register: not called CC=1 SCAR=6.9
9017 0 my $cds = shift;
9018 0 my $help = shift;
9019  
9020 0 my $node000 = CDS::Parser::Node->new(0);
9021 0 my $node001 = CDS::Parser::Node->new(0);
9022 0 my $node002 = CDS::Parser::Node->new(0);
9023 0 my $node003 = CDS::Parser::Node->new(0);
9024 0 my $node004 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&help});
9025 0 my $node005 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&useStoreForMessaging});
9026 0 $cds->addArrow($node001, 1, 0, 'use');
9027 0 $help->addArrow($node000, 1, 0, 'messaging');
9028 0 $node000->addArrow($node004, 1, 0, 'store');
9029 0 $node001->addArrow($node002, 1, 0, 'STORE', \&collectStore);
9030 0 $node002->addArrow($node003, 1, 0, 'for');
9031 0 $node003->addArrow($node005, 1, 0, 'messaging');
9032 }
9033  
9034 sub collectStore {
9035 0 ▶ my $o = shift;
Subroutine collectStore: not called CC=1 SCAR=6.9
9036 0 my $label = shift;
9037 0 my $value = shift;
9038  
9039 0 $o->{store} = $value;
9040 }
9041  
9042 sub new {
9043 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
9044 0 my $actor = shift;
9045 0 bless {actor => $actor, ui => $actor->ui} }
9046  
9047 # END AUTOGENERATED
9048  
9049 # HTML FOLDER NAME use-store
9050 # HTML TITLE Set the messaging store
9051 sub help {
9052 0 ▶ my $o = shift;
Subroutine help: not called CC=1 SCAR=6.9
9053 0 my $cmd = shift;
9054  
9055 0 my $ui = $o->{ui};
9056 0 $ui->space;
9057 0 $ui->command('cds use STORE for messaging');
9058 0 $ui->p('Uses STORE to send and receive messages.');
9059 0 $ui->space;
9060 }
9061  
9062 sub useStoreForMessaging {
9063 0 ▶ my $o = shift;
Subroutine useStoreForMessaging: not called CC=1 SCAR=6.9
9064 0 my $cmd = shift;
9065  
9066 0 $cmd->collect($o);
9067  
9068 0 $o->{actor}->{configuration}->setMessagingStoreUrl($o->{store}->url);
9069 0 $o->{ui}->pGreen('The messaging store is now ', $o->{store}->url);
9070 }
9071  
9072 # BEGIN AUTOGENERATED
9073 package CDS::Commands::Welcome;
9074  
9075 sub register {
9076 0 ▶ my $class = shift;
Subroutine register: not called CC=1 SCAR=6.9
9077 0 my $cds = shift;
9078 0 my $help = shift;
9079  
9080 0 my $node000 = CDS::Parser::Node->new(0);
9081 0 my $node001 = CDS::Parser::Node->new(0);
9082 0 my $node002 = CDS::Parser::Node->new(0);
9083 0 my $node003 = CDS::Parser::Node->new(0);
9084 0 my $node004 = CDS::Parser::Node->new(0);
9085 0 my $node005 = CDS::Parser::Node->new(0);
9086 0 my $node006 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&help});
9087 0 my $node007 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&suppress});
9088 0 my $node008 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&enable});
9089 0 my $node009 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&show});
9090 0 $cds->addArrow($node000, 1, 0, 'suppress');
9091 0 $cds->addArrow($node002, 1, 0, 'enable');
9092 0 $cds->addArrow($node004, 1, 0, 'show');
9093 0 $help->addArrow($node006, 1, 0, 'welcome');
9094 0 $node000->addArrow($node001, 1, 0, 'welcome');
9095 0 $node001->addArrow($node007, 1, 0, 'message');
9096 0 $node002->addArrow($node003, 1, 0, 'welcome');
9097 0 $node003->addArrow($node008, 1, 0, 'message');
9098 0 $node004->addArrow($node005, 1, 0, 'welcome');
9099 0 $node005->addArrow($node009, 1, 0, 'message');
9100 }
9101  
9102 sub new {
9103 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
9104 0 my $actor = shift;
9105 0 bless {actor => $actor, ui => $actor->ui} }
9106  
9107 # END AUTOGENERATED
9108  
9109 # HTML FOLDER NAME welcome
9110 # HTML TITLE Welcome message
9111 sub help {
9112 0 ▶ my $o = shift;
Subroutine help: not called CC=1 SCAR=6.9
9113 0 my $cmd = shift;
9114  
9115 0 my $ui = $o->{ui};
9116 0 $ui->space;
9117 0 $ui->command('cds suppress welcome message');
9118 0 $ui->p('Suppresses the welcome message when typing "cds".');
9119 0 $ui->space;
9120 0 $ui->command('cds enable welcome message');
9121 0 $ui->p('Enables the welcome message when typing "cds".');
9122 0 $ui->space;
9123 0 $ui->command('cds show welcome message');
9124 0 $ui->p('Shows the welcome message.');
9125 0 $ui->space;
9126 }
9127  
9128 sub suppress {
9129 0 ▶ my $o = shift;
Subroutine suppress: not called CC=2 SCAR=17.9
9130 0 my $cmd = shift;
9131  
9132 0 $o->{actor}->localRoot->child('suppress welcome message')->setBoolean(1);
9133 0 ▶ $o->{actor}->saveOrShowError // return;
Condition0%0/2
$o->{"actor"}->saveOrShowError // (return)
l!l
00
MC/DC0%0/1
$o->{"actor"}->saveOrShowError // (return)
$o->{"actor"}->saveOrShowError
Truth table0%0/2
A
A= $o->{"actor"}->saveOrShowError
Aresult
11
00
9134  
9135 0 $o->{ui}->space;
9136 0 $o->{ui}->p('The welcome message will not be shown any more.');
9137 0 $o->{ui}->space;
9138 0 $o->{ui}->line('You can manually display the message by typing:');
9139 0 $o->{ui}->line($o->{ui}->blue(' cds show welcome message'));
9140 0 $o->{ui}->line('or re-enable it using:');
9141 0 $o->{ui}->line($o->{ui}->blue(' cds enable welcome message'));
9142 0 $o->{ui}->space;
9143 }
9144  
9145 sub enable {
9146 0 ▶ my $o = shift;
Subroutine enable: not called CC=2 SCAR=17.9
9147 0 my $cmd = shift;
9148  
9149 0 $o->{actor}->localRoot->child('suppress welcome message')->clear;
9150 0 ▶ $o->{actor}->saveOrShowError // return;
Condition0%0/2
$o->{"actor"}->saveOrShowError // (return)
l!l
00
MC/DC0%0/1
$o->{"actor"}->saveOrShowError // (return)
$o->{"actor"}->saveOrShowError
Truth table0%0/2
A
A= $o->{"actor"}->saveOrShowError
Aresult
11
00
9151  
9152 0 $o->{ui}->space;
9153 0 $o->{ui}->p('The welcome message will be shown when you type "cds".');
9154 0 $o->{ui}->space;
9155 }
9156  
9157 sub isEnabled {
9158 0 ▶ my $o = shift;
Subroutine isEnabled: not called CC=1 SCAR=6.9
9159 0 ! $o->{actor}->localRoot->child('suppress welcome message')->isSet }
9160  
9161 sub show {
9162 0 ▶ my $o = shift;
Subroutine show: not called CC=1 SCAR=6.9
9163 0 my $cmd = shift;
9164  
9165 0 my $ui = $o->{ui};
9166 0 $ui->space;
9167 0 $ui->title('Hi there!');
9168 0 $ui->p('This is the command line interface (CLI) of Condensation ', $CDS::VERSION, ', ', $CDS::releaseDate, '. Condensation is a distributed data system with conflict-free forward merging and end-to-end security. More information is available on https://condensation.io.');
9169 0 $ui->space;
9170 0 $ui->p('Commands resemble short english sentences. For example, the following "sentence" will show the record of an object:');
9171 0 $ui->line($ui->blue(' cds show record e5cbfc282e1f3e6fd0f3e5fffd41964c645f44d7fae8ef5cb350c2dfd2196c9f \\'));
9172 0 $ui->line($ui->blue(' from http://examples.condensation.io'));
9173 0 $ui->p('Type a "?" to explore possible commands, e.g.');
9174 0 $ui->line($ui->blue(' cds show ?'));
9175 0 $ui->p('or use TAB or TAB-TAB for command completion.');
9176 0 $ui->space;
9177 0 $ui->p('To get help, type');
9178 0 $ui->line($ui->blue(' cds help'));
9179 0 $ui->space;
9180 0 $ui->p('To suppress this welcome message, type');
9181 0 $ui->line($ui->blue(' cds suppress welcome message'));
9182 0 $ui->space;
9183 }
9184  
9185 package CDS::Commands::WhatIs;
9186  
9187 # BEGIN AUTOGENERATED
9188  
9189 sub register {
9190 0 ▶ my $class = shift;
Subroutine register: not called CC=1 SCAR=6.9
9191 0 my $cds = shift;
9192 0 my $help = shift;
9193  
9194 0 my $node000 = CDS::Parser::Node->new(0);
9195 0 my $node001 = CDS::Parser::Node->new(0);
9196 0 my $node002 = CDS::Parser::Node->new(0);
9197 0 my $node003 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&help});
9198 0 my $node004 = CDS::Parser::Node->new(1, {constructor => \&new, function => \&whatIs});
9199 0 $cds->addArrow($node001, 1, 0, 'what');
9200 0 $help->addArrow($node000, 1, 0, 'what');
9201 0 $node000->addArrow($node003, 1, 0, 'is');
9202 0 $node001->addArrow($node002, 1, 0, 'is');
9203 0 $node002->addArrow($node004, 1, 0, 'TEXT', \&collectText);
9204 }
9205  
9206 sub collectText {
9207 0 ▶ my $o = shift;
Subroutine collectText: not called CC=1 SCAR=6.9
9208 0 my $label = shift;
9209 0 my $value = shift;
9210  
9211 0 $o->{text} = $value;
9212 }
9213  
9214 sub new {
9215 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
9216 0 my $actor = shift;
9217 0 bless {actor => $actor, ui => $actor->ui} }
9218  
9219 # END AUTOGENERATED
9220  
9221 # HTML FOLDER NAME what-is
9222 # HTML TITLE What is
9223 sub help {
9224 0 ▶ my $o = shift;
Subroutine help: not called CC=1 SCAR=6.9
9225 0 my $cmd = shift;
9226  
9227 0 my $ui = $o->{ui};
9228 0 $ui->space;
9229 0 $ui->command('cds what is TEXT');
9230 0 $ui->p('Tells what TEXT could be under the current configuration.');
9231 0 $ui->space;
9232 }
9233  
9234 sub whatIs {
9235 0 ▶ my $o = shift;
Subroutine whatIs: not called CC=3 SCAR=24.8
9236 0 my $cmd = shift;
9237  
9238 0 $cmd->collect($o);
9239 0 $o->{butNot} = [];
9240  
9241 0 $o->{ui}->space;
9242 0 $o->{ui}->title($o->{ui}->blue($o->{text}), ' may be …');
9243  
9244 0 ▶ $o->test('ACCOUNT', 'an ACCOUNT', sub { shift->url });
Subroutine __ANON__: not called CC=1 SCAR=6.9
9245 0 ▶ $o->test('AESKEY', 'an AESKEY', sub { unpack('H*', shift) });
Subroutine __ANON__: not called CC=1 SCAR=6.9
9246 0 ▶ $o->test('BOX', 'a BOX', sub { shift->url });
Subroutine __ANON__: not called CC=1 SCAR=6.9
9247 0 ▶ $o->test('BOXLABEL', 'a BOXLABEL', sub { shift });
Subroutine __ANON__: not called CC=1 SCAR=6.9
9248 0 $o->test('FILE', 'a FILE', \&fileResult);
9249 0 $o->test('FILENAME', 'a FILENAME', \&fileResult);
9250 0 $o->test('FOLDER', 'a FOLDER', \&fileResult);
9251 0 ▶ $o->test('GROUP', 'a GROUP on this system', sub { shift });
Subroutine __ANON__: not called CC=1 SCAR=6.9
9252 0 ▶ $o->test('HASH', 'a HASH or ACTOR hash', sub { shift->hex });
Subroutine __ANON__: not called CC=1 SCAR=6.9
9253 0 $o->test('KEYPAIR', 'a KEYPAIR', \&keyPairResult);
9254 0 ▶ $o->test('LABEL', 'a remembered LABEL', sub { shift });
Subroutine __ANON__: not called CC=1 SCAR=6.9
9255 0 ▶ $o->test('OBJECT', 'an OBJECT', sub { shift->url });
Subroutine __ANON__: not called CC=1 SCAR=6.9
9256 0 $o->test('OBJECTFILE', 'an OBJECTFILE', \&objectFileResult);
9257 0 ▶ $o->test('STORE', 'a STORE', sub { shift->url });
Subroutine __ANON__: not called CC=1 SCAR=6.9
9258 0 ▶ $o->test('USER', 'a USER on this system', sub { shift });
Subroutine __ANON__: not called CC=1 SCAR=6.9
9259  
9260 0 for my $butNot (@{$o->{butNot}}) {
9261 0 $o->{ui}->space;
9262 0 $o->{ui}->line('… but not ', $butNot->{text}, ', because:');
9263 0 for my $warning (@{$butNot->{warnings}}) {
9264 0 $o->{ui}->warning($warning);
9265 }
9266 }
9267  
9268 0 $o->{ui}->space;
9269 }
9270  
9271 sub test {
9272 0 ▶ my $o = shift;
Subroutine test: not called CC=3 SCAR=24.8
9273 0 my $expect = shift;
9274 0 my $text = shift;
9275 0 my $resultHandler = shift;
9276  
9277 0 my $token = CDS::Parser::Token->new($o->{actor}, $o->{text});
9278 0 my $result = $token->produce($expect);
9279 0 ▶ if (defined $result) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $result) { } 0 0 0
elsif (scalar @{$token->{'warnings'};}) { } 0 0 0
9280 0 my $whichOne = &$resultHandler($result);
9281 0 $o->{ui}->line('… ', $text, ' ', $o->{ui}->gray($whichOne));
9282 0 } elsif (scalar @{$token->{warnings}}) {
9283 0 push @{$o->{butNot}}, {text => $text, warnings => $token->{warnings}};
9284 }
9285 }
9286  
9287 sub keyPairResult {
9288 0 ▶ my $keyPairToken = shift;
Subroutine keyPairResult: not called CC=1 SCAR=6.9
9289  
9290 0 return $keyPairToken->file.' ('.$keyPairToken->keyPair->publicKey->hash->hex.')';
9291 }
9292  
9293 sub objectFileResult {
9294 0 ▶ my $objectFileToken = shift;
Subroutine objectFileResult: not called CC=2 SCAR=17.9
9295  
9296 0 ▶ return $objectFileToken->file if $objectFileToken->object->byteLength > 1024 * 1024;
Branch: 1 branch
BranchTrueFalseTotal
if $objectFileToken->object->byteLength > 1048576 0 0 0
9297 0 return $objectFileToken->file.' ('.$objectFileToken->object->calculateHash->hex.')';
9298 }
9299  
9300 sub fileResult {
9301 0 ▶ my $file = shift;
Subroutine fileResult: not called CC=9 SCAR=45.0
9302  
9303 0 my @s = stat $file;
9304 0 ▶ my $label =
Branch: 8 branches
BranchTrueFalseTotal
!scalar(@s) ? : 0 0 0
Fcntl::S_ISDIR($s[2]) ? : 0 0 0
Fcntl::S_ISREG($s[2]) ? : 0 0 0
Fcntl::S_ISLNK($s[2]) ? : 0 0 0
Fcntl::S_ISBLK($s[2]) ? : 0 0 0
Fcntl::S_ISCHR($s[2]) ? : 0 0 0
Fcntl::S_ISSOCK($s[2]) ? : 0 0 0
Fcntl::S_ISFIFO($s[2]) ? : 0 0 0
9305 ! scalar @s ? ' (non-existing)' :
9306 Fcntl::S_ISDIR($s[2]) ? ' (folder)' :
9307 Fcntl::S_ISREG($s[2]) ? ' (file, '.$s[7].' bytes)' :
9308 Fcntl::S_ISLNK($s[2]) ? ' (symbolic link)' :
9309 Fcntl::S_ISBLK($s[2]) ? ' (block device)' :
9310 Fcntl::S_ISCHR($s[2]) ? ' (char device)' :
9311 Fcntl::S_ISSOCK($s[2]) ? ' (socket)' :
9312 Fcntl::S_ISFIFO($s[2]) ? ' (pipe)' : ' (unknown type)';
9313  
9314 0 return $file.$label;
9315 }
9316  
9317 package CDS::Configuration;
9318  
9319 1 ▶our $xdgConfigurationFolder = ($ENV{XDG_CONFIG_HOME} || $ENV{HOME}.'/.config').'/condensation';
Condition50%1/2
$ENV{'XDG_CONFIG_HOME'} || $ENV{'HOME'} . '/.config'
l!l
01
MC/DC0%0/1
$ENV{'XDG_CONFIG_HOME'} || $ENV{'HOME'} . '/.config'
$ENV{'XDG_CONFIG_HOME'}
Truth table50%1/2
A
A= $ENV{'XDG_CONFIG_HOME'}
Aresult
11
00
9320 1 ▶our $xdgDataFolder = ($ENV{XDG_DATA_HOME} || $ENV{HOME}.'/.local/share').'/condensation';
Condition50%1/2
$ENV{'XDG_DATA_HOME'} || $ENV{'HOME'} . '/.local/share'
l!l
01
MC/DC0%0/1
$ENV{'XDG_DATA_HOME'} || $ENV{'HOME'} . '/.local/share'
$ENV{'XDG_DATA_HOME'}
Truth table50%1/2
A
A= $ENV{'XDG_DATA_HOME'}
Aresult
11
00
9321  
9322 sub getOrCreateDefault {
9323 0 ▶ my $class = shift;
Subroutine getOrCreateDefault: not called CC=1 SCAR=6.9
9324 0 my $ui = shift;
9325  
9326 0 my $configuration = $class->new($ui, $xdgConfigurationFolder, $xdgDataFolder);
9327 0 $configuration->createIfNecessary();
9328 0 return $configuration;
9329 }
9330  
9331 sub new {
9332 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
9333 0 my $ui = shift;
9334 0 my $folder = shift;
9335 0 my $defaultStoreFolder = shift;
9336  
9337 0 return bless {ui => $ui, folder => $folder, defaultStoreFolder => $defaultStoreFolder};
9338 }
9339  
9340 0 ▶sub ui { shift->{ui} }
Subroutine ui: not called CC=1 SCAR=6.9
9341 0 ▶sub folder { shift->{folder} }
Subroutine folder: not called CC=1 SCAR=6.9
9342  
9343 sub createIfNecessary {
9344 0 ▶ my $o = shift;
Subroutine createIfNecessary: not called CC=5 SCAR=34.0
9345  
9346 0 my $keyPairFile = $o->{folder}.'/key-pair';
9347 0 ▶ return 1 if -f $keyPairFile;
Branch: 1 branch
BranchTrueFalseTotal
if -f $keyPairFile 0 0 0
9348  
9349 0 $o->{ui}->progress('Creating configuration folders …');
9350 0 ▶ $o->createFolder($o->{folder}) // return $o->{ui}->error('Failed to create the folder "', $o->{folder}, '".');
Condition0%0/2
$o->createFolder($o->{"folder"}) // (return $o->{"ui"}->error("Failed to create the folder \"", $o->{"folder"}, "\"."))
l!l
00
MC/DC0%0/1
$o->createFolder($o->{"folder"}) // (return $o->{"ui"}->error("Failed to create the folder \"", $o->{"folder"}, "\"."))
$o->createFolder($o->{"folder"})
Truth table0%0/2
A
A= $o->createFolder($o->{"folder"})
Aresult
11
00
9351 0 ▶ $o->createFolder($o->{defaultStoreFolder}) // return $o->{ui}->error('Failed to create the folder "', $o->{defaultStoreFolder}, '".');
Condition0%0/2
$o->createFolder($o->{"defaultStoreFolder"}) // (return $o->{"ui"}->error("Failed to create the folder \"", $o->{"defaultStoreFolder"}, "\"."))
l!l
00
MC/DC0%0/1
$o->createFolder($o->{"defaultStoreFolder"}) // (return $o->{"ui"}->error("Failed to create the folder \"", $o->{"defaultStoreFolder"}, "\"."))
$o->createFolder($o->{"defaultStoreFolder"})
Truth table0%0/2
A
A= $o->createFolder($o->{"defaultStoreFolder"})
Aresult
11
00
9352 0 CDS::FolderStore->new($o->{defaultStoreFolder})->createIfNecessary;
9353  
9354 0 $o->{ui}->progress('Generating key pair …');
9355 0 my $keyPair = CDS::KeyPair->generate;
9356 0 ▶ $keyPair->writeToFile($keyPairFile) // return $o->{ui}->error('Failed to write the configuration file "', $keyPairFile, '". Make sure that this location is writable.');
Condition0%0/2
$keyPair->writeToFile($keyPairFile) // (return $o->{"ui"}->error("Failed to write the configuration file \"", $keyPairFile, "\". Make sure that this location is writable."))
l!l
00
MC/DC0%0/1
$keyPair->writeToFile($keyPairFile) // (return $o->{"ui"}->error("Failed to write the configuration file \"", $keyPairFile, "\". Make sure that this location is writable."))
$keyPair->writeToFile($keyPairFile)
Truth table0%0/2
A
A= $keyPair->writeToFile($keyPairFile)
Aresult
11
00
9357 0 $o->{ui}->removeProgress;
9358 0 return 1;
9359 }
9360  
9361 sub createFolder {
9362 0 ▶ my $o = shift;
Subroutine createFolder: not called CC=2 SCAR=17.9
9363 0 my $folder = shift;
9364  
9365 0 for my $path (CDS->intermediateFolders($folder)) {
9366 0 mkdir $path;
9367 }
9368  
9369 0 return -d $folder;
9370 }
9371  
9372 sub file {
9373 0 ▶ my $o = shift;
Subroutine file: not called CC=1 SCAR=6.9
9374 0 my $filename = shift;
9375  
9376 0 return $o->{folder}.'/'.$filename;
9377 }
9378  
9379 sub messagingStoreUrl {
9380 0 ▶ my $o = shift;
Subroutine messagingStoreUrl: not called CC=2 SCAR=17.9
9381  
9382 0 ▶ return $o->readFirstLine('messaging-store') // 'file://'.$o->{defaultStoreFolder};
Condition0%0/2
$o->readFirstLine("messaging-store") // 'file://' . $o->{"defaultStoreFolder"}
l!l
00
MC/DC0%0/1
$o->readFirstLine("messaging-store") // 'file://' . $o->{"defaultStoreFolder"}
$o->readFirstLine("messaging-store")
Truth table0%0/2
A
A= $o->readFirstLine("messaging-store")
Aresult
11
00
9383 }
9384  
9385 sub storageStoreUrl {
9386 0 ▶ my $o = shift;
Subroutine storageStoreUrl: not called CC=2 SCAR=17.9
9387  
9388 0 ▶ return $o->readFirstLine('store') // 'file://'.$o->{defaultStoreFolder};
Condition0%0/2
$o->readFirstLine("store") // 'file://' . $o->{"defaultStoreFolder"}
l!l
00
MC/DC0%0/1
$o->readFirstLine("store") // 'file://' . $o->{"defaultStoreFolder"}
$o->readFirstLine("store")
Truth table0%0/2
A
A= $o->readFirstLine("store")
Aresult
11
00
9389 }
9390  
9391 sub setMessagingStoreUrl {
9392 0 ▶ my $o = shift;
Subroutine setMessagingStoreUrl: not called CC=1 SCAR=6.9
9393 0 my $storeUrl = shift;
9394  
9395 0 CDS->writeTextToFile($o->file('messaging-store'), $storeUrl);
9396 }
9397  
9398 sub setStorageStoreUrl {
9399 0 ▶ my $o = shift;
Subroutine setStorageStoreUrl: not called CC=1 SCAR=6.9
9400 0 my $storeUrl = shift;
9401  
9402 0 CDS->writeTextToFile($o->file('store'), $storeUrl);
9403 }
9404  
9405 sub keyPair {
9406 0 ▶ my $o = shift;
Subroutine keyPair: not called CC=1 SCAR=6.9
9407  
9408 0 return CDS::KeyPair->fromFile($o->file('key-pair'));
9409 }
9410  
9411 sub setKeyPair {
9412 0 ▶ my $o = shift;
Subroutine setKeyPair: not called CC=3 SCAR=24.8
9413 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
9414  
9415 0 $keyPair->writeToFile($o->file('key-pair'));
9416 }
9417  
9418 sub readFirstLine {
9419 0 ▶ my $o = shift;
Subroutine readFirstLine: not called CC=4 SCAR=30.0
9420 0 my $file = shift;
9421  
9422 0 ▶ my $content = CDS->readTextFromFile($o->file($file)) // return;
Condition0%0/2
"CDS"->readTextFromFile($o->file($file)) // (return)
l!l
00
MC/DC0%0/1
"CDS"->readTextFromFile($o->file($file)) // (return)
"CDS"->readTextFromFile($o->file($file))
Truth table0%0/2
A
A= "CDS"->readTextFromFile($o->file($file))
Aresult
11
00
9423 0 ▶ $content = $1 if $content =~ /^(.*)\n/;
Branch: 1 branch
BranchTrueFalseTotal
if $content =~ /^(.*)\n/ 0 0 0
9424 0 ▶ $content = $1 if $content =~ /^\s*(.*?)\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
if $content =~ /^\s*(.*?)\s*$/ 0 0 0
9425 0 return $content;
9426 }
9427  
9428 package CDS::DetachedDocument;
9429  
9430 1 ▶use parent -norequire, 'CDS::Document';
Subroutine BEGIN: called CC=1 SCAR=0.0
9431  
9432 sub new {
9433 0 ▶ my $class = shift;
Subroutine new: not called CC=3 SCAR=24.8
9434 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
9435  
9436 0 return $class->SUPER::new($keyPair, CDS::InMemoryStore->create);
9437 }
9438  
9439 sub savingDone {
9440 0 ▶ my $o = shift;
Subroutine savingDone: not called CC=1 SCAR=6.9
9441 0 my $revision = shift;
9442 0 my $newPart = shift;
9443 0 my $obsoleteParts = shift;
9444  
9445 # We don't do anything
9446 0 $o->{unsaved}->savingDone;
9447 }
9448  
9449 package CDS::DiscoverActorGroup;
9450  
9451 sub discover {
9452 0 ▶ my $class = shift;
Subroutine discover: not called CC=24 SCAR=64.0
9453 0 ▶ my $builder = shift; die 'wrong type '.ref($builder).' for $builder' if defined $builder && ref $builder ne 'CDS::ActorGroupBuilder';
Branch: 1 branch
BranchTrueFalseTotal
if defined $builder and ref $builder ne "CDS::ActorGroupBuilder" 0 0 0
Condition0%0/3
defined $builder and ref $builder ne "CDS::ActorGroupBuilder"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $builder and ref $builder ne "CDS::ActorGroupBuilder"
defined $builder ref $builder ne "CDS::ActorGroupBuilder"
Truth table0%0/3
A and B
A= defined $builderB= ref $builder ne "CDS::ActorGroupBuilder"
ABresult
0X0
100
111
9454 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
9455 0 my $delegate = shift;
9456  
9457 0 my $o = bless {
9458 knownPublicKeys => $builder->knownPublicKeys, # A hashref of known public keys (e.g. from the existing actor group)
9459 keyPair => $keyPair,
9460 delegate => $delegate, # The delegate
9461 nodesByUrl => {}, # Nodes on which this actor group is active, by URL
9462 coverage => {}, # Hashes that belong to this actor group
9463 };
9464  
9465 # Add all active members
9466 0 for my $member ($builder->members) {
9467 0 ▶ next if $member->status ne 'active';
Branch: 1 branch
BranchTrueFalseTotal
if $member->status ne "active" 0 0 0
9468 0 my $node = $o->node($member->hash, $member->storeUrl);
9469 0 ▶ if ($node->{revision} < $member->revision) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->{"revision"} < $member->revision) 0 0 0
9470 0 $node->{revision} = $member->revision;
9471 0 $node->{status} = 'active';
9472 }
9473  
9474 0 $o->{coverage}->{$member->hash->bytes} = 1;
9475 }
9476  
9477 # Determine the revision at start
9478 0 my $revisionAtStart = 0;
9479 0 for my $node (values %{$o->{nodesByUrl}}) {
9480 0 ▶ $revisionAtStart = $node->{revision} if $revisionAtStart < $node->{revision};
Branch: 1 branch
BranchTrueFalseTotal
if $revisionAtStart < $node->{"revision"} 0 0 0
9481 }
9482  
9483 # Reload the cards of all known accounts
9484 0 for my $node (values %{$o->{nodesByUrl}}) {
9485 0 $node->discover;
9486 }
9487  
9488 # From here, try extending to other accounts
9489 0 ▶ while ($o->extend) {}
Branch: 1 branch
BranchTrueFalseTotal
if ($o->extend) 0 0 0
9490  
9491 # Compile the list of actors and cards
9492 0 my @members;
9493 my @cards;
9494 0 for my $node (values %{$o->{nodesByUrl}}) {
9495 0 ▶ next if ! $node->{reachable};
Branch: 1 branch
BranchTrueFalseTotal
unless $node->{"reachable"} 0 0 0
9496 0 ▶ next if ! $node->{attachedToUs};
Branch: 1 branch
BranchTrueFalseTotal
unless $node->{"attachedToUs"} 0 0 0
9497 0 ▶ next if ! $node->{actorOnStore};
Branch: 1 branch
BranchTrueFalseTotal
unless $node->{"actorOnStore"} 0 0 0
9498 0 ▶ next if ! $node->isActiveOrIdle;
Branch: 1 branch
BranchTrueFalseTotal
unless $node->isActiveOrIdle 0 0 0
9499 #-- member ++ $node->{actorHash}->hex ++ $node->{cardsRead} ++ $node->{cards} // 'undef' ++ $node->{actorOnStore} // 'undef'
9500 0 push @members, CDS::ActorGroup::Member->new($node->{actorOnStore}, $node->{storeUrl}, $node->{revision}, $node->isActive);
9501 0 push @cards, @{$node->{cards}};
9502 }
9503  
9504 # Get the newest list of entrusted actors
9505 0 my $parser = CDS::ActorGroupBuilder->new;
9506 0 for my $card (@cards) {
9507 0 $parser->parseEntrustedActors($card->card->child('entrusted actors'), 0);
9508 }
9509  
9510 # Get the entrusted actors
9511 0 my $entrustedActors = [];
9512 0 for my $actor ($parser->entrustedActors) {
9513 0 my $store = $o->{delegate}->onDiscoverActorGroupVerifyStore($actor->storeUrl);
9514 0 ▶ next if ! $store;
Branch: 1 branch
BranchTrueFalseTotal
unless $store 0 0 0
9515  
9516 0 my $knownPublicKey = $o->{knownPublicKeys}->{$actor->hash->bytes};
9517 0 ▶ if ($knownPublicKey) {
Branch: 1 branch
BranchTrueFalseTotal
if ($knownPublicKey) 0 0 0
9518 0 push @$entrustedActors, CDS::ActorGroup::EntrustedActor->new(CDS::ActorOnStore->new($knownPublicKey, $store), $actor->storeUrl);
9519 0 next;
9520 }
9521  
9522 0 my ($publicKey, $invalidReason, $storeError) = $keyPair->getPublicKey($actor->hash, $store);
9523  
9524 0 ▶ if (defined $invalidReason) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $invalidReason) 0 0 0
9525 0 $o->{discoverer}->{delegate}->onDiscoverActorGroupInvalidPublicKey($actor->hash, $store, $invalidReason);
9526 0 next;
9527 }
9528  
9529 0 ▶ if (defined $storeError) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $storeError) 0 0 0
9530 0 $o->{discoverer}->{delegate}->onDiscoverActorGroupStoreError($store, $storeError);
9531 0 next;
9532 }
9533  
9534 0 push @$entrustedActors, CDS::ActorGroup::EntrustedActor->new(CDS::ActorOnStore->new($publicKey, $store), $actor->storeUrl);
9535 }
9536  
9537 0 ▶ my $members = [sort { $b->{revision} <=> $a->{revision} || $b->{status} cmp $a->{status} } @members];
Branch: 1 branch
BranchTrueFalseTotal
$CDS::DiscoverActorGroup::b->{"revision"} <=> $CDS::DiscoverActorGroup::a->{"revision"} or $CDS::DiscoverActorGroup::b->{"status"} cmp $CDS::DiscoverActorGroup::a->{"status"} 0 0 0
9538 0 return CDS::ActorGroup->new($members, $parser->entrustedActorsRevision, $entrustedActors), [@cards], [grep { $_->{attachedToUs} } values %{$o->{nodesByUrl}}];
9539 }
9540  
9541 sub node {
9542 0 ▶ my $o = shift;
Subroutine node: not called CC=4 SCAR=30.0
9543 0 ▶ my $actorHash = shift; die 'wrong type '.ref($actorHash).' for $actorHash' if defined $actorHash && ref $actorHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $actorHash and ref $actorHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $actorHash and ref $actorHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $actorHash and ref $actorHash ne "CDS::Hash"
defined $actorHash ref $actorHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $actorHashB= ref $actorHash ne "CDS::Hash"
ABresult
0X0
100
111
9544 0 my $storeUrl = shift;
9545 # private
9546 0 my $url = $storeUrl.'/accounts/'.$actorHash->hex;
9547 0 my $node = $o->{nodesByUrl}->{$url};
9548 0 ▶ return $node if $node;
Branch: 1 branch
BranchTrueFalseTotal
if $node 0 0 0
9549 0 return $o->{nodesByUrl}->{$url} = CDS::DiscoverActorGroup::Node->new($o, $actorHash, $storeUrl);
9550 }
9551  
9552 sub covers {
9553 0 ▶ my $o = shift;
Subroutine covers: not called CC=3 SCAR=24.8
9554 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
9555 0 $o->{coverage}->{$hash->bytes} }
9556  
9557 sub extend {
9558 0 ▶ my $o = shift;
Subroutine extend: not called CC=15 SCAR=54.8
9559  
9560 # Start with the newest node
9561 0 my $mainNode;
9562 0 my $mainRevision = -1;
9563 0 for my $node (values %{$o->{nodesByUrl}}) {
9564 0 ▶ next if ! $node->{attachedToUs};
Branch: 1 branch
BranchTrueFalseTotal
unless $node->{"attachedToUs"} 0 0 0
9565 0 ▶ next if $node->{revision} <= $mainRevision;
Branch: 1 branch
BranchTrueFalseTotal
if $node->{"revision"} <= $mainRevision 0 0 0
9566 0 $mainNode = $node;
9567 0 $mainRevision = $node->{revision};
9568 }
9569  
9570 0 ▶ return 0 if ! $mainNode;
Branch: 1 branch
BranchTrueFalseTotal
unless $mainNode 0 0 0
9571  
9572 # Reset the reachable flag
9573 0 for my $node (values %{$o->{nodesByUrl}}) {
9574 0 $node->{reachable} = 0;
9575 }
9576 0 $mainNode->{reachable} = 1;
9577  
9578 # Traverse the graph along active links to find accounts to discover.
9579 0 my @toDiscover;
9580 0 my @toCheck = ($mainNode);
9581 0 while (1) {
9582 0 ▶ my $currentNode = shift(@toCheck) // last;
Condition0%0/2
shift @toCheck // (last)
l!l
00
MC/DC0%0/1
shift @toCheck // (last)
shift @toCheck
Truth table0%0/2
A
A= shift @toCheck
Aresult
11
00
9583 0 for my $link (@{$currentNode->{links}}) {
9584 0 my $node = $link->{node};
9585 0 ▶ next if $node->{reachable};
Branch: 1 branch
BranchTrueFalseTotal
if $node->{"reachable"} 0 0 0
9586 0 ▶ my $prospectiveStatus = $link->{revision} > $node->{revision} ? $link->{status} : $node->{status};
Branch: 1 branch
BranchTrueFalseTotal
$link->{'revision'} > $node->{'revision'} ? : 0 0 0
9587 0 ▶ next if $prospectiveStatus ne 'active';
Branch: 1 branch
BranchTrueFalseTotal
if $prospectiveStatus ne "active" 0 0 0
9588 0 $node->{reachable} = 1;
9589 0 ▶ push @toCheck, $node if $node->{attachedToUs};
Branch: 1 branch
BranchTrueFalseTotal
if $node->{"attachedToUs"} 0 0 0
9590 0 ▶ push @toDiscover, $node if ! $node->{attachedToUs};
Branch: 1 branch
BranchTrueFalseTotal
unless $node->{"attachedToUs"} 0 0 0
9591 }
9592 }
9593  
9594 # Discover these accounts
9595 0 my $hasChanges = 0;
9596 0 for my $node (sort { $b->{revision} <=> $a->{revision} } @toDiscover) {
9597 0 $node->discover;
9598 0 ▶ next if ! $node->{attachedToUs};
Branch: 1 branch
BranchTrueFalseTotal
unless $node->{"attachedToUs"} 0 0 0
9599 0 $hasChanges = 1;
9600 }
9601  
9602 0 return $hasChanges;
9603 }
9604  
9605 package CDS::DiscoverActorGroup::Card;
9606  
9607 sub new {
9608 0 ▶ my $class = shift;
Subroutine new: not called CC=9 SCAR=45.0
9609 0 my $storeUrl = shift;
9610 0 ▶ my $actorOnStore = shift; die 'wrong type '.ref($actorOnStore).' for $actorOnStore' if defined $actorOnStore && ref $actorOnStore ne 'CDS::ActorOnStore';
Branch: 1 branch
BranchTrueFalseTotal
if defined $actorOnStore and ref $actorOnStore ne "CDS::ActorOnStore" 0 0 0
Condition0%0/3
defined $actorOnStore and ref $actorOnStore ne "CDS::ActorOnStore"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $actorOnStore and ref $actorOnStore ne "CDS::ActorOnStore"
defined $actorOnStore ref $actorOnStore ne "CDS::ActorOnStore"
Truth table0%0/3
A and B
A= defined $actorOnStoreB= ref $actorOnStore ne "CDS::ActorOnStore"
ABresult
0X0
100
111
9611 0 ▶ my $envelopeHash = shift; die 'wrong type '.ref($envelopeHash).' for $envelopeHash' if defined $envelopeHash && ref $envelopeHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $envelopeHash and ref $envelopeHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $envelopeHash and ref $envelopeHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $envelopeHash and ref $envelopeHash ne "CDS::Hash"
defined $envelopeHash ref $envelopeHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $envelopeHashB= ref $envelopeHash ne "CDS::Hash"
ABresult
0X0
100
111
9612 0 ▶ my $envelope = shift; die 'wrong type '.ref($envelope).' for $envelope' if defined $envelope && ref $envelope ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $envelope and ref $envelope ne "CDS::Record" 0 0 0
Condition0%0/3
defined $envelope and ref $envelope ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $envelope and ref $envelope ne "CDS::Record"
defined $envelope ref $envelope ne "CDS::Record"
Truth table0%0/3
A and B
A= defined $envelopeB= ref $envelope ne "CDS::Record"
ABresult
0X0
100
111
9613 0 ▶ my $cardHash = shift; die 'wrong type '.ref($cardHash).' for $cardHash' if defined $cardHash && ref $cardHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $cardHash and ref $cardHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $cardHash and ref $cardHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $cardHash and ref $cardHash ne "CDS::Hash"
defined $cardHash ref $cardHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $cardHashB= ref $cardHash ne "CDS::Hash"
ABresult
0X0
100
111
9614 0 my $card = shift;
9615  
9616 0 return bless {
9617 storeUrl => $storeUrl,
9618 actorOnStore => $actorOnStore,
9619 envelopeHash => $envelopeHash,
9620 envelope => $envelope,
9621 cardHash => $cardHash,
9622 card => $card,
9623 };
9624 }
9625  
9626 0 ▶sub storeUrl { shift->{storeUrl} }
Subroutine storeUrl: not called CC=1 SCAR=6.9
9627 0 ▶sub actorOnStore { shift->{actorOnStore} }
Subroutine actorOnStore: not called CC=1 SCAR=6.9
9628 0 ▶sub envelopeHash { shift->{envelopeHash} }
Subroutine envelopeHash: not called CC=1 SCAR=6.9
9629 0 ▶sub envelope { shift->{envelope} }
Subroutine envelope: not called CC=1 SCAR=6.9
9630 0 ▶sub cardHash { shift->{cardHash} }
Subroutine cardHash: not called CC=1 SCAR=6.9
9631 0 ▶sub card { shift->{card} }
Subroutine card: not called CC=1 SCAR=6.9
9632  
9633 package CDS::DiscoverActorGroup::Link;
9634  
9635 sub new {
9636 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
9637 0 my $node = shift;
9638 0 my $revision = shift;
9639 0 my $status = shift;
9640  
9641 0 bless {
9642 node => $node,
9643 revision => $revision,
9644 status => $status,
9645 };
9646 }
9647  
9648 0 ▶sub node { shift->{node} }
Subroutine node: not called CC=1 SCAR=6.9
9649 0 ▶sub revision { shift->{revision} }
Subroutine revision: not called CC=1 SCAR=6.9
9650 0 ▶sub status { shift->{status} }
Subroutine status: not called CC=1 SCAR=6.9
9651  
9652 package CDS::DiscoverActorGroup::Node;
9653  
9654 sub new {
9655 0 ▶ my $class = shift;
Subroutine new: not called CC=3 SCAR=24.8
9656 0 my $discoverer = shift;
9657 0 ▶ my $actorHash = shift; die 'wrong type '.ref($actorHash).' for $actorHash' if defined $actorHash && ref $actorHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $actorHash and ref $actorHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $actorHash and ref $actorHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $actorHash and ref $actorHash ne "CDS::Hash"
defined $actorHash ref $actorHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $actorHashB= ref $actorHash ne "CDS::Hash"
ABresult
0X0
100
111
9658 0 my $storeUrl = shift;
9659  
9660 0 return bless {
9661 discoverer => $discoverer,
9662 actorHash => $actorHash,
9663 storeUrl => $storeUrl,
9664 revision => -1,
9665 status => 'idle',
9666 reachable => 0, # whether this node is reachable from the main node
9667 store => undef,
9668 actorOnStore => undef,
9669 links => [], # all links found in the cards
9670 attachedToUs => 0, # whether the account belongs to us
9671 cardsRead => 0,
9672 cards => [],
9673 };
9674 }
9675  
9676 sub cards {
9677 0 ▶ my $o = shift;
Subroutine cards: not called CC=1 SCAR=6.9
9678 0 @{$o->{cards}} }
9679 sub isActive {
9680 0 ▶ my $o = shift;
Subroutine isActive: not called CC=1 SCAR=6.9
9681 0 $o->{status} eq 'active' }
9682 sub isActiveOrIdle {
9683 0 ▶ my $o = shift;
Subroutine isActiveOrIdle: not called CC=2 SCAR=17.9
9684 0 ▶ $o->{status} eq 'active' || $o->{status} eq 'idle' }
Branch: 1 branch
BranchTrueFalseTotal
$o->{"status"} eq "active" or $o->{"status"} eq "idle" 0 0 0
9685  
9686 0 ▶sub actorHash { shift->{actorHash} }
Subroutine actorHash: not called CC=1 SCAR=6.9
9687 0 ▶sub storeUrl { shift->{storeUrl} }
Subroutine storeUrl: not called CC=1 SCAR=6.9
9688 0 ▶sub revision { shift->{revision} }
Subroutine revision: not called CC=1 SCAR=6.9
9689 0 ▶sub status { shift->{status} }
Subroutine status: not called CC=1 SCAR=6.9
9690 0 ▶sub attachedToUs { shift->{attachedToUs} }
Subroutine attachedToUs: not called CC=1 SCAR=6.9
9691 sub links {
9692 0 ▶ my $o = shift;
Subroutine links: not called CC=1 SCAR=6.9
9693 0 @{$o->{links}} }
9694  
9695 sub discover {
9696 0 ▶ my $o = shift;
Subroutine discover: not called CC=1 SCAR=6.9
9697  
9698 #-- discover ++ $o->{actorHash}->hex
9699 0 $o->readCards;
9700 0 $o->attach;
9701 }
9702  
9703 sub readCards {
9704 0 ▶ my $o = shift;
Subroutine readCards: not called CC=18 SCAR=58.3
9705  
9706 0 ▶ return if $o->{cardsRead};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"cardsRead"} 0 0 0
9707 0 $o->{cardsRead} = 1;
9708 #-- read cards of ++ $o->{actorHash}->hex
9709  
9710 # Get the store
9711 0 ▶ my $store = $o->{discoverer}->{delegate}->onDiscoverActorGroupVerifyStore($o->{storeUrl}, $o->{actorHash}) // return;
Condition0%0/2
$o->{"discoverer"}{"delegate"}->onDiscoverActorGroupVerifyStore($o->{"storeUrl"}, $o->{"actorHash"}) // (return)
l!l
00
MC/DC0%0/1
$o->{"discoverer"}{"delegate"}->onDiscoverActorGroupVerifyStore($o->{"storeUrl"}, $o->{"actorHash"}) // (return)
$o->{"discoverer"}{"delegate"}->onDiscoverActorGroupVerifyStore($o->{"storeUrl"}, $o->{"actorHash"})
Truth table0%0/2
A
A= $o->{"discoverer"}{"delegate"}->onDiscoverActorGroupVerifyStore($o->{"storeUrl"}, $o->{"actorHash"})
Aresult
11
00
9712  
9713 # Get the public key if necessary
9714 0 ▶ if (! $o->{actorOnStore}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($o->{"actorOnStore"}) 0 0 0
9715 0 my $publicKey = $o->{discoverer}->{knownPublicKeys}->{$o->{actorHash}->bytes};
9716 0 ▶ if (! $publicKey) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($publicKey) 0 0 0
9717 0 my ($downloadedPublicKey, $invalidReason, $storeError) = $o->{discoverer}->{keyPair}->getPublicKey($o->{actorHash}, $store);
9718 0 ▶ return $o->{discoverer}->{delegate}->onDiscoverActorGroupStoreError($store, $storeError) if defined $storeError;
Branch: 1 branch
BranchTrueFalseTotal
if defined $storeError 0 0 0
9719 0 ▶ return $o->{discoverer}->{delegate}->onDiscoverActorGroupInvalidPublicKey($o->{actorHash}, $store, $invalidReason) if defined $invalidReason;
Branch: 1 branch
BranchTrueFalseTotal
if defined $invalidReason 0 0 0
9720 0 $publicKey = $downloadedPublicKey;
9721 }
9722  
9723 0 $o->{actorOnStore} = CDS::ActorOnStore->new($publicKey, $store);
9724 }
9725  
9726 # List the public box
9727 0 my ($hashes, $storeError) = $store->list($o->{actorHash}, 'public', 0, $o->{discoverer}->{keyPair});
9728 0 ▶ return $o->{discoverer}->{delegate}->onDiscoverActorGroupStoreError($store, $storeError) if defined $storeError;
Branch: 1 branch
BranchTrueFalseTotal
if defined $storeError 0 0 0
9729  
9730 0 for my $envelopeHash (@$hashes) {
9731 # Open the envelope
9732 0 my ($object, $storeError) = $store->get($envelopeHash, $o->{discoverer}->{keyPair});
9733 0 ▶ return $o->{discoverer}->{delegate}->onDiscoverActorGroupStoreError($store, $storeError) if defined $storeError;
Branch: 1 branch
BranchTrueFalseTotal
if defined $storeError 0 0 0
9734 0 ▶ if (! $object) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($object) 0 0 0
9735 0 $o->{discoverer}->{delegate}->onDiscoverActorGroupInvalidCard($o->{actorOnStore}, $envelopeHash, 'Envelope object not found.');
9736 0 next;
9737 }
9738  
9739 0 my $envelope = CDS::Record->fromObject($object);
9740 0 ▶ if (! $envelope) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($envelope) 0 0 0
9741 0 $o->{discoverer}->{delegate}->onDiscoverActorGroupInvalidCard($o->{actorOnStore}, $envelopeHash, 'Envelope is not a record.');
9742 0 next;
9743 }
9744  
9745 0 my $cardHash = $envelope->child('content')->hashValue;
9746 0 ▶ if (! $cardHash) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($cardHash) 0 0 0
9747 0 $o->{discoverer}->{delegate}->onDiscoverActorGroupInvalidCard($o->{actorOnStore}, $envelopeHash, 'Missing content hash.');
9748 0 next;
9749 }
9750  
9751 0 ▶ if (! CDS->verifyEnvelopeSignature($envelope, $o->{actorOnStore}->publicKey, $cardHash)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ("CDS"->verifyEnvelopeSignature($envelope, $o->{"actorOnStore"}->publicKey, $cardHash)) 0 0 0
9752 0 $o->{discoverer}->{delegate}->onDiscoverActorGroupInvalidCard($o->{actorOnStore}, $envelopeHash, 'Invalid signature.');
9753 0 next;
9754 }
9755  
9756 # Read the card
9757 0 my ($cardObject, $storeError1) = $store->get($cardHash, $o->{discoverer}->{keyPair});
9758 0 ▶ return $o->{discoverer}->{delegate}->onDiscoverActorGroupStoreError($store, $storeError) if defined $storeError1;
Branch: 1 branch
BranchTrueFalseTotal
if defined $storeError1 0 0 0
9759 0 ▶ if (! $cardObject) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($cardObject) 0 0 0
9760 0 $o->{discoverer}->{delegate}->onDiscoverActorGroupInvalidCard($o->{actorOnStore}, $envelopeHash, 'Card object not found.');
9761 0 next;
9762 }
9763  
9764 0 my $card = CDS::Record->fromObject($cardObject);
9765 0 ▶ if (! $card) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($card) 0 0 0
9766 0 $o->{discoverer}->{delegate}->onDiscoverActorGroupInvalidCard($o->{actorOnStore}, $envelopeHash, 'Card is not a record.');
9767 0 next;
9768 }
9769  
9770 # Add the card to the list of cards
9771 0 push @{$o->{cards}}, CDS::DiscoverActorGroup::Card->new($o->{storeUrl}, $o->{actorOnStore}, $envelopeHash, $envelope, $cardHash, $card);
9772  
9773 # Parse the account list
9774 0 my $builder = CDS::ActorGroupBuilder->new;
9775 0 $builder->parseMembers($card->child('actor group'), 0);
9776 0 for my $member ($builder->members) {
9777 0 my $node = $o->{discoverer}->node($member->hash, $member->storeUrl);
9778 #-- new link ++ $o->{actorHash}->hex ++ $status ++ $hash->hex
9779 0 push @{$o->{links}}, CDS::DiscoverActorGroup::Link->new($node, $member->revision, $member->status);
9780 }
9781 }
9782 }
9783  
9784 sub attach {
9785 0 ▶ my $o = shift;
Subroutine attach: not called CC=4 SCAR=30.0
9786  
9787 0 ▶ return if $o->{attachedToUs};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"attachedToUs"} 0 0 0
9788 0 ▶ return if ! $o->hasLinkToUs;
Branch: 1 branch
BranchTrueFalseTotal
unless $o->hasLinkToUs 0 0 0
9789  
9790 # Attach this node
9791 0 $o->{attachedToUs} = 1;
9792  
9793 # Merge all links
9794 0 for my $link (@{$o->{links}}) {
9795 0 $link->{node}->merge($link->{revision}, $link->{status});
9796 }
9797  
9798 # Add the hash to the coverage
9799 0 $o->{discoverer}->{coverage}->{$o->{actorHash}->bytes} = 1;
9800 }
9801  
9802 sub merge {
9803 0 ▶ my $o = shift;
Subroutine merge: not called CC=2 SCAR=17.9
9804 0 my $revision = shift;
9805 0 my $status = shift;
9806  
9807 0 ▶ return if $o->{revision} >= $revision;
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"revision"} >= $revision 0 0 0
9808 0 $o->{revision} = $revision;
9809 0 $o->{status} = $status;
9810 }
9811  
9812 sub hasLinkToUs {
9813 0 ▶ my $o = shift;
Subroutine hasLinkToUs: not called CC=4 SCAR=30.0
9814  
9815 0 ▶ return 1 if $o->{discoverer}->covers($o->{actorHash});
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"discoverer"}->covers($o->{"actorHash"}) 0 0 0
9816 0 for my $link (@{$o->{links}}) {
9817 0 ▶ return 1 if $o->{discoverer}->covers($link->{node}->{actorHash});
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"discoverer"}->covers($link->{"node"}{"actorHash"}) 0 0 0
9818 }
9819 0 return;
9820 }
9821  
9822 package CDS::Document;
9823  
9824 sub new {
9825 0 ▶ my $class = shift;
Subroutine new: not called CC=3 SCAR=24.8
9826 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
9827 0 my $store = shift;
9828  
9829 0 my $o = bless {
9830 keyPair => $keyPair,
9831 unsaved => CDS::Unsaved->new($store),
9832 itemsBySelector => {},
9833 parts => {},
9834 hasPartsToMerge => 0,
9835 }, $class;
9836  
9837 0 $o->{root} = CDS::Selector->root($o);
9838 0 $o->{changes} = CDS::Document::Part->new;
9839 0 return $o;
9840 }
9841  
9842 0 ▶sub keyPair { shift->{keyPair} }
Subroutine keyPair: not called CC=1 SCAR=6.9
9843 0 ▶sub unsaved { shift->{unsaved} }
Subroutine unsaved: not called CC=1 SCAR=6.9
9844 sub parts {
9845 0 ▶ my $o = shift;
Subroutine parts: not called CC=1 SCAR=6.9
9846 0 values %{$o->{parts}} }
9847 0 ▶sub hasPartsToMerge { shift->{hasPartsToMerge} }
Subroutine hasPartsToMerge: not called CC=1 SCAR=6.9
9848  
9849 ### Items
9850  
9851 0 ▶sub root { shift->{root} }
Subroutine root: not called CC=1 SCAR=6.9
9852 sub rootItem {
9853 0 ▶ my $o = shift;
Subroutine rootItem: not called CC=1 SCAR=6.9
9854 0 $o->getOrCreate($o->{root}) }
9855  
9856 sub get {
9857 0 ▶ my $o = shift;
Subroutine get: not called CC=3 SCAR=24.8
9858 0 ▶ my $selector = shift; die 'wrong type '.ref($selector).' for $selector' if defined $selector && ref $selector ne 'CDS::Selector';
Branch: 1 branch
BranchTrueFalseTotal
if defined $selector and ref $selector ne "CDS::Selector" 0 0 0
Condition0%0/3
defined $selector and ref $selector ne "CDS::Selector"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $selector and ref $selector ne "CDS::Selector"
defined $selector ref $selector ne "CDS::Selector"
Truth table0%0/3
A and B
A= defined $selectorB= ref $selector ne "CDS::Selector"
ABresult
0X0
100
111
9859 0 $o->{itemsBySelector}->{$selector->{id}} }
9860  
9861 sub getOrCreate {
9862 0 ▶ my $o = shift;
Subroutine getOrCreate: not called CC=4 SCAR=30.0
9863 0 ▶ my $selector = shift; die 'wrong type '.ref($selector).' for $selector' if defined $selector && ref $selector ne 'CDS::Selector';
Branch: 1 branch
BranchTrueFalseTotal
if defined $selector and ref $selector ne "CDS::Selector" 0 0 0
Condition0%0/3
defined $selector and ref $selector ne "CDS::Selector"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $selector and ref $selector ne "CDS::Selector"
defined $selector ref $selector ne "CDS::Selector"
Truth table0%0/3
A and B
A= defined $selectorB= ref $selector ne "CDS::Selector"
ABresult
0X0
100
111
9864  
9865 0 my $item = $o->{itemsBySelector}->{$selector->{id}};
9866 0 ▶ $o->{itemsBySelector}->{$selector->{id}} = $item = CDS::Document::Item->new($selector) if ! $item;
Branch: 1 branch
BranchTrueFalseTotal
unless $item 0 0 0
9867 0 return $item;
9868 }
9869  
9870 sub prune {
9871 0 ▶ my $o = shift;
Subroutine prune: not called CC=1 SCAR=6.9
9872 0 $o->rootItem->pruneTree; }
9873  
9874 ### Merging
9875  
9876 sub merge {
9877 0 ▶ my $o = shift;
Subroutine merge: not called CC=4 SCAR=30.0
9878  
9879 0 for my $hashAndKey (@_) {
9880 0 ▶ next if ! $hashAndKey;
Branch: 1 branch
BranchTrueFalseTotal
unless $hashAndKey 0 0 0
9881 0 ▶ next if $o->{parts}->{$hashAndKey->hash->bytes};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"parts"}{$hashAndKey->hash->bytes} 0 0 0
9882 0 my $part = CDS::Document::Part->new;
9883 0 $part->{hashAndKey} = $hashAndKey;
9884 0 $o->{parts}->{$hashAndKey->hash->bytes} = $part;
9885 0 $o->{hasPartsToMerge} = 1;
9886 }
9887 }
9888  
9889 sub read {
9890 0 ▶ my $o = shift;
Subroutine read: not called CC=11 SCAR=48.8
9891  
9892 0 ▶ return 1 if ! $o->{hasPartsToMerge};
Branch: 1 branch
BranchTrueFalseTotal
unless $o->{"hasPartsToMerge"} 0 0 0
9893  
9894 # Load the parts
9895 0 for my $part (values %{$o->{parts}}) {
9896 0 ▶ next if $part->{isMerged};
Branch: 1 branch
BranchTrueFalseTotal
if $part->{"isMerged"} 0 0 0
9897 0 ▶ next if $part->{loadedRecord};
Branch: 1 branch
BranchTrueFalseTotal
if $part->{"loadedRecord"} 0 0 0
9898  
9899 0 my ($record, $object, $invalidReason, $storeError) = $o->{keyPair}->getAndDecryptRecord($part->{hashAndKey}, $o->{unsaved});
9900 0 ▶ return if defined $storeError;
Branch: 1 branch
BranchTrueFalseTotal
if defined $storeError 0 0 0
9901  
9902 0 ▶ delete $o->{parts}->{$part->{hashAndKey}->hash->bytes} if defined $invalidReason;
Branch: 1 branch
BranchTrueFalseTotal
if defined $invalidReason 0 0 0
9903 0 $part->{loadedRecord} = $record;
9904 }
9905  
9906 # Merge the loaded parts
9907 0 for my $part (values %{$o->{parts}}) {
9908 0 ▶ next if $part->{isMerged};
Branch: 1 branch
BranchTrueFalseTotal
if $part->{"isMerged"} 0 0 0
9909 0 ▶ next if ! $part->{loadedRecord};
Branch: 1 branch
BranchTrueFalseTotal
unless $part->{"loadedRecord"} 0 0 0
9910 0 ▶ my $oldFormat = $part->{loadedRecord}->child('client')->textValue =~ /0.19/ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$part->{'loadedRecord'}->child('client')->textValue =~ /0.19/ ? : 0 0 0
9911 0 $o->mergeNode($part, $o->{root}, $part->{loadedRecord}->child('root'), $oldFormat);
9912 0 delete $part->{loadedRecord};
9913 0 $part->{isMerged} = 1;
9914 }
9915  
9916 0 $o->{hasPartsToMerge} = 0;
9917 0 return 1;
9918 }
9919  
9920 sub mergeNode {
9921 0 ▶ my $o = shift;
Subroutine mergeNode: not called CC=8 SCAR=42.8
9922 0 my $part = shift;
9923 0 ▶ my $selector = shift; die 'wrong type '.ref($selector).' for $selector' if defined $selector && ref $selector ne 'CDS::Selector';
Branch: 1 branch
BranchTrueFalseTotal
if defined $selector and ref $selector ne "CDS::Selector" 0 0 0
Condition0%0/3
defined $selector and ref $selector ne "CDS::Selector"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $selector and ref $selector ne "CDS::Selector"
defined $selector ref $selector ne "CDS::Selector"
Truth table0%0/3
A and B
A= defined $selectorB= ref $selector ne "CDS::Selector"
ABresult
0X0
100
111
9924 0 ▶ my $record = shift; die 'wrong type '.ref($record).' for $record' if defined $record && ref $record ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $record and ref $record ne "CDS::Record" 0 0 0
Condition0%0/3
defined $record and ref $record ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $record and ref $record ne "CDS::Record"
defined $record ref $record ne "CDS::Record"
Truth table0%0/3
A and B
A= defined $recordB= ref $record ne "CDS::Record"
ABresult
0X0
100
111
9925 0 my $oldFormat = shift;
9926  
9927 # Prepare
9928 0 my @children = $record->children;
9929 0 ▶ return if ! scalar @children;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @children 0 0 0
9930 0 my $item = $o->getOrCreate($selector);
9931  
9932 # Merge value
9933 0 my $valueRecord = shift @children;
9934 0 ▶ $valueRecord = $valueRecord->firstChild if $oldFormat;
Branch: 1 branch
BranchTrueFalseTotal
if $oldFormat 0 0 0
9935 0 $item->mergeValue($part, $valueRecord->asInteger, $valueRecord);
9936  
9937 # Merge children
9938 0 for my $child (@children) { $o->mergeNode($part, $selector->child($child->bytes), $child, $oldFormat); }
9939 }
9940  
9941 # *** Saving
9942 # Call $document->save at any time to save the current state (if necessary).
9943  
9944 # This is called by the items whenever some data changes.
9945 sub dataChanged {
9946 0 ▶ my $o = shift;
Subroutine dataChanged: not called CC=1 SCAR=6.9
9947 }
9948  
9949 sub save {
9950 0 ▶ my $o = shift;
Subroutine save: not called CC=13 SCAR=52.0
9951  
9952 0 $o->{unsaved}->startSaving;
9953 0 my $revision = CDS->now;
9954 0 my $newPart = undef;
9955  
9956 #-- saving ++ $o->{changes}->{count}
9957 0 ▶ if ($o->{changes}->{count}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"changes"}{"count"}) 0 0 0
9958 # Take the changes
9959 0 $newPart = $o->{changes};
9960 0 $o->{changes} = CDS::Document::Part->new;
9961  
9962 # Select all parts smaller than 2 * changes
9963 0 $newPart->{selected} = 1;
9964 0 my $count = $newPart->{count};
9965 0 while (1) {
9966 0 my $addedPart = 0;
9967 0 for my $part (values %{$o->{parts}}) {
9968 #-- candidate ++ $part->{count} ++ $count
9969 0 ▶ next if ! $part->{isMerged} || $part->{selected} || $part->{count} >= $count * 2;
Branch: 1 branch
BranchTrueFalseTotal
if not $part->{"isMerged"} or $part->{"selected"} or $part->{"count"} >= $count * 2 0 0 0
Condition0%0/6
not $part->{"isMerged"} or $part->{"selected"} or $part->{"count"} >= $count * 2
l!l&&r!l&&!r
000
not $part->{"isMerged"} or $part->{"selected"}
l!l&&r!l&&!r
000
MC/DC0%0/3
not $part->{"isMerged"} or $part->{"selected"} or $part->{"count"} >= $count * 2
not $part->{"isMerged"} $part->{"selected"} $part->{"count"} >= $count * 2
Truth table0%0/4
not(A) or B or C
A= not $part->{"isMerged"}B= $part->{"selected"}C= $part->{"count"} >= $count * 2
ABCresult
1XX1
01X1
0011
0000
9970 0 $count += $part->{count};
9971 0 $part->{selected} = 1;
9972 0 $addedPart = 1;
9973 }
9974  
9975 0 ▶ last if ! $addedPart;
Branch: 1 branch
BranchTrueFalseTotal
unless $addedPart 0 0 0
9976 }
9977  
9978 # Include the selected items
9979 0 for my $item (values %{$o->{itemsBySelector}}) {
9980 0 ▶ next if ! $item->{part}->{selected};
Branch: 1 branch
BranchTrueFalseTotal
unless $item->{"part"}{"selected"} 0 0 0
9981 0 $item->setPart($newPart);
9982 0 $item->createSaveRecord;
9983 }
9984  
9985 0 my $record = CDS::Record->new;
9986 0 $record->add('created')->addInteger($revision);
9987 0 $record->add('client')->add(CDS->version);
9988 0 $record->addRecord($o->rootItem->createSaveRecord);
9989  
9990 # Detach the save records
9991 0 for my $item (values %{$o->{itemsBySelector}}) {
9992 0 $item->detachSaveRecord;
9993 }
9994  
9995 # Serialize and encrypt the record
9996 0 my $key = CDS->randomKey;
9997 0 my $newObject = $record->toObject->crypt($key);
9998 0 $newPart->{hashAndKey} = CDS::HashAndKey->new($newObject->calculateHash, $key);
9999 0 $newPart->{isMerged} = 1;
10000 0 $newPart->{selected} = 0;
10001 0 $o->{parts}->{$newPart->{hashAndKey}->hash->bytes} = $newPart;
10002 #-- added ++ $o->{parts} ++ scalar keys %{$o->{parts}} ++ $newPart->{count}
10003 0 $o->{unsaved}->{savingState}->addObject($newPart->{hashAndKey}->hash, $newObject);
10004 }
10005  
10006 # Remove obsolete parts
10007 0 my $obsoleteParts = [];
10008 0 for my $part (values %{$o->{parts}}) {
10009 0 ▶ next if ! $part->{isMerged};
Branch: 1 branch
BranchTrueFalseTotal
unless $part->{"isMerged"} 0 0 0
10010 0 ▶ next if $part->{count};
Branch: 1 branch
BranchTrueFalseTotal
if $part->{"count"} 0 0 0
10011 0 push @$obsoleteParts, $part;
10012 0 delete $o->{parts}->{$part->{hashAndKey}->hash->bytes};
10013 }
10014  
10015 # Commit
10016 #-- saving done ++ $revision ++ $newPart ++ $obsoleteParts
10017 0 return $o->savingDone($revision, $newPart, $obsoleteParts);
10018 }
10019  
10020 package CDS::Document::Item;
10021  
10022 sub new {
10023 0 ▶ my $class = shift;
Subroutine new: not called CC=5 SCAR=34.0
10024 0 ▶ my $selector = shift; die 'wrong type '.ref($selector).' for $selector' if defined $selector && ref $selector ne 'CDS::Selector';
Branch: 1 branch
BranchTrueFalseTotal
if defined $selector and ref $selector ne "CDS::Selector" 0 0 0
Condition0%0/3
defined $selector and ref $selector ne "CDS::Selector"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $selector and ref $selector ne "CDS::Selector"
defined $selector ref $selector ne "CDS::Selector"
Truth table0%0/3
A and B
A= defined $selectorB= ref $selector ne "CDS::Selector"
ABresult
0X0
100
111
10025  
10026 0 my $parentSelector = $selector->parent;
10027 0 ▶ my $parent = $parentSelector ? $selector->document->getOrCreate($parentSelector) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$parentSelector ? : 0 0 0
10028  
10029 0 my $o = bless {
10030 document => $selector->document,
10031 selector => $selector,
10032 parent => $parent,
10033 children => [],
10034 part => undef,
10035 revision => 0,
10036 record => CDS::Record->new
10037 };
10038  
10039 0 ▶ push @{$parent->{children}}, $o if $parent;
Branch: 1 branch
BranchTrueFalseTotal
if $parent 0 0 0
10040 0 return $o;
10041 }
10042  
10043 sub pruneTree {
10044 0 ▶ my $o = shift;
Subroutine pruneTree: not called CC=5 SCAR=34.0
10045  
10046 # Try to remove children
10047 0 for my $child (@{$o->{children}}) { $child->pruneTree; }
10048  
10049 # Don't remove the root item
10050 0 ▶ return if ! $o->{parent};
Branch: 1 branch
BranchTrueFalseTotal
unless $o->{"parent"} 0 0 0
10051  
10052 # Don't remove if the item has children, or a value
10053 0 ▶ return if scalar @{$o->{children}};
Branch: 1 branch
BranchTrueFalseTotal
if scalar @{$o->{"children"};} 0 0 0
10054 0 ▶ return if $o->{revision} > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"revision"} > 0 0 0 0
10055  
10056 # Remove this from the tree
10057 0 $o->{parent}->{children} = [grep { $_ != $o } @{$o->{parent}->{children}}];
10058  
10059 # Remove this from the document hash
10060 0 delete $o->{document}->{itemsBySelector}->{$o->{selector}->{id}};
10061 }
10062  
10063 # Low-level part change.
10064 sub setPart {
10065 0 ▶ my $o = shift;
Subroutine setPart: not called CC=3 SCAR=24.8
10066 0 my $part = shift;
10067  
10068 0 ▶ $o->{part}->{count} -= 1 if $o->{part};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"part"} 0 0 0
10069 0 $o->{part} = $part;
10070 0 ▶ $o->{part}->{count} += 1 if $o->{part};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"part"} 0 0 0
10071 }
10072  
10073 # Merge a value
10074  
10075 sub mergeValue {
10076 0 ▶ my $o = shift;
Subroutine mergeValue: not called CC=7 SCAR=40.3
10077 0 my $part = shift;
10078 0 my $revision = shift;
10079 0 ▶ my $record = shift; die 'wrong type '.ref($record).' for $record' if defined $record && ref $record ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $record and ref $record ne "CDS::Record" 0 0 0
Condition0%0/3
defined $record and ref $record ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $record and ref $record ne "CDS::Record"
defined $record ref $record ne "CDS::Record"
Truth table0%0/3
A and B
A= defined $recordB= ref $record ne "CDS::Record"
ABresult
0X0
100
111
10080  
10081 0 ▶ return if $revision <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $revision <= 0 0 0 0
10082 0 ▶ return if $revision < $o->{revision};
Branch: 1 branch
BranchTrueFalseTotal
if $revision < $o->{"revision"} 0 0 0
10083 0 ▶ return if $revision == $o->{revision} && $part->{size} < $o->{part}->{size};
Branch: 1 branch
BranchTrueFalseTotal
if $revision == $o->{"revision"} and $part->{"size"} < $o->{"part"}{"size"} 0 0 0
Condition0%0/3
$revision == $o->{"revision"} and $part->{"size"} < $o->{"part"}{"size"}
!ll&&!rl&&r
000
MC/DC0%0/2
$revision == $o->{"revision"} and $part->{"size"} < $o->{"part"}{"size"}
$revision == $o->{"revision"} $part->{"size"} < $o->{"part"}{"size"}
Truth table0%0/3
A and B
A= $revision == $o->{"revision"}B= $part->{"size"} < $o->{"part"}{"size"}
ABresult
0X0
100
111
10084 0 $o->setPart($part);
10085 0 $o->{revision} = $revision;
10086 0 $o->{record} = $record;
10087 0 $o->{document}->dataChanged;
10088 0 return 1;
10089 }
10090  
10091 sub forget {
10092 0 ▶ my $o = shift;
Subroutine forget: not called CC=2 SCAR=17.9
10093  
10094 0 ▶ return if $o->{revision} <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"revision"} <= 0 0 0 0
10095 0 $o->{revision} = 0;
10096 0 $o->{record} = CDS::Record->new;
10097 0 $o->setPart;
10098 }
10099  
10100 # Saving
10101  
10102 sub createSaveRecord {
10103 0 ▶ my $o = shift;
Subroutine createSaveRecord: not called CC=5 SCAR=34.0
10104  
10105 0 ▶ return $o->{saveRecord} if $o->{saveRecord};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"saveRecord"} 0 0 0
10106 0 ▶ $o->{saveRecord} = $o->{parent} ? $o->{parent}->createSaveRecord->add($o->{selector}->{label}) : CDS::Record->new('root');
Branch: 1 branch
BranchTrueFalseTotal
$o->{'parent'} ? : 0 0 0
10107 0 ▶ if ($o->{part}->{selected}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{'part'}{'selected'}) { } 0 0 0
10108 0 ▶ CDS->log('Item saving zero revision of ', $o->{selector}->label) if $o->{revision} <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"revision"} <= 0 0 0 0
10109 0 $o->{saveRecord}->addInteger($o->{revision})->addRecord($o->{record}->children);
10110 } else {
10111 0 $o->{saveRecord}->add('');
10112 }
10113 0 return $o->{saveRecord};
10114 }
10115  
10116 sub detachSaveRecord {
10117 0 ▶ my $o = shift;
Subroutine detachSaveRecord: not called CC=3 SCAR=24.8
10118  
10119 0 ▶ return if ! $o->{saveRecord};
Branch: 1 branch
BranchTrueFalseTotal
unless $o->{"saveRecord"} 0 0 0
10120 0 delete $o->{saveRecord};
10121 0 ▶ $o->{parent}->detachSaveRecord if $o->{parent};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"parent"} 0 0 0
10122 }
10123  
10124 package CDS::Document::Part;
10125  
10126 sub new {
10127 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
10128  
10129 0 return bless {
10130 isMerged => 0,
10131 hashAndKey => undef,
10132 size => 0,
10133 count => 0,
10134 selected => 0,
10135 };
10136 }
10137  
10138 # In this implementation, we only keep track of the number of values of the list, but
10139 # not of the corresponding items. This saves memory (~100 MiB for 1M items), but takes
10140 # more time (0.5 s for 1M items) when saving. Since command line programs usually write
10141 # the document only once, this is acceptable. Reading the tree anyway takes about 10
10142 # times more time.
10143  
10144 package CDS::ErrorHandlingStore;
10145  
10146 1 ▶use parent -norequire, 'CDS::Store';
Subroutine BEGIN: called CC=1 SCAR=0.0
10147  
10148 sub new {
10149 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
10150 0 my $store = shift;
10151 0 my $url = shift;
10152 0 my $errorHandler = shift;
10153  
10154 0 return bless {
10155 store => $store,
10156 url => $url,
10157 errorHandler => $errorHandler,
10158 }
10159 }
10160  
10161 0 ▶sub store { shift->{store} }
Subroutine store: not called CC=1 SCAR=6.9
10162 0 ▶sub url { shift->{url} }
Subroutine url: not called CC=1 SCAR=6.9
10163 0 ▶sub errorHandler { shift->{errorHandler} }
Subroutine errorHandler: not called CC=1 SCAR=6.9
10164  
10165 sub id {
10166 0 ▶ my $o = shift;
Subroutine id: not called CC=1 SCAR=6.9
10167 0 'Error handling'."\n ".$o->{store}->id }
10168  
10169 sub get {
10170 0 ▶ my $o = shift;
Subroutine get: not called CC=7 SCAR=40.3
10171 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
10172 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
10173  
10174 0 ▶ return undef, 'Store disabled.' if $o->{errorHandler}->hasStoreError($o, 'GET');
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"errorHandler"}->hasStoreError($o, "GET") 0 0 0
10175  
10176 0 my ($object, $error) = $o->{store}->get($hash, $keyPair);
10177 0 ▶ if (defined $error) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $error) 0 0 0
10178 0 $o->{errorHandler}->onStoreError($o, 'GET', $error);
10179 0 return undef, $error;
10180 }
10181  
10182 0 $o->{errorHandler}->onStoreSuccess($o, 'GET');
10183 0 return $object, $error;
10184 }
10185  
10186 sub book {
10187 0 ▶ my $o = shift;
Subroutine book: not called CC=7 SCAR=40.3
10188 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
10189 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
10190  
10191 0 ▶ return undef, 'Store disabled.' if $o->{errorHandler}->hasStoreError($o, 'BOOK');
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"errorHandler"}->hasStoreError($o, "BOOK") 0 0 0
10192  
10193 0 my ($booked, $error) = $o->{store}->book($hash, $keyPair);
10194 0 ▶ if (defined $error) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $error) 0 0 0
10195 0 $o->{errorHandler}->onStoreError($o, 'BOOK', $error);
10196 0 return undef, $error;
10197 }
10198  
10199 0 $o->{errorHandler}->onStoreSuccess($o, 'BOOK');
10200 0 return $booked;
10201 }
10202  
10203 sub put {
10204 0 ▶ my $o = shift;
Subroutine put: not called CC=9 SCAR=45.0
10205 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
10206 0 ▶ my $object = shift; die 'wrong type '.ref($object).' for $object' if defined $object && ref $object ne 'CDS::Object';
Branch: 1 branch
BranchTrueFalseTotal
if defined $object and ref $object ne "CDS::Object" 0 0 0
Condition0%0/3
defined $object and ref $object ne "CDS::Object"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $object and ref $object ne "CDS::Object"
defined $object ref $object ne "CDS::Object"
Truth table0%0/3
A and B
A= defined $objectB= ref $object ne "CDS::Object"
ABresult
0X0
100
111
10207 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
10208  
10209 0 ▶ return 'Store disabled.' if $o->{errorHandler}->hasStoreError($o, 'PUT');
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"errorHandler"}->hasStoreError($o, "PUT") 0 0 0
10210  
10211 0 my $error = $o->{store}->put($hash, $object, $keyPair);
10212 0 ▶ if (defined $error) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $error) 0 0 0
10213 0 $o->{errorHandler}->onStoreError($o, 'PUT', $error);
10214 0 return $error;
10215 }
10216  
10217 0 $o->{errorHandler}->onStoreSuccess($o, 'PUT');
10218 0 return;
10219 }
10220  
10221 sub list {
10222 0 ▶ my $o = shift;
Subroutine list: not called CC=7 SCAR=40.3
10223 0 ▶ my $accountHash = shift; die 'wrong type '.ref($accountHash).' for $accountHash' if defined $accountHash && ref $accountHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $accountHash and ref $accountHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $accountHash and ref $accountHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $accountHash and ref $accountHash ne "CDS::Hash"
defined $accountHash ref $accountHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $accountHashB= ref $accountHash ne "CDS::Hash"
ABresult
0X0
100
111
10224 0 my $boxLabel = shift;
10225 0 my $timeout = shift;
10226 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
10227  
10228 0 ▶ return undef, 'Store disabled.' if $o->{errorHandler}->hasStoreError($o, 'LIST');
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"errorHandler"}->hasStoreError($o, "LIST") 0 0 0
10229  
10230 0 my ($hashes, $error) = $o->{store}->list($accountHash, $boxLabel, $timeout, $keyPair);
10231 0 ▶ if (defined $error) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $error) 0 0 0
10232 0 $o->{errorHandler}->onStoreError($o, 'LIST', $error);
10233 0 return undef, $error;
10234 }
10235  
10236 0 $o->{errorHandler}->onStoreSuccess($o, 'LIST');
10237 0 return $hashes;
10238 }
10239  
10240 sub add {
10241 0 ▶ my $o = shift;
Subroutine add: not called CC=9 SCAR=45.0
10242 0 ▶ my $accountHash = shift; die 'wrong type '.ref($accountHash).' for $accountHash' if defined $accountHash && ref $accountHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $accountHash and ref $accountHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $accountHash and ref $accountHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $accountHash and ref $accountHash ne "CDS::Hash"
defined $accountHash ref $accountHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $accountHashB= ref $accountHash ne "CDS::Hash"
ABresult
0X0
100
111
10243 0 my $boxLabel = shift;
10244 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
10245 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
10246  
10247 0 ▶ return 'Store disabled.' if $o->{errorHandler}->hasStoreError($o, 'ADD');
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"errorHandler"}->hasStoreError($o, "ADD") 0 0 0
10248  
10249 0 my $error = $o->{store}->add($accountHash, $boxLabel, $hash, $keyPair);
10250 0 ▶ if (defined $error) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $error) 0 0 0
10251 0 $o->{errorHandler}->onStoreError($o, 'ADD', $error);
10252 0 return $error;
10253 }
10254  
10255 0 $o->{errorHandler}->onStoreSuccess($o, 'ADD');
10256 0 return;
10257 }
10258  
10259 sub remove {
10260 0 ▶ my $o = shift;
Subroutine remove: not called CC=9 SCAR=45.0
10261 0 ▶ my $accountHash = shift; die 'wrong type '.ref($accountHash).' for $accountHash' if defined $accountHash && ref $accountHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $accountHash and ref $accountHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $accountHash and ref $accountHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $accountHash and ref $accountHash ne "CDS::Hash"
defined $accountHash ref $accountHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $accountHashB= ref $accountHash ne "CDS::Hash"
ABresult
0X0
100
111
10262 0 my $boxLabel = shift;
10263 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
10264 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
10265  
10266 0 ▶ return 'Store disabled.' if $o->{errorHandler}->hasStoreError($o, 'REMOVE');
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"errorHandler"}->hasStoreError($o, "REMOVE") 0 0 0
10267  
10268 0 my $error = $o->{store}->remove($accountHash, $boxLabel, $hash, $keyPair);
10269 0 ▶ if (defined $error) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $error) 0 0 0
10270 0 $o->{errorHandler}->onStoreError($o, 'REMOVE', $error);
10271 0 return $error;
10272 }
10273  
10274 0 $o->{errorHandler}->onStoreSuccess($o, 'REMOVE');
10275 0 return;
10276 }
10277  
10278 sub modify {
10279 0 ▶ my $o = shift;
Subroutine modify: not called CC=5 SCAR=34.0
10280 0 my $modifications = shift;
10281 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
10282  
10283 0 ▶ return 'Store disabled.' if $o->{errorHandler}->hasStoreError($o, 'MODIFY');
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"errorHandler"}->hasStoreError($o, "MODIFY") 0 0 0
10284  
10285 0 my $error = $o->{store}->modify($modifications, $keyPair);
10286 0 ▶ if (defined $error) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $error) 0 0 0
10287 0 $o->{errorHandler}->onStoreError($o, 'MODIFY', $error);
10288 0 return $error;
10289 }
10290  
10291 0 $o->{errorHandler}->onStoreSuccess($o, 'MODIFY');
10292 0 return;
10293 }
10294  
10295 # A Condensation store on a local folder.
10296 package CDS::FolderStore;
10297  
10298 1 ▶use parent -norequire, 'CDS::Store';
Subroutine BEGIN: called CC=1 SCAR=0.0
10299  
10300 sub forUrl {
10301 0 ▶ my $class = shift;
Subroutine forUrl: not called CC=2 SCAR=17.9
10302 0 my $url = shift;
10303  
10304 0 ▶ return if substr($url, 0, 8) ne 'file:///';
Branch: 1 branch
BranchTrueFalseTotal
if substr($url, 0, 8) ne "file:///" 0 0 0
10305 0 return $class->new(substr($url, 7));
10306 }
10307  
10308 sub new {
10309 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
10310 0 my $folder = shift;
10311  
10312 0 return bless {
10313 folder => $folder,
10314 permissions => CDS::FolderStore::PosixPermissions->forFolder($folder.'/accounts'),
10315 };
10316 }
10317  
10318 sub id {
10319 0 ▶ my $o = shift;
Subroutine id: not called CC=1 SCAR=6.9
10320 0 'file://'.$o->{folder} }
10321 0 ▶sub folder { shift->{folder} }
Subroutine folder: not called CC=1 SCAR=6.9
10322  
10323 0 ▶sub permissions { shift->{permissions} }
Subroutine permissions: not called CC=1 SCAR=6.9
10324 sub setPermissions {
10325 0 ▶ my $o = shift;
Subroutine setPermissions: not called CC=1 SCAR=6.9
10326 0 my $permissions = shift;
10327 0 $o->{permissions} = $permissions; }
10328  
10329 sub get {
10330 0 ▶ my $o = shift;
Subroutine get: not called CC=5 SCAR=34.0
10331 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
10332 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
10333  
10334 0 my $hashHex = $hash->hex;
10335 0 my $file = $o->{folder}.'/objects/'.substr($hashHex, 0, 2).'/'.substr($hashHex, 2);
10336 0 return CDS::Object->fromBytes(CDS->readBytesFromFile($file));
10337 }
10338  
10339 sub book {
10340 0 ▶ my $o = shift;
Subroutine book: not called CC=7 SCAR=40.3
10341 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
10342 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
10343  
10344 # Book the object if it exists
10345 0 my $hashHex = $hash->hex;
10346 0 my $folder = $o->{folder}.'/objects/'.substr($hashHex, 0, 2);
10347 0 my $file = $folder.'/'.substr($hashHex, 2);
10348 0 ▶ return 1 if -e $file && utime(undef, undef, $file);
Branch: 1 branch
BranchTrueFalseTotal
if -e $file and utime undef, undef, $file 0 0 0
Condition0%0/3
-e $file and utime undef, undef, $file
!ll&&!rl&&r
000
MC/DC0%0/2
-e $file and utime undef, undef, $file
-e $file utime undef, undef, $file
Truth table0%0/3
A and B
A= -e $fileB= utime undef, undef, $file
ABresult
0X0
100
111
10349 0 return;
10350 }
10351  
10352 sub put {
10353 0 ▶ my $o = shift;
Subroutine put: not called CC=11 SCAR=48.8
10354 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
10355 0 ▶ my $object = shift; die 'wrong type '.ref($object).' for $object' if defined $object && ref $object ne 'CDS::Object';
Branch: 1 branch
BranchTrueFalseTotal
if defined $object and ref $object ne "CDS::Object" 0 0 0
Condition0%0/3
defined $object and ref $object ne "CDS::Object"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $object and ref $object ne "CDS::Object"
defined $object ref $object ne "CDS::Object"
Truth table0%0/3
A and B
A= defined $objectB= ref $object ne "CDS::Object"
ABresult
0X0
100
111
10356 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
10357  
10358 # Book the object if it exists
10359 0 my $hashHex = $hash->hex;
10360 0 my $folder = $o->{folder}.'/objects/'.substr($hashHex, 0, 2);
10361 0 my $file = $folder.'/'.substr($hashHex, 2);
10362 0 ▶ return if -e $file && utime(undef, undef, $file);
Branch: 1 branch
BranchTrueFalseTotal
if -e $file and utime undef, undef, $file 0 0 0
Condition0%0/3
-e $file and utime undef, undef, $file
!ll&&!rl&&r
000
MC/DC0%0/2
-e $file and utime undef, undef, $file
-e $file utime undef, undef, $file
Truth table0%0/3
A and B
A= -e $fileB= utime undef, undef, $file
ABresult
0X0
100
111
10363  
10364 # Write the file, set the permissions, and move it to the right place
10365 0 my $permissions = $o->{permissions};
10366 0 $permissions->mkdir($folder, $permissions->objectFolderMode);
10367 0 ▶ my $temporaryFile = $permissions->writeTemporaryFile($folder, $permissions->objectFileMode, $object->bytes) // return 'Failed to write object';
Condition0%0/2
$permissions->writeTemporaryFile($folder, $permissions->objectFileMode, $object->bytes) // (return "Failed to write object")
l!l
00
MC/DC0%0/1
$permissions->writeTemporaryFile($folder, $permissions->objectFileMode, $object->bytes) // (return "Failed to write object")
$permissions->writeTemporaryFile($folder, $permissions->objectFileMode, $object->bytes)
Truth table0%0/2
A
A= $permissions->writeTemporaryFile($folder, $permissions->objectFileMode, $object->bytes)
Aresult
11
00
10368 0 ▶ rename($temporaryFile, $file) || return 'Failed to rename object.';
Branch: 1 branch
BranchTrueFalseTotal
rename $temporaryFile, $file or return "Failed to rename object." 0 0 0
10369 0 return;
10370 }
10371  
10372 sub list {
10373 0 ▶ my $o = shift;
Subroutine list: not called CC=9 SCAR=45.0
10374 0 ▶ my $accountHash = shift; die 'wrong type '.ref($accountHash).' for $accountHash' if defined $accountHash && ref $accountHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $accountHash and ref $accountHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $accountHash and ref $accountHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $accountHash and ref $accountHash ne "CDS::Hash"
defined $accountHash ref $accountHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $accountHashB= ref $accountHash ne "CDS::Hash"
ABresult
0X0
100
111
10375 0 my $boxLabel = shift;
10376 0 my $timeout = shift;
10377 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
10378  
10379 0 ▶ return undef, 'Invalid box label.' if ! CDS->isValidBoxLabel($boxLabel);
Branch: 1 branch
BranchTrueFalseTotal
unless "CDS"->isValidBoxLabel($boxLabel) 0 0 0
10380  
10381 # Prepare
10382 0 my $boxFolder = $o->{folder}.'/accounts/'.$accountHash->hex.'/'.$boxLabel;
10383  
10384 # List
10385 0 ▶ return $o->listFolder($boxFolder) if ! $timeout;
Branch: 1 branch
BranchTrueFalseTotal
unless $timeout 0 0 0
10386  
10387 # Watch
10388 0 my $hashes;
10389 0 my $watcher = CDS::FolderStore::Watcher->new($boxFolder);
10390 0 my $watchUntil = CDS->now + $timeout;
10391 0 while (1) {
10392 # List
10393 0 $hashes = $o->listFolder($boxFolder);
10394 0 ▶ last if scalar @$hashes;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @$hashes 0 0 0
10395  
10396 # Wait
10397 0 ▶ $watcher->wait($watchUntil - CDS->now, $watchUntil) // last;
Condition0%0/2
$watcher->wait($watchUntil - "CDS"->now, $watchUntil) // (last)
l!l
00
MC/DC0%0/1
$watcher->wait($watchUntil - "CDS"->now, $watchUntil) // (last)
$watcher->wait($watchUntil - "CDS"->now, $watchUntil)
Truth table0%0/2
A
A= $watcher->wait($watchUntil - "CDS"->now, $watchUntil)
Aresult
11
00
10398 }
10399  
10400 0 $watcher->done;
10401 0 return $hashes;
10402 }
10403  
10404 sub listFolder {
10405 0 ▶ my $o = shift;
Subroutine listFolder: not called CC=3 SCAR=24.8
10406 0 my $boxFolder = shift;
10407 # private
10408 0 my $hashes = [];
10409 0 for my $file (CDS->listFolder($boxFolder)) {
10410 0 ▶ push @$hashes, CDS::Hash->fromHex($file) // next;
Condition0%0/2
"CDS::Hash"->fromHex($file) // (next)
l!l
00
MC/DC0%0/1
"CDS::Hash"->fromHex($file) // (next)
"CDS::Hash"->fromHex($file)
Truth table0%0/2
A
A= "CDS::Hash"->fromHex($file)
Aresult
11
00
10411 }
10412  
10413 0 return $hashes;
10414 }
10415  
10416 sub add {
10417 0 ▶ my $o = shift;
Subroutine add: not called CC=10 SCAR=47.0
10418 0 ▶ my $accountHash = shift; die 'wrong type '.ref($accountHash).' for $accountHash' if defined $accountHash && ref $accountHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $accountHash and ref $accountHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $accountHash and ref $accountHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $accountHash and ref $accountHash ne "CDS::Hash"
defined $accountHash ref $accountHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $accountHashB= ref $accountHash ne "CDS::Hash"
ABresult
0X0
100
111
10419 0 my $boxLabel = shift;
10420 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
10421 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
10422  
10423 0 my $permissions = $o->{permissions};
10424  
10425 0 ▶ next if ! CDS->isValidBoxLabel($boxLabel);
Branch: 1 branch
BranchTrueFalseTotal
unless "CDS"->isValidBoxLabel($boxLabel) 0 0 0
10426 0 my $accountFolder = $o->{folder}.'/accounts/'.$accountHash->hex;
10427 0 $permissions->mkdir($accountFolder, $permissions->accountFolderMode);
10428 0 my $boxFolder = $accountFolder.'/'.$boxLabel;
10429 0 $permissions->mkdir($boxFolder, $permissions->boxFolderMode($boxLabel));
10430 0 my $boxFileMode = $permissions->boxFileMode($boxLabel);
10431  
10432 0 ▶ my $temporaryFile = $permissions->writeTemporaryFile($boxFolder, $boxFileMode, '') // return 'Failed to write file.';
Condition0%0/2
$permissions->writeTemporaryFile($boxFolder, $boxFileMode, "") // (return "Failed to write file.")
l!l
00
MC/DC0%0/1
$permissions->writeTemporaryFile($boxFolder, $boxFileMode, "") // (return "Failed to write file.")
$permissions->writeTemporaryFile($boxFolder, $boxFileMode, "")
Truth table0%0/2
A
A= $permissions->writeTemporaryFile($boxFolder, $boxFileMode, "")
Aresult
11
00
10433 0 ▶ rename($temporaryFile, $boxFolder.'/'.$hash->hex) || return 'Failed to rename file.';
Branch: 1 branch
BranchTrueFalseTotal
rename $temporaryFile, $boxFolder . '/' . $hash->hex or return "Failed to rename file." 0 0 0
10434 0 return;
10435 }
10436  
10437 sub remove {
10438 0 ▶ my $o = shift;
Subroutine remove: not called CC=9 SCAR=45.0
10439 0 ▶ my $accountHash = shift; die 'wrong type '.ref($accountHash).' for $accountHash' if defined $accountHash && ref $accountHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $accountHash and ref $accountHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $accountHash and ref $accountHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $accountHash and ref $accountHash ne "CDS::Hash"
defined $accountHash ref $accountHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $accountHashB= ref $accountHash ne "CDS::Hash"
ABresult
0X0
100
111
10440 0 my $boxLabel = shift;
10441 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
10442 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
10443  
10444 0 ▶ next if ! CDS->isValidBoxLabel($boxLabel);
Branch: 1 branch
BranchTrueFalseTotal
unless "CDS"->isValidBoxLabel($boxLabel) 0 0 0
10445 0 my $accountFolder = $o->{folder}.'/accounts/'.$accountHash->hex;
10446 0 my $boxFolder = $accountFolder.'/'.$boxLabel;
10447 0 ▶ next if ! -d $boxFolder;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $boxFolder 0 0 0
10448 0 unlink $boxFolder.'/'.$hash->hex;
10449 0 return;
10450 }
10451  
10452 sub modify {
10453 0 ▶ my $o = shift;
Subroutine modify: not called CC=3 SCAR=24.8
10454 0 my $modifications = shift;
10455 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
10456  
10457 0 return $modifications->executeIndividually($o, $keyPair);
10458 }
10459  
10460 # Store administration functions
10461  
10462 sub exists {
10463 0 ▶ my $o = shift;
Subroutine exists: not called CC=2 SCAR=17.9
10464  
10465 0 ▶ return -d $o->{folder}.'/accounts' && -d $o->{folder}.'/objects';
Condition0%0/3
-d $o->{'folder'} . '/accounts' && -d $o->{'folder'} . '/objects'
!ll&&!rl&&r
000
MC/DC0%0/2
-d $o->{'folder'} . '/accounts' && -d $o->{'folder'} . '/objects'
-d $o->{'folder'} . '/accounts' -d $o->{'folder'} . '/objects'
Truth table0%0/3
A && B
A= -d $o->{'folder'} . '/accounts'B= -d $o->{'folder'} . '/objects'
ABresult
0X0
100
111
10466 }
10467  
10468 # Creates the store if it does not exist. The store folder itself must exist.
10469 sub createIfNecessary {
10470 0 ▶ my $o = shift;
Subroutine createIfNecessary: not called CC=2 SCAR=17.9
10471  
10472 0 my $accountsFolder = $o->{folder}.'/accounts';
10473 0 my $objectsFolder = $o->{folder}.'/objects';
10474 0 $o->{permissions}->mkdir($accountsFolder, $o->{permissions}->baseFolderMode);
10475 0 $o->{permissions}->mkdir($objectsFolder, $o->{permissions}->baseFolderMode);
10476 0 ▶ return -d $accountsFolder && -d $objectsFolder;
Condition0%0/3
-d $accountsFolder && -d $objectsFolder
!ll&&!rl&&r
000
MC/DC0%0/2
-d $accountsFolder && -d $objectsFolder
-d $accountsFolder -d $objectsFolder
Truth table0%0/3
A && B
A= -d $accountsFolderB= -d $objectsFolder
ABresult
0X0
100
111
10477 }
10478  
10479 # Lists accounts. This is a non-standard extension.
10480 sub accounts {
10481 0 ▶ my $o = shift;
Subroutine accounts: not called CC=1 SCAR=6.9
10482  
10483 0 return grep { defined $_ }
10484 0 map { CDS::Hash->fromHex($_) }
10485 0 CDS->listFolder($o->{folder}.'/accounts');
10486 }
10487  
10488 # Adds an account. This is a non-standard extension.
10489 sub addAccount {
10490 0 ▶ my $o = shift;
Subroutine addAccount: not called CC=3 SCAR=24.8
10491 0 ▶ my $accountHash = shift; die 'wrong type '.ref($accountHash).' for $accountHash' if defined $accountHash && ref $accountHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $accountHash and ref $accountHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $accountHash and ref $accountHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $accountHash and ref $accountHash ne "CDS::Hash"
defined $accountHash ref $accountHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $accountHashB= ref $accountHash ne "CDS::Hash"
ABresult
0X0
100
111
10492  
10493 0 my $accountFolder = $o->{folder}.'/accounts/'.$accountHash->hex;
10494 0 $o->{permissions}->mkdir($accountFolder, $o->{permissions}->accountFolderMode);
10495 0 return -d $accountFolder;
10496 }
10497  
10498 # Removes an account. This is a non-standard extension.
10499 sub removeAccount {
10500 0 ▶ my $o = shift;
Subroutine removeAccount: not called CC=3 SCAR=24.8
10501 0 ▶ my $accountHash = shift; die 'wrong type '.ref($accountHash).' for $accountHash' if defined $accountHash && ref $accountHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $accountHash and ref $accountHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $accountHash and ref $accountHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $accountHash and ref $accountHash ne "CDS::Hash"
defined $accountHash ref $accountHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $accountHashB= ref $accountHash ne "CDS::Hash"
ABresult
0X0
100
111
10502  
10503 0 my $accountFolder = $o->{folder}.'/accounts/'.$accountHash->hex;
10504 0 my $trashFolder = $o->{folder}.'/accounts/.deleted-'.CDS->randomHex(16);
10505 0 rename $accountFolder, $trashFolder;
10506 0 system('rm', '-rf', $trashFolder);
10507 0 return ! -d $accountFolder;
10508 }
10509  
10510 # Checks (and optionally fixes) the POSIX permissions of all files and folders. This is a non-standard extension.
10511 sub checkPermissions {
10512 0 ▶ my $o = shift;
Subroutine checkPermissions: not called CC=18 SCAR=58.3
10513 0 my $logger = shift;
10514  
10515 0 my $permissions = $o->{permissions};
10516  
10517 # Check the accounts folder
10518 0 my $accountsFolder = $o->{folder}.'/accounts';
10519 0 ▶ $permissions->checkPermissions($accountsFolder, $permissions->baseFolderMode, $logger) || return;
Branch: 1 branch
BranchTrueFalseTotal
$permissions->checkPermissions($accountsFolder, $permissions->baseFolderMode, $logger) or return 0 0 0
10520  
10521 # Check the account folders
10522 0 for my $account (sort { $a cmp $b } CDS->listFolder($accountsFolder)) {
10523 0 ▶ next if $account !~ /^[0-9a-f]{64}$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $account =~ /^[0-9a-f]{64}$/ 0 0 0
10524 0 my $accountFolder = $accountsFolder.'/'.$account;
10525 0 ▶ $permissions->checkPermissions($accountFolder, $permissions->accountFolderMode, $logger) || return;
Branch: 1 branch
BranchTrueFalseTotal
$permissions->checkPermissions($accountFolder, $permissions->accountFolderMode, $logger) or return 0 0 0
10526  
10527 # Check the box folders
10528 0 for my $boxLabel (sort { $a cmp $b } CDS->listFolder($accountFolder)) {
10529 0 ▶ next if $boxLabel =~ /^\./;
Branch: 1 branch
BranchTrueFalseTotal
if $boxLabel =~ /^\./ 0 0 0
10530 0 my $boxFolder = $accountFolder.'/'.$boxLabel;
10531 0 ▶ $permissions->checkPermissions($boxFolder, $permissions->boxFolderMode($boxLabel), $logger) || return;
Branch: 1 branch
BranchTrueFalseTotal
$permissions->checkPermissions($boxFolder, $permissions->boxFolderMode($boxLabel), $logger) or return 0 0 0
10532  
10533 # Check each file
10534 0 my $filePermissions = $permissions->boxFileMode($boxLabel);
10535 0 for my $file (sort { $a cmp $b } CDS->listFolder($boxFolder)) {
10536 0 ▶ next if $file !~ /^[0-9a-f]{64}/;
Branch: 1 branch
BranchTrueFalseTotal
unless $file =~ /^[0-9a-f]{64}/ 0 0 0
10537 0 ▶ $permissions->checkPermissions($boxFolder.'/'.$file, $filePermissions, $logger) || return;
Branch: 1 branch
BranchTrueFalseTotal
$permissions->checkPermissions($boxFolder . '/' . $file, $filePermissions, $logger) or return 0 0 0
10538 }
10539 }
10540 }
10541  
10542 # Check the objects folder
10543 0 my $objectsFolder = $o->{folder}.'/objects';
10544 0 my $fileMode = $permissions->objectFileMode;
10545 0 my $folderMode = $permissions->objectFolderMode;
10546 0 ▶ $permissions->checkPermissions($objectsFolder, $folderMode, $logger) || return;
Branch: 1 branch
BranchTrueFalseTotal
$permissions->checkPermissions($objectsFolder, $folderMode, $logger) or return 0 0 0
10547  
10548 # Check the 256 sub folders
10549 0 for my $sub (sort { $a cmp $b } CDS->listFolder($objectsFolder)) {
10550 0 ▶ next if $sub !~ /^[0-9a-f][0-9a-f]$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $sub =~ /^[0-9a-f][0-9a-f]$/ 0 0 0
10551 0 my $subFolder = $objectsFolder.'/'.$sub;
10552 0 ▶ $permissions->checkPermissions($subFolder, $folderMode, $logger) || return;
Branch: 1 branch
BranchTrueFalseTotal
$permissions->checkPermissions($subFolder, $folderMode, $logger) or return 0 0 0
10553  
10554 0 for my $file (sort { $a cmp $b } CDS->listFolder($subFolder)) {
10555 0 ▶ next if $file !~ /^[0-9a-f]{62}/;
Branch: 1 branch
BranchTrueFalseTotal
unless $file =~ /^[0-9a-f]{62}/ 0 0 0
10556 0 ▶ $permissions->checkPermissions($subFolder.'/'.$file, $fileMode, $logger) || return;
Branch: 1 branch
BranchTrueFalseTotal
$permissions->checkPermissions($subFolder . '/' . $file, $fileMode, $logger) or return 0 0 0
10557 }
10558 }
10559  
10560 0 return 1;
10561 }
10562  
10563 # Handles POSIX permissions (user, group, and mode).
10564 package CDS::FolderStore::PosixPermissions;
10565  
10566 # Returns the permissions set corresponding to the mode, uid, and gid of the base folder.
10567 # If the permissions are ambiguous, the more restrictive set is chosen.
10568 sub forFolder {
10569 0 ▶ my $class = shift;
Subroutine forFolder: not called CC=4 SCAR=30.0
10570 0 my $folder = shift;
10571  
10572 0 my @s = stat $folder;
10573 0 ▶ my $mode = $s[2] // 0;
Condition0%0/2
$s[2] // 0
l!l
00
MC/DC0%0/1
$s[2] // 0
$s[2]
Truth table0%0/2
A
A= $s[2]
Aresult
11
00
10574  
10575 return
10576 0 ▶ ($mode & 077) == 077 ? CDS::FolderStore::PosixPermissions::World->new :
Branch: 2 branches
BranchTrueFalseTotal
($mode & 63) == 63 ? : 0 0 0
($mode & 56) == 56 ? : 0 0 0
10577 ($mode & 070) == 070 ? CDS::FolderStore::PosixPermissions::Group->new($s[5]) :
10578 CDS::FolderStore::PosixPermissions::User->new($s[4]);
10579 }
10580  
10581 0 ▶sub uid { shift->{uid} }
Subroutine uid: not called CC=1 SCAR=6.9
10582 0 ▶sub gid { shift->{gid} }
Subroutine gid: not called CC=1 SCAR=6.9
10583  
10584 sub user {
10585 0 ▶ my $o = shift;
Subroutine user: not called CC=3 SCAR=24.8
10586  
10587 0 ▶ my $uid = $o->{uid} // return;
Condition0%0/2
$o->{"uid"} // (return)
l!l
00
MC/DC0%0/1
$o->{"uid"} // (return)
$o->{"uid"}
Truth table0%0/2
A
A= $o->{"uid"}
Aresult
11
00
10588 0 ▶ return getpwuid($uid) // $uid;
Condition0%0/3
getpwuid $uid // $uid
l!l&&r!l&&!r
000
MC/DC0%0/2
getpwuid $uid // $uid
getpwuid $uid $uid
Truth table0%0/3
A // B
A= getpwuid $uidB= $uid
ABresult
1X1
011
000
10589 }
10590  
10591 sub group {
10592 0 ▶ my $o = shift;
Subroutine group: not called CC=3 SCAR=24.8
10593  
10594 0 ▶ my $gid = $o->{gid} // return;
Condition0%0/2
$o->{"gid"} // (return)
l!l
00
MC/DC0%0/1
$o->{"gid"} // (return)
$o->{"gid"}
Truth table0%0/2
A
A= $o->{"gid"}
Aresult
11
00
10595 0 ▶ return getgrgid($gid) // $gid;
Condition0%0/3
getgrgid $gid // $gid
l!l&&r!l&&!r
000
MC/DC0%0/2
getgrgid $gid // $gid
getgrgid $gid $gid
Truth table0%0/3
A // B
A= getgrgid $gidB= $gid
ABresult
1X1
011
000
10596 }
10597  
10598 sub writeTemporaryFile {
10599 0 ▶ my $o = shift;
Subroutine writeTemporaryFile: not called CC=8 SCAR=42.8
10600 0 my $folder = shift;
10601 0 my $mode = shift;
10602  
10603 # Write the file
10604 0 my $temporaryFile = $folder.'/.'.CDS->randomHex(16);
10605 0 ▶ open(my $fh, '>:bytes', $temporaryFile) || return;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">:bytes", $temporaryFile or return 0 0 0
10606 0 print $fh @_;
10607 0 close $fh;
10608  
10609 # Set the permissions
10610 0 chmod $mode, $temporaryFile;
10611 0 my $uid = $o->uid;
10612 0 my $gid = $o->gid;
10613 0 ▶ chown $uid // -1, $gid // -1, $temporaryFile if defined $uid && $uid != $< || defined $gid && $gid != $(;
Branch: 1 branch
BranchTrueFalseTotal
if defined $uid and $uid != $< or defined $gid and $gid != $( 0 0 0
Condition0%0/13
defined $uid and $uid != $< or defined $gid and $gid != $(
l!l&&r!l&&!r
000
defined $uid and $uid != $<
!ll&&!rl&&r
000
defined $gid and $gid != $(
!ll&&!rl&&r
000
$uid // -1
l!l
00
$gid // -1
l!l
00
MC/DC0%0/4
defined $uid and $uid != $< or defined $gid and $gid != $(
defined $uid $uid != $< defined $gid $gid != $(
MC/DC0%0/1
$uid // -1
$uid
MC/DC0%0/1
$gid // -1
$gid
Truth table0%0/7
A and B or C and D
A= defined $uidB= $uid != $<C= defined $gidD= $gid != $(
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
Truth table0%0/2
A
A= $uid
Aresult
11
00
Truth table0%0/2
A
A= $gid
Aresult
11
00
10614 0 return $temporaryFile;
10615 }
10616  
10617 sub mkdir {
10618 0 ▶ my $o = shift;
Subroutine mkdir: not called CC=8 SCAR=42.8
10619 0 my $folder = shift;
10620 0 my $mode = shift;
10621  
10622 0 ▶ return if -d $folder;
Branch: 1 branch
BranchTrueFalseTotal
if -d $folder 0 0 0
10623  
10624 # Create the folder (note: mode is altered by umask)
10625 0 my $success = mkdir $folder, $mode;
10626  
10627 # Set the permissions
10628 0 chmod $mode, $folder;
10629 0 my $uid = $o->uid;
10630 0 my $gid = $o->gid;
10631 0 ▶ chown $uid // -1, $gid // -1, $folder if defined $uid && $uid != $< || defined $gid && $gid != $(;
Branch: 1 branch
BranchTrueFalseTotal
if defined $uid and $uid != $< or defined $gid and $gid != $( 0 0 0
Condition0%0/13
defined $uid and $uid != $< or defined $gid and $gid != $(
l!l&&r!l&&!r
000
defined $uid and $uid != $<
!ll&&!rl&&r
000
defined $gid and $gid != $(
!ll&&!rl&&r
000
$uid // -1
l!l
00
$gid // -1
l!l
00
MC/DC0%0/4
defined $uid and $uid != $< or defined $gid and $gid != $(
defined $uid $uid != $< defined $gid $gid != $(
MC/DC0%0/1
$uid // -1
$uid
MC/DC0%0/1
$gid // -1
$gid
Truth table0%0/7
A and B or C and D
A= defined $uidB= $uid != $<C= defined $gidD= $gid != $(
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
Truth table0%0/2
A
A= $uid
Aresult
11
00
Truth table0%0/2
A
A= $gid
Aresult
11
00
10632 0 return $success;
10633 }
10634  
10635 # Check the permissions of a file or folder, and fix them if desired.
10636 # A logger object is called for the different cases (access error, correct permissions, wrong permissions, error fixing permissions).
10637 sub checkPermissions {
10638 0 ▶ my $o = shift;
Subroutine checkPermissions: not called CC=15 SCAR=54.8
10639 0 my $item = shift;
10640 0 my $expectedMode = shift;
10641 0 my $logger = shift;
10642  
10643 0 my $expectedUid = $o->uid;
10644 0 my $expectedGid = $o->gid;
10645  
10646 # Stat the item
10647 0 my @s = stat $item;
10648 0 ▶ return $logger->accessError($item) if ! scalar @s;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @s 0 0 0
10649 0 my $mode = $s[2] & 07777;
10650 0 my $uid = $s[4];
10651 0 my $gid = $s[5];
10652  
10653 # Check
10654 0 ▶ my $wrongUid = defined $expectedUid && $uid != $expectedUid;
Condition0%0/3
defined $expectedUid && $uid != $expectedUid
!ll&&!rl&&r
000
MC/DC0%0/2
defined $expectedUid && $uid != $expectedUid
defined $expectedUid $uid != $expectedUid
Truth table0%0/3
A && B
A= defined $expectedUidB= $uid != $expectedUid
ABresult
0X0
100
111
10655 0 ▶ my $wrongGid = defined $expectedGid && $gid != $expectedGid;
Condition0%0/3
defined $expectedGid && $gid != $expectedGid
!ll&&!rl&&r
000
MC/DC0%0/2
defined $expectedGid && $gid != $expectedGid
defined $expectedGid $gid != $expectedGid
Truth table0%0/3
A && B
A= defined $expectedGidB= $gid != $expectedGid
ABresult
0X0
100
111
10656 0 my $wrongMode = $mode != $expectedMode;
10657 0 ▶ if ($wrongUid || $wrongGid || $wrongMode) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wrongUid or $wrongGid or $wrongMode) { } 0 0 0
Condition0%0/6
$wrongUid or $wrongGid or $wrongMode
l!l&&r!l&&!r
000
$wrongUid or $wrongGid
l!l&&r!l&&!r
000
MC/DC0%0/3
$wrongUid or $wrongGid or $wrongMode
$wrongUid $wrongGid $wrongMode
Truth table0%0/4
A or B or C
A= $wrongUidB= $wrongGidC= $wrongMode
ABCresult
1XX1
01X1
0011
0000
10658 # Something is wrong
10659 0 ▶ $logger->wrong($item, $uid, $gid, $mode, $expectedUid, $expectedGid, $expectedMode) || return 1;
Branch: 1 branch
BranchTrueFalseTotal
$logger->wrong($item, $uid, $gid, $mode, $expectedUid, $expectedGid, $expectedMode) or return 1 0 0 0
10660  
10661 # Fix uid and gid
10662 0 ▶ if ($wrongUid || $wrongGid) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wrongUid or $wrongGid) 0 0 0
Condition0%0/3
$wrongUid or $wrongGid
l!l&&r!l&&!r
000
MC/DC0%0/2
$wrongUid or $wrongGid
$wrongUid $wrongGid
Truth table0%0/3
A or B
A= $wrongUidB= $wrongGid
ABresult
1X1
011
000
10663 0 ▶ my $count = chown $expectedUid // -1, $expectedGid // -1, $item;
Condition0%0/4
$expectedUid // -1
l!l
00
$expectedGid // -1
l!l
00
MC/DC0%0/1
$expectedUid // -1
$expectedUid
MC/DC0%0/1
$expectedGid // -1
$expectedGid
Truth table0%0/2
A
A= $expectedUid
Aresult
11
00
Truth table0%0/2
A
A= $expectedGid
Aresult
11
00
10664 0 ▶ return $logger->setError($item) if $count < 1;
Branch: 1 branch
BranchTrueFalseTotal
if $count < 1 0 0 0
10665 }
10666  
10667 # Fix mode
10668 0 ▶ if ($wrongMode) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wrongMode) 0 0 0
10669 0 my $count = chmod $expectedMode, $item;
10670 0 ▶ return $logger->setError($item) if $count < 1;
Branch: 1 branch
BranchTrueFalseTotal
if $count < 1 0 0 0
10671 }
10672 } else {
10673 # Everything is OK
10674 0 $logger->correct($item, $mode, $uid, $gid);
10675 }
10676  
10677 0 return 1;
10678 }
10679  
10680 # The store belongs to a group. Every user belonging to the group is treated equivalent, and users are supposed to trust each other to some extent.
10681 # The resulting store will have files belonging to multiple users, but the same group.
10682 package CDS::FolderStore::PosixPermissions::Group;
10683  
10684 1 ▶use parent -norequire, 'CDS::FolderStore::PosixPermissions';
Subroutine BEGIN: called CC=1 SCAR=0.0
10685  
10686 sub new {
10687 0 ▶ my $class = shift;
Subroutine new: not called CC=2 SCAR=17.9
10688 0 my $gid = shift;
10689  
10690 0 ▶ return bless {gid => $gid // $(};
Condition0%0/3
$gid // $(
l!l&&r!l&&!r
000
MC/DC0%0/2
$gid // $(
$gid $(
Truth table0%0/3
A // B
A= $gidB= $(
ABresult
1X1
011
000
10691 }
10692  
10693 sub target {
10694 0 ▶ my $o = shift;
Subroutine target: not called CC=1 SCAR=6.9
10695 0 'members of the group '.$o->group }
10696 0 ▶sub baseFolderMode { 0771 }
Subroutine baseFolderMode: not called CC=1 SCAR=6.9
10697 0 ▶sub objectFolderMode { 0771 }
Subroutine objectFolderMode: not called CC=1 SCAR=6.9
10698 0 ▶sub objectFileMode { 0664 }
Subroutine objectFileMode: not called CC=1 SCAR=6.9
10699 0 ▶sub accountFolderMode { 0771 }
Subroutine accountFolderMode: not called CC=1 SCAR=6.9
10700 sub boxFolderMode {
10701 0 ▶ my $o = shift;
Subroutine boxFolderMode: not called CC=2 SCAR=17.9
10702 0 my $boxLabel = shift;
10703 0 ▶ $boxLabel eq 'public' ? 0775 : 0770 }
Branch: 1 branch
BranchTrueFalseTotal
$boxLabel eq 'public' ? : 0 0 0
10704 sub boxFileMode {
10705 0 ▶ my $o = shift;
Subroutine boxFileMode: not called CC=2 SCAR=17.9
10706 0 my $boxLabel = shift;
10707 0 ▶ $boxLabel eq 'public' ? 0664 : 0660 }
Branch: 1 branch
BranchTrueFalseTotal
$boxLabel eq 'public' ? : 0 0 0
10708  
10709 # The store belongs to a single user. Other users shall only be able to read objects and the public box, and post to the message box.
10710 package CDS::FolderStore::PosixPermissions::User;
10711  
10712 1 ▶use parent -norequire, 'CDS::FolderStore::PosixPermissions';
Subroutine BEGIN: called CC=1 SCAR=0.0
10713  
10714 sub new {
10715 0 ▶ my $class = shift;
Subroutine new: not called CC=2 SCAR=17.9
10716 0 my $uid = shift;
10717  
10718 0 ▶ return bless {uid => $uid // $<};
Condition0%0/3
$uid // $<
l!l&&r!l&&!r
000
MC/DC0%0/2
$uid // $<
$uid $<
Truth table0%0/3
A // B
A= $uidB= $<
ABresult
1X1
011
000
10719 }
10720  
10721 sub target {
10722 0 ▶ my $o = shift;
Subroutine target: not called CC=1 SCAR=6.9
10723 0 'user '.$o->user }
10724 0 ▶sub baseFolderMode { 0711 }
Subroutine baseFolderMode: not called CC=1 SCAR=6.9
10725 0 ▶sub objectFolderMode { 0711 }
Subroutine objectFolderMode: not called CC=1 SCAR=6.9
10726 0 ▶sub objectFileMode { 0644 }
Subroutine objectFileMode: not called CC=1 SCAR=6.9
10727 0 ▶sub accountFolderMode { 0711 }
Subroutine accountFolderMode: not called CC=1 SCAR=6.9
10728 sub boxFolderMode {
10729 0 ▶ my $o = shift;
Subroutine boxFolderMode: not called CC=2 SCAR=17.9
10730 0 my $boxLabel = shift;
10731 0 ▶ $boxLabel eq 'public' ? 0755 : 0700 }
Branch: 1 branch
BranchTrueFalseTotal
$boxLabel eq 'public' ? : 0 0 0
10732 sub boxFileMode {
10733 0 ▶ my $o = shift;
Subroutine boxFileMode: not called CC=2 SCAR=17.9
10734 0 my $boxLabel = shift;
10735 0 ▶ $boxLabel eq 'public' ? 0644 : 0600 }
Branch: 1 branch
BranchTrueFalseTotal
$boxLabel eq 'public' ? : 0 0 0
10736  
10737 # The store is open to everybody. This does not usually make sense, but is offered here for completeness.
10738 # This is the simplest permission scheme.
10739 package CDS::FolderStore::PosixPermissions::World;
10740  
10741 1 ▶use parent -norequire, 'CDS::FolderStore::PosixPermissions';
Subroutine BEGIN: called CC=1 SCAR=0.0
10742  
10743 sub new {
10744 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
10745  
10746 0 return bless {};
10747 }
10748  
10749 0 ▶sub target { 'everybody' }
Subroutine target: not called CC=1 SCAR=6.9
10750 0 ▶sub baseFolderMode { 0777 }
Subroutine baseFolderMode: not called CC=1 SCAR=6.9
10751 0 ▶sub objectFolderMode { 0777 }
Subroutine objectFolderMode: not called CC=1 SCAR=6.9
10752 0 ▶sub objectFileMode { 0666 }
Subroutine objectFileMode: not called CC=1 SCAR=6.9
10753 0 ▶sub accountFolderMode { 0777 }
Subroutine accountFolderMode: not called CC=1 SCAR=6.9
10754 0 ▶sub boxFolderMode { 0777 }
Subroutine boxFolderMode: not called CC=1 SCAR=6.9
10755 0 ▶sub boxFileMode { 0666 }
Subroutine boxFileMode: not called CC=1 SCAR=6.9
10756  
10757 package CDS::FolderStore::Watcher;
10758  
10759 sub new {
10760 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
10761 0 my $folder = shift;
10762  
10763 0 return bless {folder => $folder};
10764 }
10765  
10766 sub wait {
10767 0 ▶ my $o = shift;
Subroutine wait: not called CC=2 SCAR=17.9
10768 0 my $remaining = shift;
10769 0 my $until = shift;
10770  
10771 0 ▶ return if $remaining <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $remaining <= 0 0 0 0
10772 0 sleep 1;
10773 0 return 1;
10774 }
10775  
10776 sub done {
10777 0 ▶ my $o = shift;
Subroutine done: not called CC=1 SCAR=6.9
10778 }
10779  
10780 package CDS::GroupDataSharer;
10781  
10782 sub new {
10783 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
10784 0 my $actor = shift;
10785  
10786 0 my $o = bless {
10787 actor => $actor,
10788 label => 'shared group data',
10789 dataHandlers => {},
10790 messageChannel => CDS::MessageChannel->new($actor, 'group data', CDS->MONTH),
10791 revision => 0,
10792 version => '',
10793 }, $class;
10794  
10795 0 $actor->storagePrivateRoot->addDataHandler($o->{label}, $o);
10796 0 return $o;
10797 }
10798  
10799 ### Group data handlers
10800  
10801 sub addDataHandler {
10802 0 ▶ my $o = shift;
Subroutine addDataHandler: not called CC=1 SCAR=6.9
10803 0 my $label = shift;
10804 0 my $dataHandler = shift;
10805  
10806 0 $o->{dataHandlers}->{$label} = $dataHandler;
10807 }
10808  
10809 sub removeDataHandler {
10810 0 ▶ my $o = shift;
Subroutine removeDataHandler: not called CC=2 SCAR=17.9
10811 0 my $label = shift;
10812 0 my $dataHandler = shift;
10813  
10814 0 my $registered = $o->{dataHandlers}->{$label};
10815 0 ▶ return if $registered != $dataHandler;
Branch: 1 branch
BranchTrueFalseTotal
if $registered != $dataHandler 0 0 0
10816 0 delete $o->{dataHandlers}->{$label};
10817 }
10818  
10819 ### MergeableData interface
10820  
10821 sub addDataTo {
10822 0 ▶ my $o = shift;
Subroutine addDataTo: not called CC=4 SCAR=30.0
10823 0 ▶ my $record = shift; die 'wrong type '.ref($record).' for $record' if defined $record && ref $record ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $record and ref $record ne "CDS::Record" 0 0 0
Condition0%0/3
defined $record and ref $record ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $record and ref $record ne "CDS::Record"
defined $record ref $record ne "CDS::Record"
Truth table0%0/3
A and B
A= defined $recordB= ref $record ne "CDS::Record"
ABresult
0X0
100
111
10824  
10825 0 ▶ return if ! $o->{revision};
Branch: 1 branch
BranchTrueFalseTotal
unless $o->{"revision"} 0 0 0
10826 0 $record->addInteger($o->{revision})->add($o->{version});
10827 }
10828  
10829 sub mergeData {
10830 0 ▶ my $o = shift;
Subroutine mergeData: not called CC=5 SCAR=34.0
10831 0 ▶ my $record = shift; die 'wrong type '.ref($record).' for $record' if defined $record && ref $record ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $record and ref $record ne "CDS::Record" 0 0 0
Condition0%0/3
defined $record and ref $record ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $record and ref $record ne "CDS::Record"
defined $record ref $record ne "CDS::Record"
Truth table0%0/3
A and B
A= defined $recordB= ref $record ne "CDS::Record"
ABresult
0X0
100
111
10832  
10833 0 for my $child ($record->children) {
10834 0 my $revision = $child->asInteger;
10835 0 ▶ next if $revision <= $o->{revision};
Branch: 1 branch
BranchTrueFalseTotal
if $revision <= $o->{"revision"} 0 0 0
10836  
10837 0 $o->{revision} = $revision;
10838 0 $o->{version} = $child->bytesValue;
10839 }
10840 }
10841  
10842 sub mergeExternalData {
10843 0 ▶ my $o = shift;
Subroutine mergeExternalData: not called CC=6 SCAR=37.4
10844 0 my $store = shift;
10845 0 ▶ my $record = shift; die 'wrong type '.ref($record).' for $record' if defined $record && ref $record ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $record and ref $record ne "CDS::Record" 0 0 0
Condition0%0/3
defined $record and ref $record ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $record and ref $record ne "CDS::Record"
defined $record ref $record ne "CDS::Record"
Truth table0%0/3
A and B
A= defined $recordB= ref $record ne "CDS::Record"
ABresult
0X0
100
111
10846 0 ▶ my $source = shift; die 'wrong type '.ref($source).' for $source' if defined $source && ref $source ne 'CDS::Source';
Branch: 1 branch
BranchTrueFalseTotal
if defined $source and ref $source ne "CDS::Source" 0 0 0
Condition0%0/3
defined $source and ref $source ne "CDS::Source"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $source and ref $source ne "CDS::Source"
defined $source ref $source ne "CDS::Source"
Truth table0%0/3
A and B
A= defined $sourceB= ref $source ne "CDS::Source"
ABresult
0X0
100
111
10847  
10848 0 $o->mergeData($record);
10849 0 ▶ return if ! $source;
Branch: 1 branch
BranchTrueFalseTotal
unless $source 0 0 0
10850 0 $source->keep;
10851 0 $o->{actor}->storagePrivateRoot->unsaved->state->addMergedSource($source);
10852 }
10853  
10854 ### Sending messages
10855  
10856 sub createMessage {
10857 0 ▶ my $o = shift;
Subroutine createMessage: not called CC=2 SCAR=17.9
10858  
10859 0 my $message = CDS::Record->new;
10860 0 my $data = $message->add('group data');
10861 0 for my $label (keys %{$o->{dataHandlers}}) {
10862 0 my $dataHandler = $o->{dataHandlers}->{$label};
10863 0 $dataHandler->addDataTo($data->add($label));
10864 }
10865 0 return $message;
10866 }
10867  
10868 sub share {
10869 0 ▶ my $o = shift;
Subroutine share: not called CC=8 SCAR=42.8
10870  
10871 # Get the group data members
10872 0 ▶ my $members = $o->{actor}->getGroupDataMembers // return;
Condition0%0/2
$o->{"actor"}->getGroupDataMembers // (return)
l!l
00
MC/DC0%0/1
$o->{"actor"}->getGroupDataMembers // (return)
$o->{"actor"}->getGroupDataMembers
Truth table0%0/2
A
A= $o->{"actor"}->getGroupDataMembers
Aresult
11
00
10873 0 ▶ return 1 if ! scalar @$members;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @$members 0 0 0
10874  
10875 # Create the group data message, and check if it changed
10876 0 my $message = $o->createMessage;
10877 0 my $versionHash = $message->toObject->calculateHash;
10878 0 ▶ return if $versionHash->bytes eq $o->{version};
Branch: 1 branch
BranchTrueFalseTotal
if $versionHash->bytes eq $o->{"version"} 0 0 0
10879  
10880 0 $o->{revision} = CDS->now;
10881 0 $o->{version} = $versionHash->bytes;
10882 0 $o->{actor}->storagePrivateRoot->dataChanged;
10883  
10884 # Procure the sent list
10885 0 ▶ $o->{actor}->procureSentList // return;
Condition0%0/2
$o->{"actor"}->procureSentList // (return)
l!l
00
MC/DC0%0/1
$o->{"actor"}->procureSentList // (return)
$o->{"actor"}->procureSentList
Truth table0%0/2
A
A= $o->{"actor"}->procureSentList
Aresult
11
00
10886  
10887 # Get the entrusted keys
10888 0 ▶ my $entrustedKeys = $o->{actor}->getEntrustedKeys // return;
Condition0%0/2
$o->{"actor"}->getEntrustedKeys // (return)
l!l
00
MC/DC0%0/1
$o->{"actor"}->getEntrustedKeys // (return)
$o->{"actor"}->getEntrustedKeys
Truth table0%0/2
A
A= $o->{"actor"}->getEntrustedKeys
Aresult
11
00
10889  
10890 # Transfer the data
10891 0 $o->{messageChannel}->addTransfer([$message->dependentHashes], $o->{actor}->storagePrivateRoot->unsaved, 'group data message');
10892  
10893 # Send the message
10894 0 $o->{messageChannel}->setRecipients($members, $entrustedKeys);
10895 0 my ($submission, $missingObject) = $o->{messageChannel}->submit($message, $o);
10896 0 ▶ $o->{actor}->onMissingObject($missingObject) if $missingObject;
Branch: 1 branch
BranchTrueFalseTotal
if $missingObject 0 0 0
10897 0 ▶ return if ! $submission;
Branch: 1 branch
BranchTrueFalseTotal
unless $submission 0 0 0
10898 0 return 1;
10899 }
10900  
10901 sub onMessageChannelSubmissionCancelled {
10902 0 ▶ my $o = shift;
Subroutine onMessageChannelSubmissionCancelled: not called CC=1 SCAR=6.9
10903 }
10904  
10905 sub onMessageChannelSubmissionRecipientDone {
10906 0 ▶ my $o = shift;
Subroutine onMessageChannelSubmissionRecipientDone: not called CC=3 SCAR=24.8
10907 0 ▶ my $recipientActorOnStore = shift; die 'wrong type '.ref($recipientActorOnStore).' for $recipientActorOnStore' if defined $recipientActorOnStore && ref $recipientActorOnStore ne 'CDS::ActorOnStore';
Branch: 1 branch
BranchTrueFalseTotal
if defined $recipientActorOnStore and ref $recipientActorOnStore ne "CDS::ActorOnStore" 0 0 0
Condition0%0/3
defined $recipientActorOnStore and ref $recipientActorOnStore ne "CDS::ActorOnStore"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $recipientActorOnStore and ref $recipientActorOnStore ne "CDS::ActorOnStore"
defined $recipientActorOnStore ref $recipientActorOnStore ne "CDS::ActorOnStore"
Truth table0%0/3
A and B
A= defined $recipientActorOnStoreB= ref $recipientActorOnStore ne "CDS::ActorOnStore"
ABresult
0X0
100
111
10908 }
10909  
10910 sub onMessageChannelSubmissionRecipientFailed {
10911 0 ▶ my $o = shift;
Subroutine onMessageChannelSubmissionRecipientFailed: not called CC=3 SCAR=24.8
10912 0 ▶ my $recipientActorOnStore = shift; die 'wrong type '.ref($recipientActorOnStore).' for $recipientActorOnStore' if defined $recipientActorOnStore && ref $recipientActorOnStore ne 'CDS::ActorOnStore';
Branch: 1 branch
BranchTrueFalseTotal
if defined $recipientActorOnStore and ref $recipientActorOnStore ne "CDS::ActorOnStore" 0 0 0
Condition0%0/3
defined $recipientActorOnStore and ref $recipientActorOnStore ne "CDS::ActorOnStore"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $recipientActorOnStore and ref $recipientActorOnStore ne "CDS::ActorOnStore"
defined $recipientActorOnStore ref $recipientActorOnStore ne "CDS::ActorOnStore"
Truth table0%0/3
A and B
A= defined $recipientActorOnStoreB= ref $recipientActorOnStore ne "CDS::ActorOnStore"
ABresult
0X0
100
111
10913 }
10914  
10915 sub onMessageChannelSubmissionDone {
10916 0 ▶ my $o = shift;
Subroutine onMessageChannelSubmissionDone: not called CC=1 SCAR=6.9
10917 0 my $succeeded = shift;
10918 0 my $failed = shift;
10919 }
10920  
10921 ### Receiving messages
10922  
10923 sub processGroupDataMessage {
10924 0 ▶ my $o = shift;
Subroutine processGroupDataMessage: not called CC=4 SCAR=30.0
10925 0 my $message = shift;
10926 0 my $section = shift;
10927  
10928 0 ▶ if (! $o->{actor}->isGroupMember($message->sender->publicKey->hash)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($o->{"actor"}->isGroupMember($message->sender->publicKey->hash)) 0 0 0
10929 # TODO:
10930 # If the sender is not a known group member, we should run actor group discovery on the sender. He may be part of us, but we don't know that yet.
10931 # At the very least, we should keep this message, and reconsider it if the actor group changes within the next few minutes (e.g. through another message).
10932 0 return;
10933 }
10934  
10935 0 for my $child ($section->children) {
10936 0 ▶ my $dataHandler = $o->{dataHandlers}->{$child->bytes} // next;
Condition0%0/2
$o->{"dataHandlers"}{$child->bytes} // (next)
l!l
00
MC/DC0%0/1
$o->{"dataHandlers"}{$child->bytes} // (next)
$o->{"dataHandlers"}{$child->bytes}
Truth table0%0/2
A
A= $o->{"dataHandlers"}{$child->bytes}
Aresult
11
00
10937 0 $dataHandler->mergeExternalData($message->sender->store, $child, $message->source);
10938 }
10939  
10940 0 return 1;
10941 }
10942  
10943 package CDS::HTTPServer;
10944  
10945 1 ▶use parent -norequire, 'HTTP::Server::Simple';
Subroutine BEGIN: called CC=1 SCAR=0.0
10946  
10947 sub new {
10948 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
10949  
10950 0 my $o = $class->SUPER::new(@_);
10951 0 $o->{logger} = CDS::HTTPServer::Logger->new(*STDERR);
10952 0 $o->{handlers} = [];
10953 0 return $o;
10954 }
10955  
10956 sub addHandler {
10957 0 ▶ my $o = shift;
Subroutine addHandler: not called CC=1 SCAR=6.9
10958 0 my $handler = shift;
10959  
10960 0 push @{$o->{handlers}}, $handler;
10961 }
10962  
10963 sub setLogger {
10964 0 ▶ my $o = shift;
Subroutine setLogger: not called CC=1 SCAR=6.9
10965 0 my $logger = shift;
10966  
10967 0 $o->{logger} = $logger;
10968 }
10969  
10970 0 ▶sub logger { shift->{logger} }
Subroutine logger: not called CC=1 SCAR=6.9
10971  
10972 sub setCorsAllowEverybody {
10973 0 ▶ my $o = shift;
Subroutine setCorsAllowEverybody: not called CC=1 SCAR=6.9
10974 0 my $value = shift;
10975  
10976 0 $o->{corsAllowEverybody} = $value;
10977 }
10978  
10979 0 ▶sub corsAllowEverybody { shift->{corsAllowEverybody} }
Subroutine corsAllowEverybody: not called CC=1 SCAR=6.9
10980  
10981 # *** HTTP::Server::Simple interface
10982  
10983 sub print_banner {
10984 0 ▶ my $o = shift;
Subroutine print_banner: not called CC=1 SCAR=6.9
10985  
10986 0 $o->{logger}->onServerStarts($o->port);
10987 }
10988  
10989 sub setup {
10990 0 ▶ my $o = shift;
Subroutine setup: not called CC=1 SCAR=6.9
10991  
10992 0 my %parameters = @_;
10993 $o->{request} = CDS::HTTPServer::Request->new({
10994 logger => $o->logger,
10995 method => $parameters{method},
10996 path => $parameters{path},
10997 protocol => $parameters{protocol},
10998 queryString => $parameters{query_string},
10999 peerAddress => $parameters{peeraddr},
11000 peerPort => $parameters{peerport},
11001 0 headers => {},
11002 corsAllowEverybody => $o->corsAllowEverybody,
11003 });
11004 }
11005  
11006 sub headers {
11007 0 ▶ my $o = shift;
Subroutine headers: not called CC=3 SCAR=24.8
11008 0 my $headers = shift;
11009  
11010 0 ▶ while (scalar @$headers) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$headers) 0 0 0
11011 0 my $key = shift @$headers;
11012 0 my $value = shift @$headers;
11013 0 $o->{request}->setHeader($key, $value);
11014 }
11015  
11016 # Read the content length
11017 0 ▶ $o->{request}->setRemainingData($o->{request}->header('content-length') // 0);
Condition0%0/2
$o->{"request"}->header("content-length") // 0
l!l
00
MC/DC0%0/1
$o->{"request"}->header("content-length") // 0
$o->{"request"}->header("content-length")
Truth table0%0/2
A
A= $o->{"request"}->header("content-length")
Aresult
11
00
11018 }
11019  
11020 sub handler {
11021 0 ▶ my $o = shift;
Subroutine handler: not called CC=1 SCAR=6.9
11022  
11023 # Start writing the log line
11024 0 $o->{logger}->onRequestStarts($o->{request});
11025  
11026 # Process the request
11027 0 my $responseCode = $o->process;
11028 0 $o->{logger}->onRequestDone($o->{request}, $responseCode);
11029  
11030 # Wrap up
11031 0 $o->{request}->dropData;
11032 0 $o->{request} = undef;
11033 0 return;
11034 }
11035  
11036 sub process {
11037 0 ▶ my $o = shift;
Subroutine process: not called CC=3 SCAR=24.8
11038  
11039 # Run the handler
11040 0 for my $handler (@{$o->{handlers}}) {
11041 0 ▶ my $responseCode = $handler->process($o->{request}) || next;
Condition0%0/2
$handler->process($o->{'request'}) || (next)
l!l
00
MC/DC0%0/1
$handler->process($o->{'request'}) || (next)
$handler->process($o->{'request'})
Truth table0%0/2
A
A= $handler->process($o->{'request'})
Aresult
11
00
11042 0 return $responseCode;
11043 }
11044  
11045 # Default handler
11046 0 return $o->{request}->reply404;
11047 }
11048  
11049 sub bad_request {
11050 0 ▶ my $o = shift;
Subroutine bad_request: not called CC=1 SCAR=6.9
11051  
11052 0 my $content = 'Bad Request';
11053 0 print 'HTTP/1.1 400 Bad Request', "\r\n";
11054 0 print 'Content-Length: ', length $content, "\r\n";
11055 0 print 'Content-Type: text/plain; charset=utf-8', "\r\n";
11056 0 print "\r\n";
11057 0 print $content;
11058 0 $o->{request} = undef;
11059 }
11060  
11061 package CDS::HTTPServer::IdentificationHandler;
11062  
11063 sub new {
11064 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
11065 0 my $root = shift;
11066  
11067 0 return bless {root => $root};
11068 }
11069  
11070 sub process {
11071 0 ▶ my $o = shift;
Subroutine process: not called CC=6 SCAR=37.4
11072 0 my $request = shift;
11073  
11074 0 ▶ my $path = $request->pathAbove($o->{root}) // return;
Condition0%0/2
$request->pathAbove($o->{"root"}) // (return)
l!l
00
MC/DC0%0/1
$request->pathAbove($o->{"root"}) // (return)
$request->pathAbove($o->{"root"})
Truth table0%0/2
A
A= $request->pathAbove($o->{"root"})
Aresult
11
00
11075 0 ▶ return if $path ne '/';
Branch: 1 branch
BranchTrueFalseTotal
if $path ne "/" 0 0 0
11076  
11077 # Options
11078 0 ▶ return $request->replyOptions('HEAD', 'GET') if $request->method eq 'OPTIONS';
Branch: 1 branch
BranchTrueFalseTotal
if $request->method eq "OPTIONS" 0 0 0
11079  
11080 # Get
11081 0 ▶ return $request->reply200HTML('<!DOCTYPE html><html><head><meta charset="utf-8"><title>Condensation HTTP Store</title></head><body>This is a <a href="https://condensation.io/specifications/store/http/">Condensation HTTP Store</a> server.</body></html>') if $request->method eq 'HEAD' || $request->method eq 'GET';
Branch: 1 branch
BranchTrueFalseTotal
if $request->method eq "HEAD" or $request->method eq "GET" 0 0 0
Condition0%0/3
$request->method eq "HEAD" or $request->method eq "GET"
l!l&&r!l&&!r
000
MC/DC0%0/2
$request->method eq "HEAD" or $request->method eq "GET"
$request->method eq "HEAD" $request->method eq "GET"
Truth table0%0/3
A or B
A= $request->method eq "HEAD"B= $request->method eq "GET"
ABresult
1X1
011
000
11082  
11083 0 return $request->reply405;
11084 }
11085  
11086 package CDS::HTTPServer::Logger;
11087  
11088 sub new {
11089 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
11090 0 my $fileHandle = shift;
11091  
11092 0 return bless {
11093 fileHandle => $fileHandle,
11094 lineStarted => 0,
11095 };
11096 }
11097  
11098 sub onServerStarts {
11099 0 ▶ my $o = shift;
Subroutine onServerStarts: not called CC=1 SCAR=6.9
11100 0 my $port = shift;
11101  
11102 0 my $fh = $o->{fileHandle};
11103 0 my @t = localtime(time);
11104 0 printf $fh '%04d-%02d-%02d %02d:%02d:%02d ', $t[5] + 1900, $t[4] + 1, $t[3], $t[2], $t[1], $t[0];
11105 0 print $fh 'Server ready at http://localhost:', $port, "\n";
11106 }
11107  
11108 sub onRequestStarts {
11109 0 ▶ my $o = shift;
Subroutine onRequestStarts: not called CC=1 SCAR=6.9
11110 0 my $request = shift;
11111  
11112 0 my $fh = $o->{fileHandle};
11113 0 my @t = localtime(time);
11114 0 printf $fh '%04d-%02d-%02d %02d:%02d:%02d ', $t[5] + 1900, $t[4] + 1, $t[3], $t[2], $t[1], $t[0];
11115 0 print $fh $request->peerAddress, ' ', $request->method, ' ', $request->path;
11116 0 $o->{lineStarted} = 1;
11117 }
11118  
11119 sub onRequestError {
11120 0 ▶ my $o = shift;
Subroutine onRequestError: not called CC=2 SCAR=17.9
11121 0 my $request = shift;
11122  
11123 0 my $fh = $o->{fileHandle};
11124 0 ▶ print $fh "\n" if $o->{lineStarted};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"lineStarted"} 0 0 0
11125 0 print $fh ' ', @_, "\n";
11126 0 $o->{lineStarted} = 0;
11127 }
11128  
11129 sub onRequestDone {
11130 0 ▶ my $o = shift;
Subroutine onRequestDone: not called CC=2 SCAR=17.9
11131 0 my $request = shift;
11132 0 my $responseCode = shift;
11133  
11134 0 my $fh = $o->{fileHandle};
11135 0 ▶ print $fh ' ===> ' if ! $o->{lineStarted};
Branch: 1 branch
BranchTrueFalseTotal
unless $o->{"lineStarted"} 0 0 0
11136 0 print $fh ' ', $responseCode, "\n";
11137 0 $o->{lineStarted} = 0;
11138 }
11139  
11140 package CDS::HTTPServer::MessageGatewayHandler;
11141  
11142 sub new {
11143 0 ▶ my $class = shift;
Subroutine new: not called CC=3 SCAR=24.8
11144 0 my $root = shift;
11145 0 my $actor = shift;
11146 0 my $store = shift;
11147 0 ▶ my $recipientHash = shift; die 'wrong type '.ref($recipientHash).' for $recipientHash' if defined $recipientHash && ref $recipientHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $recipientHash and ref $recipientHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $recipientHash and ref $recipientHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $recipientHash and ref $recipientHash ne "CDS::Hash"
defined $recipientHash ref $recipientHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $recipientHashB= ref $recipientHash ne "CDS::Hash"
ABresult
0X0
100
111
11148  
11149 0 return bless {root => $root, actor => $actor, store => $store, recipientHash => $recipientHash};
11150 }
11151  
11152 sub process {
11153 0 ▶ my $o = shift;
Subroutine process: not called CC=8 SCAR=42.8
11154 0 my $request = shift;
11155  
11156 0 ▶ my $path = $request->pathAbove($o->{root}) // return;
Condition0%0/2
$request->pathAbove($o->{"root"}) // (return)
l!l
00
MC/DC0%0/1
$request->pathAbove($o->{"root"}) // (return)
$request->pathAbove($o->{"root"})
Truth table0%0/2
A
A= $request->pathAbove($o->{"root"})
Aresult
11
00
11157 0 ▶ return if $path ne '/';
Branch: 1 branch
BranchTrueFalseTotal
if $path ne "/" 0 0 0
11158  
11159 # Options
11160 0 ▶ return $request->replyOptions('HEAD', 'GET', 'PUT', 'POST', 'DELETE') if $request->method eq 'OPTIONS';
Branch: 1 branch
BranchTrueFalseTotal
if $request->method eq "OPTIONS" 0 0 0
11161  
11162 # Prepare a message
11163 0 my $message = CDS::Record->new;
11164 0 $message->add('time')->addInteger(CDS->now);
11165 0 $message->add('ip')->add($request->peerAddress);
11166 0 $message->add('method')->add($request->method);
11167 0 $message->add('path')->add($request->path);
11168 0 $message->add('query string')->add($request->queryString);
11169  
11170 0 my $headersRecord = $message->add('headers');
11171 0 my $headers = $request->headers;
11172 0 for my $key (keys %$headers) {
11173 0 $headersRecord->add($key)->add($headers->{$key});
11174 }
11175  
11176 # Prepare a channel
11177 0 my $channel = CDS::MessageChannel->new($o->{actor}, CDS->randomBytes(8), CDS->WEEK);
11178 0 $o->{messageChannel}->setRecipients([$o->{recipientHash}], []);
11179  
11180 # Add the data
11181 0 ▶ if ($request->remainingData > 1024) {
Branch: 2 branches
BranchTrueFalseTotal
if ($request->remainingData > 1024) { } 0 0 0
elsif ($request->remainingData) { } 0 0 0
11182 # Store the data as a separate object
11183 0 my $object = CDS::Object->create(CDS::Object->emptyHeader, $request->readData);
11184 0 my $key = CDS->randomKey;
11185 0 my $encryptedObject = $object->crypt($key);
11186 0 my $hash = $encryptedObject->calculateHash;
11187 0 $message->add('data')->addHash($hash);
11188 0 $channel->addObject($hash, $encryptedObject);
11189 } elsif ($request->remainingData) {
11190 0 $message->add('data')->add($request->readData)
11191 }
11192  
11193 # Submit
11194 0 my ($submission, $missingObject) = $channel->submit($message, $o);
11195 0 $o->{actor}->sendMessages;
11196  
11197 0 ▶ return $submission ? $request->reply200 : $request->reply500('Unable to send the message.');
Branch: 1 branch
BranchTrueFalseTotal
$submission ? : 0 0 0
11198 }
11199  
11200 sub onMessageChannelSubmissionCancelled {
11201 0 ▶ my $o = shift;
Subroutine onMessageChannelSubmissionCancelled: not called CC=1 SCAR=6.9
11202 }
11203  
11204 sub onMessageChannelSubmissionRecipientDone {
11205 0 ▶ my $o = shift;
Subroutine onMessageChannelSubmissionRecipientDone: not called CC=3 SCAR=24.8
11206 0 ▶ my $recipientActorOnStore = shift; die 'wrong type '.ref($recipientActorOnStore).' for $recipientActorOnStore' if defined $recipientActorOnStore && ref $recipientActorOnStore ne 'CDS::ActorOnStore';
Branch: 1 branch
BranchTrueFalseTotal
if defined $recipientActorOnStore and ref $recipientActorOnStore ne "CDS::ActorOnStore" 0 0 0
Condition0%0/3
defined $recipientActorOnStore and ref $recipientActorOnStore ne "CDS::ActorOnStore"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $recipientActorOnStore and ref $recipientActorOnStore ne "CDS::ActorOnStore"
defined $recipientActorOnStore ref $recipientActorOnStore ne "CDS::ActorOnStore"
Truth table0%0/3
A and B
A= defined $recipientActorOnStoreB= ref $recipientActorOnStore ne "CDS::ActorOnStore"
ABresult
0X0
100
111
11207 }
11208  
11209 sub onMessageChannelSubmissionRecipientFailed {
11210 0 ▶ my $o = shift;
Subroutine onMessageChannelSubmissionRecipientFailed: not called CC=3 SCAR=24.8
11211 0 ▶ my $recipientActorOnStore = shift; die 'wrong type '.ref($recipientActorOnStore).' for $recipientActorOnStore' if defined $recipientActorOnStore && ref $recipientActorOnStore ne 'CDS::ActorOnStore';
Branch: 1 branch
BranchTrueFalseTotal
if defined $recipientActorOnStore and ref $recipientActorOnStore ne "CDS::ActorOnStore" 0 0 0
Condition0%0/3
defined $recipientActorOnStore and ref $recipientActorOnStore ne "CDS::ActorOnStore"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $recipientActorOnStore and ref $recipientActorOnStore ne "CDS::ActorOnStore"
defined $recipientActorOnStore ref $recipientActorOnStore ne "CDS::ActorOnStore"
Truth table0%0/3
A and B
A= defined $recipientActorOnStoreB= ref $recipientActorOnStore ne "CDS::ActorOnStore"
ABresult
0X0
100
111
11212 }
11213  
11214 sub onMessageChannelSubmissionDone {
11215 0 ▶ my $o = shift;
Subroutine onMessageChannelSubmissionDone: not called CC=1 SCAR=6.9
11216 0 my $succeeded = shift;
11217 0 my $failed = shift;
11218 }
11219  
11220 package CDS::HTTPServer::Request;
11221  
11222 sub new {
11223 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
11224 0 my $parameters = shift;
11225  
11226 0 return bless $parameters;
11227 }
11228  
11229 0 ▶sub logger { shift->{logger} }
Subroutine logger: not called CC=1 SCAR=6.9
11230 0 ▶sub method { shift->{method} }
Subroutine method: not called CC=1 SCAR=6.9
11231 0 ▶sub path { shift->{path} }
Subroutine path: not called CC=1 SCAR=6.9
11232 0 ▶sub queryString { shift->{queryString} }
Subroutine queryString: not called CC=1 SCAR=6.9
11233 0 ▶sub peerAddress { shift->{peerAddress} }
Subroutine peerAddress: not called CC=1 SCAR=6.9
11234 0 ▶sub peerPort { shift->{peerPort} }
Subroutine peerPort: not called CC=1 SCAR=6.9
11235 0 ▶sub headers { shift->{headers} }
Subroutine headers: not called CC=1 SCAR=6.9
11236 0 ▶sub remainingData { shift->{remainingData} }
Subroutine remainingData: not called CC=1 SCAR=6.9
11237 0 ▶sub corsAllowEverybody { shift->{corsAllowEverybody} }
Subroutine corsAllowEverybody: not called CC=1 SCAR=6.9
11238  
11239 # *** Path
11240  
11241 sub pathAbove {
11242 0 ▶ my $o = shift;
Subroutine pathAbove: not called CC=3 SCAR=24.8
11243 0 my $root = shift;
11244  
11245 0 ▶ $root .= '/' if $root !~ /\/$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $root =~ m[/$] 0 0 0
11246 0 ▶ return if substr($o->{path}, 0, length $root) ne $root;
Branch: 1 branch
BranchTrueFalseTotal
if substr($o->{"path"}, 0, length $root) ne $root 0 0 0
11247 0 return substr($o->{path}, length($root) - 1);
11248 }
11249  
11250 # *** Request data
11251  
11252 sub setRemainingData {
11253 0 ▶ my $o = shift;
Subroutine setRemainingData: not called CC=1 SCAR=6.9
11254 0 my $remainingData = shift;
11255  
11256 0 $o->{remainingData} = $remainingData;
11257 }
11258  
11259 # Reads the request data
11260 sub readData {
11261 0 ▶ my $o = shift;
Subroutine readData: not called CC=3 SCAR=24.8
11262  
11263 0 my @buffers;
11264 0 ▶ while ($o->{remainingData} > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"remainingData"} > 0) 0 0 0
11265 0 ▶ my $read = sysread(STDIN, my $buffer, $o->{remainingData}) || return;
Condition0%0/2
sysread(STDIN, my $buffer, $o->{'remainingData'}) || (return)
l!l
00
MC/DC0%0/1
sysread(STDIN, my $buffer, $o->{'remainingData'}) || (return)
sysread(STDIN, my $buffer, $o->{'remainingData'})
Truth table0%0/2
A
A= sysread(STDIN, my $buffer, $o->{'remainingData'})
Aresult
11
00
11266 0 $o->{remainingData} -= $read;
11267 0 push @buffers, $buffer;
11268 }
11269  
11270 0 return join('', @buffers);
11271 }
11272  
11273 # Read the request data and writes it directly to a file handle
11274 sub copyDataAndCalculateHash {
11275 0 ▶ my $o = shift;
Subroutine copyDataAndCalculateHash: not called CC=3 SCAR=24.8
11276 0 my $fh = shift;
11277  
11278 0 my $sha = Digest::SHA->new(256);
11279 0 ▶ while ($o->{remainingData} > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"remainingData"} > 0) 0 0 0
11280 0 ▶ my $read = sysread(STDIN, my $buffer, $o->{remainingData}) || return;
Condition0%0/2
sysread(STDIN, my $buffer, $o->{'remainingData'}) || (return)
l!l
00
MC/DC0%0/1
sysread(STDIN, my $buffer, $o->{'remainingData'}) || (return)
sysread(STDIN, my $buffer, $o->{'remainingData'})
Truth table0%0/2
A
A= sysread(STDIN, my $buffer, $o->{'remainingData'})
Aresult
11
00
11281 0 $o->{remainingData} -= $read;
11282 0 $sha->add($buffer);
11283 0 print $fh $buffer;
11284 }
11285  
11286 0 return $sha->digest;
11287 }
11288  
11289 # Reads and drops the request data
11290 sub dropData {
11291 0 ▶ my $o = shift;
Subroutine dropData: not called CC=3 SCAR=24.8
11292  
11293 0 ▶ while ($o->{remainingData} > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"remainingData"} > 0) 0 0 0
11294 0 ▶ $o->{remainingData} -= read(STDIN, my $buffer, $o->{remainingData}) || return;
Condition0%0/2
read(STDIN, my $buffer, $o->{'remainingData'}) || (return)
l!l
00
MC/DC0%0/1
read(STDIN, my $buffer, $o->{'remainingData'}) || (return)
read(STDIN, my $buffer, $o->{'remainingData'})
Truth table0%0/2
A
A= read(STDIN, my $buffer, $o->{'remainingData'})
Aresult
11
00
11295 }
11296 }
11297  
11298 # *** Headers
11299  
11300 sub setHeader {
11301 0 ▶ my $o = shift;
Subroutine setHeader: not called CC=1 SCAR=6.9
11302 0 my $key = shift;
11303 0 my $value = shift;
11304  
11305 0 $o->{headers}->{lc($key)} = $value;
11306 }
11307  
11308 sub header {
11309 0 ▶ my $o = shift;
Subroutine header: not called CC=1 SCAR=6.9
11310 0 my $key = shift;
11311  
11312 0 return $o->{headers}->{lc($key)};
11313 }
11314  
11315 # *** Query string
11316  
11317 sub parseQueryString {
11318 0 ▶ my $o = shift;
Subroutine parseQueryString: not called CC=4 SCAR=30.0
11319  
11320 0 ▶ return {} if ! defined $o->{queryString};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $o->{"queryString"} 0 0 0
11321  
11322 0 my $values = {};
11323 0 for my $pair (split /&/, $o->{queryString}) {
11324 0 ▶ if ($pair =~ /^(.*?)=(.*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pair =~ /^(.*?)=(.*)$/) { } 0 0 0
11325 0 my $key = $1;
11326 0 my $value = $2;
11327 0 $values->{&uri_decode($key)} = &uri_decode($value);
11328 } else {
11329 0 $values->{&uri_decode($pair)} = 1;
11330 }
11331 }
11332  
11333 0 return $values;
11334 }
11335  
11336 sub uri_decode {
11337 0 ▶ my $encoded = shift;
Subroutine uri_decode: not called CC=1 SCAR=6.9
11338  
11339 0 $encoded =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg;
11340 0 return $encoded;
11341 }
11342  
11343 # *** Condensation signature
11344  
11345 sub checkSignature {
11346 0 ▶ my $o = shift;
Subroutine checkSignature: not called CC=14 SCAR=53.5
11347 0 my $store = shift;
11348 0 my $contentBytesToSign = shift;
11349  
11350 # Check the date
11351 0 ▶ my $dateString = $o->{headers}->{'condensation-date'} // $o->{headers}->{'date'} // return;
Condition0%0/5
($o->{"headers"}{"condensation-date"} // $o->{"headers"}{"date"}) // (return)
l!l
00
$o->{"headers"}{"condensation-date"} // $o->{"headers"}{"date"}
l!l&&r!l&&!r
000
MC/DC0%0/2
($o->{"headers"}{"condensation-date"} // $o->{"headers"}{"date"}) // (return)
$o->{"headers"}{"condensation-date"} $o->{"headers"}{"date"}
Truth table0%0/3
A // B
A= $o->{"headers"}{"condensation-date"}B= $o->{"headers"}{"date"}
ABresult
1X1
011
000
11352 0 ▶ my $date = HTTP::Date::str2time($dateString) // return;
Condition0%0/2
&HTTP::Date::str2time($dateString) // (return)
l!l
00
MC/DC0%0/1
&HTTP::Date::str2time($dateString) // (return)
&HTTP::Date::str2time($dateString)
Truth table0%0/2
A
A= &HTTP::Date::str2time($dateString)
Aresult
11
00
11353 0 my $now = time;
11354 0 ▶ return if $date < $now - 120 || $date > $now + 60;
Branch: 1 branch
BranchTrueFalseTotal
if $date < $now - 120 or $date > $now + 60 0 0 0
Condition0%0/3
$date < $now - 120 or $date > $now + 60
l!l&&r!l&&!r
000
MC/DC0%0/2
$date < $now - 120 or $date > $now + 60
$date < $now - 120 $date > $now + 60
Truth table0%0/3
A or B
A= $date < $now - 120B= $date > $now + 60
ABresult
1X1
011
000
11355  
11356 # Get and check the actor
11357 0 ▶ my $actorHash = CDS::Hash->fromHex($o->{headers}->{'condensation-actor'}) // return;
Condition0%0/2
"CDS::Hash"->fromHex($o->{"headers"}{"condensation-actor"}) // (return)
l!l
00
MC/DC0%0/1
"CDS::Hash"->fromHex($o->{"headers"}{"condensation-actor"}) // (return)
"CDS::Hash"->fromHex($o->{"headers"}{"condensation-actor"})
Truth table0%0/2
A
A= "CDS::Hash"->fromHex($o->{"headers"}{"condensation-actor"})
Aresult
11
00
11358 0 my ($publicKeyObject, $error) = $store->get($actorHash);
11359 0 ▶ return if ! $publicKeyObject;
Branch: 1 branch
BranchTrueFalseTotal
unless $publicKeyObject 0 0 0
11360 0 ▶ return if ! $publicKeyObject->calculateHash->equals($actorHash);
Branch: 1 branch
BranchTrueFalseTotal
unless $publicKeyObject->calculateHash->equals($actorHash) 0 0 0
11361 0 ▶ my $publicKey = CDS::PublicKey->fromObject($publicKeyObject) // return;
Condition0%0/2
"CDS::PublicKey"->fromObject($publicKeyObject) // (return)
l!l
00
MC/DC0%0/1
"CDS::PublicKey"->fromObject($publicKeyObject) // (return)
"CDS::PublicKey"->fromObject($publicKeyObject)
Truth table0%0/2
A
A= "CDS::PublicKey"->fromObject($publicKeyObject)
Aresult
11
00
11362  
11363 # Text to sign
11364 0 my $bytesToSign = $dateString."\0".uc($o->{method})."\0".$o->{headers}->{'host'}.$o->{path};
11365 0 ▶ $bytesToSign .= "\0".$contentBytesToSign if defined $contentBytesToSign;
Branch: 1 branch
BranchTrueFalseTotal
if defined $contentBytesToSign 0 0 0
11366 0 my $hashToSign = CDS::Hash->calculateFor($bytesToSign);
11367  
11368 # Check the signature
11369 0 ▶ my $signatureString = $o->{headers}->{'condensation-signature'} // return;
Condition0%0/2
$o->{"headers"}{"condensation-signature"} // (return)
l!l
00
MC/DC0%0/1
$o->{"headers"}{"condensation-signature"} // (return)
$o->{"headers"}{"condensation-signature"}
Truth table0%0/2
A
A= $o->{"headers"}{"condensation-signature"}
Aresult
11
00
11370 0 ▶ $signatureString =~ /^\s*([0-9a-z]{512,512})\s*$/ // return;
Condition0%0/2
$signatureString =~ /^\s*([0-9a-z]{512,512})\s*$/ // (return)
l!l
00
MC/DC0%0/1
$signatureString =~ /^\s*([0-9a-z]{512,512})\s*$/ // (return)
$signatureString =~ /^\s*([0-9a-z]{512,512})\s*$/
Truth table0%0/2
A
A= $signatureString =~ /^\s*([0-9a-z]{512,512})\s*$/
Aresult
11
00
11371 0 my $signature = pack('H*', $1);
11372 0 ▶ return if ! $publicKey->verifyHash($hashToSign, $signature);
Branch: 1 branch
BranchTrueFalseTotal
unless $publicKey->verifyHash($hashToSign, $signature) 0 0 0
11373  
11374 # Return the verified actor hash
11375 0 return $actorHash;
11376 }
11377  
11378 # *** Reply functions
11379  
11380 sub reply200 {
11381 0 ▶ my $o = shift;
Subroutine reply200: not called CC=3 SCAR=24.8
11382 0 ▶ my $content = shift // '';
Condition0%0/2
shift() // ""
l!l
00
MC/DC0%0/1
shift() // ""
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
11383  
11384 0 ▶ return length $content ? $o->reply(200, 'OK', &textContentType, $content) : $o->reply(204, 'No Content', {});
Branch: 1 branch
BranchTrueFalseTotal
length $content ? : 0 0 0
11385 }
11386  
11387 sub reply200Bytes {
11388 0 ▶ my $o = shift;
Subroutine reply200Bytes: not called CC=3 SCAR=24.8
11389 0 ▶ my $content = shift // '';
Condition0%0/2
shift() // ""
l!l
00
MC/DC0%0/1
shift() // ""
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
11390  
11391 0 ▶ return length $content ? $o->reply(200, 'OK', {'Content-Type' => 'application/octet-stream'}, $content) : $o->reply(204, 'No Content', {});
Branch: 1 branch
BranchTrueFalseTotal
length $content ? : 0 0 0
11392 }
11393  
11394 sub reply200HTML {
11395 0 ▶ my $o = shift;
Subroutine reply200HTML: not called CC=3 SCAR=24.8
11396 0 ▶ my $content = shift // '';
Condition0%0/2
shift() // ""
l!l
00
MC/DC0%0/1
shift() // ""
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
11397  
11398 0 ▶ return length $content ? $o->reply(200, 'OK', {'Content-Type' => 'text/html; charset=utf-8'}, $content) : $o->reply(204, 'No Content', {});
Branch: 1 branch
BranchTrueFalseTotal
length $content ? : 0 0 0
11399 }
11400  
11401 sub replyOptions {
11402 0 ▶ my $o = shift;
Subroutine replyOptions: not called CC=3 SCAR=24.8
11403  
11404 0 my $headers = {};
11405 0 $headers->{'Allow'} = join(', ', @_, 'OPTIONS');
11406 0 ▶ $headers->{'Access-Control-Allow-Methods'} = join(', ', @_, 'OPTIONS') if $o->corsAllowEverybody && $o->{headers}->{'origin'};
Branch: 1 branch
BranchTrueFalseTotal
if $o->corsAllowEverybody and $o->{"headers"}{"origin"} 0 0 0
Condition0%0/3
$o->corsAllowEverybody and $o->{"headers"}{"origin"}
!ll&&!rl&&r
000
MC/DC0%0/2
$o->corsAllowEverybody and $o->{"headers"}{"origin"}
$o->corsAllowEverybody $o->{"headers"}{"origin"}
Truth table0%0/3
A and B
A= $o->corsAllowEverybodyB= $o->{"headers"}{"origin"}
ABresult
0X0
100
111
11407 0 return $o->reply(200, 'OK', $headers);
11408 }
11409  
11410 sub replyFatalError {
11411 0 ▶ my $o = shift;
Subroutine replyFatalError: not called CC=1 SCAR=6.9
11412  
11413 0 $o->{logger}->onRequestError($o, @_);
11414 0 return $o->reply500;
11415 }
11416  
11417 sub reply303 {
11418 0 ▶ my $o = shift;
Subroutine reply303: not called CC=1 SCAR=6.9
11419 0 my $location = shift;
11420 0 $o->reply(303, 'See Other', {'Location' => $location}) }
11421 0 ▶sub reply400 { shift->reply(400, 'Bad Request', &textContentType, @_) }
Subroutine reply400: not called CC=1 SCAR=6.9
11422 0 ▶sub reply403 { shift->reply(403, 'Forbidden', &textContentType, @_) }
Subroutine reply403: not called CC=1 SCAR=6.9
11423 0 ▶sub reply404 { shift->reply(404, 'Not Found', &textContentType, @_) }
Subroutine reply404: not called CC=1 SCAR=6.9
11424 0 ▶sub reply405 { shift->reply(405, 'Method Not Allowed', &textContentType, @_) }
Subroutine reply405: not called CC=1 SCAR=6.9
11425 0 ▶sub reply500 { shift->reply(500, 'Internal Server Error', &textContentType, @_) }
Subroutine reply500: not called CC=1 SCAR=6.9
11426 0 ▶sub reply503 { shift->reply(503, 'Service Not Available', &textContentType, @_) }
Subroutine reply503: not called CC=1 SCAR=6.9
11427  
11428 sub reply {
11429 0 ▶ my $o = shift;
Subroutine reply: not called CC=7 SCAR=40.3
11430 0 my $responseCode = shift;
11431 0 my $responseLabel = shift;
11432 0 ▶ my $headers = shift // {};
Condition0%0/2
shift() // {}
l!l
00
MC/DC0%0/1
shift() // {}
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
11433 0 ▶ my $content = shift // '';
Condition0%0/2
shift() // ""
l!l
00
MC/DC0%0/1
shift() // ""
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
11434  
11435 # Content-related headers
11436 0 $headers->{'Content-Length'} = length($content);
11437  
11438 # Origin
11439 0 ▶ if ($o->corsAllowEverybody && (my $origin = $o->{headers}->{'origin'})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->corsAllowEverybody and my $origin = $o->{"headers"}{"origin"}) 0 0 0
Condition0%0/3
$o->corsAllowEverybody and my $origin = $o->{"headers"}{"origin"}
!ll&&!rl&&r
000
MC/DC0%0/2
$o->corsAllowEverybody and my $origin = $o->{"headers"}{"origin"}
$o->corsAllowEverybody my $origin = $o->{"headers"}{"origin"}
Truth table0%0/3
A and B
A= $o->corsAllowEverybodyB= my $origin = $o->{"headers"}{"origin"}
ABresult
0X0
100
111
11440 0 $headers->{'Access-Control-Allow-Origin'} = $origin;
11441 0 $headers->{'Access-Control-Allow-Headers'} = 'Content-Type';
11442 0 $headers->{'Access-Control-Max-Age'} = '86400';
11443 }
11444  
11445 # Write the reply
11446 0 print 'HTTP/1.1 ', $responseCode, ' ', $responseLabel, "\r\n";
11447 0 for my $key (keys %$headers) {
11448 0 print $key, ': ', $headers->{$key}, "\r\n";
11449 }
11450 0 print "\r\n";
11451 0 ▶ print $content if $o->{method} ne 'HEAD';
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"method"} ne "HEAD" 0 0 0
11452  
11453 # Return the response code
11454 0 return $responseCode;
11455 }
11456  
11457 0 ▶sub textContentType { {'Content-Type' => 'text/plain; charset=utf-8'} }
Subroutine textContentType: not called CC=1 SCAR=6.9
11458  
11459 package CDS::HTTPServer::StaticContentHandler;
11460  
11461 sub new {
11462 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
11463 0 my $path = shift;
11464 0 my $content = shift;
11465 0 my $contentType = shift;
11466  
11467 0 return bless {
11468 path => $path,
11469 content => $content,
11470 contentType => $contentType,
11471 };
11472 }
11473  
11474 sub process {
11475 0 ▶ my $o = shift;
Subroutine process: not called CC=4 SCAR=30.0
11476 0 my $request = shift;
11477  
11478 0 ▶ return if $request->path ne $o->{path};
Branch: 1 branch
BranchTrueFalseTotal
if $request->path ne $o->{"path"} 0 0 0
11479  
11480 # Options
11481 0 ▶ return $request->replyOptions('HEAD', 'GET') if $request->method eq 'OPTIONS';
Branch: 1 branch
BranchTrueFalseTotal
if $request->method eq "OPTIONS" 0 0 0
11482  
11483 # GET
11484 0 ▶ return $request->reply(200, 'OK', {'Content-Type' => $o->{contentType}}, $o->{content}) if $request->method eq 'GET';
Branch: 1 branch
BranchTrueFalseTotal
if $request->method eq "GET" 0 0 0
11485  
11486 # Everything else
11487 0 return $request->reply405;
11488 }
11489  
11490 package CDS::HTTPServer::StaticFilesHandler;
11491  
11492 sub new {
11493 0 ▶ my $class = shift;
Subroutine new: not called CC=2 SCAR=17.9
11494 0 my $root = shift;
11495 0 my $folder = shift;
11496 0 ▶ my $defaultFile = shift // '';
Condition0%0/2
shift() // ""
l!l
00
MC/DC0%0/1
shift() // ""
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
11497  
11498 0 return bless {
11499 root => $root,
11500 folder => $folder,
11501 defaultFile => $defaultFile,
11502 mimeTypesByExtension => {
11503 'css' => 'text/css',
11504 'gif' => 'image/gif',
11505 'html' => 'text/html',
11506 'jpg' => 'image/jpeg',
11507 'jpeg' => 'image/jpeg',
11508 'js' => 'application/javascript',
11509 'mp4' => 'video/mp4',
11510 'ogg' => 'video/ogg',
11511 'pdf' => 'application/pdf',
11512 'png' => 'image/png',
11513 'svg' => 'image/svg+xml',
11514 'txt' => 'text/plain',
11515 'webm' => 'video/webm',
11516 'zip' => 'application/zip',
11517 },
11518 };
11519 }
11520  
11521 0 ▶sub folder { shift->{folder} }
Subroutine folder: not called CC=1 SCAR=6.9
11522 0 ▶sub defaultFile { shift->{defaultFile} }
Subroutine defaultFile: not called CC=1 SCAR=6.9
11523 0 ▶sub mimeTypesByExtension { shift->{mimeTypesByExtension} }
Subroutine mimeTypesByExtension: not called CC=1 SCAR=6.9
11524  
11525 sub setContentType {
11526 0 ▶ my $o = shift;
Subroutine setContentType: not called CC=1 SCAR=6.9
11527 0 my $extension = shift;
11528 0 my $contentType = shift;
11529  
11530 0 $o->{mimeTypesByExtension}->{$extension} = $contentType;
11531 }
11532  
11533 sub process {
11534 0 ▶ my $o = shift;
Subroutine process: not called CC=4 SCAR=30.0
11535 0 my $request = shift;
11536  
11537 # Options
11538 0 ▶ return $request->replyOptions('HEAD', 'GET') if $request->method eq 'OPTIONS';
Branch: 1 branch
BranchTrueFalseTotal
if $request->method eq "OPTIONS" 0 0 0
11539  
11540 # Get
11541 0 ▶ return $o->get($request) if $request->method eq 'GET' || $request->method eq 'HEAD';
Branch: 1 branch
BranchTrueFalseTotal
if $request->method eq "GET" or $request->method eq "HEAD" 0 0 0
Condition0%0/3
$request->method eq "GET" or $request->method eq "HEAD"
l!l&&r!l&&!r
000
MC/DC0%0/2
$request->method eq "GET" or $request->method eq "HEAD"
$request->method eq "GET" $request->method eq "HEAD"
Truth table0%0/3
A or B
A= $request->method eq "GET"B= $request->method eq "HEAD"
ABresult
1X1
011
000
11542  
11543 # Anything else
11544 0 return $request->reply405;
11545 }
11546  
11547 sub get {
11548 0 ▶ my $o = shift;
Subroutine get: not called CC=2 SCAR=17.9
11549 0 my $request = shift;
11550  
11551 0 ▶ my $path = $request->pathAbove($o->{root}) // return;
Condition0%0/2
$request->pathAbove($o->{"root"}) // (return)
l!l
00
MC/DC0%0/1
$request->pathAbove($o->{"root"}) // (return)
$request->pathAbove($o->{"root"})
Truth table0%0/2
A
A= $request->pathAbove($o->{"root"})
Aresult
11
00
11552 0 return $o->deliverFileForPath($request, $path);
11553 }
11554  
11555 sub deliverFileForPath {
11556 0 ▶ my $o = shift;
Subroutine deliverFileForPath: not called CC=6 SCAR=37.4
11557 0 my $request = shift;
11558 0 my $path = shift;
11559  
11560 # Hidden files (starting with a dot), as well as "." and ".." never exist
11561 0 for my $segment (split /\/+/, $path) {
11562 0 ▶ return $request->reply404 if $segment =~ /^\./;
Branch: 1 branch
BranchTrueFalseTotal
if $segment =~ /^\./ 0 0 0
11563 }
11564  
11565 # If a folder is requested, we serve the default file
11566 0 my $file = $o->{folder}.$path;
11567 0 ▶ if (-d $file) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $file) 0 0 0
11568 0 ▶ return $request->reply404 if ! length $o->{defaultFile};
Branch: 1 branch
BranchTrueFalseTotal
unless length $o->{"defaultFile"} 0 0 0
11569 0 ▶ return $request->reply303($request->path.'/') if $file !~ /\/$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $file =~ m[/$] 0 0 0
11570 0 $file .= $o->{defaultFile};
11571 }
11572  
11573 0 return $o->deliverFile($request, $file);
11574 }
11575  
11576 sub deliverFile {
11577 0 ▶ my $o = shift;
Subroutine deliverFile: not called CC=3 SCAR=24.8
11578 0 my $request = shift;
11579 0 my $file = shift;
11580 0 ▶ my $contentType = shift // $o->guessContentType($file);
Condition0%0/3
shift() // $o->guessContentType($file)
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() // $o->guessContentType($file)
shift() $o->guessContentType($file)
Truth table0%0/3
A // B
A= shift()B= $o->guessContentType($file)
ABresult
1X1
011
000
11581  
11582 0 ▶ my $bytes = $o->readFile($file) // return $request->reply404;
Condition0%0/2
$o->readFile($file) // (return $request->reply404)
l!l
00
MC/DC0%0/1
$o->readFile($file) // (return $request->reply404)
$o->readFile($file)
Truth table0%0/2
A
A= $o->readFile($file)
Aresult
11
00
11583 0 return $request->reply(200, 'OK', {'Content-Type' => $contentType}, $bytes);
11584 }
11585  
11586 # Guesses the content type from the extension
11587 sub guessContentType {
11588 0 ▶ my $o = shift;
Subroutine guessContentType: not called CC=3 SCAR=24.8
11589 0 my $file = shift;
11590  
11591 0 ▶ my $extension = $file =~ /\.([A-Za-z0-9]*)$/ ? lc($1) : '';
Branch: 1 branch
BranchTrueFalseTotal
$file =~ /\.([A-Za-z0-9]*)$/ ? : 0 0 0
11592 0 ▶ return $o->{mimeTypesByExtension}->{$extension} // 'application/octet-stream';
Condition0%0/2
$o->{"mimeTypesByExtension"}{$extension} // "application/octet-stream"
l!l
00
MC/DC0%0/1
$o->{"mimeTypesByExtension"}{$extension} // "application/octet-stream"
$o->{"mimeTypesByExtension"}{$extension}
Truth table0%0/2
A
A= $o->{"mimeTypesByExtension"}{$extension}
Aresult
11
00
11593 }
11594  
11595 # Reads a file
11596 sub readFile {
11597 0 ▶ my $o = shift;
Subroutine readFile: not called CC=3 SCAR=24.8
11598 0 my $file = shift;
11599  
11600 0 ▶ open(my $fh, '<:bytes', $file) || return;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<:bytes", $file or return 0 0 0
11601 0 ▶ if (! -f $fh) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-f $fh) 0 0 0
11602 0 close $fh;
11603 0 return;
11604 }
11605  
11606 0 local $/ = undef;
11607 0 my $bytes = <$fh>;
11608 0 close $fh;
11609 0 return $bytes;
11610 }
11611  
11612 package CDS::HTTPServer::StoreHandler;
11613  
11614 sub new {
11615 0 ▶ my $class = shift;
Subroutine new: not called CC=2 SCAR=17.9
11616 0 my $root = shift;
11617 0 my $store = shift;
11618 0 my $checkPutHash = shift;
11619 0 ▶ my $checkSignatures = shift // 1;
Condition0%0/2
shift() // 1
l!l
00
MC/DC0%0/1
shift() // 1
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
11620  
11621 0 return bless {
11622 root => $root,
11623 store => $store,
11624 checkPutHash => $checkPutHash,
11625 checkEnvelopeHash => $checkPutHash,
11626 checkSignatures => $checkSignatures,
11627 maximumWatchTimeout => 0,
11628 };
11629 }
11630  
11631 sub process {
11632 0 ▶ my $o = shift;
Subroutine process: not called CC=9 SCAR=45.0
11633 0 my $request = shift;
11634  
11635 0 ▶ my $path = $request->pathAbove($o->{root}) // return;
Condition0%0/2
$request->pathAbove($o->{"root"}) // (return)
l!l
00
MC/DC0%0/1
$request->pathAbove($o->{"root"}) // (return)
$request->pathAbove($o->{"root"})
Truth table0%0/2
A
A= $request->pathAbove($o->{"root"})
Aresult
11
00
11636  
11637 # Objects request
11638 0 ▶ if ($request->path =~ /^\/objects\/([0-9a-f]{64})$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($request->path =~ m[^/objects/([0-9a-f]{64})$]) 0 0 0
11639 0 my $hash = CDS::Hash->fromHex($1);
11640 0 return $o->objects($request, $hash);
11641 }
11642  
11643 # Box request
11644 0 ▶ if ($request->path =~ /^\/accounts\/([0-9a-f]{64})\/(messages|private|public)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($request->path =~ m[^/accounts/([0-9a-f]{64})/(messages|private|public)$]) 0 0 0
11645 0 my $accountHash = CDS::Hash->fromHex($1);
11646 0 my $boxLabel = $2;
11647 0 return $o->box($request, $accountHash, $boxLabel);
11648 }
11649  
11650 # Box entry request
11651 0 ▶ if ($request->path =~ /^\/accounts\/([0-9a-f]{64})\/(messages|private|public)\/([0-9a-f]{64})$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($request->path =~ m[^/accounts/([0-9a-f]{64})/(messages|private|public)/([0-9a-f]{64})$]) 0 0 0
11652 0 my $accountHash = CDS::Hash->fromHex($1);
11653 0 my $boxLabel = $2;
11654 0 my $hash = CDS::Hash->fromHex($3);
11655 0 return $o->boxEntry($request, $accountHash, $boxLabel, $hash);
11656 }
11657  
11658 # Account request
11659 0 ▶ if ($request->path =~ /^\/accounts\/([0-9a-f]{64})$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($request->path =~ m[^/accounts/([0-9a-f]{64})$]) 0 0 0
11660 0 ▶ return $request->replyOptions if $request->method eq 'OPTIONS';
Branch: 1 branch
BranchTrueFalseTotal
if $request->method eq "OPTIONS" 0 0 0
11661 0 return $request->reply405;
11662 }
11663  
11664 # Accounts request
11665 0 ▶ if ($request->path =~ /^\/accounts$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($request->path =~ m[^/accounts$]) 0 0 0
11666 0 return $o->accounts($request);
11667 }
11668  
11669 # Other requests on /objects or /accounts
11670 0 ▶ if ($request->path =~ /^\/(accounts|objects)(\/|$)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($request->path =~ m[^/(accounts|objects)(/|$)]) 0 0 0
11671 0 return $request->reply404;
11672 }
11673  
11674 # Nothing for us
11675 0 return;
11676 }
11677  
11678 sub objects {
11679 0 ▶ my $o = shift;
Subroutine objects: not called CC=22 SCAR=62.3
11680 0 my $request = shift;
11681 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
11682  
11683 # Options
11684 0 ▶ if ($request->method eq 'OPTIONS') {
Branch: 1 branch
BranchTrueFalseTotal
if ($request->method eq "OPTIONS") 0 0 0
11685 0 return $request->replyOptions('HEAD', 'GET', 'PUT', 'POST');
11686 }
11687  
11688 # Retrieve object
11689 0 ▶ if ($request->method eq 'HEAD' || $request->method eq 'GET') {
Branch: 1 branch
BranchTrueFalseTotal
if ($request->method eq "HEAD" or $request->method eq "GET") 0 0 0
Condition0%0/3
$request->method eq "HEAD" or $request->method eq "GET"
l!l&&r!l&&!r
000
MC/DC0%0/2
$request->method eq "HEAD" or $request->method eq "GET"
$request->method eq "HEAD" $request->method eq "GET"
Truth table0%0/3
A or B
A= $request->method eq "HEAD"B= $request->method eq "GET"
ABresult
1X1
011
000
11690 0 my ($object, $error) = $o->{store}->get($hash);
11691 0 ▶ return $request->replyFatalError($error) if defined $error;
Branch: 1 branch
BranchTrueFalseTotal
if defined $error 0 0 0
11692 0 ▶ return $request->reply404 if ! $object;
Branch: 1 branch
BranchTrueFalseTotal
unless $object 0 0 0
11693 # We don't check the SHA256 sum here - this should be done by the client
11694 0 return $request->reply200Bytes($object->bytes);
11695 }
11696  
11697 # Put object
11698 0 ▶ if ($request->method eq 'PUT') {
Branch: 1 branch
BranchTrueFalseTotal
if ($request->method eq "PUT") 0 0 0
11699 0 ▶ my $bytes = $request->readData // return $request->reply400('No data received.');
Condition0%0/2
$request->readData // (return $request->reply400("No data received."))
l!l
00
MC/DC0%0/1
$request->readData // (return $request->reply400("No data received."))
$request->readData
Truth table0%0/2
A
A= $request->readData
Aresult
11
00
11700 0 ▶ my $object = CDS::Object->fromBytes($bytes) // return $request->reply400('Not a Condensation object.');
Condition0%0/2
"CDS::Object"->fromBytes($bytes) // (return $request->reply400("Not a Condensation object."))
l!l
00
MC/DC0%0/1
"CDS::Object"->fromBytes($bytes) // (return $request->reply400("Not a Condensation object."))
"CDS::Object"->fromBytes($bytes)
Truth table0%0/2
A
A= "CDS::Object"->fromBytes($bytes)
Aresult
11
00
11701 0 ▶ return $request->reply400('SHA256 sum does not match hash.') if $o->{checkPutHash} && ! $object->calculateHash->equals($hash);
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"checkPutHash"} and not $object->calculateHash->equals($hash) 0 0 0
Condition0%0/3
$o->{"checkPutHash"} and not $object->calculateHash->equals($hash)
!ll&&!rl&&r
000
MC/DC0%0/2
$o->{"checkPutHash"} and not $object->calculateHash->equals($hash)
$o->{"checkPutHash"} not $object->calculateHash->equals($hash)
Truth table0%0/3
A and not(B)
A= $o->{"checkPutHash"}B= not $object->calculateHash->equals($hash)
ABresult
0X0
100
111
11702  
11703 0 ▶ if ($o->{checkSignatures}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"checkSignatures"}) 0 0 0
11704 0 my $checkSignatureStore = CDS::CheckSignatureStore->new($o->{store});
11705 0 $checkSignatureStore->put($hash, $object);
11706 0 ▶ return $request->reply403 if ! $request->checkSignature($checkSignatureStore);
Branch: 1 branch
BranchTrueFalseTotal
unless $request->checkSignature($checkSignatureStore) 0 0 0
11707 }
11708  
11709 0 my $error = $o->{store}->put($hash, $object);
11710 0 ▶ return $request->replyFatalError($error) if defined $error;
Branch: 1 branch
BranchTrueFalseTotal
if defined $error 0 0 0
11711 0 return $request->reply200;
11712 }
11713  
11714 # Book object
11715 0 ▶ if ($request->method eq 'POST') {
Branch: 1 branch
BranchTrueFalseTotal
if ($request->method eq "POST") 0 0 0
11716 0 ▶ return $request->reply403 if $o->{checkSignatures} && ! $request->checkSignature($o->{store});
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"checkSignatures"} and not $request->checkSignature($o->{"store"}) 0 0 0
Condition0%0/3
$o->{"checkSignatures"} and not $request->checkSignature($o->{"store"})
!ll&&!rl&&r
000
MC/DC0%0/2
$o->{"checkSignatures"} and not $request->checkSignature($o->{"store"})
$o->{"checkSignatures"} not $request->checkSignature($o->{"store"})
Truth table0%0/3
A and not(B)
A= $o->{"checkSignatures"}B= not $request->checkSignature($o->{"store"})
ABresult
0X0
100
111
11717 0 ▶ return $request->reply400('You cannot send data when booking an object.') if $request->remainingData;
Branch: 1 branch
BranchTrueFalseTotal
if $request->remainingData 0 0 0
11718 0 my ($booked, $error) = $o->{store}->book($hash);
11719 0 ▶ return $request->replyFatalError($error) if defined $error;
Branch: 1 branch
BranchTrueFalseTotal
if defined $error 0 0 0
11720 0 ▶ return $booked ? $request->reply200 : $request->reply404;
Branch: 1 branch
BranchTrueFalseTotal
$booked ? : 0 0 0
11721 }
11722  
11723 0 return $request->reply405;
11724 }
11725  
11726 sub box {
11727 0 ▶ my $o = shift;
Subroutine box: not called CC=10 SCAR=47.0
11728 0 my $request = shift;
11729 0 ▶ my $accountHash = shift; die 'wrong type '.ref($accountHash).' for $accountHash' if defined $accountHash && ref $accountHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $accountHash and ref $accountHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $accountHash and ref $accountHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $accountHash and ref $accountHash ne "CDS::Hash"
defined $accountHash ref $accountHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $accountHashB= ref $accountHash ne "CDS::Hash"
ABresult
0X0
100
111
11730 0 my $boxLabel = shift;
11731  
11732 # Options
11733 0 ▶ if ($request->method eq 'OPTIONS') {
Branch: 1 branch
BranchTrueFalseTotal
if ($request->method eq "OPTIONS") 0 0 0
11734 0 return $request->replyOptions('HEAD', 'GET', 'PUT', 'POST');
11735 }
11736  
11737 # List box
11738 0 ▶ if ($request->method eq 'HEAD' || $request->method eq 'GET') {
Branch: 1 branch
BranchTrueFalseTotal
if ($request->method eq "HEAD" or $request->method eq "GET") 0 0 0
Condition0%0/3
$request->method eq "HEAD" or $request->method eq "GET"
l!l&&r!l&&!r
000
MC/DC0%0/2
$request->method eq "HEAD" or $request->method eq "GET"
$request->method eq "HEAD" $request->method eq "GET"
Truth table0%0/3
A or B
A= $request->method eq "HEAD"B= $request->method eq "GET"
ABresult
1X1
011
000
11739 0 ▶ my $watch = $request->headers->{'condensation-watch'} // '';
Condition0%0/2
$request->headers->{"condensation-watch"} // ""
l!l
00
MC/DC0%0/1
$request->headers->{"condensation-watch"} // ""
$request->headers->{"condensation-watch"}
Truth table0%0/2
A
A= $request->headers->{"condensation-watch"}
Aresult
11
00
11740 0 ▶ my $timeout = $watch =~ /^(\d+)\s*ms$/ ? $1 + 0 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$watch =~ /^(\d+)\s*ms$/ ? : 0 0 0
11741 0 ▶ $timeout = $o->{maximumWatchTimeout} if $timeout > $o->{maximumWatchTimeout};
Branch: 1 branch
BranchTrueFalseTotal
if $timeout > $o->{"maximumWatchTimeout"} 0 0 0
11742 0 my ($hashes, $error) = $o->{store}->list($accountHash, $boxLabel, $timeout);
11743 0 ▶ return $request->replyFatalError($error) if defined $error;
Branch: 1 branch
BranchTrueFalseTotal
if defined $error 0 0 0
11744 0 return $request->reply200Bytes(join('', map { $_->bytes } @$hashes));
11745 }
11746  
11747 0 return $request->reply405;
11748 }
11749  
11750 sub boxEntry {
11751 0 ▶ my $o = shift;
Subroutine boxEntry: not called CC=16 SCAR=56.1
11752 0 my $request = shift;
11753 0 ▶ my $accountHash = shift; die 'wrong type '.ref($accountHash).' for $accountHash' if defined $accountHash && ref $accountHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $accountHash and ref $accountHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $accountHash and ref $accountHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $accountHash and ref $accountHash ne "CDS::Hash"
defined $accountHash ref $accountHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $accountHashB= ref $accountHash ne "CDS::Hash"
ABresult
0X0
100
111
11754 0 my $boxLabel = shift;
11755 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
11756  
11757 # Options
11758 0 ▶ if ($request->method eq 'OPTIONS') {
Branch: 1 branch
BranchTrueFalseTotal
if ($request->method eq "OPTIONS") 0 0 0
11759 0 return $request->replyOptions('HEAD', 'PUT', 'DELETE');
11760 }
11761  
11762 # Add
11763 0 ▶ if ($request->method eq 'PUT') {
Branch: 1 branch
BranchTrueFalseTotal
if ($request->method eq "PUT") 0 0 0
11764 0 ▶ if ($o->{checkSignatures}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"checkSignatures"}) 0 0 0
11765 0 my $actorHash = $request->checkSignature($o->{store});
11766 0 ▶ return $request->reply403 if ! $actorHash;
Branch: 1 branch
BranchTrueFalseTotal
unless $actorHash 0 0 0
11767 0 ▶ return $request->reply403 if ! $o->verifyAddition($actorHash, $accountHash, $boxLabel, $hash);
Branch: 1 branch
BranchTrueFalseTotal
unless $o->verifyAddition($actorHash, $accountHash, $boxLabel, $hash) 0 0 0
11768 }
11769  
11770 0 my $error = $o->{store}->add($accountHash, $boxLabel, $hash);
11771 0 ▶ return $request->replyFatalError($error) if defined $error;
Branch: 1 branch
BranchTrueFalseTotal
if defined $error 0 0 0
11772 0 return $request->reply200;
11773 }
11774  
11775 # Remove
11776 0 ▶ if ($request->method eq 'DELETE') {
Branch: 1 branch
BranchTrueFalseTotal
if ($request->method eq "DELETE") 0 0 0
11777 0 ▶ if ($o->{checkSignatures}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"checkSignatures"}) 0 0 0
11778 0 my $actorHash = $request->checkSignature($o->{store});
11779 0 ▶ return $request->reply403 if ! $actorHash;
Branch: 1 branch
BranchTrueFalseTotal
unless $actorHash 0 0 0
11780 0 ▶ return $request->reply403 if ! $o->verifyRemoval($actorHash, $accountHash, $boxLabel, $hash);
Branch: 1 branch
BranchTrueFalseTotal
unless $o->verifyRemoval($actorHash, $accountHash, $boxLabel, $hash) 0 0 0
11781 }
11782  
11783 0 my ($booked, $error) = $o->{store}->remove($accountHash, $boxLabel, $hash);
11784 0 ▶ return $request->replyFatalError($error) if defined $error;
Branch: 1 branch
BranchTrueFalseTotal
if defined $error 0 0 0
11785 0 return $request->reply200;
11786 }
11787  
11788 0 return $request->reply405;
11789 }
11790  
11791 sub accounts {
11792 0 ▶ my $o = shift;
Subroutine accounts: not called CC=9 SCAR=45.0
11793 0 my $request = shift;
11794  
11795 # Options
11796 0 ▶ if ($request->method eq 'OPTIONS') {
Branch: 1 branch
BranchTrueFalseTotal
if ($request->method eq "OPTIONS") 0 0 0
11797 0 return $request->replyOptions('POST');
11798 }
11799  
11800 # Modify boxes
11801 0 ▶ if ($request->method eq 'POST') {
Branch: 1 branch
BranchTrueFalseTotal
if ($request->method eq "POST") 0 0 0
11802 0 ▶ my $bytes = $request->readData // return $request->reply400('No data received.');
Condition0%0/2
$request->readData // (return $request->reply400("No data received."))
l!l
00
MC/DC0%0/1
$request->readData // (return $request->reply400("No data received."))
$request->readData
Truth table0%0/2
A
A= $request->readData
Aresult
11
00
11803 0 my $modifications = CDS::StoreModifications->fromBytes($bytes);
11804 0 ▶ return $request->reply400('Invalid modifications.') if ! $modifications;
Branch: 1 branch
BranchTrueFalseTotal
unless $modifications 0 0 0
11805  
11806 0 ▶ if ($o->{checkSignatures}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"checkSignatures"}) 0 0 0
11807 0 my $actorHash = $request->checkSignature(CDS::CheckSignatureStore->new($o->{store}, $modifications->objects), $bytes);
11808 0 ▶ return $request->reply403 if ! $actorHash;
Branch: 1 branch
BranchTrueFalseTotal
unless $actorHash 0 0 0
11809 0 ▶ return $request->reply403 if ! $o->verifyModifications($actorHash, $modifications);
Branch: 1 branch
BranchTrueFalseTotal
unless $o->verifyModifications($actorHash, $modifications) 0 0 0
11810 }
11811  
11812 0 my $error = $o->{store}->modify($modifications);
11813 0 ▶ return $request->replyFatalError($error) if defined $error;
Branch: 1 branch
BranchTrueFalseTotal
if defined $error 0 0 0
11814 0 return $request->reply200;
11815 }
11816  
11817 0 return $request->reply405;
11818 }
11819  
11820 sub verifyModifications {
11821 0 ▶ my $o = shift;
Subroutine verifyModifications: not called CC=7 SCAR=40.3
11822 0 ▶ my $actorHash = shift; die 'wrong type '.ref($actorHash).' for $actorHash' if defined $actorHash && ref $actorHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $actorHash and ref $actorHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $actorHash and ref $actorHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $actorHash and ref $actorHash ne "CDS::Hash"
defined $actorHash ref $actorHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $actorHashB= ref $actorHash ne "CDS::Hash"
ABresult
0X0
100
111
11823 0 my $modifications = shift;
11824  
11825 0 for my $operation (@{$modifications->additions}) {
11826 0 ▶ return if ! $o->verifyAddition($actorHash, $operation->{accountHash}, $operation->{boxLabel}, $operation->{hash});
Branch: 1 branch
BranchTrueFalseTotal
unless $o->verifyAddition($actorHash, $operation->{"accountHash"}, $operation->{"boxLabel"}, $operation->{"hash"}) 0 0 0
11827 }
11828  
11829 0 for my $operation (@{$modifications->removals}) {
11830 0 ▶ return if ! $o->verifyRemoval($actorHash, $operation->{accountHash}, $operation->{boxLabel}, $operation->{hash});
Branch: 1 branch
BranchTrueFalseTotal
unless $o->verifyRemoval($actorHash, $operation->{"accountHash"}, $operation->{"boxLabel"}, $operation->{"hash"}) 0 0 0
11831 }
11832  
11833 0 return 1;
11834 }
11835  
11836 sub verifyAddition {
11837 0 ▶ my $o = shift;
Subroutine verifyAddition: not called CC=9 SCAR=45.0
11838 0 ▶ my $actorHash = shift; die 'wrong type '.ref($actorHash).' for $actorHash' if defined $actorHash && ref $actorHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $actorHash and ref $actorHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $actorHash and ref $actorHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $actorHash and ref $actorHash ne "CDS::Hash"
defined $actorHash ref $actorHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $actorHashB= ref $actorHash ne "CDS::Hash"
ABresult
0X0
100
111
11839 0 ▶ my $accountHash = shift; die 'wrong type '.ref($accountHash).' for $accountHash' if defined $accountHash && ref $accountHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $accountHash and ref $accountHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $accountHash and ref $accountHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $accountHash and ref $accountHash ne "CDS::Hash"
defined $accountHash ref $accountHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $accountHashB= ref $accountHash ne "CDS::Hash"
ABresult
0X0
100
111
11840 0 my $boxLabel = shift;
11841 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
11842  
11843 0 ▶ return 1 if $accountHash->equals($actorHash);
Branch: 1 branch
BranchTrueFalseTotal
if $accountHash->equals($actorHash) 0 0 0
11844 0 ▶ return 1 if $boxLabel eq 'messages';
Branch: 1 branch
BranchTrueFalseTotal
if $boxLabel eq "messages" 0 0 0
11845 0 return;
11846 }
11847  
11848 sub verifyRemoval {
11849 0 ▶ my $o = shift;
Subroutine verifyRemoval: not called CC=14 SCAR=53.5
11850 0 ▶ my $actorHash = shift; die 'wrong type '.ref($actorHash).' for $actorHash' if defined $actorHash && ref $actorHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $actorHash and ref $actorHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $actorHash and ref $actorHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $actorHash and ref $actorHash ne "CDS::Hash"
defined $actorHash ref $actorHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $actorHashB= ref $actorHash ne "CDS::Hash"
ABresult
0X0
100
111
11851 0 ▶ my $accountHash = shift; die 'wrong type '.ref($accountHash).' for $accountHash' if defined $accountHash && ref $accountHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $accountHash and ref $accountHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $accountHash and ref $accountHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $accountHash and ref $accountHash ne "CDS::Hash"
defined $accountHash ref $accountHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $accountHashB= ref $accountHash ne "CDS::Hash"
ABresult
0X0
100
111
11852 0 my $boxLabel = shift;
11853 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
11854  
11855 0 ▶ return 1 if $accountHash->equals($actorHash);
Branch: 1 branch
BranchTrueFalseTotal
if $accountHash->equals($actorHash) 0 0 0
11856  
11857 # Get the envelope
11858 0 my ($bytes, $error) = $o->{store}->get($hash);
11859 0 ▶ return if defined $error;
Branch: 1 branch
BranchTrueFalseTotal
if defined $error 0 0 0
11860 0 ▶ return 1 if ! defined $bytes;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bytes 0 0 0
11861 0 ▶ my $record = CDS::Record->fromObject(CDS::Object->fromBytes($bytes)) // return;
Condition0%0/2
"CDS::Record"->fromObject("CDS::Object"->fromBytes($bytes)) // (return)
l!l
00
MC/DC0%0/1
"CDS::Record"->fromObject("CDS::Object"->fromBytes($bytes)) // (return)
"CDS::Record"->fromObject("CDS::Object"->fromBytes($bytes))
Truth table0%0/2
A
A= "CDS::Record"->fromObject("CDS::Object"->fromBytes($bytes))
Aresult
11
00
11862  
11863 # Allow anyone listed under "updated by"
11864 0 my $actorHashBytes24 = substr($actorHash->bytes, 0, 24);
11865 0 for my $child ($record->child('updated by')->children) {
11866 0 my $hashBytes24 = $child->bytes;
11867 0 ▶ next if length $hashBytes24 != 24;
Branch: 1 branch
BranchTrueFalseTotal
if length $hashBytes24 != 24 0 0 0
11868 0 ▶ return 1 if $hashBytes24 eq $actorHashBytes24;
Branch: 1 branch
BranchTrueFalseTotal
if $hashBytes24 eq $actorHashBytes24 0 0 0
11869 }
11870  
11871 0 return;
11872 }
11873  
11874 # A Condensation store accessed through HTTP or HTTPS.
11875 package CDS::HTTPStore;
11876  
11877 1 ▶use parent -norequire, 'CDS::Store';
Subroutine BEGIN: called CC=1 SCAR=0.0
11878  
11879 sub forUrl {
11880 1 ▶ my $class = shift;
Subroutine forUrl: called CC=2 SCAR=7.0
11881 1 my $url = shift;
11882  
11883 1 ▶ $url =~ /^(http|https):\/\// || return;
Branch: 1 branch
BranchTrueFalseTotal
$url =~ m[^(http|https)://] or return 0 1 1
11884 1 return $class->new($url);
11885 }
11886  
11887 sub new {
11888 1 ▶ my $class = shift;
Subroutine new: called CC=1 SCAR=0.0
11889 1 my $url = shift;
11890  
11891 1 return bless {url => $url};
11892 }
11893  
11894 sub id {
11895 0 ▶ my $o = shift;
Subroutine id: not called CC=1 SCAR=6.9
11896 0 $o->{url} }
11897  
11898 sub get {
11899 0 ▶ my $o = shift;
Subroutine get: not called CC=7 SCAR=40.3
11900 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
11901 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
11902  
11903 0 my $response = $o->request('GET', $o->{url}.'/objects/'.$hash->hex, HTTP::Headers->new);
11904 0 ▶ return if $response->code == 404;
Branch: 1 branch
BranchTrueFalseTotal
if $response->code == 404 0 0 0
11905 0 ▶ return undef, 'get ==> HTTP '.$response->status_line if ! $response->is_success;
Branch: 1 branch
BranchTrueFalseTotal
unless $response->is_success 0 0 0
11906 0 return CDS::Object->fromBytes($response->decoded_content(charset => 'none'));
11907 }
11908  
11909 sub put {
11910 0 ▶ my $o = shift;
Subroutine put: not called CC=8 SCAR=42.8
11911 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
11912 0 ▶ my $object = shift; die 'wrong type '.ref($object).' for $object' if defined $object && ref $object ne 'CDS::Object';
Branch: 1 branch
BranchTrueFalseTotal
if defined $object and ref $object ne "CDS::Object" 0 0 0
Condition0%0/3
defined $object and ref $object ne "CDS::Object"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $object and ref $object ne "CDS::Object"
defined $object ref $object ne "CDS::Object"
Truth table0%0/3
A and B
A= defined $objectB= ref $object ne "CDS::Object"
ABresult
0X0
100
111
11913 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
11914  
11915 0 my $headers = HTTP::Headers->new;
11916 0 $headers->header('Content-Type' => 'application/condensation-object');
11917 0 my $response = $o->request('PUT', $o->{url}.'/objects/'.$hash->hex, $headers, $keyPair, $object->bytes);
11918 0 ▶ return if $response->is_success;
Branch: 1 branch
BranchTrueFalseTotal
if $response->is_success 0 0 0
11919 0 return 'put ==> HTTP '.$response->status_line;
11920 }
11921  
11922 sub book {
11923 0 ▶ my $o = shift;
Subroutine book: not called CC=7 SCAR=40.3
11924 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
11925 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
11926  
11927 0 my $response = $o->request('POST', $o->{url}.'/objects/'.$hash->hex, HTTP::Headers->new, $keyPair);
11928 0 ▶ return if $response->code == 404;
Branch: 1 branch
BranchTrueFalseTotal
if $response->code == 404 0 0 0
11929 0 ▶ return 1 if $response->is_success;
Branch: 1 branch
BranchTrueFalseTotal
if $response->is_success 0 0 0
11930 0 return undef, 'book ==> HTTP '.$response->status_line;
11931 }
11932  
11933 sub list {
11934 0 ▶ my $o = shift;
Subroutine list: not called CC=10 SCAR=47.0
11935 0 ▶ my $accountHash = shift; die 'wrong type '.ref($accountHash).' for $accountHash' if defined $accountHash && ref $accountHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $accountHash and ref $accountHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $accountHash and ref $accountHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $accountHash and ref $accountHash ne "CDS::Hash"
defined $accountHash ref $accountHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $accountHashB= ref $accountHash ne "CDS::Hash"
ABresult
0X0
100
111
11936 0 my $boxLabel = shift;
11937 0 my $timeout = shift;
11938 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
11939  
11940 0 my $boxUrl = $o->{url}.'/accounts/'.$accountHash->hex.'/'.$boxLabel;
11941 0 my $headers = HTTP::Headers->new;
11942 0 ▶ $headers->header('Condensation-Watch' => $timeout.' ms') if $timeout > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $timeout > 0 0 0 0
11943 0 my $response = $o->request('GET', $boxUrl, $headers);
11944 0 ▶ return undef, 'list ==> HTTP '.$response->status_line if ! $response->is_success;
Branch: 1 branch
BranchTrueFalseTotal
unless $response->is_success 0 0 0
11945 0 my $bytes = $response->decoded_content(charset => 'none');
11946  
11947 0 ▶ if (length($bytes) % 32 != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (length($bytes) % 32 != 0) 0 0 0
11948 0 print STDERR 'old procotol', "\n";
11949 0 my $hashes = [];
11950 0 for my $line (split /\n/, $bytes) {
11951 0 ▶ push @$hashes, CDS::Hash->fromHex($line) // next;
Condition0%0/2
"CDS::Hash"->fromHex($line) // (next)
l!l
00
MC/DC0%0/1
"CDS::Hash"->fromHex($line) // (next)
"CDS::Hash"->fromHex($line)
Truth table0%0/2
A
A= "CDS::Hash"->fromHex($line)
Aresult
11
00
11952 }
11953 0 return $hashes;
11954 }
11955  
11956 0 my $countHashes = int(length($bytes) / 32);
11957 0 return [map { CDS::Hash->fromBytes(substr($bytes, $_ * 32, 32)) } 0 .. $countHashes - 1];
11958 }
11959  
11960 sub add {
11961 0 ▶ my $o = shift;
Subroutine add: not called CC=8 SCAR=42.8
11962 0 ▶ my $accountHash = shift; die 'wrong type '.ref($accountHash).' for $accountHash' if defined $accountHash && ref $accountHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $accountHash and ref $accountHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $accountHash and ref $accountHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $accountHash and ref $accountHash ne "CDS::Hash"
defined $accountHash ref $accountHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $accountHashB= ref $accountHash ne "CDS::Hash"
ABresult
0X0
100
111
11963 0 my $boxLabel = shift;
11964 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
11965 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
11966  
11967 0 my $headers = HTTP::Headers->new;
11968 0 my $response = $o->request('PUT', $o->{url}.'/accounts/'.$accountHash->hex.'/'.$boxLabel.'/'.$hash->hex, $headers, $keyPair);
11969 0 ▶ return if $response->is_success;
Branch: 1 branch
BranchTrueFalseTotal
if $response->is_success 0 0 0
11970 0 return 'add ==> HTTP '.$response->status_line;
11971 }
11972  
11973 sub remove {
11974 0 ▶ my $o = shift;
Subroutine remove: not called CC=8 SCAR=42.8
11975 0 ▶ my $accountHash = shift; die 'wrong type '.ref($accountHash).' for $accountHash' if defined $accountHash && ref $accountHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $accountHash and ref $accountHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $accountHash and ref $accountHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $accountHash and ref $accountHash ne "CDS::Hash"
defined $accountHash ref $accountHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $accountHashB= ref $accountHash ne "CDS::Hash"
ABresult
0X0
100
111
11976 0 my $boxLabel = shift;
11977 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
11978 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
11979  
11980 0 my $headers = HTTP::Headers->new;
11981 0 my $response = $o->request('DELETE', $o->{url}.'/accounts/'.$accountHash->hex.'/'.$boxLabel.'/'.$hash->hex, $headers, $keyPair);
11982 0 ▶ return if $response->is_success;
Branch: 1 branch
BranchTrueFalseTotal
if $response->is_success 0 0 0
11983 0 return 'remove ==> HTTP '.$response->status_line;
11984 }
11985  
11986 sub modify {
11987 0 ▶ my $o = shift;
Subroutine modify: not called CC=4 SCAR=30.0
11988 0 my $modifications = shift;
11989 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
11990  
11991 0 my $bytes = $modifications->toRecord->toObject->bytes;
11992 0 my $headers = HTTP::Headers->new;
11993 0 $headers->header('Content-Type' => 'application/condensation-modifications');
11994 0 my $response = $o->request('POST', $o->{url}.'/accounts', $headers, $keyPair, $bytes, 1);
11995 0 ▶ return if $response->is_success;
Branch: 1 branch
BranchTrueFalseTotal
if $response->is_success 0 0 0
11996 0 return 'modify ==> HTTP '.$response->status_line;
11997 }
11998  
11999 # Executes a HTTP request.
12000 sub request {
12001 0 ▶ my $class = shift;
Subroutine request: not called CC=6 SCAR=37.4
12002 0 my $method = shift;
12003 0 my $url = shift;
12004 0 my $headers = shift;
12005 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
12006 0 my $data = shift;
12007 0 my $signData = shift;
12008 # private
12009 0 $headers->date(time);
12010 0 $headers->header('User-Agent' => CDS->version);
12011  
12012 0 ▶ if ($keyPair) {
Branch: 1 branch
BranchTrueFalseTotal
if ($keyPair) 0 0 0
12013 0 ▶ my $hostAndPath = $url =~ /^https?:\/\/(.*)$/ ? $1 : $url;
Branch: 1 branch
BranchTrueFalseTotal
$url =~ m[^https?://(.*)$] ? : 0 0 0
12014 0 my $date = CDS::ISODate->millisecondString;
12015 0 my $bytesToSign = $date."\0".uc($method)."\0".$hostAndPath;
12016 0 ▶ $bytesToSign .= "\0".$data if $signData;
Branch: 1 branch
BranchTrueFalseTotal
if $signData 0 0 0
12017 0 my $hashBytesToSign = Digest::SHA::sha256($bytesToSign);
12018 0 my $signature = $keyPair->sign($hashBytesToSign);
12019 0 $headers->header('Condensation-Date' => $date);
12020 0 $headers->header('Condensation-Actor' => $keyPair->publicKey->hash->hex);
12021 0 $headers->header('Condensation-Signature' => unpack('H*', $signature));
12022 }
12023  
12024 0 return LWP::UserAgent->new->request(HTTP::Request->new($method, $url, $headers, $data));
12025 }
12026  
12027 # Models a hash, and offers binary and hexadecimal representation.
12028 package CDS::Hash;
12029  
12030 sub fromBytes {
12031 0 ▶ my $class = shift;
Subroutine fromBytes: not called CC=3 SCAR=24.8
12032 0 ▶ my $hashBytes = shift // return;
Condition0%0/2
shift() // (return)
l!l
00
MC/DC0%0/1
shift() // (return)
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
12033  
12034 0 ▶ return if length $hashBytes != 32;
Branch: 1 branch
BranchTrueFalseTotal
if length $hashBytes != 32 0 0 0
12035 0 return bless \$hashBytes;
12036 }
12037  
12038 sub fromHex {
12039 4 ▶ my $class = shift;
Subroutine fromHex: called CC=3 SCAR=11.0
12040 4 ▶ my $hashHex = shift // return;
Condition50%1/2
shift() // (return)
l!l
40
MC/DC0%0/1
shift() // (return)
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
12041  
12042 4 ▶ $hashHex =~ /^\s*([a-fA-F0-9]{64,64})\s*$/ || return;
Branch: 1 branch
BranchTrueFalseTotal
$hashHex =~ /^\s*([a-fA-F0-9]{64,64})\s*$/ or return 2 2 4
12043 2 my $hashBytes = pack('H*', $hashHex);
12044 2 return bless \$hashBytes;
12045 }
12046  
12047 sub calculateFor {
12048 0 ▶ my $class = shift;
Subroutine calculateFor: not called CC=1 SCAR=6.9
12049 0 my $bytes = shift;
12050  
12051 # The Perl built-in SHA256 implementation is a tad faster than our SHA256 implementation.
12052 #return $class->fromBytes(CDS::C::sha256($bytes));
12053 0 return $class->fromBytes(Digest::SHA::sha256($bytes));
12054 }
12055  
12056 sub hex {
12057 0 ▶ my $o = shift;
Subroutine hex: not called CC=1 SCAR=6.9
12058  
12059 0 return unpack('H*', $$o);
12060 }
12061  
12062 sub shortHex {
12063 0 ▶ my $o = shift;
Subroutine shortHex: not called CC=1 SCAR=6.9
12064  
12065 0 return unpack('H*', substr($$o, 0, 8)) . '…';
12066 }
12067  
12068 sub bytes {
12069 0 ▶ my $o = shift;
Subroutine bytes: not called CC=1 SCAR=6.9
12070 0 $$o }
12071  
12072 sub equals {
12073 0 ▶ my $this = shift;
Subroutine equals: not called CC=5 SCAR=34.0
12074 0 my $that = shift;
12075  
12076 0 ▶ return 1 if ! defined $this && ! defined $that;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $this or defined $that 0 0 0
Condition0%0/3
defined $this or defined $that
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $this or defined $that
defined $this defined $that
Truth table0%0/3
A or B
A= defined $thisB= defined $that
ABresult
1X1
011
000
12077 0 ▶ return if ! defined $this || ! defined $that;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $this and defined $that 0 0 0
Condition0%0/3
defined $this and defined $that
!ll&&!rl&&r
000
MC/DC0%0/2
defined $this and defined $that
defined $this defined $that
Truth table0%0/3
A and B
A= defined $thisB= defined $that
ABresult
0X0
100
111
12078 0 return $$this eq $$that;
12079 }
12080  
12081 sub cmp {
12082 0 ▶ my $this = shift;
Subroutine cmp: not called CC=1 SCAR=6.9
12083 0 my $that = shift;
12084 0 $$this cmp $$that }
12085  
12086 # A hash with an AES key.
12087 package CDS::HashAndKey;
12088  
12089 sub new {
12090 0 ▶ my $class = shift;
Subroutine new: not called CC=5 SCAR=34.0
12091 0 ▶ my $hash = shift // return; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/5
shift() // (return)
l!l
00
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/1
shift() // (return)
shift()
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/2
A
A= shift()
Aresult
11
00
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
12092 0 ▶ my $key = shift // return;
Condition0%0/2
shift() // (return)
l!l
00
MC/DC0%0/1
shift() // (return)
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
12093  
12094 0 return bless {
12095 hash => $hash,
12096 key => $key,
12097 };
12098 }
12099  
12100 0 ▶sub hash { shift->{hash} }
Subroutine hash: not called CC=1 SCAR=6.9
12101 0 ▶sub key { shift->{key} }
Subroutine key: not called CC=1 SCAR=6.9
12102  
12103 package CDS::ISODate;
12104  
12105 # Parses a date accepting various ISO variants, and calculates the timestamp using Time::Local
12106 sub parse {
12107 0 ▶ my $class = shift;
Subroutine parse: not called CC=8 SCAR=42.8
12108 0 ▶ my $dateString = shift // return;
Condition0%0/2
shift() // (return)
l!l
00
MC/DC0%0/1
shift() // (return)
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
12109  
12110 0 ▶ if ($dateString =~ /^(\d\d\d\d)-(\d\d)-(\d\d)$/) {
Branch: 6 branches
BranchTrueFalseTotal
if ($dateString =~ /^(\d\d\d\d)-(\d\d)-(\d\d)$/) { } 0 0 0
elsif ($dateString =~ /^(\d\d\d\d)-(\d\d)-(\d\d)(T|\s+)(\d\d):(\d\d):(\d\d|\d\d\.\d*)$/) { } 0 0 0
elsif ($dateString =~ /^(\d\d\d\d)-(\d\d)-(\d\d)(T|\s+)(\d\d):(\d\d):(\d\d|\d\d\.\d*)Z$/) { } 0 0 0
elsif ($dateString =~ /^(\d\d\d\d)-(\d\d)-(\d\d)(T|\s+)(\d\d):(\d\d):(\d\d|\d\d\.\d*)+(\d\d):(\d\d)$/) { } 0 0 0
elsif ($dateString =~ /^(\d\d\d\d)-(\d\d)-(\d\d)(T|\s+)(\d\d):(\d\d):(\d\d|\d\d\.\d*)-(\d\d):(\d\d)$/) { } 0 0 0
elsif ($dateString =~ /^\s*(\d+)\s*$/) { } 0 0 0
12111 0 return (timegm(0, 0, 0, $3, $2 - 1, $1 - 1900) + 86400 - 30) * 1000;
12112 } elsif ($dateString =~ /^(\d\d\d\d)-(\d\d)-(\d\d)(T|\s+)(\d\d):(\d\d):(\d\d|\d\d\.\d*)$/) {
12113 0 return (timelocal(0, $6, $5, $3, $2 - 1, $1 - 1900) + $7) * 1000;
12114 } elsif ($dateString =~ /^(\d\d\d\d)-(\d\d)-(\d\d)(T|\s+)(\d\d):(\d\d):(\d\d|\d\d\.\d*)Z$/) {
12115 0 return (timegm(0, $6, $5, $3, $2 - 1, $1 - 1900) + $7) * 1000;
12116 } elsif ($dateString =~ /^(\d\d\d\d)-(\d\d)-(\d\d)(T|\s+)(\d\d):(\d\d):(\d\d|\d\d\.\d*)+(\d\d):(\d\d)$/) {
12117 0 return (timegm(0, $6, $5, $3, $2 - 1, $1 - 1900) + $7 - $8 * 3600 - $9 * 60) * 1000;
12118 } elsif ($dateString =~ /^(\d\d\d\d)-(\d\d)-(\d\d)(T|\s+)(\d\d):(\d\d):(\d\d|\d\d\.\d*)-(\d\d):(\d\d)$/) {
12119 0 return (timegm(0, $6, $5, $3, $2 - 1, $1 - 1900) + $7 + $8 * 3600 + $9 * 60) * 1000;
12120 } elsif ($dateString =~ /^\s*(\d+)\s*$/) {
12121 0 return $1;
12122 } else {
12123 0 return;
12124 }
12125 }
12126  
12127 # Returns a properly formatted string with a precision of 1 day (i.e., the "date" only)
12128 sub dayString {
12129 0 ▶ my $class = shift;
Subroutine dayString: not called CC=2 SCAR=17.9
12130 0 ▶ my $time = shift // 1000 * time;
Condition0%0/3
shift() // 1000 * time
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() // 1000 * time
shift() 1000 * time
Truth table0%0/3
A // B
A= shift()B= 1000 * time
ABresult
1X1
011
000
12131  
12132 0 my @t = gmtime($time / 1000);
12133 0 return sprintf('%04d-%02d-%02d', $t[5] + 1900, $t[4] + 1, $t[3]);
12134 }
12135  
12136 # Returns a properly formatted string with a precision of 1 second (i.e., "time of day" and "date") using UTC
12137 sub secondString {
12138 0 ▶ my $class = shift;
Subroutine secondString: not called CC=2 SCAR=17.9
12139 0 ▶ my $time = shift // 1000 * time;
Condition0%0/3
shift() // 1000 * time
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() // 1000 * time
shift() 1000 * time
Truth table0%0/3
A // B
A= shift()B= 1000 * time
ABresult
1X1
011
000
12140  
12141 0 my @t = gmtime($time / 1000);
12142 0 return sprintf('%04d-%02d-%02dT%02d:%02d:%02dZ', $t[5] + 1900, $t[4] + 1, $t[3], $t[2], $t[1], $t[0]);
12143 }
12144  
12145 # Returns a properly formatted string with a precision of 1 second (i.e., "time of day" and "date") using UTC
12146 sub millisecondString {
12147 0 ▶ my $class = shift;
Subroutine millisecondString: not called CC=2 SCAR=17.9
12148 0 ▶ my $time = shift // 1000 * time;
Condition0%0/3
shift() // 1000 * time
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() // 1000 * time
shift() 1000 * time
Truth table0%0/3
A // B
A= shift()B= 1000 * time
ABresult
1X1
011
000
12149  
12150 0 my @t = gmtime($time / 1000);
12151 0 return sprintf('%04d-%02d-%02dT%02d:%02d:%02d.%03dZ', $t[5] + 1900, $t[4] + 1, $t[3], $t[2], $t[1], $t[0], int($time) % 1000);
12152 }
12153  
12154 # Returns a properly formatted string with a precision of 1 second (i.e., "time of day" and "date") using local time
12155 sub localSecondString {
12156 0 ▶ my $class = shift;
Subroutine localSecondString: not called CC=2 SCAR=17.9
12157 0 ▶ my $time = shift // 1000 * time;
Condition0%0/3
shift() // 1000 * time
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() // 1000 * time
shift() 1000 * time
Truth table0%0/3
A // B
A= shift()B= 1000 * time
ABresult
1X1
011
000
12158  
12159 0 my @t = localtime($time / 1000);
12160 0 return sprintf('%04d-%02d-%02dT%02d:%02d:%02d', $t[5] + 1900, $t[4] + 1, $t[3], $t[2], $t[1], $t[0]);
12161 }
12162  
12163 package CDS::InMemoryStore;
12164  
12165 sub create {
12166 0 ▶ my $class = shift;
Subroutine create: not called CC=1 SCAR=6.9
12167  
12168 0 return CDS::InMemoryStore->new('inMemoryStore:'.unpack('H*', CDS->randomBytes(16)));
12169 }
12170  
12171 sub new {
12172 0 ▶ my $o = shift;
Subroutine new: not called CC=1 SCAR=6.9
12173 0 my $id = shift;
12174  
12175 0 return bless {
12176 id => $id,
12177 objects => {},
12178 accounts => {},
12179 };
12180 }
12181  
12182 0 ▶sub id { shift->{id} }
Subroutine id: not called CC=1 SCAR=6.9
12183  
12184 sub accountForWriting {
12185 0 ▶ my $o = shift;
Subroutine accountForWriting: not called CC=4 SCAR=30.0
12186 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
12187  
12188 0 my $account = $o->{accounts}->{$hash->bytes};
12189 0 ▶ return $account if $account;
Branch: 1 branch
BranchTrueFalseTotal
if $account 0 0 0
12190 0 return $o->{accounts}->{$hash->bytes} = {messages => {}, private => {}, public => {}};
12191 }
12192  
12193 # *** Store interface
12194  
12195 sub get {
12196 0 ▶ my $o = shift;
Subroutine get: not called CC=6 SCAR=37.4
12197 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
12198 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
12199  
12200 0 ▶ my $entry = $o->{objects}->{$hash->bytes} // return;
Condition0%0/2
$o->{"objects"}{$hash->bytes} // (return)
l!l
00
MC/DC0%0/1
$o->{"objects"}{$hash->bytes} // (return)
$o->{"objects"}{$hash->bytes}
Truth table0%0/2
A
A= $o->{"objects"}{$hash->bytes}
Aresult
11
00
12201 0 return $entry->{object};
12202 }
12203  
12204 sub book {
12205 0 ▶ my $o = shift;
Subroutine book: not called CC=6 SCAR=37.4
12206 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
12207 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
12208  
12209 0 ▶ my $entry = $o->{objects}->{$hash->bytes} // return;
Condition0%0/2
$o->{"objects"}{$hash->bytes} // (return)
l!l
00
MC/DC0%0/1
$o->{"objects"}{$hash->bytes} // (return)
$o->{"objects"}{$hash->bytes}
Truth table0%0/2
A
A= $o->{"objects"}{$hash->bytes}
Aresult
11
00
12210 0 $entry->{booked} = CDS->now;
12211 0 return 1;
12212 }
12213  
12214 sub put {
12215 0 ▶ my $o = shift;
Subroutine put: not called CC=7 SCAR=40.3
12216 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
12217 0 ▶ my $object = shift; die 'wrong type '.ref($object).' for $object' if defined $object && ref $object ne 'CDS::Object';
Branch: 1 branch
BranchTrueFalseTotal
if defined $object and ref $object ne "CDS::Object" 0 0 0
Condition0%0/3
defined $object and ref $object ne "CDS::Object"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $object and ref $object ne "CDS::Object"
defined $object ref $object ne "CDS::Object"
Truth table0%0/3
A and B
A= defined $objectB= ref $object ne "CDS::Object"
ABresult
0X0
100
111
12218 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
12219  
12220 0 $o->{objects}->{$hash->bytes} = {object => $object, booked => CDS->now};
12221 0 return;
12222 }
12223  
12224 sub list {
12225 0 ▶ my $o = shift;
Subroutine list: not called CC=7 SCAR=40.3
12226 0 ▶ my $accountHash = shift; die 'wrong type '.ref($accountHash).' for $accountHash' if defined $accountHash && ref $accountHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $accountHash and ref $accountHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $accountHash and ref $accountHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $accountHash and ref $accountHash ne "CDS::Hash"
defined $accountHash ref $accountHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $accountHashB= ref $accountHash ne "CDS::Hash"
ABresult
0X0
100
111
12227 0 my $boxLabel = shift;
12228 0 my $timeout = shift;
12229 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
12230  
12231 0 ▶ my $account = $o->{accounts}->{$accountHash->bytes} // return [];
Condition0%0/2
$o->{"accounts"}{$accountHash->bytes} // (return [])
l!l
00
MC/DC0%0/1
$o->{"accounts"}{$accountHash->bytes} // (return [])
$o->{"accounts"}{$accountHash->bytes}
Truth table0%0/2
A
A= $o->{"accounts"}{$accountHash->bytes}
Aresult
11
00
12232 0 ▶ my $box = $account->{$boxLabel} // return undef, 'Invalid box label.';
Condition0%0/2
$account->{$boxLabel} // (return undef, "Invalid box label.")
l!l
00
MC/DC0%0/1
$account->{$boxLabel} // (return undef, "Invalid box label.")
$account->{$boxLabel}
Truth table0%0/2
A
A= $account->{$boxLabel}
Aresult
11
00
12233 0 return values %$box;
12234 }
12235  
12236 sub add {
12237 0 ▶ my $o = shift;
Subroutine add: not called CC=8 SCAR=42.8
12238 0 ▶ my $accountHash = shift; die 'wrong type '.ref($accountHash).' for $accountHash' if defined $accountHash && ref $accountHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $accountHash and ref $accountHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $accountHash and ref $accountHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $accountHash and ref $accountHash ne "CDS::Hash"
defined $accountHash ref $accountHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $accountHashB= ref $accountHash ne "CDS::Hash"
ABresult
0X0
100
111
12239 0 my $boxLabel = shift;
12240 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
12241 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
12242  
12243 0 ▶ my $box = $o->accountForWriting($accountHash)->{$boxLabel} // return;
Condition0%0/2
$o->accountForWriting($accountHash)->{$boxLabel} // (return)
l!l
00
MC/DC0%0/1
$o->accountForWriting($accountHash)->{$boxLabel} // (return)
$o->accountForWriting($accountHash)->{$boxLabel}
Truth table0%0/2
A
A= $o->accountForWriting($accountHash)->{$boxLabel}
Aresult
11
00
12244 0 $box->{$hash->bytes} = $hash;
12245 }
12246  
12247 sub remove {
12248 0 ▶ my $o = shift;
Subroutine remove: not called CC=8 SCAR=42.8
12249 0 ▶ my $accountHash = shift; die 'wrong type '.ref($accountHash).' for $accountHash' if defined $accountHash && ref $accountHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $accountHash and ref $accountHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $accountHash and ref $accountHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $accountHash and ref $accountHash ne "CDS::Hash"
defined $accountHash ref $accountHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $accountHashB= ref $accountHash ne "CDS::Hash"
ABresult
0X0
100
111
12250 0 my $boxLabel = shift;
12251 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
12252 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
12253  
12254 0 ▶ my $box = $o->accountForWriting($accountHash)->{$boxLabel} // return;
Condition0%0/2
$o->accountForWriting($accountHash)->{$boxLabel} // (return)
l!l
00
MC/DC0%0/1
$o->accountForWriting($accountHash)->{$boxLabel} // (return)
$o->accountForWriting($accountHash)->{$boxLabel}
Truth table0%0/2
A
A= $o->accountForWriting($accountHash)->{$boxLabel}
Aresult
11
00
12255 0 delete $box->{$hash->bytes};
12256 }
12257  
12258 sub modify {
12259 0 ▶ my $o = shift;
Subroutine modify: not called CC=3 SCAR=24.8
12260 0 my $modifications = shift;
12261 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
12262  
12263 0 return $modifications->executeIndividually($o, $keyPair);
12264 }
12265  
12266 # Garbage collection
12267  
12268 sub collectGarbage {
12269 0 ▶ my $o = shift;
Subroutine collectGarbage: not called CC=14 SCAR=53.5
12270 0 my $graceTime = shift;
12271  
12272 # Mark all objects as not used
12273 0 for my $entry (values %{$o->{objects}}) {
12274 0 $entry->{inUse} = 0;
12275 }
12276  
12277 # Mark all objects newer than the grace time
12278 0 for my $entry (values %{$o->{objects}}) {
12279 0 ▶ $o->markEntry($entry) if $entry->{booked} > $graceTime;
Branch: 1 branch
BranchTrueFalseTotal
if $entry->{"booked"} > $graceTime 0 0 0
12280 }
12281  
12282 # Mark all objects referenced from a box
12283 0 for my $account (values %{$o->{accounts}}) {
12284 0 for my $hash (values %{$account->{messages}}) { $o->markHash($hash); }
12285 0 for my $hash (values %{$account->{private}}) { $o->markHash($hash); }
12286 0 for my $hash (values %{$account->{public}}) { $o->markHash($hash); }
12287 }
12288  
12289 # Remove empty accounts
12290 0 ▶ while (my ($key, $account) = each %{$o->{accounts}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$o{"accounts"};}) 0 0 0
12291 0 ▶ next if scalar keys %{$account->{messages}};
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %{$$account{"messages"};} 0 0 0
12292 0 ▶ next if scalar keys %{$account->{private}};
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %{$$account{"private"};} 0 0 0
12293 0 ▶ next if scalar keys %{$account->{public}};
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %{$$account{"public"};} 0 0 0
12294 0 delete $o->{accounts}->{$key};
12295 }
12296  
12297 # Remove obsolete objects
12298 0 ▶ while (my ($key, $entry) = each %{$o->{objects}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$o{"objects"};}) 0 0 0
12299 0 ▶ next if $entry->{inUse};
Branch: 1 branch
BranchTrueFalseTotal
if $entry->{"inUse"} 0 0 0
12300 0 delete $o->{objects}->{$key};
12301 }
12302 }
12303  
12304 sub markHash {
12305 0 ▶ my $o = shift;
Subroutine markHash: not called CC=4 SCAR=30.0
12306 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
12307 # private
12308 0 ▶ my $child = $o->{objects}->{$hash->bytes} // return;
Condition0%0/2
$o->{"objects"}{$hash->bytes} // (return)
l!l
00
MC/DC0%0/1
$o->{"objects"}{$hash->bytes} // (return)
$o->{"objects"}{$hash->bytes}
Truth table0%0/2
A
A= $o->{"objects"}{$hash->bytes}
Aresult
11
00
12309 0 $o->mark($child);
12310 }
12311  
12312 sub markEntry {
12313 0 ▶ my $o = shift;
Subroutine markEntry: not called CC=3 SCAR=24.8
12314 0 my $entry = shift;
12315 # private
12316 0 ▶ return if $entry->{inUse};
Branch: 1 branch
BranchTrueFalseTotal
if $entry->{"inUse"} 0 0 0
12317 0 $entry->{inUse} = 1;
12318  
12319 # Mark all children
12320 0 for my $hash ($entry->{object}->hashes) {
12321 0 $o->markHash($hash);
12322 }
12323 }
12324  
12325 package CDS::KeyPair;
12326  
12327 sub transfer {
12328 0 ▶ my $o = shift;
Subroutine transfer: not called CC=4 SCAR=30.0
12329 0 my $hashes = shift;
12330 0 my $sourceStore = shift;
12331 0 my $destinationStore = shift;
12332  
12333 0 for my $hash (@$hashes) {
12334 0 my ($missing, $store, $storeError) = $o->recursiveTransfer($hash, $sourceStore, $destinationStore, {});
12335 0 ▶ return $missing if $missing;
Branch: 1 branch
BranchTrueFalseTotal
if $missing 0 0 0
12336 0 ▶ return undef, $store, $storeError if defined $storeError;
Branch: 1 branch
BranchTrueFalseTotal
if defined $storeError 0 0 0
12337 }
12338  
12339 0 return;
12340 }
12341  
12342 sub recursiveTransfer {
12343 0 ▶ my $o = shift;
Subroutine recursiveTransfer: not called CC=12 SCAR=50.5
12344 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
12345 0 my $sourceStore = shift;
12346 0 my $destinationStore = shift;
12347 0 my $done = shift;
12348 # private
12349 0 ▶ return if $done->{$hash->bytes};
Branch: 1 branch
BranchTrueFalseTotal
if $$done{$hash->bytes} 0 0 0
12350 0 $done->{$hash->bytes} = 1;
12351  
12352 # Book
12353 0 my ($booked, $bookError) = $destinationStore->book($hash, $o);
12354 0 ▶ return undef, $destinationStore, $bookError if defined $bookError;
Branch: 1 branch
BranchTrueFalseTotal
if defined $bookError 0 0 0
12355 0 ▶ return if $booked;
Branch: 1 branch
BranchTrueFalseTotal
if $booked 0 0 0
12356  
12357 # Get
12358 0 my ($object, $getError) = $sourceStore->get($hash, $o);
12359 0 ▶ return undef, $sourceStore, $getError if defined $getError;
Branch: 1 branch
BranchTrueFalseTotal
if defined $getError 0 0 0
12360 0 ▶ return CDS::MissingObject->new($hash, $sourceStore) if ! defined $object;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $object 0 0 0
12361  
12362 # Process children
12363 0 for my $child ($object->hashes) {
12364 0 my ($missing, $store, $error) = $o->recursiveTransfer($child, $sourceStore, $destinationStore, $done);
12365 0 ▶ return undef, $store, $error if defined $error;
Branch: 1 branch
BranchTrueFalseTotal
if defined $error 0 0 0
12366 0 ▶ if (defined $missing) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $missing) 0 0 0
12367 0 push @{$missing->{path}}, $child;
12368 0 return $missing;
12369 }
12370 }
12371  
12372 # Put
12373 0 my $putError = $destinationStore->put($hash, $object, $o);
12374 0 ▶ return undef, $destinationStore, $putError if defined $putError;
Branch: 1 branch
BranchTrueFalseTotal
if defined $putError 0 0 0
12375 0 return;
12376 }
12377  
12378 sub createPublicEnvelope {
12379 0 ▶ my $o = shift;
Subroutine createPublicEnvelope: not called CC=3 SCAR=24.8
12380 0 ▶ my $contentHash = shift; die 'wrong type '.ref($contentHash).' for $contentHash' if defined $contentHash && ref $contentHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $contentHash and ref $contentHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $contentHash and ref $contentHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $contentHash and ref $contentHash ne "CDS::Hash"
defined $contentHash ref $contentHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $contentHashB= ref $contentHash ne "CDS::Hash"
ABresult
0X0
100
111
12381  
12382 0 my $envelope = CDS::Record->new;
12383 0 $envelope->add('content')->addHash($contentHash);
12384 0 $envelope->add('signature')->add($o->signHash($contentHash));
12385 0 return $envelope;
12386 }
12387  
12388 sub createPrivateEnvelope {
12389 0 ▶ my $o = shift;
Subroutine createPrivateEnvelope: not called CC=1 SCAR=6.9
12390 0 my $contentHashAndKey = shift;
12391 0 my $recipientPublicKeys = shift;
12392  
12393 0 my $envelope = CDS::Record->new;
12394 0 $envelope->add('content')->addHash($contentHashAndKey->hash);
12395 0 $o->addRecipientsToEnvelope($envelope, $contentHashAndKey->key, $recipientPublicKeys);
12396 0 $envelope->add('signature')->add($o->signHash($contentHashAndKey->hash));
12397 0 return $envelope;
12398 }
12399  
12400 sub createMessageEnvelope {
12401 0 ▶ my $o = shift;
Subroutine createMessageEnvelope: not called CC=4 SCAR=30.0
12402 0 my $storeUrl = shift;
12403 0 ▶ my $messageRecord = shift; die 'wrong type '.ref($messageRecord).' for $messageRecord' if defined $messageRecord && ref $messageRecord ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $messageRecord and ref $messageRecord ne "CDS::Record" 0 0 0
Condition0%0/3
defined $messageRecord and ref $messageRecord ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $messageRecord and ref $messageRecord ne "CDS::Record"
defined $messageRecord ref $messageRecord ne "CDS::Record"
Truth table0%0/3
A and B
A= defined $messageRecordB= ref $messageRecord ne "CDS::Record"
ABresult
0X0
100
111
12404 0 my $recipientPublicKeys = shift;
12405 0 my $expires = shift;
12406  
12407 0 my $contentRecord = CDS::Record->new;
12408 0 $contentRecord->add('store')->addText($storeUrl);
12409 0 $contentRecord->add('sender')->addHash($o->publicKey->hash);
12410 0 $contentRecord->addRecord($messageRecord->children);
12411 0 my $contentObject = $contentRecord->toObject;
12412 0 my $contentKey = CDS->randomKey;
12413 0 my $encryptedContent = CDS::C::aesCrypt($contentObject->bytes, $contentKey, CDS->zeroCTR);
12414 #my $hashToSign = $contentObject->calculateHash; # prior to 2020-05-05
12415 0 my $hashToSign = CDS::Hash->calculateFor($encryptedContent);
12416  
12417 0 my $envelope = CDS::Record->new;
12418 0 $envelope->add('content')->add($encryptedContent);
12419 0 $o->addRecipientsToEnvelope($envelope, $contentKey, $recipientPublicKeys);
12420 0 $envelope->add('updated by')->add(substr($o->publicKey->hash->bytes, 0, 24));
12421 0 ▶ $envelope->add('expires')->addInteger($expires) if defined $expires;
Branch: 1 branch
BranchTrueFalseTotal
if defined $expires 0 0 0
12422 0 $envelope->add('signature')->add($o->signHash($hashToSign));
12423 0 return $envelope;
12424 }
12425  
12426 sub addRecipientsToEnvelope {
12427 0 ▶ my $o = shift;
Subroutine addRecipientsToEnvelope: not called CC=5 SCAR=34.0
12428 0 ▶ my $envelope = shift; die 'wrong type '.ref($envelope).' for $envelope' if defined $envelope && ref $envelope ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $envelope and ref $envelope ne "CDS::Record" 0 0 0
Condition0%0/3
defined $envelope and ref $envelope ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $envelope and ref $envelope ne "CDS::Record"
defined $envelope ref $envelope ne "CDS::Record"
Truth table0%0/3
A and B
A= defined $envelopeB= ref $envelope ne "CDS::Record"
ABresult
0X0
100
111
12429 0 my $key = shift;
12430 0 my $recipientPublicKeys = shift;
12431 # private
12432 0 my $encryptedKeyRecord = $envelope->add('encrypted for');
12433 0 my $myHashBytes24 = substr($o->{publicKey}->hash->bytes, 0, 24);
12434 0 $encryptedKeyRecord->add($myHashBytes24)->add($o->{publicKey}->encrypt($key));
12435 0 for my $publicKey (@$recipientPublicKeys) {
12436 0 ▶ next if $publicKey->hash->equals($o->{publicKey}->hash);
Branch: 1 branch
BranchTrueFalseTotal
if $publicKey->hash->equals($o->{"publicKey"}->hash) 0 0 0
12437 0 my $hashBytes24 = substr($publicKey->hash->bytes, 0, 24);
12438 0 $encryptedKeyRecord->add($hashBytes24)->add($publicKey->encrypt($key));
12439 }
12440 }
12441  
12442 sub generate {
12443 0 ▶ my $class = shift;
Subroutine generate: not called CC=1 SCAR=6.9
12444  
12445 # Generate a new private key
12446 0 my $rsaPrivateKey = CDS::C::privateKeyGenerate();
12447  
12448 # Serialize the public key
12449 0 my $rsaPublicKey = CDS::C::publicKeyFromPrivateKey($rsaPrivateKey);
12450 0 my $record = CDS::Record->new;
12451 0 $record->add('e')->add(CDS::C::publicKeyE($rsaPublicKey));
12452 0 $record->add('n')->add(CDS::C::publicKeyN($rsaPublicKey));
12453 0 my $publicKey = CDS::PublicKey->fromObject($record->toObject);
12454  
12455 # Return a new CDS::KeyPair instance
12456 0 return CDS::KeyPair->new($publicKey, $rsaPrivateKey);
12457 }
12458  
12459 sub fromFile {
12460 0 ▶ my $class = shift;
Subroutine fromFile: not called CC=2 SCAR=17.9
12461 0 my $file = shift;
12462  
12463 0 ▶ my $bytes = CDS->readBytesFromFile($file) // return;
Condition0%0/2
"CDS"->readBytesFromFile($file) // (return)
l!l
00
MC/DC0%0/1
"CDS"->readBytesFromFile($file) // (return)
"CDS"->readBytesFromFile($file)
Truth table0%0/2
A
A= "CDS"->readBytesFromFile($file)
Aresult
11
00
12464 0 my $record = CDS::Record->fromObject(CDS::Object->fromBytes($bytes));
12465 0 return $class->fromRecord($record);
12466 }
12467  
12468 sub fromHex {
12469 0 ▶ my $class = shift;
Subroutine fromHex: not called CC=1 SCAR=6.9
12470 0 my $hex = shift;
12471  
12472 0 return $class->fromRecord(CDS::Record->fromObject(CDS::Object->fromBytes(pack 'H*', $hex)));
12473 }
12474  
12475 sub fromRecord {
12476 0 ▶ my $class = shift;
Subroutine fromRecord: not called CC=6 SCAR=37.4
12477 0 ▶ my $record = shift // return; die 'wrong type '.ref($record).' for $record' if defined $record && ref $record ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $record and ref $record ne "CDS::Record" 0 0 0
Condition0%0/5
shift() // (return)
l!l
00
defined $record and ref $record ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/1
shift() // (return)
shift()
MC/DC0%0/2
defined $record and ref $record ne "CDS::Record"
defined $record ref $record ne "CDS::Record"
Truth table0%0/2
A
A= shift()
Aresult
11
00
Truth table0%0/3
A and B
A= defined $recordB= ref $record ne "CDS::Record"
ABresult
0X0
100
111
12478  
12479 0 ▶ my $publicKey = CDS::PublicKey->fromObject(CDS::Object->fromBytes($record->child('public key object')->bytesValue)) // return;
Condition0%0/2
"CDS::PublicKey"->fromObject("CDS::Object"->fromBytes($record->child("public key object")->bytesValue)) // (return)
l!l
00
MC/DC0%0/1
"CDS::PublicKey"->fromObject("CDS::Object"->fromBytes($record->child("public key object")->bytesValue)) // (return)
"CDS::PublicKey"->fromObject("CDS::Object"->fromBytes($record->child("public key object")->bytesValue))
Truth table0%0/2
A
A= "CDS::PublicKey"->fromObject("CDS::Object"->fromBytes($record->child("public key object")->bytesValue))
Aresult
11
00
12480 0 my $rsaKey = $record->child('rsa key');
12481 0 my $e = $rsaKey->child('e')->bytesValue;
12482 0 my $p = $rsaKey->child('p')->bytesValue;
12483 0 my $q = $rsaKey->child('q')->bytesValue;
12484 0 ▶ return $class->new($publicKey, CDS::C::privateKeyNew($e, $p, $q) // return);
Condition0%0/2
CDS::C::privateKeyNew($e, $p, $q) // (return)
l!l
00
MC/DC0%0/1
CDS::C::privateKeyNew($e, $p, $q) // (return)
CDS::C::privateKeyNew($e, $p, $q)
Truth table0%0/2
A
A= CDS::C::privateKeyNew($e, $p, $q)
Aresult
11
00
12485 }
12486  
12487 sub new {
12488 0 ▶ my $class = shift;
Subroutine new: not called CC=3 SCAR=24.8
12489 0 ▶ my $publicKey = shift; die 'wrong type '.ref($publicKey).' for $publicKey' if defined $publicKey && ref $publicKey ne 'CDS::PublicKey';
Branch: 1 branch
BranchTrueFalseTotal
if defined $publicKey and ref $publicKey ne "CDS::PublicKey" 0 0 0
Condition0%0/3
defined $publicKey and ref $publicKey ne "CDS::PublicKey"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $publicKey and ref $publicKey ne "CDS::PublicKey"
defined $publicKey ref $publicKey ne "CDS::PublicKey"
Truth table0%0/3
A and B
A= defined $publicKeyB= ref $publicKey ne "CDS::PublicKey"
ABresult
0X0
100
111
12490 0 my $rsaPrivateKey = shift;
12491  
12492 0 return bless {
12493 publicKey => $publicKey, # The public key
12494 rsaPrivateKey => $rsaPrivateKey, # The private key
12495 };
12496 }
12497  
12498 0 ▶sub publicKey { shift->{publicKey} }
Subroutine publicKey: not called CC=1 SCAR=6.9
12499 0 ▶sub rsaPrivateKey { shift->{rsaPrivateKey} }
Subroutine rsaPrivateKey: not called CC=1 SCAR=6.9
12500  
12501 ### Serialization ###
12502  
12503 sub toRecord {
12504 0 ▶ my $o = shift;
Subroutine toRecord: not called CC=1 SCAR=6.9
12505  
12506 0 my $record = CDS::Record->new;
12507 0 $record->add('public key object')->add($o->{publicKey}->object->bytes);
12508 0 my $rsaKeyRecord = $record->add('rsa key');
12509 0 $rsaKeyRecord->add('e')->add(CDS::C::privateKeyE($o->{rsaPrivateKey}));
12510 0 $rsaKeyRecord->add('p')->add(CDS::C::privateKeyP($o->{rsaPrivateKey}));
12511 0 $rsaKeyRecord->add('q')->add(CDS::C::privateKeyQ($o->{rsaPrivateKey}));
12512 0 return $record;
12513 }
12514  
12515 sub toHex {
12516 0 ▶ my $o = shift;
Subroutine toHex: not called CC=1 SCAR=6.9
12517  
12518 0 my $object = $o->toRecord->toObject;
12519 0 return unpack('H*', $object->header).unpack('H*', $object->data);
12520 }
12521  
12522 sub writeToFile {
12523 0 ▶ my $o = shift;
Subroutine writeToFile: not called CC=1 SCAR=6.9
12524 0 my $file = shift;
12525  
12526 0 my $object = $o->toRecord->toObject;
12527 0 return CDS->writeBytesToFile($file, $object->bytes);
12528 }
12529  
12530 ### Private key interface ###
12531  
12532 sub decrypt {
12533 0 ▶ my $o = shift;
Subroutine decrypt: not called CC=1 SCAR=6.9
12534 0 my $bytes = shift;
12535 # decrypt(bytes) -> bytes
12536 0 return CDS::C::privateKeyDecrypt($o->{rsaPrivateKey}, $bytes);
12537 }
12538  
12539 sub sign {
12540 0 ▶ my $o = shift;
Subroutine sign: not called CC=1 SCAR=6.9
12541 0 my $digest = shift;
12542 # sign(bytes) -> bytes
12543 0 return CDS::C::privateKeySign($o->{rsaPrivateKey}, $digest);
12544 }
12545  
12546 sub signHash {
12547 0 ▶ my $o = shift;
Subroutine signHash: not called CC=3 SCAR=24.8
12548 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
12549 # signHash(hash) -> bytes
12550 0 return CDS::C::privateKeySign($o->{rsaPrivateKey}, $hash->bytes);
12551 }
12552  
12553 ### Retrieval ###
12554  
12555 # Retrieves an object from one of the stores, and decrypts it.
12556 sub getAndDecrypt {
12557 0 ▶ my $o = shift;
Subroutine getAndDecrypt: not called CC=5 SCAR=34.0
12558 0 ▶ my $hashAndKey = shift; die 'wrong type '.ref($hashAndKey).' for $hashAndKey' if defined $hashAndKey && ref $hashAndKey ne 'CDS::HashAndKey';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hashAndKey and ref $hashAndKey ne "CDS::HashAndKey" 0 0 0
Condition0%0/3
defined $hashAndKey and ref $hashAndKey ne "CDS::HashAndKey"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hashAndKey and ref $hashAndKey ne "CDS::HashAndKey"
defined $hashAndKey ref $hashAndKey ne "CDS::HashAndKey"
Truth table0%0/3
A and B
A= defined $hashAndKeyB= ref $hashAndKey ne "CDS::HashAndKey"
ABresult
0X0
100
111
12559 0 my $store = shift;
12560  
12561 0 my ($object, $error) = $store->get($hashAndKey->hash, $o);
12562 0 ▶ return undef, undef, $error if defined $error;
Branch: 1 branch
BranchTrueFalseTotal
if defined $error 0 0 0
12563 0 ▶ return undef, 'Not found.', undef if ! $object;
Branch: 1 branch
BranchTrueFalseTotal
unless $object 0 0 0
12564 0 return $object->crypt($hashAndKey->key);
12565 }
12566  
12567 # Retrieves an object from one of the stores, and parses it as record.
12568 sub getRecord {
12569 0 ▶ my $o = shift;
Subroutine getRecord: not called CC=6 SCAR=37.4
12570 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
12571 0 my $store = shift;
12572  
12573 0 my ($object, $error) = $store->get($hash, $o);
12574 0 ▶ return undef, undef, undef, $error if defined $error;
Branch: 1 branch
BranchTrueFalseTotal
if defined $error 0 0 0
12575 0 ▶ return undef, undef, 'Not found.', undef if ! $object;
Branch: 1 branch
BranchTrueFalseTotal
unless $object 0 0 0
12576 0 ▶ my $record = CDS::Record->fromObject($object) // return undef, undef, 'Not a record.', undef;
Condition0%0/2
"CDS::Record"->fromObject($object) // (return undef, undef, "Not a record.", undef)
l!l
00
MC/DC0%0/1
"CDS::Record"->fromObject($object) // (return undef, undef, "Not a record.", undef)
"CDS::Record"->fromObject($object)
Truth table0%0/2
A
A= "CDS::Record"->fromObject($object)
Aresult
11
00
12577 0 return $record, $object;
12578 }
12579  
12580 # Retrieves an object from one of the stores, decrypts it, and parses it as record.
12581 sub getAndDecryptRecord {
12582 0 ▶ my $o = shift;
Subroutine getAndDecryptRecord: not called CC=6 SCAR=37.4
12583 0 ▶ my $hashAndKey = shift; die 'wrong type '.ref($hashAndKey).' for $hashAndKey' if defined $hashAndKey && ref $hashAndKey ne 'CDS::HashAndKey';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hashAndKey and ref $hashAndKey ne "CDS::HashAndKey" 0 0 0
Condition0%0/3
defined $hashAndKey and ref $hashAndKey ne "CDS::HashAndKey"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hashAndKey and ref $hashAndKey ne "CDS::HashAndKey"
defined $hashAndKey ref $hashAndKey ne "CDS::HashAndKey"
Truth table0%0/3
A and B
A= defined $hashAndKeyB= ref $hashAndKey ne "CDS::HashAndKey"
ABresult
0X0
100
111
12584 0 my $store = shift;
12585  
12586 0 my ($object, $error) = $store->get($hashAndKey->hash, $o);
12587 0 ▶ return undef, undef, undef, $error if defined $error;
Branch: 1 branch
BranchTrueFalseTotal
if defined $error 0 0 0
12588 0 ▶ return undef, undef, 'Not found.', undef if ! $object;
Branch: 1 branch
BranchTrueFalseTotal
unless $object 0 0 0
12589 0 my $decrypted = $object->crypt($hashAndKey->key);
12590 0 ▶ my $record = CDS::Record->fromObject($decrypted) // return undef, undef, 'Not a record.', undef;
Condition0%0/2
"CDS::Record"->fromObject($decrypted) // (return undef, undef, "Not a record.", undef)
l!l
00
MC/DC0%0/1
"CDS::Record"->fromObject($decrypted) // (return undef, undef, "Not a record.", undef)
"CDS::Record"->fromObject($decrypted)
Truth table0%0/2
A
A= "CDS::Record"->fromObject($decrypted)
Aresult
11
00
12591 0 return $record, $object;
12592 }
12593  
12594 # Retrieves an public key object from one of the stores, and parses its public key.
12595 sub getPublicKey {
12596 0 ▶ my $o = shift;
Subroutine getPublicKey: not called CC=6 SCAR=37.4
12597 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
12598 0 my $store = shift;
12599  
12600 0 my ($object, $error) = $store->get($hash, $o);
12601 0 ▶ return undef, undef, $error if defined $error;
Branch: 1 branch
BranchTrueFalseTotal
if defined $error 0 0 0
12602 0 ▶ return undef, 'Not found.', undef if ! $object;
Branch: 1 branch
BranchTrueFalseTotal
unless $object 0 0 0
12603 0 ▶ return CDS::PublicKey->fromObject($object) // return undef, 'Not a public key.', undef;
Condition0%0/2
"CDS::PublicKey"->fromObject($object) // (return undef, "Not a public key.", undef)
l!l
00
MC/DC0%0/1
"CDS::PublicKey"->fromObject($object) // (return undef, "Not a public key.", undef)
"CDS::PublicKey"->fromObject($object)
Truth table0%0/2
A
A= "CDS::PublicKey"->fromObject($object)
Aresult
11
00
12604 }
12605  
12606 ### Equality ###
12607  
12608 sub equals {
12609 0 ▶ my $this = shift;
Subroutine equals: not called CC=5 SCAR=34.0
12610 0 my $that = shift;
12611  
12612 0 ▶ return 1 if ! defined $this && ! defined $that;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $this or defined $that 0 0 0
Condition0%0/3
defined $this or defined $that
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $this or defined $that
defined $this defined $that
Truth table0%0/3
A or B
A= defined $thisB= defined $that
ABresult
1X1
011
000
12613 0 ▶ return if ! defined $this || ! defined $that;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $this and defined $that 0 0 0
Condition0%0/3
defined $this and defined $that
!ll&&!rl&&r
000
MC/DC0%0/2
defined $this and defined $that
defined $this defined $that
Truth table0%0/3
A and B
A= defined $thisB= defined $that
ABresult
0X0
100
111
12614 0 return $this->publicKey->hash->equals($that->publicKey->hash);
12615 }
12616  
12617 ### Open envelopes ###
12618  
12619 sub decryptKeyOnEnvelope {
12620 0 ▶ my $o = shift;
Subroutine decryptKeyOnEnvelope: not called CC=7 SCAR=40.3
12621 0 ▶ my $envelope = shift; die 'wrong type '.ref($envelope).' for $envelope' if defined $envelope && ref $envelope ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $envelope and ref $envelope ne "CDS::Record" 0 0 0
Condition0%0/3
defined $envelope and ref $envelope ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $envelope and ref $envelope ne "CDS::Record"
defined $envelope ref $envelope ne "CDS::Record"
Truth table0%0/3
A and B
A= defined $envelopeB= ref $envelope ne "CDS::Record"
ABresult
0X0
100
111
12622  
12623 # Read the AES key
12624 0 my $hashBytes24 = substr($o->{publicKey}->hash->bytes, 0, 24);
12625 0 my $encryptedAesKey = $envelope->child('encrypted for')->child($hashBytes24)->bytesValue;
12626 0 ▶ $encryptedAesKey = $envelope->child('encrypted for')->child($o->{publicKey}->hash->bytes)->bytesValue if ! length $encryptedAesKey; # todo: remove this
Branch: 1 branch
BranchTrueFalseTotal
unless length $encryptedAesKey 0 0 0
12627 0 ▶ return if ! length $encryptedAesKey;
Branch: 1 branch
BranchTrueFalseTotal
unless length $encryptedAesKey 0 0 0
12628  
12629 # Decrypt the AES key
12630 0 my $aesKeyBytes = $o->decrypt($encryptedAesKey);
12631 0 ▶ return if ! $aesKeyBytes || length $aesKeyBytes != 32;
Branch: 1 branch
BranchTrueFalseTotal
if not $aesKeyBytes or length $aesKeyBytes != 32 0 0 0
Condition0%0/3
not $aesKeyBytes or length $aesKeyBytes != 32
l!l&&r!l&&!r
000
MC/DC0%0/2
not $aesKeyBytes or length $aesKeyBytes != 32
not $aesKeyBytes length $aesKeyBytes != 32
Truth table0%0/3
not(A) or B
A= not $aesKeyBytesB= length $aesKeyBytes != 32
ABresult
1X1
011
000
12632  
12633 0 return $aesKeyBytes;
12634 }
12635  
12636 # The result of parsing a KEYPAIR token (see Token.pm).
12637 package CDS::KeyPairToken;
12638  
12639 sub new {
12640 0 ▶ my $class = shift;
Subroutine new: not called CC=3 SCAR=24.8
12641 0 my $file = shift;
12642 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
12643  
12644 0 return bless {
12645 file => $file,
12646 keyPair => $keyPair,
12647 };
12648 }
12649  
12650 0 ▶sub file { shift->{file} }
Subroutine file: not called CC=1 SCAR=6.9
12651 0 ▶sub keyPair { shift->{keyPair} }
Subroutine keyPair: not called CC=1 SCAR=6.9
12652  
12653 package CDS::LoadActorGroup;
12654  
12655 sub load {
12656 0 ▶ my $class = shift;
Subroutine load: not called CC=15 SCAR=54.8
12657 0 ▶ my $builder = shift; die 'wrong type '.ref($builder).' for $builder' if defined $builder && ref $builder ne 'CDS::ActorGroupBuilder';
Branch: 1 branch
BranchTrueFalseTotal
if defined $builder and ref $builder ne "CDS::ActorGroupBuilder" 0 0 0
Condition0%0/3
defined $builder and ref $builder ne "CDS::ActorGroupBuilder"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $builder and ref $builder ne "CDS::ActorGroupBuilder"
defined $builder ref $builder ne "CDS::ActorGroupBuilder"
Truth table0%0/3
A and B
A= defined $builderB= ref $builder ne "CDS::ActorGroupBuilder"
ABresult
0X0
100
111
12658 0 my $store = shift;
12659 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
12660 0 my $delegate = shift;
12661  
12662 0 my $o = bless {
12663 store => $store,
12664 keyPair => $keyPair,
12665 knownPublicKeys => $builder->knownPublicKeys,
12666 };
12667  
12668 0 my $members = [];
12669 0 for my $member ($builder->members) {
12670 0 my $isActive = $member->status eq 'active';
12671 0 my $isIdle = $member->status eq 'idle';
12672 0 ▶ next if ! $isActive && ! $isIdle;
Branch: 1 branch
BranchTrueFalseTotal
unless $isActive or $isIdle 0 0 0
Condition0%0/3
$isActive or $isIdle
l!l&&r!l&&!r
000
MC/DC0%0/2
$isActive or $isIdle
$isActive $isIdle
Truth table0%0/3
A or B
A= $isActiveB= $isIdle
ABresult
1X1
011
000
12673  
12674 0 my ($publicKey, $storeError) = $o->getPublicKey($member->hash);
12675 0 ▶ return undef, $storeError if defined $storeError;
Branch: 1 branch
BranchTrueFalseTotal
if defined $storeError 0 0 0
12676 0 ▶ next if ! $publicKey;
Branch: 1 branch
BranchTrueFalseTotal
unless $publicKey 0 0 0
12677  
12678 0 ▶ my $accountStore = $delegate->onLoadActorGroupVerifyStore($member->storeUrl) // next;
Condition0%0/2
$delegate->onLoadActorGroupVerifyStore($member->storeUrl) // (next)
l!l
00
MC/DC0%0/1
$delegate->onLoadActorGroupVerifyStore($member->storeUrl) // (next)
$delegate->onLoadActorGroupVerifyStore($member->storeUrl)
Truth table0%0/2
A
A= $delegate->onLoadActorGroupVerifyStore($member->storeUrl)
Aresult
11
00
12679 0 my $actorOnStore = CDS::ActorOnStore->new($publicKey, $accountStore);
12680 0 push @$members, CDS::ActorGroup::Member->new($actorOnStore, $member->storeUrl, $member->revision, $isActive);
12681 }
12682  
12683 0 my $entrustedActors = [];
12684 0 for my $actor ($builder->entrustedActors) {
12685 0 my ($publicKey, $storeError) = $o->getPublicKey($actor->hash);
12686 0 ▶ return undef, $storeError if defined $storeError;
Branch: 1 branch
BranchTrueFalseTotal
if defined $storeError 0 0 0
12687 0 ▶ next if ! $publicKey;
Branch: 1 branch
BranchTrueFalseTotal
unless $publicKey 0 0 0
12688  
12689 0 ▶ my $accountStore = $delegate->onLoadActorGroupVerifyStore($actor->storeUrl) // next;
Condition0%0/2
$delegate->onLoadActorGroupVerifyStore($actor->storeUrl) // (next)
l!l
00
MC/DC0%0/1
$delegate->onLoadActorGroupVerifyStore($actor->storeUrl) // (next)
$delegate->onLoadActorGroupVerifyStore($actor->storeUrl)
Truth table0%0/2
A
A= $delegate->onLoadActorGroupVerifyStore($actor->storeUrl)
Aresult
11
00
12690 0 my $actorOnStore = CDS::ActorOnStore->new($publicKey, $accountStore);
12691 0 push @$entrustedActors, CDS::ActorGroup::EntrustedActor->new($actorOnStore, $actor->storeUrl);
12692 }
12693  
12694 0 return CDS::ActorGroup->new($members, $builder->entrustedActorsRevision, $entrustedActors);
12695 }
12696  
12697 sub getPublicKey {
12698 0 ▶ my $o = shift;
Subroutine getPublicKey: not called CC=6 SCAR=37.4
12699 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
12700  
12701 0 my $knownPublicKey = $o->{knownPublicKeys}->{$hash->bytes};
12702 0 ▶ return $knownPublicKey if $knownPublicKey;
Branch: 1 branch
BranchTrueFalseTotal
if $knownPublicKey 0 0 0
12703  
12704 0 my ($publicKey, $invalidReason, $storeError) = $o->{keyPair}->getPublicKey($hash, $o->{store});
12705 0 ▶ return undef, $storeError if defined $storeError;
Branch: 1 branch
BranchTrueFalseTotal
if defined $storeError 0 0 0
12706 0 ▶ return if defined $invalidReason;
Branch: 1 branch
BranchTrueFalseTotal
if defined $invalidReason 0 0 0
12707  
12708 0 $o->{knownPublicKeys}->{$hash->bytes} = $publicKey;
12709 0 return $publicKey;
12710 };
12711  
12712 # A store that prints all accesses to a filehandle (STDERR by default).
12713 package CDS::LogStore;
12714  
12715 1 ▶use parent -norequire, 'CDS::Store';
Subroutine BEGIN: called CC=1 SCAR=0.0
12716  
12717 sub new {
12718 0 ▶ my $class = shift;
Subroutine new: not called CC=3 SCAR=24.8
12719 0 my $store = shift;
12720 0 ▶ my $fileHandle = shift // *STDERR;
Condition0%0/3
shift() // *STDERR
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() // *STDERR
shift() *STDERR
Truth table0%0/3
A // B
A= shift()B= *STDERR
ABresult
1X1
011
000
12721 0 ▶ my $prefix = shift // '';
Condition0%0/2
shift() // ""
l!l
00
MC/DC0%0/1
shift() // ""
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
12722  
12723 0 return bless {
12724 id => "Log Store\n".$store->id,
12725 store => $store,
12726 fileHandle => $fileHandle,
12727 prefix => '',
12728 };
12729 }
12730  
12731 0 ▶sub id { shift->{id} }
Subroutine id: not called CC=1 SCAR=6.9
12732 0 ▶sub store { shift->{store} }
Subroutine store: not called CC=1 SCAR=6.9
12733 0 ▶sub fileHandle { shift->{fileHandle} }
Subroutine fileHandle: not called CC=1 SCAR=6.9
12734 0 ▶sub prefix { shift->{prefix} }
Subroutine prefix: not called CC=1 SCAR=6.9
12735  
12736 sub get {
12737 0 ▶ my $o = shift;
Subroutine get: not called CC=7 SCAR=40.3
12738 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
12739 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
12740  
12741 0 my $start = CDS::C::performanceStart();
12742 0 my ($object, $error) = $o->{store}->get($hash, $keyPair);
12743 0 my $elapsed = CDS::C::performanceElapsed($start);
12744 0 ▶ $o->log('get', $hash->shortHex, defined $object ? &formatByteLength($object->byteLength).' bytes' : defined $error ? 'failed: '.$error : 'not found', $elapsed);
Branch: 2 branches
BranchTrueFalseTotal
defined $object ? : 0 0 0
defined $error ? : 0 0 0
12745 0 return $object, $error;
12746 }
12747  
12748 sub put {
12749 0 ▶ my $o = shift;
Subroutine put: not called CC=8 SCAR=42.8
12750 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
12751 0 ▶ my $object = shift; die 'wrong type '.ref($object).' for $object' if defined $object && ref $object ne 'CDS::Object';
Branch: 1 branch
BranchTrueFalseTotal
if defined $object and ref $object ne "CDS::Object" 0 0 0
Condition0%0/3
defined $object and ref $object ne "CDS::Object"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $object and ref $object ne "CDS::Object"
defined $object ref $object ne "CDS::Object"
Truth table0%0/3
A and B
A= defined $objectB= ref $object ne "CDS::Object"
ABresult
0X0
100
111
12752 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
12753  
12754 0 my $start = CDS::C::performanceStart();
12755 0 my $error = $o->{store}->put($hash, $object, $keyPair);
12756 0 my $elapsed = CDS::C::performanceElapsed($start);
12757 0 ▶ $o->log('put', $hash->shortHex . ' ' . &formatByteLength($object->byteLength) . ' bytes', defined $error ? 'failed: '.$error : 'OK', $elapsed);
Branch: 1 branch
BranchTrueFalseTotal
defined $error ? : 0 0 0
12758 0 return $error;
12759 }
12760  
12761 sub book {
12762 0 ▶ my $o = shift;
Subroutine book: not called CC=7 SCAR=40.3
12763 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
12764 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
12765  
12766 0 my $start = CDS::C::performanceStart();
12767 0 my ($booked, $error) = $o->{store}->book($hash, $keyPair);
12768 0 my $elapsed = CDS::C::performanceElapsed($start);
12769 0 ▶ $o->log('book', $hash->shortHex, defined $booked ? 'OK' : defined $error ? 'failed: '.$error : 'not found', $elapsed);
Branch: 2 branches
BranchTrueFalseTotal
defined $booked ? : 0 0 0
defined $error ? : 0 0 0
12770 0 return $booked, $error;
12771 }
12772  
12773 sub list {
12774 0 ▶ my $o = shift;
Subroutine list: not called CC=7 SCAR=40.3
12775 0 ▶ my $accountHash = shift; die 'wrong type '.ref($accountHash).' for $accountHash' if defined $accountHash && ref $accountHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $accountHash and ref $accountHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $accountHash and ref $accountHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $accountHash and ref $accountHash ne "CDS::Hash"
defined $accountHash ref $accountHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $accountHashB= ref $accountHash ne "CDS::Hash"
ABresult
0X0
100
111
12776 0 my $boxLabel = shift;
12777 0 my $timeout = shift;
12778 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
12779  
12780 0 my $start = CDS::C::performanceStart();
12781 0 my ($hashes, $error) = $o->{store}->list($accountHash, $boxLabel, $timeout, $keyPair);
12782 0 my $elapsed = CDS::C::performanceElapsed($start);
12783 0 ▶ $o->log('list', $accountHash->shortHex . ' ' . $boxLabel . ($timeout ? ' ' . $timeout . ' s' : ''), defined $hashes ? scalar(@$hashes).' entries' : 'failed: '.$error, $elapsed);
Branch: 2 branches
BranchTrueFalseTotal
$timeout ? : 0 0 0
defined $hashes ? : 0 0 0
12784 0 return $hashes, $error;
12785 }
12786  
12787 sub add {
12788 0 ▶ my $o = shift;
Subroutine add: not called CC=8 SCAR=42.8
12789 0 ▶ my $accountHash = shift; die 'wrong type '.ref($accountHash).' for $accountHash' if defined $accountHash && ref $accountHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $accountHash and ref $accountHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $accountHash and ref $accountHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $accountHash and ref $accountHash ne "CDS::Hash"
defined $accountHash ref $accountHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $accountHashB= ref $accountHash ne "CDS::Hash"
ABresult
0X0
100
111
12790 0 my $boxLabel = shift;
12791 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
12792 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
12793  
12794 0 my $start = CDS::C::performanceStart();
12795 0 my $error = $o->{store}->add($accountHash, $boxLabel, $hash, $keyPair);
12796 0 my $elapsed = CDS::C::performanceElapsed($start);
12797 0 ▶ $o->log('add', $accountHash->shortHex . ' ' . $boxLabel . ' ' . $hash->shortHex, defined $error ? 'failed: '.$error : 'OK', $elapsed);
Branch: 1 branch
BranchTrueFalseTotal
defined $error ? : 0 0 0
12798 0 return $error;
12799 }
12800  
12801 sub remove {
12802 0 ▶ my $o = shift;
Subroutine remove: not called CC=8 SCAR=42.8
12803 0 ▶ my $accountHash = shift; die 'wrong type '.ref($accountHash).' for $accountHash' if defined $accountHash && ref $accountHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $accountHash and ref $accountHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $accountHash and ref $accountHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $accountHash and ref $accountHash ne "CDS::Hash"
defined $accountHash ref $accountHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $accountHashB= ref $accountHash ne "CDS::Hash"
ABresult
0X0
100
111
12804 0 my $boxLabel = shift;
12805 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
12806 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
12807  
12808 0 my $start = CDS::C::performanceStart();
12809 0 my $error = $o->{store}->remove($accountHash, $boxLabel, $hash, $keyPair);
12810 0 my $elapsed = CDS::C::performanceElapsed($start);
12811 0 ▶ $o->log('remove', $accountHash->shortHex . ' ' . $boxLabel . ' ' . $hash->shortHex, defined $error ? 'failed: '.$error : 'OK', $elapsed);
Branch: 1 branch
BranchTrueFalseTotal
defined $error ? : 0 0 0
12812 0 return $error;
12813 }
12814  
12815 sub modify {
12816 0 ▶ my $o = shift;
Subroutine modify: not called CC=4 SCAR=30.0
12817 0 my $modifications = shift;
12818 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
12819  
12820 0 my $start = CDS::C::performanceStart();
12821 0 my $error = $o->{store}->modify($modifications, $keyPair);
12822 0 my $elapsed = CDS::C::performanceElapsed($start);
12823 0 ▶ $o->log('modify', scalar(keys %{$modifications->objects}) . ' objects ' . scalar @{$modifications->additions} . ' additions ' . scalar @{$modifications->removals} . ' removals', defined $error ? 'failed: '.$error : 'OK', $elapsed);
Branch: 1 branch
BranchTrueFalseTotal
defined $error ? : 0 0 0
12824 0 return $error;
12825 }
12826  
12827 sub log {
12828 0 ▶ my $o = shift;
Subroutine log: not called CC=2 SCAR=17.9
12829 0 my $cmd = shift;
12830 0 my $input = shift;
12831 0 my $output = shift;
12832 0 my $elapsed = shift;
12833  
12834 0 ▶ my $fh = $o->{fileHandle} // return;
Condition0%0/2
$o->{"fileHandle"} // (return)
l!l
00
MC/DC0%0/1
$o->{"fileHandle"} // (return)
$o->{"fileHandle"}
Truth table0%0/2
A
A= $o->{"fileHandle"}
Aresult
11
00
12835 0 print $fh $o->{prefix}, &left(8, $cmd), &left(40, $input), ' => ', &left(40, $output), &formatDuration($elapsed), ' us', "\n";
12836 }
12837  
12838 sub left {
12839 0 ▶ my $width = shift;
Subroutine left: not called CC=2 SCAR=17.9
12840 0 my $text = shift;
12841 # private
12842 0 ▶ return $text . (' ' x ($width - length $text)) if length $text < $width;
Branch: 1 branch
BranchTrueFalseTotal
if length $text < $width 0 0 0
12843 0 return $text;
12844 }
12845  
12846 sub formatByteLength {
12847 0 ▶ my $byteLength = shift;
Subroutine formatByteLength: not called CC=2 SCAR=17.9
12848 # private
12849 0 my $s = ''.$byteLength;
12850 0 ▶ $s = ' ' x (9 - length $s) . $s if length $s < 9;
Branch: 1 branch
BranchTrueFalseTotal
if length $s < 9 0 0 0
12851 0 my $len = length $s;
12852 0 return substr($s, 0, $len - 6).' '.substr($s, $len - 6, 3).' '.substr($s, $len - 3, 3);
12853 }
12854  
12855 sub formatDuration {
12856 0 ▶ my $elapsed = shift;
Subroutine formatDuration: not called CC=2 SCAR=17.9
12857 # private
12858 0 my $s = ''.$elapsed;
12859 0 ▶ $s = ' ' x (9 - length $s) . $s if length $s < 9;
Branch: 1 branch
BranchTrueFalseTotal
if length $s < 9 0 0 0
12860 0 my $len = length $s;
12861 0 return substr($s, 0, $len - 6).' '.substr($s, $len - 6, 3).' '.substr($s, $len - 3, 3);
12862 }
12863  
12864 # Reads the message box of an actor.
12865 package CDS::MessageBoxReader;
12866  
12867 sub new {
12868 0 ▶ my $class = shift;
Subroutine new: not called CC=4 SCAR=30.0
12869 0 my $pool = shift;
12870 0 ▶ my $actorOnStore = shift; die 'wrong type '.ref($actorOnStore).' for $actorOnStore' if defined $actorOnStore && ref $actorOnStore ne 'CDS::ActorOnStore';
Branch: 1 branch
BranchTrueFalseTotal
if defined $actorOnStore and ref $actorOnStore ne "CDS::ActorOnStore" 0 0 0
Condition0%0/3
defined $actorOnStore and ref $actorOnStore ne "CDS::ActorOnStore"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $actorOnStore and ref $actorOnStore ne "CDS::ActorOnStore"
defined $actorOnStore ref $actorOnStore ne "CDS::ActorOnStore"
Truth table0%0/3
A and B
A= defined $actorOnStoreB= ref $actorOnStore ne "CDS::ActorOnStore"
ABresult
0X0
100
111
12871 0 my $streamTimeout = shift;
12872  
12873 0 ▶ return bless {
Condition0%0/3
$streamTimeout // "CDS"->MINUTE
l!l&&r!l&&!r
000
MC/DC0%0/2
$streamTimeout // "CDS"->MINUTE
$streamTimeout "CDS"->MINUTE
Truth table0%0/3
A // B
A= $streamTimeoutB= "CDS"->MINUTE
ABresult
1X1
011
000
12874 pool => $pool,
12875 actorOnStore => $actorOnStore,
12876 streamCache => CDS::StreamCache->new($pool, $actorOnStore, $streamTimeout // CDS->MINUTE),
12877 entries => {},
12878 };
12879 }
12880  
12881 0 ▶sub pool { shift->{pool} }
Subroutine pool: not called CC=1 SCAR=6.9
12882 0 ▶sub actorOnStore { shift->{actorOnStore} }
Subroutine actorOnStore: not called CC=1 SCAR=6.9
12883  
12884 sub read {
12885 0 ▶ my $o = shift;
Subroutine read: not called CC=14 SCAR=53.5
12886 0 ▶ my $timeout = shift // 0;
Condition0%0/2
shift() // 0
l!l
00
MC/DC0%0/1
shift() // 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
12887  
12888 0 my $store = $o->{actorOnStore}->store;
12889 0 my ($hashes, $listError) = $store->list($o->{actorOnStore}->publicKey->hash, 'messages', $timeout, $o->{pool}->{keyPair});
12890 0 ▶ return if defined $listError;
Branch: 1 branch
BranchTrueFalseTotal
if defined $listError 0 0 0
12891  
12892 0 for my $hash (@$hashes) {
12893 0 my $entry = $o->{entries}->{$hash->bytes};
12894 0 ▶ $o->{entries}->{$hash->bytes} = $entry = CDS::MessageBoxReader::Entry->new($hash) if ! $entry;
Branch: 1 branch
BranchTrueFalseTotal
unless $entry 0 0 0
12895 0 ▶ next if $entry->{processed};
Branch: 1 branch
BranchTrueFalseTotal
if $entry->{"processed"} 0 0 0
12896  
12897 # Check the sender store, if necessary
12898 0 ▶ if ($entry->{waitingForStore}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($entry->{"waitingForStore"}) 0 0 0
12899 0 my ($dummy, $checkError) = $entry->{waitingForStore}->get(CDS->emptyBytesHash, $o->{pool}->{keyPair});
12900 0 ▶ next if defined $checkError;
Branch: 1 branch
BranchTrueFalseTotal
if defined $checkError 0 0 0
12901 }
12902  
12903 # Get the envelope
12904 0 my ($object, $getError) = $o->{actorOnStore}->store->get($entry->{hash}, $o->{pool}->{keyPair});
12905 0 ▶ return if defined $getError;
Branch: 1 branch
BranchTrueFalseTotal
if defined $getError 0 0 0
12906  
12907 # Mark the entry as processed
12908 0 $entry->{processed} = 1;
12909  
12910 0 ▶ if (! defined $object) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $object) 0 0 0
12911 0 $o->invalid($entry, 'Envelope object not found.');
12912 0 next;
12913 }
12914  
12915 # Parse the record
12916 0 my $envelope = CDS::Record->fromObject($object);
12917 0 ▶ if (! $envelope) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($envelope) 0 0 0
12918 0 $o->invalid($entry, 'Envelope is not a record.');
12919 0 next;
12920 }
12921  
12922 0 ▶ my $message =
Branch: 1 branch
BranchTrueFalseTotal
$envelope->contains('head') && $envelope->contains('mac') ? : 0 0 0
Condition0%0/3
$envelope->contains("head") and $envelope->contains("mac")
!ll&&!rl&&r
000
MC/DC0%0/2
$envelope->contains("head") and $envelope->contains("mac")
$envelope->contains("head") $envelope->contains("mac")
Truth table0%0/3
A and B
A= $envelope->contains("head")B= $envelope->contains("mac")
ABresult
0X0
100
111
12923 $envelope->contains('head') && $envelope->contains('mac') ?
12924 $o->readStreamMessage($entry, $envelope) :
12925 $o->readNormalMessage($entry, $envelope);
12926 0 ▶ next if ! $message;
Branch: 1 branch
BranchTrueFalseTotal
unless $message 0 0 0
12927  
12928 0 $o->{pool}->{delegate}->onMessageBoxEntry($message);
12929 }
12930  
12931 0 $o->{streamCache}->removeObsolete;
12932 0 return 1;
12933 }
12934  
12935 sub readNormalMessage {
12936 0 ▶ my $o = shift;
Subroutine readNormalMessage: not called CC=14 SCAR=53.5
12937 0 my $entry = shift;
12938 0 ▶ my $envelope = shift; die 'wrong type '.ref($envelope).' for $envelope' if defined $envelope && ref $envelope ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $envelope and ref $envelope ne "CDS::Record" 0 0 0
Condition0%0/3
defined $envelope and ref $envelope ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $envelope and ref $envelope ne "CDS::Record"
defined $envelope ref $envelope ne "CDS::Record"
Truth table0%0/3
A and B
A= defined $envelopeB= ref $envelope ne "CDS::Record"
ABresult
0X0
100
111
12939 # private
12940 # Read the embedded content object
12941 0 my $encryptedBytes = $envelope->child('content')->bytesValue;
12942 0 ▶ return $o->invalid($entry, 'Missing content object.') if ! length $encryptedBytes;
Branch: 1 branch
BranchTrueFalseTotal
unless length $encryptedBytes 0 0 0
12943  
12944 # Decrypt the key
12945 0 my $aesKey = $o->{pool}->{keyPair}->decryptKeyOnEnvelope($envelope);
12946 0 ▶ return $o->invalid($entry, 'Not encrypted for us.') if ! $aesKey;
Branch: 1 branch
BranchTrueFalseTotal
unless $aesKey 0 0 0
12947  
12948 # Decrypt the content
12949 0 my $contentObject = CDS::Object->fromBytes(CDS::C::aesCrypt($encryptedBytes, $aesKey, CDS->zeroCTR));
12950 0 ▶ return $o->invalid($entry, 'Invalid content object.') if ! $contentObject;
Branch: 1 branch
BranchTrueFalseTotal
unless $contentObject 0 0 0
12951  
12952 0 my $content = CDS::Record->fromObject($contentObject);
12953 0 ▶ return $o->invalid($entry, 'Content object is not a record.') if ! $content;
Branch: 1 branch
BranchTrueFalseTotal
unless $content 0 0 0
12954  
12955 # Verify the sender hash
12956 0 my $senderHash = $content->child('sender')->hashValue;
12957 0 ▶ return $o->invalid($entry, 'Missing sender hash.') if ! $senderHash;
Branch: 1 branch
BranchTrueFalseTotal
unless $senderHash 0 0 0
12958  
12959 # Verify the sender store
12960 0 my $storeRecord = $content->child('store');
12961 0 ▶ return $o->invalid($entry, 'Missing sender store.') if ! scalar $storeRecord->children;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar $storeRecord->children 0 0 0
12962  
12963 0 my $senderStoreUrl = $storeRecord->textValue;
12964 0 my $senderStore = $o->{pool}->{delegate}->onMessageBoxVerifyStore($senderStoreUrl, $entry->{hash}, $envelope, $senderHash);
12965 0 ▶ return $o->invalid($entry, 'Invalid sender store.') if ! $senderStore;
Branch: 1 branch
BranchTrueFalseTotal
unless $senderStore 0 0 0
12966  
12967 # Retrieve the sender's public key
12968 0 my ($senderPublicKey, $invalidReason, $publicKeyStoreError) = $o->getPublicKey($senderHash, $senderStore);
12969 0 ▶ return if defined $publicKeyStoreError;
Branch: 1 branch
BranchTrueFalseTotal
if defined $publicKeyStoreError 0 0 0
12970 0 ▶ return $o->invalid($entry, 'Failed to retrieve the sender\'s public key: '.$invalidReason) if defined $invalidReason;
Branch: 1 branch
BranchTrueFalseTotal
if defined $invalidReason 0 0 0
12971  
12972 # Verify the signature
12973 0 my $signedHash = CDS::Hash->calculateFor($encryptedBytes);
12974 0 ▶ if (! CDS->verifyEnvelopeSignature($envelope, $senderPublicKey, $signedHash)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ("CDS"->verifyEnvelopeSignature($envelope, $senderPublicKey, $signedHash)) 0 0 0
12975 # For backwards compatibility with versions before 2020-05-05
12976 0 ▶ return $o->invalid($entry, 'Invalid signature.') if ! CDS->verifyEnvelopeSignature($envelope, $senderPublicKey, $contentObject->calculateHash);
Branch: 1 branch
BranchTrueFalseTotal
unless "CDS"->verifyEnvelopeSignature($envelope, $senderPublicKey, $contentObject->calculateHash) 0 0 0
12977 }
12978  
12979 # The envelope is valid
12980 0 my $sender = CDS::ActorOnStore->new($senderPublicKey, $senderStore);
12981 0 my $source = CDS::Source->new($o->{pool}->{keyPair}, $o->{actorOnStore}, 'messages', $entry->{hash});
12982 0 return CDS::ReceivedMessage->new($o, $entry, $source, $envelope, $senderStoreUrl, $sender, $content);
12983 }
12984  
12985 sub readStreamMessage {
12986 0 ▶ my $o = shift;
Subroutine readStreamMessage: not called CC=12 SCAR=50.5
12987 0 my $entry = shift;
12988 0 ▶ my $envelope = shift; die 'wrong type '.ref($envelope).' for $envelope' if defined $envelope && ref $envelope ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $envelope and ref $envelope ne "CDS::Record" 0 0 0
Condition0%0/3
defined $envelope and ref $envelope ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $envelope and ref $envelope ne "CDS::Record"
defined $envelope ref $envelope ne "CDS::Record"
Truth table0%0/3
A and B
A= defined $envelopeB= ref $envelope ne "CDS::Record"
ABresult
0X0
100
111
12989 # private
12990 # Get the head
12991 0 my $head = $envelope->child('head')->hashValue;
12992 0 ▶ return $o->invalid($entry, 'Invalid head message hash.') if ! $head;
Branch: 1 branch
BranchTrueFalseTotal
unless $head 0 0 0
12993  
12994 # Get the head envelope
12995 0 my $streamHead = $o->{streamCache}->readStreamHead($head);
12996 0 ▶ return if ! $streamHead;
Branch: 1 branch
BranchTrueFalseTotal
unless $streamHead 0 0 0
12997 0 ▶ return $o->invalid($entry, 'Invalid stream head: '.$streamHead->error) if $streamHead->error;
Branch: 1 branch
BranchTrueFalseTotal
if $streamHead->error 0 0 0
12998  
12999 # Read the embedded content object
13000 0 my $encryptedBytes = $envelope->child('content')->bytesValue;
13001 0 ▶ return $o->invalid($entry, 'Missing content object.') if ! length $encryptedBytes;
Branch: 1 branch
BranchTrueFalseTotal
unless length $encryptedBytes 0 0 0
13002  
13003 # Get the CTR
13004 0 my $ctr = $envelope->child('ctr')->bytesValue;
13005 0 ▶ return $o->invalid($entry, 'Invalid CTR.') if length $ctr != 16;
Branch: 1 branch
BranchTrueFalseTotal
if length $ctr != 16 0 0 0
13006  
13007 # Get the MAC
13008 0 my $mac = $envelope->child('mac')->bytesValue;
13009 0 ▶ return $o->invalid($entry, 'Invalid MAC.') if ! $mac;
Branch: 1 branch
BranchTrueFalseTotal
unless $mac 0 0 0
13010  
13011 # Verify the MAC
13012 0 my $signedHash = CDS::Hash->calculateFor($encryptedBytes);
13013 0 my $expectedMac = CDS::C::aesCrypt($signedHash->bytes, $streamHead->aesKey, $ctr);
13014 0 ▶ return $o->invalid($entry, 'Invalid MAC.') if $mac ne $expectedMac;
Branch: 1 branch
BranchTrueFalseTotal
if $mac ne $expectedMac 0 0 0
13015  
13016 # Decrypt the content
13017 0 my $contentObject = CDS::Object->fromBytes(CDS::C::aesCrypt($encryptedBytes, $streamHead->aesKey, CDS::C::counterPlusInt($ctr, 2)));
13018 0 ▶ return $o->invalid($entry, 'Invalid content object.') if ! $contentObject;
Branch: 1 branch
BranchTrueFalseTotal
unless $contentObject 0 0 0
13019  
13020 0 my $content = CDS::Record->fromObject($contentObject);
13021 0 ▶ return $o->invalid($entry, 'Content object is not a record.') if ! $content;
Branch: 1 branch
BranchTrueFalseTotal
unless $content 0 0 0
13022  
13023 # The envelope is valid
13024 0 my $source = CDS::Source->new($o->{pool}->{keyPair}, $o->{actorOnStore}, 'messages', $entry->{hash});
13025 0 return CDS::ReceivedMessage->new($o, $entry, $source, $envelope, $streamHead->senderStoreUrl, $streamHead->sender, $content, $streamHead);
13026 }
13027  
13028 sub invalid {
13029 0 ▶ my $o = shift;
Subroutine invalid: not called CC=1 SCAR=6.9
13030 0 my $entry = shift;
13031 0 my $reason = shift;
13032 # private
13033 0 my $source = CDS::Source->new($o->{pool}->{keyPair}, $o->{actorOnStore}, 'messages', $entry->{hash});
13034 0 $o->{pool}->{delegate}->onMessageBoxInvalidEntry($source, $reason);
13035 }
13036  
13037 sub getPublicKey {
13038 0 ▶ my $o = shift;
Subroutine getPublicKey: not called CC=7 SCAR=40.3
13039 0 ▶ my $senderHash = shift; die 'wrong type '.ref($senderHash).' for $senderHash' if defined $senderHash && ref $senderHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $senderHash and ref $senderHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $senderHash and ref $senderHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $senderHash and ref $senderHash ne "CDS::Hash"
defined $senderHash ref $senderHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $senderHashB= ref $senderHash ne "CDS::Hash"
ABresult
0X0
100
111
13040 0 my $senderStore = shift;
13041 0 my $senderStoreUrl = shift;
13042 # private
13043 # Use the account key if sender and recipient are the same
13044 0 ▶ return $o->{actorOnStore}->publicKey if $senderHash->equals($o->{actorOnStore}->publicKey->hash);
Branch: 1 branch
BranchTrueFalseTotal
if $senderHash->equals($o->{"actorOnStore"}->publicKey->hash) 0 0 0
13045  
13046 # Reuse a cached public key
13047 0 my $cachedPublicKey = $o->{pool}->{publicKeyCache}->get($senderHash);
13048 0 ▶ return $cachedPublicKey if $cachedPublicKey;
Branch: 1 branch
BranchTrueFalseTotal
if $cachedPublicKey 0 0 0
13049  
13050 # Retrieve the sender's public key from the sender's store
13051 0 my ($publicKey, $invalidReason, $storeError) = $o->{pool}->{keyPair}->getPublicKey($senderHash, $senderStore);
13052 0 ▶ return undef, undef, $storeError if defined $storeError;
Branch: 1 branch
BranchTrueFalseTotal
if defined $storeError 0 0 0
13053 0 ▶ return undef, $invalidReason if defined $invalidReason;
Branch: 1 branch
BranchTrueFalseTotal
if defined $invalidReason 0 0 0
13054 0 $o->{pool}->{publicKeyCache}->add($publicKey);
13055 0 return $publicKey;
13056 }
13057  
13058 package CDS::MessageBoxReader::Entry;
13059  
13060 sub new {
13061 0 ▶ my $class = shift;
Subroutine new: not called CC=3 SCAR=24.8
13062 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
13063  
13064 0 return bless {
13065 hash => $hash,
13066 processed => 0,
13067 };
13068 }
13069  
13070 package CDS::MessageBoxReaderPool;
13071  
13072 sub new {
13073 0 ▶ my $class = shift;
Subroutine new: not called CC=3 SCAR=24.8
13074 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
13075 0 my $publicKeyCache = shift;
13076 0 my $delegate = shift;
13077  
13078 0 return bless {
13079 keyPair => $keyPair,
13080 publicKeyCache => $publicKeyCache,
13081 delegate => $delegate,
13082 };
13083 }
13084  
13085 0 ▶sub keyPair { shift->{keyPair} }
Subroutine keyPair: not called CC=1 SCAR=6.9
13086 0 ▶sub publicKeyCache { shift->{publicKeyCache} }
Subroutine publicKeyCache: not called CC=1 SCAR=6.9
13087  
13088 # Delegate
13089 # onMessageBoxVerifyStore($senderStoreUrl, $hash, $envelope, $senderHash)
13090 # onMessageBoxEntry($receivedMessage)
13091 # onMessageBoxStream($receivedMessage)
13092 # onMessageBoxInvalidEntry($source, $reason)
13093  
13094 package CDS::MessageChannel;
13095  
13096 sub new {
13097 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
13098 0 my $actor = shift;
13099 0 my $label = shift;
13100 0 my $validity = shift;
13101  
13102 0 my $o = bless {
13103 actor => $actor,
13104 label => $label,
13105 validity => $validity,
13106 };
13107  
13108 0 $o->{unsaved} = CDS::Unsaved->new($actor->sentList->unsaved);
13109 0 $o->{transfers} = [];
13110 0 $o->{recipients} = [];
13111 0 $o->{entrustedKeys} = [];
13112 0 $o->{obsoleteHashes} = {};
13113 0 $o->{currentSubmissionId} = 0;
13114 0 return $o;
13115 }
13116  
13117 0 ▶sub actor { shift->{actor} }
Subroutine actor: not called CC=1 SCAR=6.9
13118 0 ▶sub label { shift->{label} }
Subroutine label: not called CC=1 SCAR=6.9
13119 0 ▶sub validity { shift->{validity} }
Subroutine validity: not called CC=1 SCAR=6.9
13120 0 ▶sub unsaved { shift->{unsaved} }
Subroutine unsaved: not called CC=1 SCAR=6.9
13121 sub item {
13122 0 ▶ my $o = shift;
Subroutine item: not called CC=1 SCAR=6.9
13123 0 $o->{actor}->sentList->getOrCreate($o->{label}) }
13124 sub recipients {
13125 0 ▶ my $o = shift;
Subroutine recipients: not called CC=1 SCAR=6.9
13126 0 @{$o->{recipients}} }
13127 sub entrustedKeys {
13128 0 ▶ my $o = shift;
Subroutine entrustedKeys: not called CC=1 SCAR=6.9
13129 0 @{$o->{entrustedKeys}} }
13130  
13131 sub addObject {
13132 0 ▶ my $o = shift;
Subroutine addObject: not called CC=5 SCAR=34.0
13133 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
13134 0 ▶ my $object = shift; die 'wrong type '.ref($object).' for $object' if defined $object && ref $object ne 'CDS::Object';
Branch: 1 branch
BranchTrueFalseTotal
if defined $object and ref $object ne "CDS::Object" 0 0 0
Condition0%0/3
defined $object and ref $object ne "CDS::Object"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $object and ref $object ne "CDS::Object"
defined $object ref $object ne "CDS::Object"
Truth table0%0/3
A and B
A= defined $objectB= ref $object ne "CDS::Object"
ABresult
0X0
100
111
13135  
13136 0 $o->{unsaved}->state->addObject($hash, $object);
13137 }
13138  
13139 sub addTransfer {
13140 0 ▶ my $o = shift;
Subroutine addTransfer: not called CC=2 SCAR=17.9
13141 0 my $hashes = shift;
13142 0 my $sourceStore = shift;
13143 0 my $context = shift;
13144  
13145 0 ▶ return if ! scalar @$hashes;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @$hashes 0 0 0
13146 0 push @{$o->{transfers}}, {hashes => $hashes, sourceStore => $sourceStore, context => $context};
13147 }
13148  
13149 sub setRecipientActorGroup {
13150 0 ▶ my $o = shift;
Subroutine setRecipientActorGroup: not called CC=3 SCAR=24.8
13151 0 ▶ my $actorGroup = shift; die 'wrong type '.ref($actorGroup).' for $actorGroup' if defined $actorGroup && ref $actorGroup ne 'CDS::ActorGroup';
Branch: 1 branch
BranchTrueFalseTotal
if defined $actorGroup and ref $actorGroup ne "CDS::ActorGroup" 0 0 0
Condition0%0/3
defined $actorGroup and ref $actorGroup ne "CDS::ActorGroup"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $actorGroup and ref $actorGroup ne "CDS::ActorGroup"
defined $actorGroup ref $actorGroup ne "CDS::ActorGroup"
Truth table0%0/3
A and B
A= defined $actorGroupB= ref $actorGroup ne "CDS::ActorGroup"
ABresult
0X0
100
111
13152  
13153 0 $o->{recipients} = [map { $_->actorOnStore } $actorGroup->members];
13154 0 $o->{entrustedKeys} = [map { $_->actorOnStore->publicKey } $actorGroup->entrustedActors];
13155 }
13156  
13157 sub setRecipients {
13158 0 ▶ my $o = shift;
Subroutine setRecipients: not called CC=1 SCAR=6.9
13159 0 my $recipients = shift;
13160 0 my $entrustedKeys = shift;
13161  
13162 0 $o->{recipients} = $recipients;
13163 0 $o->{entrustedKeys} = $entrustedKeys;
13164 }
13165  
13166 sub submit {
13167 0 ▶ my $o = shift;
Subroutine submit: not called CC=5 SCAR=34.0
13168 0 my $message = shift;
13169 0 my $done = shift;
13170  
13171 # Check if the sent list has been loaded
13172 0 ▶ return if ! $o->{actor}->sentListReady;
Branch: 1 branch
BranchTrueFalseTotal
unless $o->{"actor"}->sentListReady 0 0 0
13173  
13174 # Transfer
13175 0 my $transfers = $o->{transfers};
13176 0 $o->{transfers} = [];
13177 0 for my $transfer (@$transfers) {
13178 0 my ($missingObject, $store, $error) = $o->{actor}->keyPair->transfer($transfer->{hashes}, $transfer->{sourceStore}, $o->{actor}->messagingPrivateRoot->unsaved);
13179 0 ▶ return if defined $error;
Branch: 1 branch
BranchTrueFalseTotal
if defined $error 0 0 0
13180  
13181 0 ▶ if ($missingObject) {
Branch: 1 branch
BranchTrueFalseTotal
if ($missingObject) 0 0 0
13182 0 $missingObject->{context} = $transfer->{context};
13183 0 return undef, $missingObject;
13184 }
13185 }
13186  
13187 # Send the message
13188 0 return CDS::MessageChannel::Submission->new($o, $message, $done);
13189 }
13190  
13191 sub clear {
13192 0 ▶ my $o = shift;
Subroutine clear: not called CC=1 SCAR=6.9
13193  
13194 0 $o->item->clear(CDS->now + $o->{validity});
13195 }
13196  
13197 package CDS::MessageChannel::Submission;
13198  
13199 sub new {
13200 0 ▶ my $class = shift;
Subroutine new: not called CC=2 SCAR=17.9
13201 0 my $channel = shift;
13202 0 my $message = shift;
13203 0 my $done = shift;
13204  
13205 0 $channel->{currentSubmissionId} += 1;
13206  
13207 my $o = bless {
13208 channel => $channel,
13209 message => $message,
13210 done => $done,
13211 submissionId => $channel->{currentSubmissionId},
13212 0 recipients => [$channel->recipients],
13213 entrustedKeys => [$channel->entrustedKeys],
13214 expires => CDS->now + $channel->validity,
13215 };
13216  
13217 # Add the current envelope hash to the obsolete hashes
13218 0 my $item = $channel->item;
13219 0 ▶ $channel->{obsoleteHashes}->{$item->envelopeHash->bytes} = $item->envelopeHash if $item->envelopeHash;
Branch: 1 branch
BranchTrueFalseTotal
if $item->envelopeHash 0 0 0
13220 0 $o->{obsoleteHashesSnapshot} = [values %{$channel->{obsoleteHashes}}];
13221  
13222 # Create an envelope
13223 0 my $publicKeys = [];
13224 0 push @$publicKeys, $channel->{actor}->keyPair->publicKey;
13225 0 push @$publicKeys, map { $_->publicKey } @{$o->{recipients}};
13226 0 push @$publicKeys, @{$o->{entrustedKeys}};
13227 0 $o->{envelopeObject} = $channel->{actor}->keyPair->createMessageEnvelope($channel->{actor}->messagingStoreUrl, $message, $publicKeys, $o->{expires})->toObject;
13228 0 $o->{envelopeHash} = $o->{envelopeObject}->calculateHash;
13229  
13230 # Set the new item and wait until it gets saved
13231 0 $channel->{unsaved}->startSaving;
13232 0 $channel->{unsaved}->savingState->addDataSavedHandler($o);
13233 0 $channel->{actor}->sentList->unsaved->state->merge($channel->{unsaved}->savingState);
13234 0 $item->set($o->{expires}, $o->{envelopeHash}, $message);
13235 0 $channel->{unsaved}->savingDone;
13236  
13237 0 return $o;
13238 }
13239  
13240 0 ▶sub channel { shift->{channel} }
Subroutine channel: not called CC=1 SCAR=6.9
13241 0 ▶sub message { shift->{message} }
Subroutine message: not called CC=1 SCAR=6.9
13242 sub recipients {
13243 0 ▶ my $o = shift;
Subroutine recipients: not called CC=1 SCAR=6.9
13244 0 @{$o->{recipients}} }
13245 sub entrustedKeys {
13246 0 ▶ my $o = shift;
Subroutine entrustedKeys: not called CC=1 SCAR=6.9
13247 0 @{$o->{entrustedKeys}} }
13248 0 ▶sub expires { shift->{expires} }
Subroutine expires: not called CC=1 SCAR=6.9
13249 0 ▶sub envelopeObject { shift->{envelopeObject} }
Subroutine envelopeObject: not called CC=1 SCAR=6.9
13250 0 ▶sub envelopeHash { shift->{envelopeHash} }
Subroutine envelopeHash: not called CC=1 SCAR=6.9
13251  
13252 sub onDataSaved {
13253 0 ▶ my $o = shift;
Subroutine onDataSaved: not called CC=8 SCAR=42.8
13254  
13255 # If we are not the head any more, give up
13256 0 ▶ return $o->{done}->onMessageChannelSubmissionCancelled if $o->{submissionId} != $o->{channel}->{currentSubmissionId};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"submissionId"} != $o->{"channel"}{"currentSubmissionId"} 0 0 0
13257 0 $o->{channel}->{obsoleteHashes}->{$o->{envelopeHash}->bytes} = $o->{envelopeHash};
13258  
13259 # Process all recipients
13260 0 my $succeeded = 0;
13261 0 my $failed = 0;
13262 0 for my $recipient (@{$o->{recipients}}) {
13263 0 my $modifications = CDS::StoreModifications->new;
13264  
13265 # Prepare the list of removals
13266 0 my $removals = [];
13267 0 for my $hash (@{$o->{obsoleteHashesSnapshot}}) {
13268 0 $modifications->remove($recipient->publicKey->hash, 'messages', $hash);
13269 }
13270  
13271 # Add the message entry
13272 0 $modifications->add($recipient->publicKey->hash, 'messages', $o->{envelopeHash}, $o->{envelopeObject});
13273 0 my $error = $recipient->store->modify($modifications, $o->{channel}->{actor}->keyPair);
13274  
13275 0 ▶ if (defined $error) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $error) { } 0 0 0
13276 0 $failed += 1;
13277 0 $o->{done}->onMessageChannelSubmissionRecipientFailed($recipient, $error);
13278 } else {
13279 0 $succeeded += 1;
13280 0 $o->{done}->onMessageChannelSubmissionRecipientDone($recipient);
13281 }
13282 }
13283  
13284 0 ▶ if ($failed == 0 || scalar keys %{$o->{obsoleteHashes}} > 64) {
Branch: 1 branch
BranchTrueFalseTotal
if ($failed == 0 or scalar keys %{$$o{"obsoleteHashes"};} > 64) 0 0 0
Condition0%0/3
$failed == 0 or scalar keys %{$$o{"obsoleteHashes"};} > 64
l!l&&r!l&&!r
000
MC/DC0%0/2
$failed == 0 or scalar keys %{$$o{"obsoleteHashes"};} > 64
$failed == 0 scalar keys %{$$o{"obsoleteHashes"};} > 64
Truth table0%0/3
A or B
A= $failed == 0B= scalar keys %{$$o{"obsoleteHashes"};} > 64
ABresult
1X1
011
000
13285 0 for my $hash (@{$o->{obsoleteHashesSnapshot}}) {
13286 0 delete $o->{channel}->{obsoleteHashes}->{$hash->bytes};
13287 }
13288 }
13289  
13290 0 $o->{done}->onMessageChannelSubmissionDone($succeeded, $failed);
13291 }
13292  
13293 package CDS::MissingObject;
13294  
13295 sub new {
13296 0 ▶ my $class = shift;
Subroutine new: not called CC=3 SCAR=24.8
13297 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
13298 0 my $store = shift;
13299  
13300 0 return bless {hash => $hash, store => $store, path => [], context => undef};
13301 }
13302  
13303 0 ▶sub hash { shift->{hash} }
Subroutine hash: not called CC=1 SCAR=6.9
13304 0 ▶sub store { shift->{store} }
Subroutine store: not called CC=1 SCAR=6.9
13305 sub path {
13306 0 ▶ my $o = shift;
Subroutine path: not called CC=1 SCAR=6.9
13307 0 @{$o->{path}} }
13308 0 ▶sub context { shift->{context} }
Subroutine context: not called CC=1 SCAR=6.9
13309  
13310 package CDS::NewAnnounce;
13311  
13312 sub new {
13313 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
13314 0 my $messagingStore = shift;
13315  
13316 0 my $o = bless {
13317 messagingStore => $messagingStore,
13318 unsaved => CDS::Unsaved->new($messagingStore->store),
13319 transfers => [],
13320 card => CDS::Record->new,
13321 };
13322  
13323 0 my $publicKey = $messagingStore->actor->keyPair->publicKey;
13324 0 $o->{card}->add('public key')->addHash($publicKey->hash);
13325 0 $o->addObject($publicKey->hash, $publicKey->object);
13326 0 return $o;
13327 }
13328  
13329 0 ▶sub messagingStore { shift->{messagingStore} }
Subroutine messagingStore: not called CC=1 SCAR=6.9
13330 0 ▶sub card { shift->{card} }
Subroutine card: not called CC=1 SCAR=6.9
13331  
13332 sub addObject {
13333 0 ▶ my $o = shift;
Subroutine addObject: not called CC=5 SCAR=34.0
13334 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
13335 0 ▶ my $object = shift; die 'wrong type '.ref($object).' for $object' if defined $object && ref $object ne 'CDS::Object';
Branch: 1 branch
BranchTrueFalseTotal
if defined $object and ref $object ne "CDS::Object" 0 0 0
Condition0%0/3
defined $object and ref $object ne "CDS::Object"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $object and ref $object ne "CDS::Object"
defined $object ref $object ne "CDS::Object"
Truth table0%0/3
A and B
A= defined $objectB= ref $object ne "CDS::Object"
ABresult
0X0
100
111
13336  
13337 0 $o->{unsaved}->state->addObject($hash, $object);
13338 }
13339  
13340 sub addTransfer {
13341 0 ▶ my $o = shift;
Subroutine addTransfer: not called CC=2 SCAR=17.9
13342 0 my $hashes = shift;
13343 0 my $sourceStore = shift;
13344 0 my $context = shift;
13345  
13346 0 ▶ return if ! scalar @$hashes;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @$hashes 0 0 0
13347 0 push @{$o->{transfers}}, {hashes => $hashes, sourceStore => $sourceStore, context => $context};
13348 }
13349  
13350 sub addActorGroup {
13351 0 ▶ my $o = shift;
Subroutine addActorGroup: not called CC=1 SCAR=6.9
13352 0 my $actorGroupBuilder = shift;
13353  
13354 0 $actorGroupBuilder->addToRecord($o->{card}, 0);
13355 }
13356  
13357 sub submit {
13358 0 ▶ my $o = shift;
Subroutine submit: not called CC=7 SCAR=40.3
13359  
13360 0 my $keyPair = $o->{messagingStore}->actor->keyPair;
13361  
13362 # Create the public card
13363 0 my $cardObject = $o->{card}->toObject;
13364 0 my $cardHash = $cardObject->calculateHash;
13365 0 $o->addObject($cardHash, $cardObject);
13366  
13367 # Prepare the public envelope
13368 0 my $me = $keyPair->publicKey->hash;
13369 0 my $envelopeObject = $keyPair->createPublicEnvelope($cardHash)->toObject;
13370 0 my $envelopeHash = $envelopeObject->calculateHash;
13371 0 $o->addTransfer([$cardHash], $o->{unsaved}, 'Announcing');
13372  
13373 # Transfer all trees
13374 0 for my $transfer (@{$o->{transfers}}) {
13375 0 my ($missingObject, $store, $error) = $keyPair->transfer($transfer->{hashes}, $transfer->{sourceStore}, $o->{messagingStore}->store);
13376 0 ▶ return if defined $error;
Branch: 1 branch
BranchTrueFalseTotal
if defined $error 0 0 0
13377  
13378 0 ▶ if ($missingObject) {
Branch: 1 branch
BranchTrueFalseTotal
if ($missingObject) 0 0 0
13379 0 $missingObject->{context} = $transfer->{context};
13380 0 return undef, $missingObject;
13381 }
13382 }
13383  
13384 # Prepare a modification
13385 0 my $modifications = CDS::StoreModifications->new;
13386 0 $modifications->add($me, 'public', $envelopeHash, $envelopeObject);
13387  
13388 # List the current cards to remove them
13389 # Ignore errors, in the worst case, we are going to have multiple entries in the public box
13390 0 my ($hashes, $error) = $o->{messagingStore}->store->list($me, 'public', 0, $keyPair);
13391 0 ▶ if ($hashes) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hashes) 0 0 0
13392 0 for my $hash (@$hashes) {
13393 0 $modifications->remove($me, 'public', $hash);
13394 }
13395 }
13396  
13397 # Modify the public box
13398 0 my $modifyError = $o->{messagingStore}->store->modify($modifications, $keyPair);
13399 0 ▶ return if defined $modifyError;
Branch: 1 branch
BranchTrueFalseTotal
if defined $modifyError 0 0 0
13400 0 return $envelopeHash, $cardHash;
13401 }
13402  
13403 package CDS::NewMessagingStore;
13404  
13405 sub new {
13406 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
13407 0 my $actor = shift;
13408 0 my $store = shift;
13409  
13410 0 return bless {
13411 actor => $actor,
13412 store => $store,
13413 };
13414 }
13415  
13416 0 ▶sub actor { shift->{actor} }
Subroutine actor: not called CC=1 SCAR=6.9
13417 0 ▶sub store { shift->{store} }
Subroutine store: not called CC=1 SCAR=6.9
13418  
13419 # A Condensation object.
13420 # A valid object starts with a 4-byte length (big-endian), followed by 32 * length bytes of hashes, followed by 0 or more bytes of data.
13421 package CDS::Object;
13422  
13423 0 ▶sub emptyHeader { "\0\0\0\0" }
Subroutine emptyHeader: not called CC=1 SCAR=6.9
13424  
13425 sub create {
13426 0 ▶ my $class = shift;
Subroutine create: not called CC=3 SCAR=24.8
13427 0 my $header = shift;
13428 0 my $data = shift;
13429  
13430 0 ▶ return if length $header < 4;
Branch: 1 branch
BranchTrueFalseTotal
if length $header < 4 0 0 0
13431 0 my $hashesCount = unpack('L>', substr($header, 0, 4));
13432 0 ▶ return if length $header != 4 + $hashesCount * 32;
Branch: 1 branch
BranchTrueFalseTotal
if length $header != 4 + $hashesCount * 32 0 0 0
13433 0 return bless {
13434 bytes => $header.$data,
13435 hashesCount => $hashesCount,
13436 header => $header,
13437 data => $data
13438 };
13439 }
13440  
13441 sub fromBytes {
13442 0 ▶ my $class = shift;
Subroutine fromBytes: not called CC=4 SCAR=30.0
13443 0 ▶ my $bytes = shift // return;
Condition0%0/2
shift() // (return)
l!l
00
MC/DC0%0/1
shift() // (return)
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
13444  
13445 0 ▶ return if length $bytes < 4;
Branch: 1 branch
BranchTrueFalseTotal
if length $bytes < 4 0 0 0
13446  
13447 0 my $hashesCount = unpack 'L>', substr($bytes, 0, 4);
13448 0 my $dataStart = $hashesCount * 32 + 4;
13449 0 ▶ return if $dataStart > length $bytes;
Branch: 1 branch
BranchTrueFalseTotal
if $dataStart > length $bytes 0 0 0
13450  
13451 0 return bless {
13452 bytes => $bytes,
13453 hashesCount => $hashesCount,
13454 header => substr($bytes, 0, $dataStart),
13455 data => substr($bytes, $dataStart)
13456 };
13457 }
13458  
13459 sub fromFile {
13460 0 ▶ my $class = shift;
Subroutine fromFile: not called CC=1 SCAR=6.9
13461 0 my $file = shift;
13462  
13463 0 return $class->fromBytes(CDS->readBytesFromFile($file));
13464 }
13465  
13466 0 ▶sub bytes { shift->{bytes} }
Subroutine bytes: not called CC=1 SCAR=6.9
13467 0 ▶sub header { shift->{header} }
Subroutine header: not called CC=1 SCAR=6.9
13468 0 ▶sub data { shift->{data} }
Subroutine data: not called CC=1 SCAR=6.9
13469 0 ▶sub hashesCount { shift->{hashesCount} }
Subroutine hashesCount: not called CC=1 SCAR=6.9
13470 sub byteLength {
13471 0 ▶ my $o = shift;
Subroutine byteLength: not called CC=1 SCAR=6.9
13472 0 length($o->{header}) + length($o->{data}) }
13473  
13474 sub calculateHash {
13475 0 ▶ my $o = shift;
Subroutine calculateHash: not called CC=1 SCAR=6.9
13476  
13477 0 return CDS::Hash->calculateFor($o->{bytes});
13478 }
13479  
13480 sub hashes {
13481 0 ▶ my $o = shift;
Subroutine hashes: not called CC=1 SCAR=6.9
13482  
13483 0 return map { CDS::Hash->fromBytes(substr($o->{header}, $_ * 32 + 4, 32)) } 0 .. $o->{hashesCount} - 1;
13484 }
13485  
13486 sub hashAtIndex {
13487 0 ▶ my $o = shift;
Subroutine hashAtIndex: not called CC=4 SCAR=30.0
13488 0 ▶ my $index = shift // return;
Condition0%0/2
shift() // (return)
l!l
00
MC/DC0%0/1
shift() // (return)
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
13489  
13490 0 ▶ return if $index < 0 || $index >= $o->{hashesCount};
Branch: 1 branch
BranchTrueFalseTotal
if $index < 0 or $index >= $o->{"hashesCount"} 0 0 0
Condition0%0/3
$index < 0 or $index >= $o->{"hashesCount"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$index < 0 or $index >= $o->{"hashesCount"}
$index < 0 $index >= $o->{"hashesCount"}
Truth table0%0/3
A or B
A= $index < 0B= $index >= $o->{"hashesCount"}
ABresult
1X1
011
000
13491 0 return CDS::Hash->fromBytes(substr($o->{header}, $index * 32 + 4, 32));
13492 }
13493  
13494 sub crypt {
13495 0 ▶ my $o = shift;
Subroutine crypt: not called CC=1 SCAR=6.9
13496 0 my $key = shift;
13497  
13498 0 return CDS::Object->create($o->{header}, CDS::C::aesCrypt($o->{data}, $key, CDS->zeroCTR));
13499 }
13500  
13501 sub writeToFile {
13502 0 ▶ my $o = shift;
Subroutine writeToFile: not called CC=1 SCAR=6.9
13503 0 my $file = shift;
13504  
13505 0 return CDS->writeBytesToFile($file, $o->{bytes});
13506 }
13507  
13508 # A store using a cache store to deliver frequently accessed objects faster, and a backend store.
13509 package CDS::ObjectCache;
13510  
13511 1 ▶use parent -norequire, 'CDS::Store';
Subroutine BEGIN: called CC=1 SCAR=0.0
13512  
13513 sub new {
13514 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
13515 0 my $backend = shift;
13516 0 my $cache = shift;
13517  
13518 0 return bless {
13519 id => "Object Cache\n".$backend->id."\n".$cache->id,
13520 backend => $backend,
13521 cache => $cache,
13522 };
13523 }
13524  
13525 0 ▶sub id { shift->{id} }
Subroutine id: not called CC=1 SCAR=6.9
13526 0 ▶sub backend { shift->{backend} }
Subroutine backend: not called CC=1 SCAR=6.9
13527 0 ▶sub cache { shift->{cache} }
Subroutine cache: not called CC=1 SCAR=6.9
13528  
13529 sub get {
13530 0 ▶ my $o = shift;
Subroutine get: not called CC=7 SCAR=40.3
13531 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
13532 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
13533  
13534 0 my $objectFromCache = $o->{cache}->get($hash);
13535 0 ▶ return $objectFromCache if $objectFromCache;
Branch: 1 branch
BranchTrueFalseTotal
if $objectFromCache 0 0 0
13536  
13537 0 my ($object, $error) = $o->{backend}->get($hash, $keyPair);
13538 0 ▶ return undef, $error if ! defined $object;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $object 0 0 0
13539 0 $o->{cache}->put($hash, $object, undef);
13540 0 return $object;
13541 }
13542  
13543 sub put {
13544 0 ▶ my $o = shift;
Subroutine put: not called CC=1 SCAR=6.9
13545  
13546 # The important thing is that the backend succeeds. The cache is a nice-to-have.
13547 0 $o->{cache}->put(@_);
13548 0 return $o->{backend}->put(@_);
13549 }
13550  
13551 sub book {
13552 0 ▶ my $o = shift;
Subroutine book: not called CC=1 SCAR=6.9
13553  
13554 # The important thing is that the backend succeeds. The cache is a nice-to-have.
13555 0 $o->{cache}->book(@_);
13556 0 return $o->{backend}->book(@_);
13557 }
13558  
13559 sub list {
13560 0 ▶ my $o = shift;
Subroutine list: not called CC=1 SCAR=6.9
13561  
13562 # Just pass this through to the backend.
13563 0 return $o->{backend}->list(@_);
13564 }
13565  
13566 sub add {
13567 0 ▶ my $o = shift;
Subroutine add: not called CC=1 SCAR=6.9
13568  
13569 # Just pass this through to the backend.
13570 0 return $o->{backend}->add(@_);
13571 }
13572  
13573 sub remove {
13574 0 ▶ my $o = shift;
Subroutine remove: not called CC=1 SCAR=6.9
13575  
13576 # Just pass this through to the backend.
13577 0 return $o->{backend}->remove(@_);
13578 }
13579  
13580 sub modify {
13581 0 ▶ my $o = shift;
Subroutine modify: not called CC=1 SCAR=6.9
13582  
13583 # Just pass this through to the backend.
13584 0 return $o->{backend}->modify(@_);
13585 }
13586  
13587 # The result of parsing an OBJECTFILE token (see Token.pm).
13588 package CDS::ObjectFileToken;
13589  
13590 sub new {
13591 0 ▶ my $class = shift;
Subroutine new: not called CC=3 SCAR=24.8
13592 0 my $file = shift;
13593 0 ▶ my $object = shift; die 'wrong type '.ref($object).' for $object' if defined $object && ref $object ne 'CDS::Object';
Branch: 1 branch
BranchTrueFalseTotal
if defined $object and ref $object ne "CDS::Object" 0 0 0
Condition0%0/3
defined $object and ref $object ne "CDS::Object"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $object and ref $object ne "CDS::Object"
defined $object ref $object ne "CDS::Object"
Truth table0%0/3
A and B
A= defined $objectB= ref $object ne "CDS::Object"
ABresult
0X0
100
111
13594  
13595 0 return bless {
13596 file => $file,
13597 object => $object,
13598 };
13599 }
13600  
13601 0 ▶sub file { shift->{file} }
Subroutine file: not called CC=1 SCAR=6.9
13602 0 ▶sub object { shift->{object} }
Subroutine object: not called CC=1 SCAR=6.9
13603  
13604 # The result of parsing an OBJECT token.
13605 package CDS::ObjectToken;
13606  
13607 sub new {
13608 0 ▶ my $class = shift;
Subroutine new: not called CC=3 SCAR=24.8
13609 0 my $cliStore = shift;
13610 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
13611  
13612 0 return bless {
13613 cliStore => $cliStore,
13614 hash => $hash,
13615 };
13616 }
13617  
13618 0 ▶sub cliStore { shift->{cliStore} }
Subroutine cliStore: not called CC=1 SCAR=6.9
13619 0 ▶sub hash { shift->{hash} }
Subroutine hash: not called CC=1 SCAR=6.9
13620 sub url {
13621 0 ▶ my $o = shift;
Subroutine url: not called CC=1 SCAR=6.9
13622 0 $o->{cliStore}->url.'/objects/'.$o->{hash}->hex }
13623  
13624 package CDS::Parser;
13625  
13626 sub new {
13627 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
13628 0 my $actor = shift;
13629 0 my $command = shift;
13630  
13631 0 my $start = CDS::Parser::Node->new(0);
13632 0 return bless {
13633 actor => $actor,
13634 ui => $actor->ui,
13635 start => $start,
13636 states => [CDS::Parser::State->new($start)],
13637 command => $command,
13638 };
13639 }
13640  
13641 0 ▶sub actor { shift->{actor} }
Subroutine actor: not called CC=1 SCAR=6.9
13642 0 ▶sub start { shift->{start} }
Subroutine start: not called CC=1 SCAR=6.9
13643  
13644 sub execute {
13645 0 ▶ my $o = shift;
Subroutine execute: not called CC=9 SCAR=45.0
13646  
13647 0 my $processed = [$o->{command}];
13648 0 for my $arg (@_) {
13649 0 ▶ return $o->howToContinue($processed) if $arg eq '?';
Branch: 1 branch
BranchTrueFalseTotal
if $arg eq "?" 0 0 0
13650 0 ▶ return $o->explain if $arg eq '??';
Branch: 1 branch
BranchTrueFalseTotal
if $arg eq "??" 0 0 0
13651 0 my $token = CDS::Parser::Token->new($o->{actor}, $arg);
13652 0 $o->advance($token);
13653 0 ▶ return $o->invalid($processed, $token) if ! scalar @{$o->{states}};
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @{$o->{"states"};} 0 0 0
13654 0 push @$processed, $arg;
13655 }
13656  
13657 0 my @results = grep { $_->runHandler } @{$o->{states}};
13658 0 ▶ return $o->howToContinue($processed) if ! scalar @results;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @results 0 0 0
13659  
13660 0 my $maxWeight = 0;
13661 0 for my $result (@results) {
13662 0 ▶ $maxWeight = $result->cumulativeWeight if $maxWeight < $result->cumulativeWeight;
Branch: 1 branch
BranchTrueFalseTotal
if $maxWeight < $result->cumulativeWeight 0 0 0
13663 }
13664  
13665 0 @results = grep { $_->cumulativeWeight == $maxWeight } @results;
13666 0 ▶ return $o->ambiguous if scalar @results > 1;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @results > 1 0 0 0
13667  
13668 0 my $result = shift @results;
13669 0 my $handler = $result->runHandler;
13670 0 my $instance = &{$handler->{constructor}}(undef, $o->{actor});
13671 0 &{$handler->{function}}($instance, $result);
13672 }
13673  
13674 sub advance {
13675 0 ▶ my $o = shift;
Subroutine advance: not called CC=2 SCAR=17.9
13676 0 my $token = shift;
13677  
13678 0 $o->{previousStates} = $o->{states};
13679 0 $o->{states} = [];
13680 0 for my $state (@{$o->{previousStates}}) {
13681 0 push @{$o->{states}}, $state->advance($token);
13682 }
13683 }
13684  
13685 sub showCompletions {
13686 0 ▶ my $o = shift;
Subroutine showCompletions: not called CC=24 SCAR=64.0
13687 0 my $cmd = shift;
13688  
13689 # Parse the command line
13690 0 my $state = '';
13691 0 my $arg = '';
13692 0 my @args;
13693 0 for my $c (split //, $cmd) {
13694 0 ▶ if ($state eq '') {
Branch: 5 branches
BranchTrueFalseTotal
if ($state eq '') { } 0 0 0
elsif ($state eq '\\') { } 0 0 0
elsif ($state eq q[']) { } 0 0 0
elsif ($state eq '"') { } 0 0 0
elsif ($state eq '\\"') { } 0 0 0
13695 0 ▶ if ($c eq ' ') {
Branch: 4 branches
BranchTrueFalseTotal
if ($c eq ' ') { } 0 0 0
elsif ($c eq q[']) { } 0 0 0
elsif ($c eq '"') { } 0 0 0
elsif ($c eq '\\') { } 0 0 0
13696 0 ▶ push @args, $arg if length $arg;
Branch: 1 branch
BranchTrueFalseTotal
if length $arg 0 0 0
13697 0 $arg = '';
13698 } elsif ($c eq '\'') {
13699 0 ▶ push @args, $arg if length $arg;
Branch: 1 branch
BranchTrueFalseTotal
if length $arg 0 0 0
13700 0 $arg = '';
13701 0 $state = '\'';
13702 } elsif ($c eq '"') {
13703 0 ▶ push @args, $arg if length $arg;
Branch: 1 branch
BranchTrueFalseTotal
if length $arg 0 0 0
13704 0 $arg = '';
13705 0 $state = '"';
13706 } elsif ($c eq '\\') {
13707 0 $state = '\\';
13708 } else {
13709 0 $arg .= $c;
13710 }
13711 } elsif ($state eq '\\') {
13712 0 $arg .= $c;
13713 0 $state = '';
13714 } elsif ($state eq '\'') {
13715 0 ▶ if ($c eq '\'') {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq q[']) { } 0 0 0
13716 0 ▶ push @args, $arg if length $arg;
Branch: 1 branch
BranchTrueFalseTotal
if length $arg 0 0 0
13717 0 $arg = '';
13718 0 $state = '';
13719 } else {
13720 0 $arg .= $c;
13721 }
13722 } elsif ($state eq '"') {
13723 0 ▶ if ($c eq '"') {
Branch: 2 branches
BranchTrueFalseTotal
if ($c eq '"') { } 0 0 0
elsif ($c eq '\\') { } 0 0 0
13724 0 ▶ push @args, $arg if length $arg;
Branch: 1 branch
BranchTrueFalseTotal
if length $arg 0 0 0
13725 0 $arg = '';
13726 0 $state = '';
13727 } elsif ($c eq '\\') {
13728 0 $state = '"\\';
13729 } else {
13730 0 $arg .= $c;
13731 }
13732 } elsif ($state eq '\\"') {
13733 0 $arg .= $c;
13734 0 $state = '"';
13735 }
13736 }
13737  
13738 # Use the last token to complete
13739 0 my $lastToken = CDS::Parser::Token->new($o->{actor}, $arg);
13740  
13741 # Look for possible states
13742 0 shift @args;
13743 0 for my $arg (@args) {
13744 0 ▶ return if $arg eq '?';
Branch: 1 branch
BranchTrueFalseTotal
if $arg eq "?" 0 0 0
13745 0 $o->advance(CDS::Parser::Token->new($o->{actor}, $arg));
13746 }
13747  
13748 # Complete the last token
13749 0 my %possibilities;
13750 0 for my $state (@{$o->{states}}) {
13751 0 for my $possibility ($state->complete($lastToken)) {
13752 0 $possibilities{$possibility} = 1;
13753 }
13754 }
13755  
13756 # Print all possibilities
13757 0 for my $possibility (keys %possibilities) {
13758 0 print $possibility, "\n";
13759 }
13760 }
13761  
13762 sub ambiguous {
13763 0 ▶ my $o = shift;
Subroutine ambiguous: not called CC=1 SCAR=6.9
13764  
13765 0 $o->{ui}->space;
13766 0 $o->{ui}->pRed('Your query is ambiguous. This is an error in the command grammar.');
13767 0 $o->explain;
13768 }
13769  
13770 sub explain {
13771 0 ▶ my $o = shift;
Subroutine explain: not called CC=4 SCAR=30.0
13772  
13773 0 ▶ for my $interpretation (sort { $b->cumulativeWeight <=> $a->cumulativeWeight || $b->isExecutable <=> $a->isExecutable } @{$o->{states}}) {
Branch: 1 branch
BranchTrueFalseTotal
$b->cumulativeWeight <=> $a->cumulativeWeight or $b->isExecutable <=> $a->isExecutable 0 0 0
13774 0 $o->{ui}->space;
13775 0 ▶ $o->{ui}->title('Interpretation with weight ', $interpretation->cumulativeWeight, $interpretation->isExecutable ? $o->{ui}->green(' (executable)') : $o->{ui}->orange(' (incomplete)'));
Branch: 1 branch
BranchTrueFalseTotal
$interpretation->isExecutable ? : 0 0 0
13776 0 $o->showTuples($interpretation->path);
13777 }
13778  
13779 0 $o->{ui}->space;
13780 }
13781  
13782 sub showTuples {
13783 0 ▶ my $o = shift;
Subroutine showTuples: not called CC=8 SCAR=42.8
13784  
13785 0 for my $state (@_) {
13786 0 my $label = $state->label;
13787 0 my $value = $state->value;
13788  
13789 0 my $valueRef = ref $value;
13790 0 ▶ my $valueText =
Branch: 4 branches
BranchTrueFalseTotal
$valueRef eq '' ? : 0 0 0
$valueRef eq 'CDS::Hash' ? : 0 0 0
$valueRef eq 'CDS::ErrorHandlingStore' ? : 0 0 0
$valueRef eq 'CDS::AccountToken' ? : 0 0 0
Condition0%0/2
$value // ""
l!l
00
MC/DC0%0/1
$value // ""
$value
Truth table0%0/2
A
A= $value
Aresult
11
00
13791 $valueRef eq '' ? $value // '' :
13792 $valueRef eq 'CDS::Hash' ? $value->hex :
13793 $valueRef eq 'CDS::ErrorHandlingStore' ? $value->url :
13794 $valueRef eq 'CDS::AccountToken' ? $value->actorHash->hex . ' on ' . $value->cliStore->url :
13795 $valueRef;
13796 0 ▶ $o->{ui}->line($o->{ui}->left(12, $label), $state->collectHandler ? $valueText : $o->{ui}->gray($valueText));
Branch: 1 branch
BranchTrueFalseTotal
$state->collectHandler ? : 0 0 0
13797 }
13798 }
13799  
13800 sub cmd {
13801 0 ▶ my $o = shift;
Subroutine cmd: not called CC=2 SCAR=17.9
13802 0 my $processed = shift;
13803  
13804 0 my $cmd = join(' ', map { $_ =~ s/(\\|'|")/\\$1/g ; $_ } @$processed);
13805 0 ▶ $cmd = '…'.substr($cmd, length($cmd) - 20, 20) if length $cmd > 30;
Branch: 1 branch
BranchTrueFalseTotal
if length $cmd > 30 0 0 0
13806 0 return $cmd;
13807 }
13808  
13809 sub howToContinue {
13810 0 ▶ my $o = shift;
Subroutine howToContinue: not called CC=2 SCAR=17.9
13811 0 my $processed = shift;
13812  
13813 0 my $cmd = $o->cmd($processed);
13814 #$o->displayWarnings($o->{states});
13815 0 $o->{ui}->space;
13816 0 for my $possibility (CDS::Parser::Continuations->collect($o->{states})) {
13817 0 $o->{ui}->line($o->{ui}->gray($cmd), $possibility);
13818 }
13819 0 $o->{ui}->space;
13820 }
13821  
13822 sub invalid {
13823 0 ▶ my $o = shift;
Subroutine invalid: not called CC=4 SCAR=30.0
13824 0 my $processed = shift;
13825 0 my $invalid = shift;
13826  
13827 0 my $cmd = $o->cmd($processed);
13828 0 $o->displayWarnings($o->{previousStates});
13829 0 $o->{ui}->space;
13830  
13831 0 $o->{ui}->line($o->{ui}->gray($cmd), ' ', $o->{ui}->red($invalid->{text}));
13832 0 ▶ if (scalar @{$invalid->{warnings}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$invalid->{"warnings"};}) 0 0 0
13833 0 for my $warning (@{$invalid->{warnings}}) {
13834 0 $o->{ui}->warning($warning);
13835 }
13836 }
13837  
13838 0 $o->{ui}->space;
13839 0 $o->{ui}->title('Possible continuations');
13840 0 for my $possibility (CDS::Parser::Continuations->collect($o->{previousStates})) {
13841 0 $o->{ui}->line($o->{ui}->gray($cmd), $possibility);
13842 }
13843 0 $o->{ui}->space;
13844 }
13845  
13846 sub displayWarnings {
13847 0 ▶ my $o = shift;
Subroutine displayWarnings: not called CC=4 SCAR=30.0
13848 0 my $states = shift;
13849  
13850 0 for my $state (@$states) {
13851 0 my $current = $state;
13852 0 ▶ while ($current) {
Branch: 1 branch
BranchTrueFalseTotal
if ($current) 0 0 0
13853 0 for my $warning (@{$current->{warnings}}) {
13854 0 $o->{ui}->warning($warning);
13855 }
13856 0 $current = $current->{previous};
13857 }
13858 }
13859 }
13860  
13861 # An arrow points from one node to another. The arrow is taken in State::advance if the next argument matches to the label.
13862 package CDS::Parser::Arrow;
13863  
13864 sub new {
13865 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
13866 0 my $node = shift;
13867 0 my $official = shift;
13868 0 my $weight = shift;
13869 0 my $label = shift;
13870 0 my $handler = shift;
13871  
13872 0 return bless {
13873 node => $node, # target node
13874 official => $official, # whether to show this arrow with '?'
13875 weight => $weight, # weight
13876 label => $label, # label
13877 handler => $handler, # handler to invoke if we take this arrow
13878 };
13879 }
13880  
13881 package CDS::Parser::Continuations;
13882  
13883 sub collect {
13884 0 ▶ my $class = shift;
Subroutine collect: not called CC=4 SCAR=30.0
13885 0 my $states = shift;
13886  
13887 0 my $o = bless {possibilities => {}};
13888  
13889 0 my $visitedNodes = {};
13890 0 for my $state (@$states) {
13891 0 $o->visit($visitedNodes, $state->node, '');
13892 }
13893  
13894 0 for my $possibility (keys %{$o->{possibilities}}) {
13895 0 ▶ delete $o->{possibilities}->{$possibility} if exists $o->{possibilities}->{$possibility.' …'};
Branch: 1 branch
BranchTrueFalseTotal
if exists $o->{"possibilities"}{$possibility . " \x{2026}"} 0 0 0
13896 }
13897  
13898 0 return sort keys %{$o->{possibilities}};
13899 }
13900  
13901 sub visit {
13902 0 ▶ my $o = shift;
Subroutine visit: not called CC=7 SCAR=40.3
13903 0 my $visitedNodes = shift;
13904 0 my $node = shift;
13905 0 my $text = shift;
13906  
13907 0 $visitedNodes->{$node} = 1;
13908  
13909 0 my $arrows = [];
13910 0 $node->collectArrows($arrows);
13911  
13912 0 for my $arrow (@$arrows) {
13913 0 ▶ next if ! $arrow->{official};
Branch: 1 branch
BranchTrueFalseTotal
unless $arrow->{"official"} 0 0 0
13914  
13915 0 my $text = $text.' '.$arrow->{label};
13916 0 ▶ $o->{possibilities}->{$text} = 1 if $arrow->{node}->hasHandler;
Branch: 1 branch
BranchTrueFalseTotal
if $arrow->{"node"}->hasHandler 0 0 0
13917 0 ▶ if ($arrow->{node}->endProposals || exists $visitedNodes->{$arrow->{node}}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arrow->{"node"}->endProposals or exists $$visitedNodes{$arrow->{"node"}}) 0 0 0
Condition0%0/3
$arrow->{"node"}->endProposals or exists $$visitedNodes{$arrow->{"node"}}
l!l&&r!l&&!r
000
MC/DC0%0/2
$arrow->{"node"}->endProposals or exists $$visitedNodes{$arrow->{"node"}}
$arrow->{"node"}->endProposals exists $$visitedNodes{$arrow->{"node"}}
Truth table0%0/3
A or B
A= $arrow->{"node"}->endProposalsB= exists $$visitedNodes{$arrow->{"node"}}
ABresult
1X1
011
000
13918 0 ▶ $o->{possibilities}->{$text . ($o->canContinue($arrow->{node}) ? ' …' : '')} = 1;
Branch: 1 branch
BranchTrueFalseTotal
$o->canContinue($arrow->{'node'}) ? : 0 0 0
13919 0 next;
13920 }
13921  
13922 0 $o->visit($visitedNodes, $arrow->{node}, $text);
13923 }
13924  
13925 0 delete $visitedNodes->{$node};
13926 }
13927  
13928 sub canContinue {
13929 0 ▶ my $o = shift;
Subroutine canContinue: not called CC=3 SCAR=24.8
13930 0 my $node = shift;
13931  
13932 0 my $arrows = [];
13933 0 $node->collectArrows($arrows);
13934  
13935 0 for my $arrow (@$arrows) {
13936 0 ▶ next if ! $arrow->{official};
Branch: 1 branch
BranchTrueFalseTotal
unless $arrow->{"official"} 0 0 0
13937 0 return 1;
13938 }
13939  
13940 0 return;
13941 }
13942  
13943 # Nodes and arrows define the graph on which the parse state can move.
13944 package CDS::Parser::Node;
13945  
13946 sub new {
13947 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
13948 0 my $endProposals = shift;
13949 0 my $handler = shift;
13950  
13951 0 return bless {
13952 arrows => [], # outgoing arrows
13953 defaults => [], # default nodes, at which the current state could be as well
13954 endProposals => $endProposals, # if set, the proposal search algorithm stops at this node
13955 handler => $handler, # handler to be executed if parsing ends here
13956 };
13957 }
13958  
13959 0 ▶sub endProposals { shift->{endProposals} }
Subroutine endProposals: not called CC=1 SCAR=6.9
13960  
13961 # Adds an arrow.
13962 sub addArrow {
13963 0 ▶ my $o = shift;
Subroutine addArrow: not called CC=1 SCAR=6.9
13964 0 my $to = shift;
13965 0 my $official = shift;
13966 0 my $weight = shift;
13967 0 my $label = shift;
13968 0 my $handler = shift;
13969  
13970 0 push @{$o->{arrows}}, CDS::Parser::Arrow->new($to, $official, $weight, $label, $handler);
13971 }
13972  
13973 # Adds a default node.
13974 sub addDefault {
13975 0 ▶ my $o = shift;
Subroutine addDefault: not called CC=1 SCAR=6.9
13976 0 my $node = shift;
13977  
13978 0 push @{$o->{defaults}}, $node;
13979 }
13980  
13981 sub collectArrows {
13982 0 ▶ my $o = shift;
Subroutine collectArrows: not called CC=2 SCAR=17.9
13983 0 my $arrows = shift;
13984  
13985 0 push @$arrows, @{$o->{arrows}};
13986 0 for my $default (@{$o->{defaults}}) { $default->collectArrows($arrows); }
13987 }
13988  
13989 sub hasHandler {
13990 0 ▶ my $o = shift;
Subroutine hasHandler: not called CC=4 SCAR=30.0
13991  
13992 0 ▶ return 1 if $o->{handler};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"handler"} 0 0 0
13993 0 ▶ for my $default (@{$o->{defaults}}) { return 1 if $default->hasHandler; }
Branch: 1 branch
BranchTrueFalseTotal
if $default->hasHandler 0 0 0
13994 0 return;
13995 }
13996  
13997 sub getHandler {
13998 0 ▶ my $o = shift;
Subroutine getHandler: not called CC=4 SCAR=30.0
13999  
14000 0 ▶ return $o->{handler} if $o->{handler};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"handler"} 0 0 0
14001 0 for my $default (@{$o->{defaults}}) {
14002 0 ▶ my $handler = $default->getHandler // next;
Condition0%0/2
$default->getHandler // (next)
l!l
00
MC/DC0%0/1
$default->getHandler // (next)
$default->getHandler
Truth table0%0/2
A
A= $default->getHandler
Aresult
11
00
14003 0 return $handler;
14004 }
14005 0 return;
14006 }
14007  
14008 # A parser state denotes a possible current state (after having parsed a certain number of arguments).
14009 # A parser keeps track of multiple states. When advancing, a state may disappear (if no possibility exists), or fan out (if multiple possibilities exist).
14010 # A state is immutable.
14011 package CDS::Parser::State;
14012  
14013 sub new {
14014 0 ▶ my $class = shift;
Subroutine new: not called CC=3 SCAR=24.8
14015 0 my $node = shift;
14016 0 my $previous = shift;
14017 0 my $arrow = shift;
14018 0 my $value = shift;
14019 0 my $warnings = shift;
14020  
14021 return bless {
14022 node => $node, # current node
14023 previous => $previous, # previous state
14024 arrow => $arrow, # the arrow we took to get here
14025 value => $value, # the value we collected with the last arrow
14026 warnings => $warnings, # the warnings we collected with the last arrow
14027 0 ▶ cumulativeWeight => ($previous ? $previous->cumulativeWeight : 0) + ($arrow ? $arrow->{weight} : 0), # the weight we collected until here
Branch: 2 branches
BranchTrueFalseTotal
$previous ? : 0 0 0
$arrow ? : 0 0 0
14028 };
14029 }
14030  
14031 0 ▶sub node { shift->{node} }
Subroutine node: not called CC=1 SCAR=6.9
14032 sub runHandler {
14033 0 ▶ my $o = shift;
Subroutine runHandler: not called CC=1 SCAR=6.9
14034 0 $o->{node}->getHandler }
14035 sub isExecutable {
14036 0 ▶ my $o = shift;
Subroutine isExecutable: not called CC=2 SCAR=17.9
14037 0 ▶ $o->{node}->getHandler ? 1 : 0 }
Branch: 1 branch
BranchTrueFalseTotal
$o->{'node'}->getHandler ? : 0 0 0
14038 sub collectHandler {
14039 0 ▶ my $o = shift;
Subroutine collectHandler: not called CC=2 SCAR=17.9
14040 0 ▶ $o->{arrow} ? $o->{arrow}->{handler} : undef }
Branch: 1 branch
BranchTrueFalseTotal
$o->{'arrow'} ? : 0 0 0
14041 sub label {
14042 0 ▶ my $o = shift;
Subroutine label: not called CC=2 SCAR=17.9
14043 0 ▶ $o->{arrow} ? $o->{arrow}->{label} : 'cds' }
Branch: 1 branch
BranchTrueFalseTotal
$o->{'arrow'} ? : 0 0 0
14044 0 ▶sub value { shift->{value} }
Subroutine value: not called CC=1 SCAR=6.9
14045 0 ▶sub arrow { shift->{arrow} }
Subroutine arrow: not called CC=1 SCAR=6.9
14046 0 ▶sub cumulativeWeight { shift->{cumulativeWeight} }
Subroutine cumulativeWeight: not called CC=1 SCAR=6.9
14047  
14048 sub advance {
14049 0 ▶ my $o = shift;
Subroutine advance: not called CC=4 SCAR=30.0
14050 0 my $token = shift;
14051  
14052 0 my $arrows = [];
14053 0 $o->{node}->collectArrows($arrows);
14054  
14055 # Let the token know what possibilities we have
14056 0 for my $arrow (@$arrows) {
14057 0 $token->prepare($arrow->{label});
14058 }
14059  
14060 # Ask the token to interpret the text
14061 0 my @states;
14062 0 for my $arrow (@$arrows) {
14063 0 ▶ my $value = $token->as($arrow->{label}) // next;
Condition0%0/2
$token->as($arrow->{"label"}) // (next)
l!l
00
MC/DC0%0/1
$token->as($arrow->{"label"}) // (next)
$token->as($arrow->{"label"})
Truth table0%0/2
A
A= $token->as($arrow->{"label"})
Aresult
11
00
14064 0 push @states, CDS::Parser::State->new($arrow->{node}, $o, $arrow, $value, $token->{warnings});
14065 }
14066  
14067 0 return @states;
14068 }
14069  
14070 sub complete {
14071 0 ▶ my $o = shift;
Subroutine complete: not called CC=5 SCAR=34.0
14072 0 my $token = shift;
14073  
14074 0 my $arrows = [];
14075 0 $o->{node}->collectArrows($arrows);
14076  
14077 # Let the token know what possibilities we have
14078 0 for my $arrow (@$arrows) {
14079 0 ▶ next if ! $arrow->{official};
Branch: 1 branch
BranchTrueFalseTotal
unless $arrow->{"official"} 0 0 0
14080 0 $token->prepare($arrow->{label});
14081 }
14082  
14083 # Ask the token to interpret the text
14084 0 for my $arrow (@$arrows) {
14085 0 ▶ next if ! $arrow->{official};
Branch: 1 branch
BranchTrueFalseTotal
unless $arrow->{"official"} 0 0 0
14086 0 $token->complete($arrow->{label});
14087 }
14088  
14089 0 return @{$token->{possibilities}};
14090 }
14091  
14092 sub arrows {
14093 0 ▶ my $o = shift;
Subroutine arrows: not called CC=1 SCAR=6.9
14094  
14095 0 my $arrows = [];
14096 0 $o->{node}->collectArrows($arrows);
14097 0 return @$arrows;
14098 }
14099  
14100 sub path {
14101 0 ▶ my $o = shift;
Subroutine path: not called CC=2 SCAR=17.9
14102  
14103 0 my @path;
14104 0 my $state = $o;
14105 0 ▶ while ($state) {
Branch: 1 branch
BranchTrueFalseTotal
if ($state) 0 0 0
14106 0 unshift @path, $state;
14107 0 $state = $state->{previous};
14108 }
14109 0 return @path;
14110 }
14111  
14112 sub collect {
14113 0 ▶ my $o = shift;
Subroutine collect: not called CC=3 SCAR=24.8
14114 0 my $data = shift;
14115  
14116 0 for my $state ($o->path) {
14117 0 ▶ my $collectHandler = $state->collectHandler // next;
Condition0%0/2
$state->collectHandler // (next)
l!l
00
MC/DC0%0/1
$state->collectHandler // (next)
$state->collectHandler
Truth table0%0/2
A
A= $state->collectHandler
Aresult
11
00
14118 0 &$collectHandler($data, $state->label, $state->value);
14119 }
14120 }
14121  
14122 package CDS::Parser::Token;
14123  
14124 sub new {
14125 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
14126 0 my $actor = shift;
14127 0 my $text = shift;
14128  
14129 0 return bless {
14130 actor => $actor,
14131 text => $text,
14132 keywords => {},
14133 cache => {},
14134 warnings => [],
14135 possibilities => [],
14136 };
14137 }
14138  
14139 sub prepare {
14140 0 ▶ my $o = shift;
Subroutine prepare: not called CC=2 SCAR=17.9
14141 0 my $expect = shift;
14142  
14143 0 ▶ $o->{keywords}->{$expect} = 1 if $expect =~ /^[a-z0-9]*$/;
Branch: 1 branch
BranchTrueFalseTotal
if $expect =~ /^[a-z0-9]*$/ 0 0 0
14144 }
14145  
14146 sub as {
14147 0 ▶ my $o = shift;
Subroutine as: not called CC=2 SCAR=17.9
14148 0 my $expect = shift;
14149 0 ▶ exists $o->{cache}->{$expect} ? $o->{cache}->{$expect} : $o->{cache}->{$expect} = $o->produce($expect) }
Branch: 1 branch
BranchTrueFalseTotal
exists $o->{'cache'}{$expect} ? : 0 0 0
14150  
14151 sub produce {
14152 0 ▶ my $o = shift;
Subroutine produce: not called CC=22 SCAR=62.3
14153 0 my $expect = shift;
14154  
14155 0 ▶ return $o->account if $expect eq 'ACCOUNT';
Branch: 1 branch
BranchTrueFalseTotal
if $expect eq "ACCOUNT" 0 0 0
14156 0 ▶ return $o->hash if $expect eq 'ACTOR';
Branch: 1 branch
BranchTrueFalseTotal
if $expect eq "ACTOR" 0 0 0
14157 0 ▶ return $o->actorGroup if $expect eq 'ACTORGROUP';
Branch: 1 branch
BranchTrueFalseTotal
if $expect eq "ACTORGROUP" 0 0 0
14158 0 ▶ return $o->aesKey if $expect eq 'AESKEY';
Branch: 1 branch
BranchTrueFalseTotal
if $expect eq "AESKEY" 0 0 0
14159 0 ▶ return $o->box if $expect eq 'BOX';
Branch: 1 branch
BranchTrueFalseTotal
if $expect eq "BOX" 0 0 0
14160 0 ▶ return $o->boxLabel if $expect eq 'BOXLABEL';
Branch: 1 branch
BranchTrueFalseTotal
if $expect eq "BOXLABEL" 0 0 0
14161 0 ▶ return $o->file if $expect eq 'FILE';
Branch: 1 branch
BranchTrueFalseTotal
if $expect eq "FILE" 0 0 0
14162 0 ▶ return $o->filename if $expect eq 'FILENAME';
Branch: 1 branch
BranchTrueFalseTotal
if $expect eq "FILENAME" 0 0 0
14163 0 ▶ return $o->folder if $expect eq 'FOLDER';
Branch: 1 branch
BranchTrueFalseTotal
if $expect eq "FOLDER" 0 0 0
14164 0 ▶ return $o->foldername if $expect eq 'FOLDERNAME';
Branch: 1 branch
BranchTrueFalseTotal
if $expect eq "FOLDERNAME" 0 0 0
14165 0 ▶ return $o->group if $expect eq 'GROUP';
Branch: 1 branch
BranchTrueFalseTotal
if $expect eq "GROUP" 0 0 0
14166 0 ▶ return $o->hash if $expect eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if $expect eq "HASH" 0 0 0
14167 0 ▶ return $o->keyPair if $expect eq 'KEYPAIR';
Branch: 1 branch
BranchTrueFalseTotal
if $expect eq "KEYPAIR" 0 0 0
14168 0 ▶ return $o->label if $expect eq 'LABEL';
Branch: 1 branch
BranchTrueFalseTotal
if $expect eq "LABEL" 0 0 0
14169 0 ▶ return $o->object if $expect eq 'OBJECT';
Branch: 1 branch
BranchTrueFalseTotal
if $expect eq "OBJECT" 0 0 0
14170 0 ▶ return $o->objectFile if $expect eq 'OBJECTFILE';
Branch: 1 branch
BranchTrueFalseTotal
if $expect eq "OBJECTFILE" 0 0 0
14171 0 ▶ return $o->port if $expect eq 'PORT';
Branch: 1 branch
BranchTrueFalseTotal
if $expect eq "PORT" 0 0 0
14172 0 ▶ return $o->store if $expect eq 'STORE';
Branch: 1 branch
BranchTrueFalseTotal
if $expect eq "STORE" 0 0 0
14173 0 ▶ return $o->text if $expect eq 'TEXT';
Branch: 1 branch
BranchTrueFalseTotal
if $expect eq "TEXT" 0 0 0
14174 0 ▶ return $o->user if $expect eq 'USER';
Branch: 1 branch
BranchTrueFalseTotal
if $expect eq "USER" 0 0 0
14175 0 ▶ return $o->{text} eq $expect ? '' : undef;
Branch: 1 branch
BranchTrueFalseTotal
$o->{'text'} eq $expect ? : 0 0 0
14176 }
14177  
14178 sub complete {
14179 0 ▶ my $o = shift;
Subroutine complete: not called CC=20 SCAR=60.4
14180 0 my $expect = shift;
14181  
14182 0 ▶ return $o->completeAccount if $expect eq 'ACCOUNT';
Branch: 1 branch
BranchTrueFalseTotal
if $expect eq "ACCOUNT" 0 0 0
14183 0 ▶ return $o->completeHash if $expect eq 'ACTOR';
Branch: 1 branch
BranchTrueFalseTotal
if $expect eq "ACTOR" 0 0 0
14184 0 ▶ return $o->completeActorGroup if $expect eq 'ACTORGROUP';
Branch: 1 branch
BranchTrueFalseTotal
if $expect eq "ACTORGROUP" 0 0 0
14185 0 ▶ return if $expect eq 'AESKEY';
Branch: 1 branch
BranchTrueFalseTotal
if $expect eq "AESKEY" 0 0 0
14186 0 ▶ return $o->completeBox if $expect eq 'BOX';
Branch: 1 branch
BranchTrueFalseTotal
if $expect eq "BOX" 0 0 0
14187 0 ▶ return $o->completeBoxLabel if $expect eq 'BOXLABEL';
Branch: 1 branch
BranchTrueFalseTotal
if $expect eq "BOXLABEL" 0 0 0
14188 0 ▶ return $o->completeFile if $expect eq 'FILE';
Branch: 1 branch
BranchTrueFalseTotal
if $expect eq "FILE" 0 0 0
14189 0 ▶ return $o->completeFile if $expect eq 'FILENAME';
Branch: 1 branch
BranchTrueFalseTotal
if $expect eq "FILENAME" 0 0 0
14190 0 ▶ return $o->completeFolder if $expect eq 'FOLDER';
Branch: 1 branch
BranchTrueFalseTotal
if $expect eq "FOLDER" 0 0 0
14191 0 ▶ return $o->completeFolder if $expect eq 'FOLDERNAME';
Branch: 1 branch
BranchTrueFalseTotal
if $expect eq "FOLDERNAME" 0 0 0
14192 0 ▶ return $o->completeGroup if $expect eq 'GROUP';
Branch: 1 branch
BranchTrueFalseTotal
if $expect eq "GROUP" 0 0 0
14193 0 ▶ return $o->completeHash if $expect eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if $expect eq "HASH" 0 0 0
14194 0 ▶ return $o->completeKeyPair if $expect eq 'KEYPAIR';
Branch: 1 branch
BranchTrueFalseTotal
if $expect eq "KEYPAIR" 0 0 0
14195 0 ▶ return $o->completeLabel if $expect eq 'LABEL';
Branch: 1 branch
BranchTrueFalseTotal
if $expect eq "LABEL" 0 0 0
14196 0 ▶ return $o->completeObject if $expect eq 'OBJECT';
Branch: 1 branch
BranchTrueFalseTotal
if $expect eq "OBJECT" 0 0 0
14197 0 ▶ return $o->completeObjectFile if $expect eq 'OBJECTFILE';
Branch: 1 branch
BranchTrueFalseTotal
if $expect eq "OBJECTFILE" 0 0 0
14198 0 ▶ return $o->completeStoreUrl if $expect eq 'STORE';
Branch: 1 branch
BranchTrueFalseTotal
if $expect eq "STORE" 0 0 0
14199 0 ▶ return $o->completeUser if $expect eq 'USER';
Branch: 1 branch
BranchTrueFalseTotal
if $expect eq "USER" 0 0 0
14200 0 ▶ return if $expect eq 'TEXT';
Branch: 1 branch
BranchTrueFalseTotal
if $expect eq "TEXT" 0 0 0
14201 0 $o->addPossibility($expect);
14202 }
14203  
14204 sub addPossibility {
14205 0 ▶ my $o = shift;
Subroutine addPossibility: not called CC=2 SCAR=17.9
14206 0 my $possibility = shift;
14207  
14208 0 ▶ push @{$o->{possibilities}}, $possibility.' ' if substr($possibility, 0, length $o->{text}) eq $o->{text};
Branch: 1 branch
BranchTrueFalseTotal
if substr($possibility, 0, length $o->{"text"}) eq $o->{"text"} 0 0 0
14209 }
14210  
14211 sub addPartialPossibility {
14212 0 ▶ my $o = shift;
Subroutine addPartialPossibility: not called CC=2 SCAR=17.9
14213 0 my $possibility = shift;
14214  
14215 0 ▶ push @{$o->{possibilities}}, $possibility if substr($possibility, 0, length $o->{text}) eq $o->{text};
Branch: 1 branch
BranchTrueFalseTotal
if substr($possibility, 0, length $o->{"text"}) eq $o->{"text"} 0 0 0
14216 }
14217  
14218 sub isKeyword {
14219 0 ▶ my $o = shift;
Subroutine isKeyword: not called CC=1 SCAR=6.9
14220 0 exists $o->{keywords}->{$o->{text}} }
14221  
14222 sub account {
14223 0 ▶ my $o = shift;
Subroutine account: not called CC=9 SCAR=45.0
14224  
14225 # From a remembered account
14226 0 my $record = $o->{actor}->remembered($o->{text});
14227 0 my $storeUrl = $record->child('store')->textValue;
14228 0 my $actorHash = CDS::Hash->fromBytes($record->child('actor')->bytesValue);
14229 0 ▶ if ($actorHash && length $storeUrl) {
Branch: 1 branch
BranchTrueFalseTotal
if ($actorHash and length $storeUrl) 0 0 0
Condition0%0/3
$actorHash and length $storeUrl
!ll&&!rl&&r
000
MC/DC0%0/2
$actorHash and length $storeUrl
$actorHash length $storeUrl
Truth table0%0/3
A and B
A= $actorHashB= length $storeUrl
ABresult
0X0
100
111
14230 0 ▶ my $store = $o->{actor}->storeForUrl($storeUrl) // return $o->warning('Invalid store URL "', $storeUrl, '" in remembered account.');
Condition0%0/2
$o->{"actor"}->storeForUrl($storeUrl) // (return $o->warning("Invalid store URL \"", $storeUrl, "\" in remembered account."))
l!l
00
MC/DC0%0/1
$o->{"actor"}->storeForUrl($storeUrl) // (return $o->warning("Invalid store URL \"", $storeUrl, "\" in remembered account."))
$o->{"actor"}->storeForUrl($storeUrl)
Truth table0%0/2
A
A= $o->{"actor"}->storeForUrl($storeUrl)
Aresult
11
00
14231 0 my $accountToken = CDS::AccountToken->new($store, $actorHash);
14232 0 ▶ return $o->warning('"', $o->{text}, '" is interpreted as a keyword. If you mean the account, write "', $accountToken->url, '".') if $o->isKeyword;
Branch: 1 branch
BranchTrueFalseTotal
if $o->isKeyword 0 0 0
14233 0 return $accountToken;
14234 }
14235  
14236 # From a URL
14237 0 ▶ if ($o->{text} =~ /^\s*(.*?)\/accounts\/([0-9a-fA-F]{64,64})\/*\s*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"text"} =~ m[^\s*(.*?)/accounts/([0-9a-fA-F]{64,64})/*\s*$]) 0 0 0
14238 0 my $storeUrl = $1;
14239 0 my $actorHash = CDS::Hash->fromHex($2);
14240 0 ▶ $storeUrl = 'file://'.Cwd::abs_path($storeUrl) if $storeUrl !~ /^[a-zA-Z0-9_\+-]*:/ && -d $storeUrl;
Branch: 1 branch
BranchTrueFalseTotal
if not $storeUrl =~ /^[a-zA-Z0-9_\+-]*:/ and -d $storeUrl 0 0 0
Condition0%0/3
not $storeUrl =~ /^[a-zA-Z0-9_\+-]*:/ and -d $storeUrl
!ll&&!rl&&r
000
MC/DC0%0/2
not $storeUrl =~ /^[a-zA-Z0-9_\+-]*:/ and -d $storeUrl
not $storeUrl =~ /^[a-zA-Z0-9_\+-]*:/ -d $storeUrl
Truth table0%0/3
not(A) and B
A= not $storeUrl =~ /^[a-zA-Z0-9_\+-]*:/B= -d $storeUrl
ABresult
0X0
100
111
14241 0 ▶ my $cliStore = $o->{actor}->storeForUrl($storeUrl) // return $o->warning('Invalid store URL "', $storeUrl, '".');
Condition0%0/2
$o->{"actor"}->storeForUrl($storeUrl) // (return $o->warning("Invalid store URL \"", $storeUrl, "\"."))
l!l
00
MC/DC0%0/1
$o->{"actor"}->storeForUrl($storeUrl) // (return $o->warning("Invalid store URL \"", $storeUrl, "\"."))
$o->{"actor"}->storeForUrl($storeUrl)
Truth table0%0/2
A
A= $o->{"actor"}->storeForUrl($storeUrl)
Aresult
11
00
14242 0 return CDS::AccountToken->new($cliStore, $actorHash);
14243 }
14244  
14245 0 return;
14246 }
14247  
14248 sub completeAccount {
14249 0 ▶ my $o = shift;
Subroutine completeAccount: not called CC=4 SCAR=30.0
14250  
14251 0 $o->completeUrl;
14252  
14253 0 my $records = $o->{actor}->rememberedRecords;
14254 0 for my $label (keys %$records) {
14255 0 my $record = $records->{$label};
14256 0 my $storeUrl = $record->child('store')->textValue;
14257 0 ▶ next if ! length $storeUrl;
Branch: 1 branch
BranchTrueFalseTotal
unless length $storeUrl 0 0 0
14258 0 ▶ my $actorHash = CDS::Hash->fromBytes($record->child('actor')->bytesValue) // next;
Condition0%0/2
"CDS::Hash"->fromBytes($record->child("actor")->bytesValue) // (next)
l!l
00
MC/DC0%0/1
"CDS::Hash"->fromBytes($record->child("actor")->bytesValue) // (next)
"CDS::Hash"->fromBytes($record->child("actor")->bytesValue)
Truth table0%0/2
A
A= "CDS::Hash"->fromBytes($record->child("actor")->bytesValue)
Aresult
11
00
14259  
14260 0 $o->addPossibility($label);
14261 0 $o->addPossibility($storeUrl.'/accounts/'.$actorHash->hex);
14262 }
14263  
14264 0 return;
14265 }
14266  
14267 sub aesKey {
14268 0 ▶ my $o = shift;
Subroutine aesKey: not called CC=2 SCAR=17.9
14269  
14270 0 ▶ $o->{text} =~ /^[0-9A-Fa-f]{64}$/ || return;
Branch: 1 branch
BranchTrueFalseTotal
$o->{"text"} =~ /^[0-9A-Fa-f]{64}$/ or return 0 0 0
14271 0 return pack('H*', $o->{text});
14272 }
14273  
14274 sub box {
14275 0 ▶ my $o = shift;
Subroutine box: not called CC=5 SCAR=34.0
14276  
14277 # From a URL
14278 0 ▶ if ($o->{text} =~ /^\s*(.*?)\/accounts\/([0-9a-fA-F]{64,64})\/(messages|private|public)\/*\s*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"text"} =~ m[^\s*(.*?)/accounts/([0-9a-fA-F]{64,64})/(messages|private|public)/*\s*$]) 0 0 0
14279 0 my $storeUrl = $1;
14280 0 my $boxLabel = $3;
14281 0 my $actorHash = CDS::Hash->fromHex($2);
14282 0 ▶ $storeUrl = 'file://'.Cwd::abs_path($storeUrl) if $storeUrl !~ /^[a-zA-Z0-9_\+-]*:/ && -d $storeUrl;
Branch: 1 branch
BranchTrueFalseTotal
if not $storeUrl =~ /^[a-zA-Z0-9_\+-]*:/ and -d $storeUrl 0 0 0
Condition0%0/3
not $storeUrl =~ /^[a-zA-Z0-9_\+-]*:/ and -d $storeUrl
!ll&&!rl&&r
000
MC/DC0%0/2
not $storeUrl =~ /^[a-zA-Z0-9_\+-]*:/ and -d $storeUrl
not $storeUrl =~ /^[a-zA-Z0-9_\+-]*:/ -d $storeUrl
Truth table0%0/3
not(A) and B
A= not $storeUrl =~ /^[a-zA-Z0-9_\+-]*:/B= -d $storeUrl
ABresult
0X0
100
111
14283 0 ▶ my $cliStore = $o->{actor}->storeForUrl($storeUrl) // return $o->warning('Invalid store URL "', $storeUrl, '".');
Condition0%0/2
$o->{"actor"}->storeForUrl($storeUrl) // (return $o->warning("Invalid store URL \"", $storeUrl, "\"."))
l!l
00
MC/DC0%0/1
$o->{"actor"}->storeForUrl($storeUrl) // (return $o->warning("Invalid store URL \"", $storeUrl, "\"."))
$o->{"actor"}->storeForUrl($storeUrl)
Truth table0%0/2
A
A= $o->{"actor"}->storeForUrl($storeUrl)
Aresult
11
00
14284 0 my $accountToken = CDS::AccountToken->new($cliStore, $actorHash);
14285 0 return CDS::BoxToken->new($accountToken, $boxLabel);
14286 }
14287  
14288 0 return;
14289 }
14290  
14291 sub completeBox {
14292 0 ▶ my $o = shift;
Subroutine completeBox: not called CC=1 SCAR=6.9
14293  
14294 0 $o->completeUrl;
14295 0 return;
14296 }
14297  
14298 sub boxLabel {
14299 0 ▶ my $o = shift;
Subroutine boxLabel: not called CC=4 SCAR=30.0
14300  
14301 0 ▶ return $o->{text} if $o->{text} eq 'messages';
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"text"} eq "messages" 0 0 0
14302 0 ▶ return $o->{text} if $o->{text} eq 'private';
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"text"} eq "private" 0 0 0
14303 0 ▶ return $o->{text} if $o->{text} eq 'public';
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"text"} eq "public" 0 0 0
14304 0 return;
14305 }
14306  
14307 sub completeBoxLabel {
14308 0 ▶ my $o = shift;
Subroutine completeBoxLabel: not called CC=1 SCAR=6.9
14309  
14310 0 $o->addPossibility('messages');
14311 0 $o->addPossibility('private');
14312 0 $o->addPossibility('public');
14313 }
14314  
14315 sub file {
14316 0 ▶ my $o = shift;
Subroutine file: not called CC=4 SCAR=30.0
14317  
14318 0 ▶ my $file = Cwd::abs_path($o->{text}) // return;
Condition0%0/2
Cwd::abs_path($o->{"text"}) // (return)
l!l
00
MC/DC0%0/1
Cwd::abs_path($o->{"text"}) // (return)
Cwd::abs_path($o->{"text"})
Truth table0%0/2
A
A= Cwd::abs_path($o->{"text"})
Aresult
11
00
14319 0 ▶ return if ! -f $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $file 0 0 0
14320 0 ▶ return $o->warning('"', $o->{text}, '" is interpreted as keyword. If you mean the file, write "./', $o->{text}, '".') if $o->isKeyword;
Branch: 1 branch
BranchTrueFalseTotal
if $o->isKeyword 0 0 0
14321 0 return $file;
14322 }
14323  
14324 sub completeFile {
14325 0 ▶ my $o = shift;
Subroutine completeFile: not called CC=10 SCAR=47.0
14326  
14327 0 my $folder = './';
14328 0 my $startFilename = $o->{text};
14329 0 ▶ $startFilename = $ENV{HOME}.'/'.$1 if $startFilename =~ /^~\/(.*)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $startFilename =~ m[^~/(.*)$] 0 0 0
14330 0 ▶ if ($startFilename eq '~') {
Branch: 2 branches
BranchTrueFalseTotal
if ($startFilename eq '~') { } 0 0 0
elsif ($startFilename =~ m[^(.*/)([^/]*)$]) { } 0 0 0
14331 0 $folder = $ENV{HOME}.'/';
14332 0 $startFilename = '';
14333 } elsif ($startFilename =~ /^(.*\/)([^\/]*)$/) {
14334 0 $folder = $1;
14335 0 $startFilename = $2;
14336 }
14337  
14338 0 for my $filename (CDS->listFolder($folder)) {
14339 0 ▶ next if $filename eq '.';
Branch: 1 branch
BranchTrueFalseTotal
if $filename eq "." 0 0 0
14340 0 ▶ next if $filename eq '..';
Branch: 1 branch
BranchTrueFalseTotal
if $filename eq ".." 0 0 0
14341 0 ▶ next if substr($filename, 0, length $startFilename) ne $startFilename;
Branch: 1 branch
BranchTrueFalseTotal
if substr($filename, 0, length $startFilename) ne $startFilename 0 0 0
14342 0 my $file = $folder.$filename;
14343 0 ▶ $file .= '/' if -d $file;
Branch: 1 branch
BranchTrueFalseTotal
if -d $file 0 0 0
14344 0 ▶ $file .= ' ' if -f $file;
Branch: 1 branch
BranchTrueFalseTotal
if -f $file 0 0 0
14345 0 push @{$o->{possibilities}}, $file;
14346 }
14347 }
14348  
14349 sub filename {
14350 0 ▶ my $o = shift;
Subroutine filename: not called CC=2 SCAR=17.9
14351  
14352 0 ▶ return $o->warning('"', $o->{text}, '" is interpreted as keyword. If you mean the file, write "./', $o->{text}, '".') if $o->isKeyword;
Branch: 1 branch
BranchTrueFalseTotal
if $o->isKeyword 0 0 0
14353 0 return Cwd::abs_path($o->{text});
14354 }
14355  
14356 sub folder {
14357 0 ▶ my $o = shift;
Subroutine folder: not called CC=4 SCAR=30.0
14358  
14359 0 ▶ my $folder = Cwd::abs_path($o->{text}) // return;
Condition0%0/2
Cwd::abs_path($o->{"text"}) // (return)
l!l
00
MC/DC0%0/1
Cwd::abs_path($o->{"text"}) // (return)
Cwd::abs_path($o->{"text"})
Truth table0%0/2
A
A= Cwd::abs_path($o->{"text"})
Aresult
11
00
14360 0 ▶ return if ! -d $folder;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $folder 0 0 0
14361 0 ▶ return $o->warning('"', $o->{text}, '" is interpreted as keyword. If you mean the folder, write "./', $o->{text}, '".') if $o->isKeyword;
Branch: 1 branch
BranchTrueFalseTotal
if $o->isKeyword 0 0 0
14362 0 return $folder;
14363 }
14364  
14365 sub completeFolder {
14366 0 ▶ my $o = shift;
Subroutine completeFolder: not called CC=7 SCAR=40.3
14367  
14368 0 my $folder = './';
14369 0 my $startFilename = $o->{text};
14370 0 ▶ if ($o->{text} =~ /^(.*\/)([^\/]*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"text"} =~ m[^(.*/)([^/]*)$]) 0 0 0
14371 0 $folder = $1;
14372 0 $startFilename = $2;
14373 }
14374  
14375 0 for my $filename (CDS->listFolder($folder)) {
14376 0 ▶ next if $filename eq '.';
Branch: 1 branch
BranchTrueFalseTotal
if $filename eq "." 0 0 0
14377 0 ▶ next if $filename eq '..';
Branch: 1 branch
BranchTrueFalseTotal
if $filename eq ".." 0 0 0
14378 0 ▶ next if substr($filename, 0, length $startFilename) ne $startFilename;
Branch: 1 branch
BranchTrueFalseTotal
if substr($filename, 0, length $startFilename) ne $startFilename 0 0 0
14379 0 my $file = $folder.$filename;
14380 0 ▶ next if ! -d $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $file 0 0 0
14381 0 push @{$o->{possibilities}}, $file.'/';
14382 }
14383 }
14384  
14385 sub foldername {
14386 0 ▶ my $o = shift;
Subroutine foldername: not called CC=2 SCAR=17.9
14387  
14388 0 ▶ return $o->warning('"', $o->{text}, '" is interpreted as keyword. If you mean the folder, write "./', $o->{text}, '".') if $o->isKeyword;
Branch: 1 branch
BranchTrueFalseTotal
if $o->isKeyword 0 0 0
14389 0 return Cwd::abs_path($o->{text});
14390 }
14391  
14392 sub group {
14393 0 ▶ my $o = shift;
Subroutine group: not called CC=2 SCAR=17.9
14394  
14395 0 ▶ return int($1) if $o->{text} =~ /^\s*(\d{1,5})\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"text"} =~ /^\s*(\d{1,5})\s*$/ 0 0 0
14396 0 return getgrnam($o->{text});
14397 }
14398  
14399 sub completeGroup {
14400 0 ▶ my $o = shift;
Subroutine completeGroup: not called CC=2 SCAR=17.9
14401  
14402 0 ▶ while (my $name = getgrent) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $name = getgrent) 0 0 0
14403 0 $o->addPossibility($name);
14404 }
14405 }
14406  
14407 sub hash {
14408 0 ▶ my $o = shift;
Subroutine hash: not called CC=4 SCAR=30.0
14409  
14410 0 my $hash = CDS::Hash->fromHex($o->{text});
14411 0 ▶ return $hash if $hash;
Branch: 1 branch
BranchTrueFalseTotal
if $hash 0 0 0
14412  
14413 # Check if it's a remembered actor hash
14414 0 my $record = $o->{actor}->remembered($o->{text});
14415 0 ▶ my $actorHash = CDS::Hash->fromBytes($record->child('actor')->bytesValue) // return;
Condition0%0/2
"CDS::Hash"->fromBytes($record->child("actor")->bytesValue) // (return)
l!l
00
MC/DC0%0/1
"CDS::Hash"->fromBytes($record->child("actor")->bytesValue) // (return)
"CDS::Hash"->fromBytes($record->child("actor")->bytesValue)
Truth table0%0/2
A
A= "CDS::Hash"->fromBytes($record->child("actor")->bytesValue)
Aresult
11
00
14416 0 ▶ return $o->warning('"', $o->{text}, '" is interpreted as keyword. If you mean the actor, write "', $actorHash->hex, '".') if $o->isKeyword;
Branch: 1 branch
BranchTrueFalseTotal
if $o->isKeyword 0 0 0
14417 0 return $actorHash;
14418 }
14419  
14420 sub completeHash {
14421 0 ▶ my $o = shift;
Subroutine completeHash: not called CC=5 SCAR=34.0
14422  
14423 0 my $records = $o->{actor}->rememberedRecords;
14424 0 for my $label (keys %$records) {
14425 0 my $record = $records->{$label};
14426 0 ▶ my $hash = CDS::Hash->fromBytes($record->child('actor')->bytesValue) // next;
Condition0%0/2
"CDS::Hash"->fromBytes($record->child("actor")->bytesValue) // (next)
l!l
00
MC/DC0%0/1
"CDS::Hash"->fromBytes($record->child("actor")->bytesValue) // (next)
"CDS::Hash"->fromBytes($record->child("actor")->bytesValue)
Truth table0%0/2
A
A= "CDS::Hash"->fromBytes($record->child("actor")->bytesValue)
Aresult
11
00
14427 0 $o->addPossibility($label);
14428 0 $o->addPossibility($hash->hex);
14429 }
14430  
14431 0 for my $child ($o->{actor}->actorGroupSelector->children) {
14432 0 ▶ my $hash = $child->record->child('hash')->hashValue // next;
Condition0%0/2
$child->record->child("hash")->hashValue // (next)
l!l
00
MC/DC0%0/1
$child->record->child("hash")->hashValue // (next)
$child->record->child("hash")->hashValue
Truth table0%0/2
A
A= $child->record->child("hash")->hashValue
Aresult
11
00
14433 0 $o->addPossibility($hash->hex);
14434 }
14435 }
14436  
14437 sub keyPair {
14438 0 ▶ my $o = shift;
Subroutine keyPair: not called CC=8 SCAR=42.8
14439  
14440 # Remembered key pair
14441 0 my $record = $o->{actor}->remembered($o->{text});
14442 0 my $file = $record->child('key pair')->textValue;
14443  
14444 # Key pair from file
14445 0 ▶ if (! length $file) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length $file) 0 0 0
14446 0 ▶ $file = Cwd::abs_path($o->{text}) // return;
Condition0%0/2
Cwd::abs_path($o->{"text"}) // (return)
l!l
00
MC/DC0%0/1
Cwd::abs_path($o->{"text"}) // (return)
Cwd::abs_path($o->{"text"})
Truth table0%0/2
A
A= Cwd::abs_path($o->{"text"})
Aresult
11
00
14447 0 ▶ return $o->warning('"', $o->{text}, '" is interpreted as keyword. If you mean the file, write "./', $o->{text}, '".') if $o->isKeyword && -f $file;
Branch: 1 branch
BranchTrueFalseTotal
if $o->isKeyword and -f $file 0 0 0
Condition0%0/3
$o->isKeyword and -f $file
!ll&&!rl&&r
000
MC/DC0%0/2
$o->isKeyword and -f $file
$o->isKeyword -f $file
Truth table0%0/3
A and B
A= $o->isKeywordB= -f $file
ABresult
0X0
100
111
14448 }
14449  
14450 # Load the key pair
14451 0 ▶ return if ! -f $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $file 0 0 0
14452 0 ▶ my $bytes = CDS->readBytesFromFile($file) // return $o->warning('The key pair file "', $file, '" could not be read.');
Condition0%0/2
"CDS"->readBytesFromFile($file) // (return $o->warning("The key pair file \"", $file, "\" could not be read."))
l!l
00
MC/DC0%0/1
"CDS"->readBytesFromFile($file) // (return $o->warning("The key pair file \"", $file, "\" could not be read."))
"CDS"->readBytesFromFile($file)
Truth table0%0/2
A
A= "CDS"->readBytesFromFile($file)
Aresult
11
00
14453 0 ▶ my $keyPair = CDS::KeyPair->fromRecord(CDS::Record->fromObject(CDS::Object->fromBytes($bytes))) // return $o->warning('The file "', $file, '" does not contain a key pair.');
Condition0%0/2
"CDS::KeyPair"->fromRecord("CDS::Record"->fromObject("CDS::Object"->fromBytes($bytes))) // (return $o->warning("The file \"", $file, "\" does not contain a key pair."))
l!l
00
MC/DC0%0/1
"CDS::KeyPair"->fromRecord("CDS::Record"->fromObject("CDS::Object"->fromBytes($bytes))) // (return $o->warning("The file \"", $file, "\" does not contain a key pair."))
"CDS::KeyPair"->fromRecord("CDS::Record"->fromObject("CDS::Object"->fromBytes($bytes)))
Truth table0%0/2
A
A= "CDS::KeyPair"->fromRecord("CDS::Record"->fromObject("CDS::Object"->fromBytes($bytes)))
Aresult
11
00
14454 0 return CDS::KeyPairToken->new($file, $keyPair);
14455 }
14456  
14457 sub completeKeyPair {
14458 0 ▶ my $o = shift;
Subroutine completeKeyPair: not called CC=3 SCAR=24.8
14459  
14460 0 $o->completeFile;
14461  
14462 0 my $records = $o->{actor}->rememberedRecords;
14463 0 for my $label (keys %$records) {
14464 0 my $record = $records->{$label};
14465 0 ▶ next if ! length $record->child('key pair')->textValue;
Branch: 1 branch
BranchTrueFalseTotal
unless length $record->child("key pair")->textValue 0 0 0
14466 0 $o->addPossibility($label);
14467 }
14468 }
14469  
14470 sub label {
14471 0 ▶ my $o = shift;
Subroutine label: not called CC=2 SCAR=17.9
14472  
14473 0 my $records = $o->{actor}->remembered($o->{text});
14474 0 ▶ return $o->{text} if $records->children;
Branch: 1 branch
BranchTrueFalseTotal
if $records->children 0 0 0
14475 0 return;
14476 }
14477  
14478 sub completeLabel {
14479 0 ▶ my $o = shift;
Subroutine completeLabel: not called CC=3 SCAR=24.8
14480  
14481 0 my $records = $o->{actor}->rememberedRecords;
14482 0 for my $label (keys %$records) {
14483 0 ▶ next if substr($label, 0, length $o->{text}) ne $o->{text};
Branch: 1 branch
BranchTrueFalseTotal
if substr($label, 0, length $o->{"text"}) ne $o->{"text"} 0 0 0
14484 0 $o->addPossibility($label);
14485 }
14486 }
14487  
14488 sub object {
14489 0 ▶ my $o = shift;
Subroutine object: not called CC=6 SCAR=37.4
14490  
14491 # Folder stores use the first two hex digits as folder
14492 0 ▶ my $url = $o->{text} =~ /^\s*(.*?\/objects\/)([0-9a-fA-F]{2,2})\/([0-9a-fA-F]{62,62})\/*\s*$/ ? $1.$2.$3 : $o->{text};
Branch: 1 branch
BranchTrueFalseTotal
$o->{'text'} =~ m[^\s*(.*?/objects/)([0-9a-fA-F]{2,2})/([0-9a-fA-F]{62,62})/*\s*$] ? : 0 0 0
14493  
14494 # From a URL
14495 0 ▶ if ($url =~ /^\s*(.*?)\/objects\/([0-9a-fA-F]{64,64})\/*\s*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($url =~ m[^\s*(.*?)/objects/([0-9a-fA-F]{64,64})/*\s*$]) 0 0 0
14496 0 my $storeUrl = $1;
14497 0 my $hash = CDS::Hash->fromHex($2);
14498 0 ▶ $storeUrl = 'file://'.Cwd::abs_path($storeUrl) if $storeUrl !~ /^[a-zA-Z0-9_\+-]*:/ && -d $storeUrl;
Branch: 1 branch
BranchTrueFalseTotal
if not $storeUrl =~ /^[a-zA-Z0-9_\+-]*:/ and -d $storeUrl 0 0 0
Condition0%0/3
not $storeUrl =~ /^[a-zA-Z0-9_\+-]*:/ and -d $storeUrl
!ll&&!rl&&r
000
MC/DC0%0/2
not $storeUrl =~ /^[a-zA-Z0-9_\+-]*:/ and -d $storeUrl
not $storeUrl =~ /^[a-zA-Z0-9_\+-]*:/ -d $storeUrl
Truth table0%0/3
not(A) and B
A= not $storeUrl =~ /^[a-zA-Z0-9_\+-]*:/B= -d $storeUrl
ABresult
0X0
100
111
14499 0 ▶ my $cliStore = $o->{actor}->storeForUrl($storeUrl) // return $o->warning('Invalid store URL "', $storeUrl, '".');
Condition0%0/2
$o->{"actor"}->storeForUrl($storeUrl) // (return $o->warning("Invalid store URL \"", $storeUrl, "\"."))
l!l
00
MC/DC0%0/1
$o->{"actor"}->storeForUrl($storeUrl) // (return $o->warning("Invalid store URL \"", $storeUrl, "\"."))
$o->{"actor"}->storeForUrl($storeUrl)
Truth table0%0/2
A
A= $o->{"actor"}->storeForUrl($storeUrl)
Aresult
11
00
14500 0 return CDS::ObjectToken->new($cliStore, $hash);
14501 }
14502  
14503 0 return;
14504 }
14505  
14506 sub completeObject {
14507 0 ▶ my $o = shift;
Subroutine completeObject: not called CC=1 SCAR=6.9
14508  
14509 0 $o->completeUrl;
14510 0 return;
14511 }
14512  
14513 sub objectFile {
14514 0 ▶ my $o = shift;
Subroutine objectFile: not called CC=7 SCAR=40.3
14515  
14516 # Key pair from file
14517 0 ▶ my $file = Cwd::abs_path($o->{text}) // return;
Condition0%0/2
Cwd::abs_path($o->{"text"}) // (return)
l!l
00
MC/DC0%0/1
Cwd::abs_path($o->{"text"}) // (return)
Cwd::abs_path($o->{"text"})
Truth table0%0/2
A
A= Cwd::abs_path($o->{"text"})
Aresult
11
00
14518 0 ▶ return $o->warning('"', $o->{text}, '" is interpreted as keyword. If you mean the file, write "./', $o->{text}, '".') if $o->isKeyword && -f $file;
Branch: 1 branch
BranchTrueFalseTotal
if $o->isKeyword and -f $file 0 0 0
Condition0%0/3
$o->isKeyword and -f $file
!ll&&!rl&&r
000
MC/DC0%0/2
$o->isKeyword and -f $file
$o->isKeyword -f $file
Truth table0%0/3
A and B
A= $o->isKeywordB= -f $file
ABresult
0X0
100
111
14519  
14520 # Load the object
14521 0 ▶ return if ! -f $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $file 0 0 0
14522 0 ▶ my $bytes = CDS->readBytesFromFile($file) // return $o->warning('The object file "', $file, '" could not be read.');
Condition0%0/2
"CDS"->readBytesFromFile($file) // (return $o->warning("The object file \"", $file, "\" could not be read."))
l!l
00
MC/DC0%0/1
"CDS"->readBytesFromFile($file) // (return $o->warning("The object file \"", $file, "\" could not be read."))
"CDS"->readBytesFromFile($file)
Truth table0%0/2
A
A= "CDS"->readBytesFromFile($file)
Aresult
11
00
14523 0 ▶ my $object = CDS::Object->fromBytes($bytes) // return $o->warning('The file "', $file, '" does not contain a Condensation object.');
Condition0%0/2
"CDS::Object"->fromBytes($bytes) // (return $o->warning("The file \"", $file, "\" does not contain a Condensation object."))
l!l
00
MC/DC0%0/1
"CDS::Object"->fromBytes($bytes) // (return $o->warning("The file \"", $file, "\" does not contain a Condensation object."))
"CDS::Object"->fromBytes($bytes)
Truth table0%0/2
A
A= "CDS::Object"->fromBytes($bytes)
Aresult
11
00
14524 0 return CDS::ObjectFileToken->new($file, $object);
14525 }
14526  
14527 sub completeObjectFile {
14528 0 ▶ my $o = shift;
Subroutine completeObjectFile: not called CC=1 SCAR=6.9
14529  
14530 0 $o->completeFile;
14531 0 return;
14532 }
14533  
14534 sub actorGroup {
14535 0 ▶ my $o = shift;
Subroutine actorGroup: not called CC=4 SCAR=30.0
14536  
14537 # We only accept named actor groups. Accepting a single account as actor group is ambiguous whenever ACCOUNT and ACTORGROUP are accepted. For commands that are requiring an ACTORGROUP, they can also accept an ACCOUNT and then convert it.
14538  
14539 # Check if it's an actor group label
14540 0 my $record = $o->{actor}->remembered($o->{text})->child('actor group');
14541 0 ▶ return if ! scalar $record->children;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar $record->children 0 0 0
14542 0 ▶ return $o->warning('"', $o->{text}, '" is interpreted as keyword. To refer to the actor group, rename it.') if $o->isKeyword;
Branch: 1 branch
BranchTrueFalseTotal
if $o->isKeyword 0 0 0
14543  
14544 0 my $builder = CDS::ActorGroupBuilder->new;
14545 0 $builder->addKnownPublicKey($o->{actor}->keyPair->publicKey);
14546 0 $builder->parse($record, 1);
14547 0 my ($actorGroup, $storeError) = $builder->load($o->{actor}->groupDocument->unsaved, $o->{actor}->keyPair, $o);
14548 0 ▶ return $o->{actor}->storeError($o->{actor}->storageStore, $storeError) if defined $storeError;
Branch: 1 branch
BranchTrueFalseTotal
if defined $storeError 0 0 0
14549 0 return CDS::ActorGroupToken->new($o->{text}, $actorGroup);
14550 }
14551  
14552 sub onLoadActorGroupVerifyStore {
14553 0 ▶ my $o = shift;
Subroutine onLoadActorGroupVerifyStore: not called CC=1 SCAR=6.9
14554 0 my $storeUrl = shift;
14555 0 $o->{actor}->storeForUrl($storeUrl); }
14556  
14557 sub completeActorGroup {
14558 0 ▶ my $o = shift;
Subroutine completeActorGroup: not called CC=3 SCAR=24.8
14559  
14560 0 my $records = $o->{actor}->rememberedRecords;
14561 0 for my $label (keys %$records) {
14562 0 my $record = $records->{$label};
14563 0 ▶ next if ! scalar $record->child('actor group')->children;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar $record->child("actor group")->children 0 0 0
14564 0 $o->addPossibility($label);
14565 }
14566 0 return;
14567 }
14568  
14569 sub port {
14570 0 ▶ my $o = shift;
Subroutine port: not called CC=3 SCAR=24.8
14571  
14572 0 my $port = int($o->{text});
14573 0 ▶ return if $port <= 0 || $port > 65536;
Branch: 1 branch
BranchTrueFalseTotal
if $port <= 0 or $port > 65536 0 0 0
Condition0%0/3
$port <= 0 or $port > 65536
l!l&&r!l&&!r
000
MC/DC0%0/2
$port <= 0 or $port > 65536
$port <= 0 $port > 65536
Truth table0%0/3
A or B
A= $port <= 0B= $port > 65536
ABresult
1X1
011
000
14574 0 return $port;
14575 }
14576  
14577 sub rememberedStoreUrl {
14578 0 ▶ my $o = shift;
Subroutine rememberedStoreUrl: not called CC=3 SCAR=24.8
14579  
14580 0 my $record = $o->{actor}->remembered($o->{text});
14581 0 my $storeUrl = $record->child('store')->textValue;
14582 0 ▶ return if ! length $storeUrl;
Branch: 1 branch
BranchTrueFalseTotal
unless length $storeUrl 0 0 0
14583  
14584 0 ▶ return $o->warning('"', $o->{text}, '" is interpreted as keyword. If you mean the store, write "', $storeUrl, '".') if $o->isKeyword;
Branch: 1 branch
BranchTrueFalseTotal
if $o->isKeyword 0 0 0
14585 0 return $storeUrl;
14586 }
14587  
14588 sub directStoreUrl {
14589 0 ▶ my $o = shift;
Subroutine directStoreUrl: not called CC=7 SCAR=40.3
14590  
14591 0 ▶ return $o->warning('"', $o->{text}, '" is interpreted as keyword. If you mean the folder store, write "./', $o->{text}, '".') if $o->isKeyword;
Branch: 1 branch
BranchTrueFalseTotal
if $o->isKeyword 0 0 0
14592 0 ▶ return if $o->{text} =~ /[0-9a-f]{32}/;
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"text"} =~ /[0-9a-f]{32}/ 0 0 0
14593  
14594 0 ▶ return $o->{text} if $o->{text} =~ /^[a-zA-Z0-9_\+-]*:/;
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"text"} =~ /^[a-zA-Z0-9_\+-]*:/ 0 0 0
14595 0 ▶ return 'file://'.Cwd::abs_path($o->{text}) if -d $o->{text} && -d $o->{text}.'/accounts' && -d $o->{text}.'/objects';
Branch: 1 branch
BranchTrueFalseTotal
if -d $o->{"text"} and -d $o->{"text"} . '/accounts' and -d $o->{"text"} . '/objects' 0 0 0
Condition0%0/6
-d $o->{"text"} and -d $o->{"text"} . '/accounts' and -d $o->{"text"} . '/objects'
!ll&&!rl&&r
000
-d $o->{"text"} and -d $o->{"text"} . '/accounts'
!ll&&!rl&&r
000
MC/DC0%0/3
-d $o->{"text"} and -d $o->{"text"} . '/accounts' and -d $o->{"text"} . '/objects'
-d $o->{"text"} -d $o->{"text"} . '/accounts' -d $o->{"text"} . '/objects'
Truth table0%0/4
A and B and C
A= -d $o->{"text"}B= -d $o->{"text"} . '/accounts'C= -d $o->{"text"} . '/objects'
ABCresult
0XX0
10X0
1100
1111
14596 0 return;
14597 }
14598  
14599 sub store {
14600 0 ▶ my $o = shift;
Subroutine store: not called CC=4 SCAR=30.0
14601  
14602 0 ▶ my $url = $o->rememberedStoreUrl // $o->directStoreUrl // return;
Condition0%0/5
($o->rememberedStoreUrl // $o->directStoreUrl) // (return)
l!l
00
$o->rememberedStoreUrl // $o->directStoreUrl
l!l&&r!l&&!r
000
MC/DC0%0/2
($o->rememberedStoreUrl // $o->directStoreUrl) // (return)
$o->rememberedStoreUrl $o->directStoreUrl
Truth table0%0/3
A // B
A= $o->rememberedStoreUrlB= $o->directStoreUrl
ABresult
1X1
011
000
14603 0 ▶ return $o->{actor}->storeForUrl($url) // return $o->warning('"', $o->{text}, '" looks like a store, but no implementation is available to handle this protocol.');
Condition0%0/2
$o->{"actor"}->storeForUrl($url) // (return $o->warning("\"", $o->{"text"}, "\" looks like a store, but no implementation is available to handle this protocol."))
l!l
00
MC/DC0%0/1
$o->{"actor"}->storeForUrl($url) // (return $o->warning("\"", $o->{"text"}, "\" looks like a store, but no implementation is available to handle this protocol."))
$o->{"actor"}->storeForUrl($url)
Truth table0%0/2
A
A= $o->{"actor"}->storeForUrl($url)
Aresult
11
00
14604 }
14605  
14606 sub completeFolderStoreUrl {
14607 0 ▶ my $o = shift;
Subroutine completeFolderStoreUrl: not called CC=9 SCAR=45.0
14608  
14609 0 my $folder = './';
14610 0 my $startFilename = $o->{text};
14611 0 ▶ if ($o->{text} =~ /^(.*\/)([^\/]*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"text"} =~ m[^(.*/)([^/]*)$]) 0 0 0
14612 0 $folder = $1;
14613 0 $startFilename = $2;
14614 }
14615  
14616 0 for my $filename (CDS->listFolder($folder)) {
14617 0 ▶ next if $filename eq '.';
Branch: 1 branch
BranchTrueFalseTotal
if $filename eq "." 0 0 0
14618 0 ▶ next if $filename eq '..';
Branch: 1 branch
BranchTrueFalseTotal
if $filename eq ".." 0 0 0
14619 0 ▶ next if substr($filename, 0, length $startFilename) ne $startFilename;
Branch: 1 branch
BranchTrueFalseTotal
if substr($filename, 0, length $startFilename) ne $startFilename 0 0 0
14620 0 my $file = $folder.$filename;
14621 0 ▶ next if ! -d $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $file 0 0 0
14622 0 ▶ push @{$o->{possibilities}}, $file . (-d $file.'/accounts' && -d $file.'/objects' ? ' ' : '/');
Branch: 1 branch
BranchTrueFalseTotal
-d $file . '/accounts' && -d $file . '/objects' ? : 0 0 0
Condition0%0/3
-d $file . '/accounts' and -d $file . '/objects'
!ll&&!rl&&r
000
MC/DC0%0/2
-d $file . '/accounts' and -d $file . '/objects'
-d $file . '/accounts' -d $file . '/objects'
Truth table0%0/3
A and B
A= -d $file . '/accounts'B= -d $file . '/objects'
ABresult
0X0
100
111
14623 }
14624 }
14625  
14626 sub completeStoreUrl {
14627 0 ▶ my $o = shift;
Subroutine completeStoreUrl: not called CC=4 SCAR=30.0
14628  
14629 0 $o->completeFolderStoreUrl;
14630 0 $o->completeUrl;
14631  
14632 0 my $records = $o->{actor}->rememberedRecords;
14633 0 for my $label (keys %$records) {
14634 0 my $record = $records->{$label};
14635 0 ▶ next if length $record->child('actor')->bytesValue;
Branch: 1 branch
BranchTrueFalseTotal
if length $record->child("actor")->bytesValue 0 0 0
14636 0 my $storeUrl = $record->child('store')->textValue;
14637 0 ▶ next if ! length $storeUrl;
Branch: 1 branch
BranchTrueFalseTotal
unless length $storeUrl 0 0 0
14638 0 $o->addPossibility($label);
14639 0 $o->addPossibility($storeUrl);
14640 }
14641 }
14642  
14643 sub completeUrl {
14644 0 ▶ my $o = shift;
Subroutine completeUrl: not called CC=1 SCAR=6.9
14645  
14646 0 $o->addPartialPossibility('http://');
14647 0 $o->addPartialPossibility('https://');
14648 0 $o->addPartialPossibility('ftp://');
14649 0 $o->addPartialPossibility('sftp://');
14650 0 $o->addPartialPossibility('file://');
14651 }
14652  
14653 sub text {
14654 0 ▶ my $o = shift;
Subroutine text: not called CC=1 SCAR=6.9
14655  
14656 0 return $o->{text};
14657 }
14658  
14659 sub user {
14660 0 ▶ my $o = shift;
Subroutine user: not called CC=2 SCAR=17.9
14661  
14662 0 ▶ return int($1) if $o->{text} =~ /^\s*(\d{1,5})\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"text"} =~ /^\s*(\d{1,5})\s*$/ 0 0 0
14663 0 return getpwnam($o->{text});
14664 }
14665  
14666 sub completeUser {
14667 0 ▶ my $o = shift;
Subroutine completeUser: not called CC=2 SCAR=17.9
14668  
14669 0 ▶ while (my $name = getpwent) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $name = getpwent) 0 0 0
14670 0 $o->addPossibility($name);
14671 }
14672 }
14673  
14674 sub warning {
14675 0 ▶ my $o = shift;
Subroutine warning: not called CC=1 SCAR=6.9
14676  
14677 0 push @{$o->{warnings}}, join('', @_);
14678 0 return;
14679 }
14680  
14681 # Reads the private box of an actor.
14682 package CDS::PrivateBoxReader;
14683  
14684 sub new {
14685 0 ▶ my $class = shift;
Subroutine new: not called CC=3 SCAR=24.8
14686 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
14687 0 my $store = shift;
14688 0 my $delegate = shift;
14689  
14690 0 return bless {
14691 keyPair => $keyPair,
14692 actorOnStore => CDS::ActorOnStore->new($keyPair->publicKey, $store),
14693 delegate => $delegate,
14694 entries => {},
14695 };
14696 }
14697  
14698 0 ▶sub keyPair { shift->{keyPair} }
Subroutine keyPair: not called CC=1 SCAR=6.9
14699 0 ▶sub actorOnStore { shift->{actorOnStore} }
Subroutine actorOnStore: not called CC=1 SCAR=6.9
14700 0 ▶sub delegate { shift->{delegate} }
Subroutine delegate: not called CC=1 SCAR=6.9
14701  
14702 sub read {
14703 0 ▶ my $o = shift;
Subroutine read: not called CC=14 SCAR=53.5
14704  
14705 0 my $store = $o->{actorOnStore}->store;
14706 0 my ($hashes, $listError) = $store->list($o->{actorOnStore}->publicKey->hash, 'private', 0, $o->{keyPair});
14707 0 ▶ return if defined $listError;
Branch: 1 branch
BranchTrueFalseTotal
if defined $listError 0 0 0
14708  
14709 # Keep track of the processed entries
14710 0 my $newEntries = {};
14711 0 for my $hash (@$hashes) {
14712 0 ▶ $newEntries->{$hash->bytes} = $o->{entries}->{$hash->bytes} // {hash => $hash, processed => 0};
Condition0%0/2
$o->{"entries"}{$hash->bytes} // {"hash", $hash, "processed", 0}
l!l
00
MC/DC0%0/1
$o->{"entries"}{$hash->bytes} // {"hash", $hash, "processed", 0}
$o->{"entries"}{$hash->bytes}
Truth table0%0/2
A
A= $o->{"entries"}{$hash->bytes}
Aresult
11
00
14713 }
14714 0 $o->{entries} = $newEntries;
14715  
14716 # Process new entries
14717 0 for my $entry (values %$newEntries) {
14718 0 ▶ next if $entry->{processed};
Branch: 1 branch
BranchTrueFalseTotal
if $entry->{"processed"} 0 0 0
14719  
14720 # Get the envelope
14721 0 my ($object, $getError) = $store->get($entry->{hash}, $o->{keyPair});
14722 0 ▶ return if defined $getError;
Branch: 1 branch
BranchTrueFalseTotal
if defined $getError 0 0 0
14723  
14724 0 ▶ if (! defined $object) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $object) 0 0 0
14725 0 $o->invalid($entry, 'Envelope object not found.');
14726 0 next;
14727 }
14728  
14729 # Parse the record
14730 0 my $envelope = CDS::Record->fromObject($object);
14731 0 ▶ if (! $envelope) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($envelope) 0 0 0
14732 0 $o->invalid($entry, 'Envelope is not a record.');
14733 0 next;
14734 }
14735  
14736 # Read the content hash
14737 0 my $contentHash = $envelope->child('content')->hashValue;
14738 0 ▶ if (! $contentHash) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($contentHash) 0 0 0
14739 0 $o->invalid($entry, 'Missing content hash.');
14740 0 next;
14741 }
14742  
14743 # Verify the signature
14744 0 ▶ if (! CDS->verifyEnvelopeSignature($envelope, $o->{keyPair}->publicKey, $contentHash)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ("CDS"->verifyEnvelopeSignature($envelope, $o->{"keyPair"}->publicKey, $contentHash)) 0 0 0
14745 0 $o->invalid($entry, 'Invalid signature.');
14746 0 next;
14747 }
14748  
14749 # Decrypt the key
14750 0 my $aesKey = $o->{keyPair}->decryptKeyOnEnvelope($envelope);
14751 0 ▶ if (! $aesKey) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($aesKey) 0 0 0
14752 0 $o->invalid($entry, 'Not encrypted for us.');
14753 0 next;
14754 }
14755  
14756 # Retrieve the content
14757 0 my $contentHashAndKey = CDS::HashAndKey->new($contentHash, $aesKey);
14758 0 my ($contentRecord, $contentObject, $contentInvalidReason, $contentStoreError) = $o->{keyPair}->getAndDecryptRecord($contentHashAndKey, $store);
14759 0 ▶ return if defined $contentStoreError;
Branch: 1 branch
BranchTrueFalseTotal
if defined $contentStoreError 0 0 0
14760  
14761 0 ▶ if (defined $contentInvalidReason) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $contentInvalidReason) 0 0 0
14762 0 $o->invalid($entry, $contentInvalidReason);
14763 0 next;
14764 }
14765  
14766 0 $entry->{processed} = 1;
14767 0 my $source = CDS::Source->new($o->{keyPair}, $o->{actorOnStore}, 'private', $entry->{hash});
14768 0 $o->{delegate}->onPrivateBoxEntry($source, $envelope, $contentHashAndKey, $contentRecord);
14769 }
14770  
14771 0 return 1;
14772 }
14773  
14774 sub invalid {
14775 0 ▶ my $o = shift;
Subroutine invalid: not called CC=1 SCAR=6.9
14776 0 my $entry = shift;
14777 0 my $reason = shift;
14778  
14779 0 $entry->{processed} = 1;
14780 0 my $source = CDS::Source->new($o->{actorOnStore}, 'private', $entry->{hash});
14781 0 $o->{delegate}->onPrivateBoxInvalidEntry($source, $reason);
14782 }
14783  
14784 # Delegate
14785 # onPrivateBoxEntry($source, $envelope, $contentHashAndKey, $contentRecord)
14786 # onPrivateBoxInvalidEntry($source, $reason)
14787  
14788 package CDS::PrivateRoot;
14789  
14790 sub new {
14791 0 ▶ my $class = shift;
Subroutine new: not called CC=3 SCAR=24.8
14792 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
14793 0 my $store = shift;
14794 0 my $delegate = shift;
14795  
14796 0 my $o = bless {
14797 unsaved => CDS::Unsaved->new($store),
14798 delegate => $delegate,
14799 dataHandlers => {},
14800 hasChanges => 0,
14801 procured => 0,
14802 mergedEntries => [],
14803 };
14804  
14805 0 $o->{privateBoxReader} = CDS::PrivateBoxReader->new($keyPair, $store, $o);
14806 0 return $o;
14807 }
14808  
14809 0 ▶sub delegate { shift->{delegate} }
Subroutine delegate: not called CC=1 SCAR=6.9
14810 0 ▶sub privateBoxReader { shift->{privateBoxReader} }
Subroutine privateBoxReader: not called CC=1 SCAR=6.9
14811 0 ▶sub unsaved { shift->{unsaved} }
Subroutine unsaved: not called CC=1 SCAR=6.9
14812 0 ▶sub hasChanges { shift->{hasChanges} }
Subroutine hasChanges: not called CC=1 SCAR=6.9
14813 0 ▶sub procured { shift->{procured} }
Subroutine procured: not called CC=1 SCAR=6.9
14814  
14815 sub addDataHandler {
14816 0 ▶ my $o = shift;
Subroutine addDataHandler: not called CC=1 SCAR=6.9
14817 0 my $label = shift;
14818 0 my $dataHandler = shift;
14819  
14820 0 $o->{dataHandlers}->{$label} = $dataHandler;
14821 }
14822  
14823 sub removeDataHandler {
14824 0 ▶ my $o = shift;
Subroutine removeDataHandler: not called CC=2 SCAR=17.9
14825 0 my $label = shift;
14826 0 my $dataHandler = shift;
14827  
14828 0 my $registered = $o->{dataHandlers}->{$label};
14829 0 ▶ return if $registered != $dataHandler;
Branch: 1 branch
BranchTrueFalseTotal
if $registered != $dataHandler 0 0 0
14830 0 delete $o->{dataHandlers}->{$label};
14831 }
14832  
14833 # *** Procurement
14834  
14835 sub procure {
14836 0 ▶ my $o = shift;
Subroutine procure: not called CC=3 SCAR=24.8
14837 0 my $interval = shift;
14838  
14839 0 my $now = CDS->now;
14840 0 ▶ return $o->{procured} if $o->{procured} + $interval > $now;
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"procured"} + $interval > $now 0 0 0
14841 0 ▶ $o->{privateBoxReader}->read // return;
Condition0%0/2
$o->{"privateBoxReader"}->read // (return)
l!l
00
MC/DC0%0/1
$o->{"privateBoxReader"}->read // (return)
$o->{"privateBoxReader"}->read
Truth table0%0/2
A
A= $o->{"privateBoxReader"}->read
Aresult
11
00
14842 0 $o->{procured} = $now;
14843 0 return $now;
14844 }
14845  
14846 # *** Merging
14847  
14848 sub onPrivateBoxEntry {
14849 0 ▶ my $o = shift;
Subroutine onPrivateBoxEntry: not called CC=7 SCAR=40.3
14850 0 ▶ my $source = shift; die 'wrong type '.ref($source).' for $source' if defined $source && ref $source ne 'CDS::Source';
Branch: 1 branch
BranchTrueFalseTotal
if defined $source and ref $source ne "CDS::Source" 0 0 0
Condition0%0/3
defined $source and ref $source ne "CDS::Source"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $source and ref $source ne "CDS::Source"
defined $source ref $source ne "CDS::Source"
Truth table0%0/3
A and B
A= defined $sourceB= ref $source ne "CDS::Source"
ABresult
0X0
100
111
14851 0 ▶ my $envelope = shift; die 'wrong type '.ref($envelope).' for $envelope' if defined $envelope && ref $envelope ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $envelope and ref $envelope ne "CDS::Record" 0 0 0
Condition0%0/3
defined $envelope and ref $envelope ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $envelope and ref $envelope ne "CDS::Record"
defined $envelope ref $envelope ne "CDS::Record"
Truth table0%0/3
A and B
A= defined $envelopeB= ref $envelope ne "CDS::Record"
ABresult
0X0
100
111
14852 0 my $contentHashAndKey = shift;
14853 0 my $content = shift;
14854  
14855 0 for my $section ($content->children) {
14856 0 ▶ my $dataHandler = $o->{dataHandlers}->{$section->bytes} // next;
Condition0%0/2
$o->{"dataHandlers"}{$section->bytes} // (next)
l!l
00
MC/DC0%0/1
$o->{"dataHandlers"}{$section->bytes} // (next)
$o->{"dataHandlers"}{$section->bytes}
Truth table0%0/2
A
A= $o->{"dataHandlers"}{$section->bytes}
Aresult
11
00
14857 0 $dataHandler->mergeData($section);
14858 }
14859  
14860 0 push @{$o->{mergedEntries}}, $source->hash;
14861 }
14862  
14863 sub onPrivateBoxInvalidEntry {
14864 0 ▶ my $o = shift;
Subroutine onPrivateBoxInvalidEntry: not called CC=3 SCAR=24.8
14865 0 ▶ my $source = shift; die 'wrong type '.ref($source).' for $source' if defined $source && ref $source ne 'CDS::Source';
Branch: 1 branch
BranchTrueFalseTotal
if defined $source and ref $source ne "CDS::Source" 0 0 0
Condition0%0/3
defined $source and ref $source ne "CDS::Source"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $source and ref $source ne "CDS::Source"
defined $source ref $source ne "CDS::Source"
Truth table0%0/3
A and B
A= defined $sourceB= ref $source ne "CDS::Source"
ABresult
0X0
100
111
14866 0 my $reason = shift;
14867  
14868 0 $o->{delegate}->onPrivateRootReadingInvalidEntry($source, $reason);
14869 0 $source->discard;
14870 }
14871  
14872 # *** Saving
14873  
14874 sub dataChanged {
14875 0 ▶ my $o = shift;
Subroutine dataChanged: not called CC=1 SCAR=6.9
14876  
14877 0 $o->{hasChanges} = 1;
14878 }
14879  
14880 sub save {
14881 0 ▶ my $o = shift;
Subroutine save: not called CC=7 SCAR=40.3
14882 0 my $entrustedKeys = shift;
14883  
14884 0 $o->{unsaved}->startSaving;
14885 0 ▶ return $o->savingSucceeded if ! $o->{hasChanges};
Branch: 1 branch
BranchTrueFalseTotal
unless $o->{"hasChanges"} 0 0 0
14886 0 $o->{hasChanges} = 0;
14887  
14888 # Create the record
14889 0 my $record = CDS::Record->new;
14890 0 $record->add('created')->addInteger(CDS->now);
14891 0 $record->add('client')->add(CDS->version);
14892 0 for my $label (keys %{$o->{dataHandlers}}) {
14893 0 my $dataHandler = $o->{dataHandlers}->{$label};
14894 0 $dataHandler->addDataTo($record->add($label));
14895 }
14896  
14897 # Submit the object
14898 0 my $key = CDS->randomKey;
14899 0 my $object = $record->toObject->crypt($key);
14900 0 my $hash = $object->calculateHash;
14901 0 $o->{unsaved}->savingState->addObject($hash, $object);
14902 0 my $hashAndKey = CDS::HashAndKey->new($hash, $key);
14903  
14904 # Create the envelope
14905 0 my $keyPair = $o->{privateBoxReader}->keyPair;
14906 0 my $publicKeys = [$keyPair->publicKey, @$entrustedKeys];
14907 0 my $envelopeObject = $keyPair->createPrivateEnvelope($hashAndKey, $publicKeys)->toObject;
14908 0 my $envelopeHash = $envelopeObject->calculateHash;
14909 0 $o->{unsaved}->savingState->addObject($envelopeHash, $envelopeObject);
14910  
14911 # Transfer
14912 0 my ($missing, $store, $storeError) = $keyPair->transfer([$hash], $o->{unsaved}, $o->{privateBoxReader}->actorOnStore->store);
14913 0 ▶ return $o->savingFailed($missing) if defined $missing || defined $storeError;
Branch: 1 branch
BranchTrueFalseTotal
if defined $missing or defined $storeError 0 0 0
Condition0%0/3
defined $missing or defined $storeError
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $missing or defined $storeError
defined $missing defined $storeError
Truth table0%0/3
A or B
A= defined $missingB= defined $storeError
ABresult
1X1
011
000
14914  
14915 # Modify the private box
14916 0 my $modifications = CDS::StoreModifications->new;
14917 0 $modifications->add($keyPair->publicKey->hash, 'private', $envelopeHash, $envelopeObject);
14918 0 for my $hash (@{$o->{mergedEntries}}) {
14919 0 $modifications->remove($keyPair->publicKey->hash, 'private', $hash);
14920 }
14921  
14922 0 my $modifyError = $o->{privateBoxReader}->actorOnStore->store->modify($modifications, $keyPair);
14923 0 ▶ return $o->savingFailed if defined $modifyError;
Branch: 1 branch
BranchTrueFalseTotal
if defined $modifyError 0 0 0
14924  
14925 # Set the new merged hashes
14926 0 $o->{mergedEntries} = [$envelopeHash];
14927 0 return $o->savingSucceeded;
14928 }
14929  
14930 sub savingSucceeded {
14931 0 ▶ my $o = shift;
Subroutine savingSucceeded: not called CC=3 SCAR=24.8
14932  
14933 # Discard all merged sources
14934 0 for my $source ($o->{unsaved}->savingState->mergedSources) {
14935 0 $source->discard;
14936 }
14937  
14938 # Call all data saved handlers
14939 0 for my $handler ($o->{unsaved}->savingState->dataSavedHandlers) {
14940 0 $handler->onDataSaved;
14941 }
14942  
14943 0 $o->{unsaved}->savingDone;
14944 0 return 1;
14945 }
14946  
14947 sub savingFailed {
14948 0 ▶ my $o = shift;
Subroutine savingFailed: not called CC=1 SCAR=6.9
14949 0 my $missing = shift;
14950 # private
14951 0 $o->{unsaved}->savingFailed;
14952 0 $o->{hasChanges} = 1;
14953 0 return undef, $missing;
14954 }
14955  
14956 # A public key of somebody.
14957 package CDS::PublicKey;
14958  
14959 sub fromObject {
14960 0 ▶ my $class = shift;
Subroutine fromObject: not called CC=5 SCAR=34.0
14961 0 ▶ my $object = shift; die 'wrong type '.ref($object).' for $object' if defined $object && ref $object ne 'CDS::Object';
Branch: 1 branch
BranchTrueFalseTotal
if defined $object and ref $object ne "CDS::Object" 0 0 0
Condition0%0/3
defined $object and ref $object ne "CDS::Object"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $object and ref $object ne "CDS::Object"
defined $object ref $object ne "CDS::Object"
Truth table0%0/3
A and B
A= defined $objectB= ref $object ne "CDS::Object"
ABresult
0X0
100
111
14962  
14963 0 ▶ my $record = CDS::Record->fromObject($object) // return;
Condition0%0/2
"CDS::Record"->fromObject($object) // (return)
l!l
00
MC/DC0%0/1
"CDS::Record"->fromObject($object) // (return)
"CDS::Record"->fromObject($object)
Truth table0%0/2
A
A= "CDS::Record"->fromObject($object)
Aresult
11
00
14964 0 ▶ my $rsaPublicKey = CDS::C::publicKeyNew($record->child('e')->bytesValue, $record->child('n')->bytesValue) // return;
Condition0%0/2
CDS::C::publicKeyNew($record->child("e")->bytesValue, $record->child("n")->bytesValue) // (return)
l!l
00
MC/DC0%0/1
CDS::C::publicKeyNew($record->child("e")->bytesValue, $record->child("n")->bytesValue) // (return)
CDS::C::publicKeyNew($record->child("e")->bytesValue, $record->child("n")->bytesValue)
Truth table0%0/2
A
A= CDS::C::publicKeyNew($record->child("e")->bytesValue, $record->child("n")->bytesValue)
Aresult
11
00
14965 0 return bless {
14966 hash => $object->calculateHash,
14967 rsaPublicKey => $rsaPublicKey,
14968 object => $object,
14969 lastAccess => 0, # used by PublicKeyCache
14970 };
14971 }
14972  
14973 0 ▶sub object { shift->{object} }
Subroutine object: not called CC=1 SCAR=6.9
14974 sub bytes {
14975 0 ▶ my $o = shift;
Subroutine bytes: not called CC=1 SCAR=6.9
14976 0 $o->{object}->bytes }
14977  
14978 ### Public key interface ###
14979  
14980 0 ▶sub hash { shift->{hash} }
Subroutine hash: not called CC=1 SCAR=6.9
14981 sub encrypt {
14982 0 ▶ my $o = shift;
Subroutine encrypt: not called CC=1 SCAR=6.9
14983 0 my $bytes = shift;
14984 0 CDS::C::publicKeyEncrypt($o->{rsaPublicKey}, $bytes) }
14985 sub verifyHash {
14986 0 ▶ my $o = shift;
Subroutine verifyHash: not called CC=3 SCAR=24.8
14987 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
14988 0 my $signature = shift;
14989 0 CDS::C::publicKeyVerify($o->{rsaPublicKey}, $hash->bytes, $signature) }
14990  
14991 package CDS::PublicKeyCache;
14992  
14993 sub new {
14994 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
14995 0 my $maxSize = shift;
14996  
14997 0 return bless {
14998 cache => {},
14999 maxSize => $maxSize,
15000 };
15001 }
15002  
15003 sub add {
15004 0 ▶ my $o = shift;
Subroutine add: not called CC=3 SCAR=24.8
15005 0 ▶ my $publicKey = shift; die 'wrong type '.ref($publicKey).' for $publicKey' if defined $publicKey && ref $publicKey ne 'CDS::PublicKey';
Branch: 1 branch
BranchTrueFalseTotal
if defined $publicKey and ref $publicKey ne "CDS::PublicKey" 0 0 0
Condition0%0/3
defined $publicKey and ref $publicKey ne "CDS::PublicKey"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $publicKey and ref $publicKey ne "CDS::PublicKey"
defined $publicKey ref $publicKey ne "CDS::PublicKey"
Truth table0%0/3
A and B
A= defined $publicKeyB= ref $publicKey ne "CDS::PublicKey"
ABresult
0X0
100
111
15006  
15007 0 $o->{cache}->{$publicKey->hash->bytes} = {publicKey => $publicKey, lastAccess => CDS->now};
15008 0 $o->deleteOldest;
15009 0 return;
15010 }
15011  
15012 sub get {
15013 0 ▶ my $o = shift;
Subroutine get: not called CC=4 SCAR=30.0
15014 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
15015  
15016 0 ▶ my $entry = $o->{cache}->{$hash->bytes} // return;
Condition0%0/2
$o->{"cache"}{$hash->bytes} // (return)
l!l
00
MC/DC0%0/1
$o->{"cache"}{$hash->bytes} // (return)
$o->{"cache"}{$hash->bytes}
Truth table0%0/2
A
A= $o->{"cache"}{$hash->bytes}
Aresult
11
00
15017 0 $entry->{lastAccess} = CDS->now;
15018 0 return $entry->{publicKey};
15019 }
15020  
15021 sub deleteOldest {
15022 0 ▶ my $o = shift;
Subroutine deleteOldest: not called CC=4 SCAR=30.0
15023 # private
15024 0 ▶ return if scalar values %{$o->{cache}} < $o->{maxSize};
Branch: 1 branch
BranchTrueFalseTotal
if scalar values %{$$o{"cache"};} < $o->{"maxSize"} 0 0 0
15025  
15026 0 my @entries = sort { $a->{lastAccess} <=> $b->{lastAccess} } values %{$o->{cache}};
15027 0 my $toRemove = int(scalar(@entries) - $o->{maxSize} / 2);
15028 0 for my $entry (@entries) {
15029 0 $toRemove -= 1;
15030 0 ▶ last if $toRemove <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $toRemove <= 0 0 0 0
15031 0 delete $o->{cache}->{$entry->{publicKey}->hash->bytes};
15032 }
15033 }
15034  
15035 package CDS::PutTree;
15036  
15037 sub new {
15038 0 ▶ my $o = shift;
Subroutine new: not called CC=3 SCAR=24.8
15039 0 my $store = shift;
15040 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
15041 0 my $commitPool = shift;
15042  
15043 0 return bless {
15044 store => $store,
15045 commitPool => $commitPool,
15046 keyPair => $keyPair,
15047 done => {},
15048 };
15049 }
15050  
15051 sub put {
15052 0 ▶ my $o = shift;
Subroutine put: not called CC=9 SCAR=45.0
15053 0 ▶ my $hash = shift // return; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/5
shift() // (return)
l!l
00
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/1
shift() // (return)
shift()
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/2
A
A= shift()
Aresult
11
00
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
15054  
15055 0 ▶ return if $o->{done}->{$hash->bytes};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"done"}{$hash->bytes} 0 0 0
15056  
15057 # Get the item
15058 0 ▶ my $hashAndObject = $o->{commitPool}->object($hash) // return;
Condition0%0/2
$o->{"commitPool"}->object($hash) // (return)
l!l
00
MC/DC0%0/1
$o->{"commitPool"}->object($hash) // (return)
$o->{"commitPool"}->object($hash)
Truth table0%0/2
A
A= $o->{"commitPool"}->object($hash)
Aresult
11
00
15059  
15060 # Upload all children
15061 0 for my $hash ($hashAndObject->object->hashes) {
15062 0 my $error = $o->put($hash);
15063 0 ▶ return $error if defined $error;
Branch: 1 branch
BranchTrueFalseTotal
if defined $error 0 0 0
15064 }
15065  
15066 # Upload this object
15067 0 my $error = $o->{store}->put($hashAndObject->hash, $hashAndObject->object, $o->{keyPair});
15068 0 ▶ return $error if defined $error;
Branch: 1 branch
BranchTrueFalseTotal
if defined $error 0 0 0
15069 0 $o->{done}->{$hash->bytes} = 1;
15070 0 return;
15071 }
15072  
15073 package CDS::ReceivedMessage;
15074  
15075 sub new {
15076 0 ▶ my $class = shift;
Subroutine new: not called CC=5 SCAR=34.0
15077 0 my $messageBoxReader = shift;
15078 0 my $entry = shift;
15079 0 ▶ my $source = shift; die 'wrong type '.ref($source).' for $source' if defined $source && ref $source ne 'CDS::Source';
Branch: 1 branch
BranchTrueFalseTotal
if defined $source and ref $source ne "CDS::Source" 0 0 0
Condition0%0/3
defined $source and ref $source ne "CDS::Source"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $source and ref $source ne "CDS::Source"
defined $source ref $source ne "CDS::Source"
Truth table0%0/3
A and B
A= defined $sourceB= ref $source ne "CDS::Source"
ABresult
0X0
100
111
15080 0 ▶ my $envelope = shift; die 'wrong type '.ref($envelope).' for $envelope' if defined $envelope && ref $envelope ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $envelope and ref $envelope ne "CDS::Record" 0 0 0
Condition0%0/3
defined $envelope and ref $envelope ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $envelope and ref $envelope ne "CDS::Record"
defined $envelope ref $envelope ne "CDS::Record"
Truth table0%0/3
A and B
A= defined $envelopeB= ref $envelope ne "CDS::Record"
ABresult
0X0
100
111
15081 0 my $senderStoreUrl = shift;
15082 0 my $sender = shift;
15083 0 my $content = shift;
15084 0 my $streamHead = shift;
15085  
15086 0 return bless {
15087 messageBoxReader => $messageBoxReader,
15088 entry => $entry,
15089 source => $source,
15090 envelope => $envelope,
15091 senderStoreUrl => $senderStoreUrl,
15092 sender => $sender,
15093 content => $content,
15094 streamHead => $streamHead,
15095 isDone => 0,
15096 };
15097 }
15098  
15099 0 ▶sub source { shift->{source} }
Subroutine source: not called CC=1 SCAR=6.9
15100 0 ▶sub envelope { shift->{envelope} }
Subroutine envelope: not called CC=1 SCAR=6.9
15101 0 ▶sub senderStoreUrl { shift->{senderStoreUrl} }
Subroutine senderStoreUrl: not called CC=1 SCAR=6.9
15102 0 ▶sub sender { shift->{sender} }
Subroutine sender: not called CC=1 SCAR=6.9
15103 0 ▶sub content { shift->{content} }
Subroutine content: not called CC=1 SCAR=6.9
15104  
15105 sub waitForSenderStore {
15106 0 ▶ my $o = shift;
Subroutine waitForSenderStore: not called CC=1 SCAR=6.9
15107  
15108 0 $o->{entry}->{waitingForStore} = $o->sender->store;
15109 }
15110  
15111 sub skip {
15112 0 ▶ my $o = shift;
Subroutine skip: not called CC=1 SCAR=6.9
15113  
15114 0 $o->{entry}->{processed} = 0;
15115 }
15116  
15117 # A record is a tree, whereby each nodes holds a byte sequence and an optional hash.
15118 # Child nodes are ordered, although the order does not always matter.
15119 package CDS::Record;
15120  
15121 sub fromObject {
15122 0 ▶ my $class = shift;
Subroutine fromObject: not called CC=5 SCAR=34.0
15123 0 ▶ my $object = shift // return; die 'wrong type '.ref($object).' for $object' if defined $object && ref $object ne 'CDS::Object';
Branch: 1 branch
BranchTrueFalseTotal
if defined $object and ref $object ne "CDS::Object" 0 0 0
Condition0%0/5
shift() // (return)
l!l
00
defined $object and ref $object ne "CDS::Object"
!ll&&!rl&&r
000
MC/DC0%0/1
shift() // (return)
shift()
MC/DC0%0/2
defined $object and ref $object ne "CDS::Object"
defined $object ref $object ne "CDS::Object"
Truth table0%0/2
A
A= shift()
Aresult
11
00
Truth table0%0/3
A and B
A= defined $objectB= ref $object ne "CDS::Object"
ABresult
0X0
100
111
15124  
15125 0 my $root = CDS::Record->new;
15126 0 ▶ $root->addFromObject($object) // return;
Condition0%0/2
$root->addFromObject($object) // (return)
l!l
00
MC/DC0%0/1
$root->addFromObject($object) // (return)
$root->addFromObject($object)
Truth table0%0/2
A
A= $root->addFromObject($object)
Aresult
11
00
15127 0 return $root;
15128 }
15129  
15130 sub new {
15131 0 ▶ my $class = shift;
Subroutine new: not called CC=4 SCAR=30.0
15132 0 my $bytes = shift;
15133 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
15134  
15135 0 ▶ bless {
Condition0%0/2
$bytes // ""
l!l
00
MC/DC0%0/1
$bytes // ""
$bytes
Truth table0%0/2
A
A= $bytes
Aresult
11
00
15136 bytes => $bytes // '',
15137 hash => $hash,
15138 children => [],
15139 };
15140 }
15141  
15142 # *** Adding
15143  
15144 # Adds a record
15145 sub add {
15146 0 ▶ my $o = shift;
Subroutine add: not called CC=3 SCAR=24.8
15147 0 my $bytes = shift;
15148 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
15149  
15150 0 my $record = CDS::Record->new($bytes, $hash);
15151 0 push @{$o->{children}}, $record;
15152 0 return $record;
15153 }
15154  
15155 sub addText {
15156 0 ▶ my $o = shift;
Subroutine addText: not called CC=4 SCAR=30.0
15157 0 my $value = shift;
15158 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
15159 0 ▶ $o->add(Encode::encode_utf8($value // ''), $hash) }
Condition0%0/2
$value // ""
l!l
00
MC/DC0%0/1
$value // ""
$value
Truth table0%0/2
A
A= $value
Aresult
11
00
15160 sub addBoolean {
15161 0 ▶ my $o = shift;
Subroutine addBoolean: not called CC=3 SCAR=24.8
15162 0 my $value = shift;
15163 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
15164 0 $o->add(CDS->bytesFromBoolean($value), $hash) }
15165 sub addInteger {
15166 0 ▶ my $o = shift;
Subroutine addInteger: not called CC=4 SCAR=30.0
15167 0 my $value = shift;
15168 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
15169 0 ▶ $o->add(CDS->bytesFromInteger($value // 0), $hash) }
Condition0%0/2
$value // 0
l!l
00
MC/DC0%0/1
$value // 0
$value
Truth table0%0/2
A
A= $value
Aresult
11
00
15170 sub addUnsigned {
15171 0 ▶ my $o = shift;
Subroutine addUnsigned: not called CC=4 SCAR=30.0
15172 0 my $value = shift;
15173 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
15174 0 ▶ $o->add(CDS->bytesFromUnsigned($value // 0), $hash) }
Condition0%0/2
$value // 0
l!l
00
MC/DC0%0/1
$value // 0
$value
Truth table0%0/2
A
A= $value
Aresult
11
00
15175 sub addFloat32 {
15176 0 ▶ my $o = shift;
Subroutine addFloat32: not called CC=4 SCAR=30.0
15177 0 my $value = shift;
15178 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
15179 0 ▶ $o->add(CDS->bytesFromFloat32($value // 0), $hash) }
Condition0%0/2
$value // 0
l!l
00
MC/DC0%0/1
$value // 0
$value
Truth table0%0/2
A
A= $value
Aresult
11
00
15180 sub addFloat64 {
15181 0 ▶ my $o = shift;
Subroutine addFloat64: not called CC=4 SCAR=30.0
15182 0 my $value = shift;
15183 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
15184 0 ▶ $o->add(CDS->bytesFromFloat64($value // 0), $hash) }
Condition0%0/2
$value // 0
l!l
00
MC/DC0%0/1
$value // 0
$value
Truth table0%0/2
A
A= $value
Aresult
11
00
15185 sub addHash {
15186 0 ▶ my $o = shift;
Subroutine addHash: not called CC=3 SCAR=24.8
15187 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
15188 0 $o->add('', $hash) }
15189 sub addHashAndKey {
15190 0 ▶ my $o = shift;
Subroutine addHashAndKey: not called CC=4 SCAR=30.0
15191 0 ▶ my $hashAndKey = shift; die 'wrong type '.ref($hashAndKey).' for $hashAndKey' if defined $hashAndKey && ref $hashAndKey ne 'CDS::HashAndKey';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hashAndKey and ref $hashAndKey ne "CDS::HashAndKey" 0 0 0
Condition0%0/3
defined $hashAndKey and ref $hashAndKey ne "CDS::HashAndKey"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hashAndKey and ref $hashAndKey ne "CDS::HashAndKey"
defined $hashAndKey ref $hashAndKey ne "CDS::HashAndKey"
Truth table0%0/3
A and B
A= defined $hashAndKeyB= ref $hashAndKey ne "CDS::HashAndKey"
ABresult
0X0
100
111
15192 0 ▶ $hashAndKey ? $o->add($hashAndKey->key, $hashAndKey->hash) : $o->add('') }
Branch: 1 branch
BranchTrueFalseTotal
$hashAndKey ? : 0 0 0
15193 sub addRecord {
15194 0 ▶ my $o = shift;
Subroutine addRecord: not called CC=1 SCAR=6.9
15195 0 push @{$o->{children}}, @_; return; }
15196  
15197 sub addFromObject {
15198 0 ▶ my $o = shift;
Subroutine addFromObject: not called CC=5 SCAR=34.0
15199 0 ▶ my $object = shift // return; die 'wrong type '.ref($object).' for $object' if defined $object && ref $object ne 'CDS::Object';
Branch: 1 branch
BranchTrueFalseTotal
if defined $object and ref $object ne "CDS::Object" 0 0 0
Condition0%0/5
shift() // (return)
l!l
00
defined $object and ref $object ne "CDS::Object"
!ll&&!rl&&r
000
MC/DC0%0/1
shift() // (return)
shift()
MC/DC0%0/2
defined $object and ref $object ne "CDS::Object"
defined $object ref $object ne "CDS::Object"
Truth table0%0/2
A
A= shift()
Aresult
11
00
Truth table0%0/3
A and B
A= defined $objectB= ref $object ne "CDS::Object"
ABresult
0X0
100
111
15200  
15201 0 ▶ return 1 if ! length $object->data;
Branch: 1 branch
BranchTrueFalseTotal
unless length $object->data 0 0 0
15202 0 return CDS::RecordReader->new($object)->readChildren($o);
15203 }
15204  
15205 # *** Set value
15206  
15207 sub set {
15208 0 ▶ my $o = shift;
Subroutine set: not called CC=3 SCAR=24.8
15209 0 my $bytes = shift;
15210 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
15211  
15212 0 $o->{bytes} = $bytes;
15213 0 $o->{hash} = $hash;
15214 0 return;
15215 }
15216  
15217 # *** Querying
15218  
15219 # Returns true if the record contains a child with the indicated bytes.
15220 sub contains {
15221 0 ▶ my $o = shift;
Subroutine contains: not called CC=3 SCAR=24.8
15222 0 my $bytes = shift;
15223  
15224 0 for my $child (@{$o->{children}}) {
15225 0 ▶ return 1 if $child->{bytes} eq $bytes;
Branch: 1 branch
BranchTrueFalseTotal
if $child->{"bytes"} eq $bytes 0 0 0
15226 }
15227 0 return;
15228 }
15229  
15230 # Returns the child record for the given bytes. If no record with these bytes exists, a record with these bytes is returned (but not added).
15231 sub child {
15232 0 ▶ my $o = shift;
Subroutine child: not called CC=3 SCAR=24.8
15233 0 my $bytes = shift;
15234  
15235 0 for my $child (@{$o->{children}}) {
15236 0 ▶ return $child if $child->{bytes} eq $bytes;
Branch: 1 branch
BranchTrueFalseTotal
if $child->{"bytes"} eq $bytes 0 0 0
15237 }
15238 0 return $o->new($bytes);
15239 }
15240  
15241 # Returns the first child, or an empty record.
15242 sub firstChild {
15243 0 ▶ my $o = shift;
Subroutine firstChild: not called CC=2 SCAR=17.9
15244 0 ▶ $o->{children}->[0] // $o->new }
Condition0%0/3
$o->{"children"}[0] // $o->new
l!l&&r!l&&!r
000
MC/DC0%0/2
$o->{"children"}[0] // $o->new
$o->{"children"}[0] $o->new
Truth table0%0/3
A // B
A= $o->{"children"}[0]B= $o->new
ABresult
1X1
011
000
15245  
15246 # Returns the nth child, or an empty record.
15247 sub nthChild {
15248 0 ▶ my $o = shift;
Subroutine nthChild: not called CC=2 SCAR=17.9
15249 0 my $i = shift;
15250 0 ▶ $o->{children}->[$i] // $o->new }
Condition0%0/3
$o->{"children"}[$i] // $o->new
l!l&&r!l&&!r
000
MC/DC0%0/2
$o->{"children"}[$i] // $o->new
$o->{"children"}[$i] $o->new
Truth table0%0/3
A // B
A= $o->{"children"}[$i]B= $o->new
ABresult
1X1
011
000
15251  
15252 sub containsText {
15253 0 ▶ my $o = shift;
Subroutine containsText: not called CC=2 SCAR=17.9
15254 0 my $text = shift;
15255 0 ▶ $o->contains(Encode::encode_utf8($text // '')) }
Condition0%0/2
$text // ""
l!l
00
MC/DC0%0/1
$text // ""
$text
Truth table0%0/2
A
A= $text
Aresult
11
00
15256 sub childWithText {
15257 0 ▶ my $o = shift;
Subroutine childWithText: not called CC=2 SCAR=17.9
15258 0 my $text = shift;
15259 0 ▶ $o->child(Encode::encode_utf8($text // '')) }
Condition0%0/2
$text // ""
l!l
00
MC/DC0%0/1
$text // ""
$text
Truth table0%0/2
A
A= $text
Aresult
11
00
15260  
15261 # *** Get value
15262  
15263 0 ▶sub bytes { shift->{bytes} }
Subroutine bytes: not called CC=1 SCAR=6.9
15264 0 ▶sub hash { shift->{hash} }
Subroutine hash: not called CC=1 SCAR=6.9
15265 sub children {
15266 0 ▶ my $o = shift;
Subroutine children: not called CC=1 SCAR=6.9
15267 0 @{$o->{children}} }
15268  
15269 sub asText {
15270 0 ▶ my $o = shift;
Subroutine asText: not called CC=2 SCAR=17.9
15271 0 ▶ Encode::decode_utf8($o->{bytes}) // '' }
Condition0%0/2
&Encode::decode_utf8($o->{"bytes"}) // ""
l!l
00
MC/DC0%0/1
&Encode::decode_utf8($o->{"bytes"}) // ""
&Encode::decode_utf8($o->{"bytes"})
Truth table0%0/2
A
A= &Encode::decode_utf8($o->{"bytes"})
Aresult
11
00
15272 sub asBoolean {
15273 0 ▶ my $o = shift;
Subroutine asBoolean: not called CC=1 SCAR=6.9
15274 0 CDS->booleanFromBytes($o->{bytes}) }
15275 sub asInteger {
15276 0 ▶ my $o = shift;
Subroutine asInteger: not called CC=2 SCAR=17.9
15277 0 ▶ CDS->integerFromBytes($o->{bytes}) // 0 }
Condition0%0/2
"CDS"->integerFromBytes($o->{"bytes"}) // 0
l!l
00
MC/DC0%0/1
"CDS"->integerFromBytes($o->{"bytes"}) // 0
"CDS"->integerFromBytes($o->{"bytes"})
Truth table0%0/2
A
A= "CDS"->integerFromBytes($o->{"bytes"})
Aresult
11
00
15278 sub asUnsigned {
15279 0 ▶ my $o = shift;
Subroutine asUnsigned: not called CC=2 SCAR=17.9
15280 0 ▶ CDS->unsignedFromBytes($o->{bytes}) // 0 }
Condition0%0/2
"CDS"->unsignedFromBytes($o->{"bytes"}) // 0
l!l
00
MC/DC0%0/1
"CDS"->unsignedFromBytes($o->{"bytes"}) // 0
"CDS"->unsignedFromBytes($o->{"bytes"})
Truth table0%0/2
A
A= "CDS"->unsignedFromBytes($o->{"bytes"})
Aresult
11
00
15281 sub asFloat {
15282 0 ▶ my $o = shift;
Subroutine asFloat: not called CC=2 SCAR=17.9
15283 0 ▶ CDS->floatFromBytes($o->{bytes}) // 0 }
Condition0%0/2
"CDS"->floatFromBytes($o->{"bytes"}) // 0
l!l
00
MC/DC0%0/1
"CDS"->floatFromBytes($o->{"bytes"}) // 0
"CDS"->floatFromBytes($o->{"bytes"})
Truth table0%0/2
A
A= "CDS"->floatFromBytes($o->{"bytes"})
Aresult
11
00
15284  
15285 sub asHashAndKey {
15286 0 ▶ my $o = shift;
Subroutine asHashAndKey: not called CC=3 SCAR=24.8
15287  
15288 0 ▶ return if ! $o->{hash};
Branch: 1 branch
BranchTrueFalseTotal
unless $o->{"hash"} 0 0 0
15289 0 ▶ return if length $o->{bytes} != 32;
Branch: 1 branch
BranchTrueFalseTotal
if length $o->{"bytes"} != 32 0 0 0
15290 0 return CDS::HashAndKey->new($o->{hash}, $o->{bytes});
15291 }
15292  
15293 sub bytesValue {
15294 0 ▶ my $o = shift;
Subroutine bytesValue: not called CC=1 SCAR=6.9
15295 0 $o->firstChild->bytes }
15296 sub hashValue {
15297 0 ▶ my $o = shift;
Subroutine hashValue: not called CC=1 SCAR=6.9
15298 0 $o->firstChild->hash }
15299 sub textValue {
15300 0 ▶ my $o = shift;
Subroutine textValue: not called CC=1 SCAR=6.9
15301 0 $o->firstChild->asText }
15302 sub booleanValue {
15303 0 ▶ my $o = shift;
Subroutine booleanValue: not called CC=1 SCAR=6.9
15304 0 $o->firstChild->asBoolean }
15305 sub integerValue {
15306 0 ▶ my $o = shift;
Subroutine integerValue: not called CC=1 SCAR=6.9
15307 0 $o->firstChild->asInteger }
15308 sub unsignedValue {
15309 0 ▶ my $o = shift;
Subroutine unsignedValue: not called CC=1 SCAR=6.9
15310 0 $o->firstChild->asUnsigned }
15311 sub floatValue {
15312 0 ▶ my $o = shift;
Subroutine floatValue: not called CC=1 SCAR=6.9
15313 0 $o->firstChild->asFloat }
15314 sub hashAndKeyValue {
15315 0 ▶ my $o = shift;
Subroutine hashAndKeyValue: not called CC=1 SCAR=6.9
15316 0 $o->firstChild->asHashAndKey }
15317  
15318 # *** Dependent hashes
15319  
15320 sub dependentHashes {
15321 0 ▶ my $o = shift;
Subroutine dependentHashes: not called CC=1 SCAR=6.9
15322  
15323 0 my $hashes = {};
15324 0 $o->traverseHashes($hashes);
15325 0 return values %$hashes;
15326 }
15327  
15328 sub traverseHashes {
15329 0 ▶ my $o = shift;
Subroutine traverseHashes: not called CC=3 SCAR=24.8
15330 0 my $hashes = shift;
15331 # private
15332 0 ▶ $hashes->{$o->{hash}->bytes} = $o->{hash} if $o->{hash};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"hash"} 0 0 0
15333 0 for my $child (@{$o->{children}}) {
15334 0 $child->traverseHashes($hashes);
15335 }
15336 }
15337  
15338 # *** Size
15339  
15340 sub countEntries {
15341 0 ▶ my $o = shift;
Subroutine countEntries: not called CC=2 SCAR=17.9
15342  
15343 0 my $count = 1;
15344 0 for my $child (@{$o->{children}}) { $count += $child->countEntries; }
15345 0 return $count;
15346 }
15347  
15348 sub calculateSize {
15349 0 ▶ my $o = shift;
Subroutine calculateSize: not called CC=1 SCAR=6.9
15350  
15351 0 return 4 + $o->calculateSizeContribution;
15352 }
15353  
15354 sub calculateSizeContribution {
15355 0 ▶ my $o = shift;
Subroutine calculateSizeContribution: not called CC=5 SCAR=34.0
15356 # private
15357 0 my $byteLength = length $o->{bytes};
15358 0 ▶ my $size = $byteLength < 30 ? 1 : $byteLength < 286 ? 2 : 9;
Branch: 2 branches
BranchTrueFalseTotal
$byteLength < 30 ? : 0 0 0
$byteLength < 286 ? : 0 0 0
15359 0 $size += $byteLength;
15360 0 ▶ $size += 32 + 4 if $o->{hash};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"hash"} 0 0 0
15361 0 for my $child (@{$o->{children}}) {
15362 0 $size += $child->calculateSizeContribution;
15363 }
15364 0 return $size;
15365 }
15366  
15367 # *** Serialization
15368  
15369 # Serializes this record into a Condensation object.
15370 sub toObject {
15371 0 ▶ my $o = shift;
Subroutine toObject: not called CC=1 SCAR=6.9
15372  
15373 0 my $writer = CDS::RecordWriter->new;
15374 0 $writer->writeChildren($o);
15375 0 return CDS::Object->create($writer->header, $writer->data);
15376 }
15377  
15378 package CDS::RecordReader;
15379  
15380 sub new {
15381 0 ▶ my $class = shift;
Subroutine new: not called CC=3 SCAR=24.8
15382 0 ▶ my $object = shift; die 'wrong type '.ref($object).' for $object' if defined $object && ref $object ne 'CDS::Object';
Branch: 1 branch
BranchTrueFalseTotal
if defined $object and ref $object ne "CDS::Object" 0 0 0
Condition0%0/3
defined $object and ref $object ne "CDS::Object"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $object and ref $object ne "CDS::Object"
defined $object ref $object ne "CDS::Object"
Truth table0%0/3
A and B
A= defined $objectB= ref $object ne "CDS::Object"
ABresult
0X0
100
111
15383  
15384 0 return bless {
15385 object => $object,
15386 data => $object->data,
15387 pos => 0,
15388 hasError => 0
15389 };
15390 }
15391  
15392 0 ▶sub hasError { shift->{hasError} }
Subroutine hasError: not called CC=1 SCAR=6.9
15393  
15394 sub readChildren {
15395 0 ▶ my $o = shift;
Subroutine readChildren: not called CC=14 SCAR=53.5
15396 0 ▶ my $record = shift; die 'wrong type '.ref($record).' for $record' if defined $record && ref $record ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $record and ref $record ne "CDS::Record" 0 0 0
Condition0%0/3
defined $record and ref $record ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $record and ref $record ne "CDS::Record"
defined $record ref $record ne "CDS::Record"
Truth table0%0/3
A and B
A= defined $recordB= ref $record ne "CDS::Record"
ABresult
0X0
100
111
15397  
15398 0 while (1) {
15399 # Flags
15400 0 ▶ my $flags = $o->readUnsigned8 // return;
Condition0%0/2
$o->readUnsigned8 // (return)
l!l
00
MC/DC0%0/1
$o->readUnsigned8 // (return)
$o->readUnsigned8
Truth table0%0/2
A
A= $o->readUnsigned8
Aresult
11
00
15401  
15402 # Data
15403 0 my $length = $flags & 0x1f;
15404 0 ▶ my $byteLength = $length == 30 ? 30 + ($o->readUnsigned8 // return) : $length == 31 ? ($o->readUnsigned64 // return) : $length;
Branch: 2 branches
BranchTrueFalseTotal
$length == 30 ? : 0 0 0
$length == 31 ? : 0 0 0
Condition0%0/4
$o->readUnsigned8 // (return)
l!l
00
$o->readUnsigned64 // (return)
l!l
00
MC/DC0%0/1
$o->readUnsigned8 // (return)
$o->readUnsigned8
MC/DC0%0/1
$o->readUnsigned64 // (return)
$o->readUnsigned64
Truth table0%0/2
A
A= $o->readUnsigned8
Aresult
11
00
Truth table0%0/2
A
A= $o->readUnsigned64
Aresult
11
00
15405 0 my $bytes = $o->readBytes($byteLength);
15406 0 ▶ my $hash = $flags & 0x20 ? $o->{object}->hashAtIndex($o->readUnsigned32 // return) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$flags & 32 ? : 0 0 0
Condition0%0/2
$o->readUnsigned32 // (return)
l!l
00
MC/DC0%0/1
$o->readUnsigned32 // (return)
$o->readUnsigned32
Truth table0%0/2
A
A= $o->readUnsigned32
Aresult
11
00
15407 0 ▶ return if $o->{hasError};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"hasError"} 0 0 0
15408  
15409 # Children
15410 0 my $child = $record->add($bytes, $hash);
15411 0 ▶ return if $flags & 0x40 && ! $o->readChildren($child);
Branch: 1 branch
BranchTrueFalseTotal
if $flags & 64 and not $o->readChildren($child) 0 0 0
Condition0%0/3
$flags & 64 and not $o->readChildren($child)
!ll&&!rl&&r
000
MC/DC0%0/2
$flags & 64 and not $o->readChildren($child)
$flags & 64 not $o->readChildren($child)
Truth table0%0/3
A and not(B)
A= $flags & 64B= not $o->readChildren($child)
ABresult
0X0
100
111
15412 0 ▶ return 1 if ! ($flags & 0x80);
Branch: 1 branch
BranchTrueFalseTotal
unless $flags & 128 0 0 0
15413 }
15414 }
15415  
15416 sub use {
15417 0 ▶ my $o = shift;
Subroutine use: not called CC=2 SCAR=17.9
15418 0 my $length = shift;
15419  
15420 0 my $start = $o->{pos};
15421 0 $o->{pos} += $length;
15422 0 ▶ return substr($o->{data}, $start, $length) if $o->{pos} <= length $o->{data};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"pos"} <= length $o->{"data"} 0 0 0
15423 0 $o->{hasError} = 1;
15424 0 return;
15425 }
15426  
15427 sub readUnsigned8 {
15428 0 ▶ my $o = shift;
Subroutine readUnsigned8: not called CC=2 SCAR=17.9
15429 0 ▶ unpack('C', $o->use(1) // return) }
Condition0%0/2
$o->use(1) // (return)
l!l
00
MC/DC0%0/1
$o->use(1) // (return)
$o->use(1)
Truth table0%0/2
A
A= $o->use(1)
Aresult
11
00
15430 sub readUnsigned32 {
15431 0 ▶ my $o = shift;
Subroutine readUnsigned32: not called CC=2 SCAR=17.9
15432 0 ▶ unpack('L>', $o->use(4) // return) }
Condition0%0/2
$o->use(4) // (return)
l!l
00
MC/DC0%0/1
$o->use(4) // (return)
$o->use(4)
Truth table0%0/2
A
A= $o->use(4)
Aresult
11
00
15433 sub readUnsigned64 {
15434 0 ▶ my $o = shift;
Subroutine readUnsigned64: not called CC=2 SCAR=17.9
15435 0 ▶ unpack('Q>', $o->use(8) // return) }
Condition0%0/2
$o->use(8) // (return)
l!l
00
MC/DC0%0/1
$o->use(8) // (return)
$o->use(8)
Truth table0%0/2
A
A= $o->use(8)
Aresult
11
00
15436 sub readBytes {
15437 0 ▶ my $o = shift;
Subroutine readBytes: not called CC=1 SCAR=6.9
15438 0 my $length = shift;
15439 0 $o->use($length) }
15440 sub trailer {
15441 0 ▶ my $o = shift;
Subroutine trailer: not called CC=1 SCAR=6.9
15442 0 substr($o->{data}, $o->{pos}) }
15443  
15444 package CDS::RecordWriter;
15445  
15446 sub new {
15447 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
15448  
15449 0 return bless {
15450 hashesCount => 0,
15451 hashes => '',
15452 data => ''
15453 };
15454 }
15455  
15456 sub header {
15457 0 ▶ my $o = shift;
Subroutine header: not called CC=1 SCAR=6.9
15458 0 pack('L>', $o->{hashesCount}).$o->{hashes} }
15459 0 ▶sub data { shift->{data} }
Subroutine data: not called CC=1 SCAR=6.9
15460  
15461 sub writeChildren {
15462 0 ▶ my $o = shift;
Subroutine writeChildren: not called CC=5 SCAR=34.0
15463 0 ▶ my $record = shift; die 'wrong type '.ref($record).' for $record' if defined $record && ref $record ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $record and ref $record ne "CDS::Record" 0 0 0
Condition0%0/3
defined $record and ref $record ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $record and ref $record ne "CDS::Record"
defined $record ref $record ne "CDS::Record"
Truth table0%0/3
A and B
A= defined $recordB= ref $record ne "CDS::Record"
ABresult
0X0
100
111
15464  
15465 0 my @children = @{$record->{children}};
15466 0 ▶ return if ! scalar @children;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @children 0 0 0
15467 0 my $lastChild = pop @children;
15468 0 for my $child (@children) { $o->writeNode($child, 1); }
15469 0 $o->writeNode($lastChild, 0);
15470 }
15471  
15472 sub writeNode {
15473 0 ▶ my $o = shift;
Subroutine writeNode: not called CC=11 SCAR=48.8
15474 0 ▶ my $record = shift; die 'wrong type '.ref($record).' for $record' if defined $record && ref $record ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $record and ref $record ne "CDS::Record" 0 0 0
Condition0%0/3
defined $record and ref $record ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $record and ref $record ne "CDS::Record"
defined $record ref $record ne "CDS::Record"
Truth table0%0/3
A and B
A= defined $recordB= ref $record ne "CDS::Record"
ABresult
0X0
100
111
15475 0 my $hasMoreSiblings = shift;
15476  
15477 # Flags
15478 0 my $byteLength = length $record->{bytes};
15479 0 ▶ my $flags = $byteLength < 30 ? $byteLength : $byteLength < 286 ? 30 : 31;
Branch: 2 branches
BranchTrueFalseTotal
$byteLength < 30 ? : 0 0 0
$byteLength < 286 ? : 0 0 0
15480 0 ▶ $flags |= 0x20 if defined $record->{hash};
Branch: 1 branch
BranchTrueFalseTotal
if defined $record->{"hash"} 0 0 0
15481 0 my $countChildren = scalar @{$record->{children}};
15482 0 ▶ $flags |= 0x40 if $countChildren;
Branch: 1 branch
BranchTrueFalseTotal
if $countChildren 0 0 0
15483 0 ▶ $flags |= 0x80 if $hasMoreSiblings;
Branch: 1 branch
BranchTrueFalseTotal
if $hasMoreSiblings 0 0 0
15484 0 $o->writeUnsigned8($flags);
15485  
15486 # Data
15487 0 ▶ $o->writeUnsigned8($byteLength - 30) if ($flags & 0x1f) == 30;
Branch: 1 branch
BranchTrueFalseTotal
if ($flags & 31) == 30 0 0 0
15488 0 ▶ $o->writeUnsigned64($byteLength) if ($flags & 0x1f) == 31;
Branch: 1 branch
BranchTrueFalseTotal
if ($flags & 31) == 31 0 0 0
15489 0 $o->writeBytes($record->{bytes});
15490 0 ▶ $o->writeUnsigned32($o->addHash($record->{hash})) if $flags & 0x20;
Branch: 1 branch
BranchTrueFalseTotal
if $flags & 32 0 0 0
15491  
15492 # Children
15493 0 $o->writeChildren($record);
15494 }
15495  
15496 sub writeUnsigned8 {
15497 0 ▶ my $o = shift;
Subroutine writeUnsigned8: not called CC=1 SCAR=6.9
15498 0 my $value = shift;
15499 0 $o->{data} .= pack('C', $value) }
15500 sub writeUnsigned32 {
15501 0 ▶ my $o = shift;
Subroutine writeUnsigned32: not called CC=1 SCAR=6.9
15502 0 my $value = shift;
15503 0 $o->{data} .= pack('L>', $value) }
15504 sub writeUnsigned64 {
15505 0 ▶ my $o = shift;
Subroutine writeUnsigned64: not called CC=1 SCAR=6.9
15506 0 my $value = shift;
15507 0 $o->{data} .= pack('Q>', $value) }
15508  
15509 sub writeBytes {
15510 0 ▶ my $o = shift;
Subroutine writeBytes: not called CC=2 SCAR=17.9
15511 0 my $bytes = shift;
15512  
15513 0 ▶ warn $bytes.' is a utf8 string, not a byte string.' if utf8::is_utf8($bytes);
Branch: 1 branch
BranchTrueFalseTotal
if utf8::is_utf8($bytes) 0 0 0
15514 0 $o->{data} .= $bytes;
15515 }
15516  
15517 sub addHash {
15518 0 ▶ my $o = shift;
Subroutine addHash: not called CC=3 SCAR=24.8
15519 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
15520  
15521 0 my $index = $o->{hashesCount};
15522 0 $o->{hashes} .= $hash->bytes;
15523 0 $o->{hashesCount} += 1;
15524 0 return $index;
15525 }
15526  
15527 package CDS::RootDocument;
15528  
15529 1 ▶use parent -norequire, 'CDS::Document';
Subroutine BEGIN: called CC=1 SCAR=0.0
15530  
15531 sub new {
15532 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
15533 0 my $privateRoot = shift;
15534 0 my $label = shift;
15535  
15536 0 my $o = $class->SUPER::new($privateRoot->privateBoxReader->keyPair, $privateRoot->unsaved);
15537 0 $o->{privateRoot} = $privateRoot;
15538 0 $o->{label} = $label;
15539 0 $privateRoot->addDataHandler($label, $o);
15540  
15541 # State
15542 0 $o->{dataSharingMessage} = undef;
15543 0 return $o;
15544 }
15545  
15546 0 ▶sub privateRoot { shift->{privateRoot} }
Subroutine privateRoot: not called CC=1 SCAR=6.9
15547 0 ▶sub label { shift->{label} }
Subroutine label: not called CC=1 SCAR=6.9
15548  
15549 sub savingDone {
15550 0 ▶ my $o = shift;
Subroutine savingDone: not called CC=3 SCAR=24.8
15551 0 my $revision = shift;
15552 0 my $newPart = shift;
15553 0 my $obsoleteParts = shift;
15554  
15555 0 $o->{privateRoot}->unsaved->state->merge($o->{unsaved}->savingState);
15556 0 $o->{unsaved}->savingDone;
15557 0 ▶ $o->{privateRoot}->dataChanged if $newPart || scalar @$obsoleteParts;
Branch: 1 branch
BranchTrueFalseTotal
if $newPart or scalar @$obsoleteParts 0 0 0
Condition0%0/2
$newPart or scalar @$obsoleteParts
l!l
00
MC/DC0%0/1
$newPart or scalar @$obsoleteParts
$newPart
Truth table0%0/2
A
A= $newPart
Aresult
11
00
15558 }
15559  
15560 sub addDataTo {
15561 0 ▶ my $o = shift;
Subroutine addDataTo: not called CC=4 SCAR=30.0
15562 0 ▶ my $record = shift; die 'wrong type '.ref($record).' for $record' if defined $record && ref $record ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $record and ref $record ne "CDS::Record" 0 0 0
Condition0%0/3
defined $record and ref $record ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $record and ref $record ne "CDS::Record"
defined $record ref $record ne "CDS::Record"
Truth table0%0/3
A and B
A= defined $recordB= ref $record ne "CDS::Record"
ABresult
0X0
100
111
15563  
15564 0 for my $part (sort { $a->{hashAndKey}->hash->bytes cmp $b->{hashAndKey}->hash->bytes } values %{$o->{parts}}) {
15565 0 $record->addHashAndKey($part->{hashAndKey});
15566 }
15567 }
15568 sub mergeData {
15569 0 ▶ my $o = shift;
Subroutine mergeData: not called CC=5 SCAR=34.0
15570 0 ▶ my $record = shift; die 'wrong type '.ref($record).' for $record' if defined $record && ref $record ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $record and ref $record ne "CDS::Record" 0 0 0
Condition0%0/3
defined $record and ref $record ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $record and ref $record ne "CDS::Record"
defined $record ref $record ne "CDS::Record"
Truth table0%0/3
A and B
A= defined $recordB= ref $record ne "CDS::Record"
ABresult
0X0
100
111
15571  
15572 0 my @hashesAndKeys;
15573 0 for my $child ($record->children) {
15574 0 ▶ push @hashesAndKeys, $child->asHashAndKey // next;
Condition0%0/2
$child->asHashAndKey // (next)
l!l
00
MC/DC0%0/1
$child->asHashAndKey // (next)
$child->asHashAndKey
Truth table0%0/2
A
A= $child->asHashAndKey
Aresult
11
00
15575 }
15576  
15577 0 $o->merge(@hashesAndKeys);
15578 }
15579  
15580 sub mergeExternalData {
15581 0 ▶ my $o = shift;
Subroutine mergeExternalData: not called CC=11 SCAR=48.8
15582 0 my $store = shift;
15583 0 ▶ my $record = shift; die 'wrong type '.ref($record).' for $record' if defined $record && ref $record ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $record and ref $record ne "CDS::Record" 0 0 0
Condition0%0/3
defined $record and ref $record ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $record and ref $record ne "CDS::Record"
defined $record ref $record ne "CDS::Record"
Truth table0%0/3
A and B
A= defined $recordB= ref $record ne "CDS::Record"
ABresult
0X0
100
111
15584 0 ▶ my $source = shift; die 'wrong type '.ref($source).' for $source' if defined $source && ref $source ne 'CDS::Source';
Branch: 1 branch
BranchTrueFalseTotal
if defined $source and ref $source ne "CDS::Source" 0 0 0
Condition0%0/3
defined $source and ref $source ne "CDS::Source"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $source and ref $source ne "CDS::Source"
defined $source ref $source ne "CDS::Source"
Truth table0%0/3
A and B
A= defined $sourceB= ref $source ne "CDS::Source"
ABresult
0X0
100
111
15585  
15586 0 my @hashes;
15587 my @hashesAndKeys;
15588 0 for my $child ($record->children) {
15589 0 ▶ my $hashAndKey = $child->asHashAndKey // next;
Condition0%0/2
$child->asHashAndKey // (next)
l!l
00
MC/DC0%0/1
$child->asHashAndKey // (next)
$child->asHashAndKey
Truth table0%0/2
A
A= $child->asHashAndKey
Aresult
11
00
15590 0 ▶ next if $o->{parts}->{$hashAndKey->hash->bytes};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"parts"}{$hashAndKey->hash->bytes} 0 0 0
15591 0 push @hashes, $hashAndKey->hash;
15592 0 push @hashesAndKeys, $hashAndKey;
15593 }
15594  
15595 0 my ($missing, $transferStore, $storeError) = $o->{keyPair}->transfer([@hashes], $store, $o->{privateRoot}->unsaved);
15596 0 ▶ return if defined $storeError;
Branch: 1 branch
BranchTrueFalseTotal
if defined $storeError 0 0 0
15597 0 ▶ return if $missing;
Branch: 1 branch
BranchTrueFalseTotal
if $missing 0 0 0
15598  
15599 0 ▶ if ($source) {
Branch: 1 branch
BranchTrueFalseTotal
if ($source) 0 0 0
15600 0 $source->keep;
15601 0 $o->{privateRoot}->unsaved->state->addMergedSource($source);
15602 }
15603  
15604 0 $o->merge(@hashesAndKeys);
15605 0 return 1;
15606 }
15607  
15608 package CDS::Selector;
15609  
15610 sub root {
15611 0 ▶ my $class = shift;
Subroutine root: not called CC=1 SCAR=6.9
15612 0 my $document = shift;
15613  
15614 0 return bless {document => $document, id => 'ROOT', label => ''};
15615 }
15616  
15617 0 ▶sub document { shift->{document} }
Subroutine document: not called CC=1 SCAR=6.9
15618 0 ▶sub parent { shift->{parent} }
Subroutine parent: not called CC=1 SCAR=6.9
15619 0 ▶sub label { shift->{label} }
Subroutine label: not called CC=1 SCAR=6.9
15620  
15621 sub child {
15622 0 ▶ my $o = shift;
Subroutine child: not called CC=1 SCAR=6.9
15623 0 my $label = shift;
15624  
15625 return bless {
15626 document => $o->{document},
15627 0 id => $o->{id}.'/'.unpack('H*', $label),
15628 parent => $o,
15629 label => $label,
15630 };
15631 }
15632  
15633 sub childWithText {
15634 0 ▶ my $o = shift;
Subroutine childWithText: not called CC=2 SCAR=17.9
15635 0 my $label = shift;
15636  
15637 0 ▶ return $o->child(Encode::encode_utf8($label // ''));
Condition0%0/2
$label // ""
l!l
00
MC/DC0%0/1
$label // ""
$label
Truth table0%0/2
A
A= $label
Aresult
11
00
15638 }
15639  
15640 sub children {
15641 0 ▶ my $o = shift;
Subroutine children: not called CC=2 SCAR=17.9
15642  
15643 0 ▶ my $item = $o->{document}->get($o) // return;
Condition0%0/2
$o->{"document"}->get($o) // (return)
l!l
00
MC/DC0%0/1
$o->{"document"}->get($o) // (return)
$o->{"document"}->get($o)
Truth table0%0/2
A
A= $o->{"document"}->get($o)
Aresult
11
00
15644 0 return map { $_->{selector} } @{$item->{children}};
15645 }
15646  
15647 # Value
15648  
15649 sub revision {
15650 0 ▶ my $o = shift;
Subroutine revision: not called CC=2 SCAR=17.9
15651  
15652 0 ▶ my $item = $o->{document}->get($o) // return 0;
Condition0%0/2
$o->{"document"}->get($o) // (return 0)
l!l
00
MC/DC0%0/1
$o->{"document"}->get($o) // (return 0)
$o->{"document"}->get($o)
Truth table0%0/2
A
A= $o->{"document"}->get($o)
Aresult
11
00
15653 0 return $item->{revision};
15654 }
15655  
15656 sub isSet {
15657 0 ▶ my $o = shift;
Subroutine isSet: not called CC=2 SCAR=17.9
15658  
15659 0 ▶ my $item = $o->{document}->get($o) // return;
Condition0%0/2
$o->{"document"}->get($o) // (return)
l!l
00
MC/DC0%0/1
$o->{"document"}->get($o) // (return)
$o->{"document"}->get($o)
Truth table0%0/2
A
A= $o->{"document"}->get($o)
Aresult
11
00
15660 0 return scalar $item->{record}->children > 0;
15661 }
15662  
15663 sub record {
15664 0 ▶ my $o = shift;
Subroutine record: not called CC=2 SCAR=17.9
15665  
15666 0 ▶ my $item = $o->{document}->get($o) // return CDS::Record->new;
Condition0%0/2
$o->{"document"}->get($o) // (return "CDS::Record"->new)
l!l
00
MC/DC0%0/1
$o->{"document"}->get($o) // (return "CDS::Record"->new)
$o->{"document"}->get($o)
Truth table0%0/2
A
A= $o->{"document"}->get($o)
Aresult
11
00
15667 0 return $item->{record};
15668 }
15669  
15670 sub set {
15671 0 ▶ my $o = shift;
Subroutine set: not called CC=5 SCAR=34.0
15672 0 ▶ my $record = shift // return; die 'wrong type '.ref($record).' for $record' if defined $record && ref $record ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $record and ref $record ne "CDS::Record" 0 0 0
Condition0%0/5
shift() // (return)
l!l
00
defined $record and ref $record ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/1
shift() // (return)
shift()
MC/DC0%0/2
defined $record and ref $record ne "CDS::Record"
defined $record ref $record ne "CDS::Record"
Truth table0%0/2
A
A= shift()
Aresult
11
00
Truth table0%0/3
A and B
A= defined $recordB= ref $record ne "CDS::Record"
ABresult
0X0
100
111
15673  
15674 0 my $now = CDS->now;
15675 0 my $item = $o->{document}->getOrCreate($o);
15676 0 ▶ $item->mergeValue($o->{document}->{changes}, $item->{revision} >= $now ? $item->{revision} + 1 : $now, $record);
Branch: 1 branch
BranchTrueFalseTotal
$item->{'revision'} >= $now ? : 0 0 0
15677 }
15678  
15679 sub merge {
15680 0 ▶ my $o = shift;
Subroutine merge: not called CC=4 SCAR=30.0
15681 0 my $revision = shift;
15682 0 ▶ my $record = shift // return; die 'wrong type '.ref($record).' for $record' if defined $record && ref $record ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $record and ref $record ne "CDS::Record" 0 0 0
Condition0%0/5
shift() // (return)
l!l
00
defined $record and ref $record ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/1
shift() // (return)
shift()
MC/DC0%0/2
defined $record and ref $record ne "CDS::Record"
defined $record ref $record ne "CDS::Record"
Truth table0%0/2
A
A= shift()
Aresult
11
00
Truth table0%0/3
A and B
A= defined $recordB= ref $record ne "CDS::Record"
ABresult
0X0
100
111
15683  
15684 0 my $item = $o->{document}->getOrCreate($o);
15685 0 return $item->mergeValue($o->{document}->{changes}, $revision, $record);
15686 }
15687  
15688 sub clear {
15689 0 ▶ my $o = shift;
Subroutine clear: not called CC=1 SCAR=6.9
15690 0 $o->set(CDS::Record->new) }
15691  
15692 sub clearInThePast {
15693 0 ▶ my $o = shift;
Subroutine clearInThePast: not called CC=2 SCAR=17.9
15694  
15695 0 ▶ $o->merge($o->revision + 1, CDS::Record->new) if $o->isSet;
Branch: 1 branch
BranchTrueFalseTotal
if $o->isSet 0 0 0
15696 }
15697  
15698 sub forget {
15699 0 ▶ my $o = shift;
Subroutine forget: not called CC=2 SCAR=17.9
15700  
15701 0 ▶ my $item = $o->{document}->get($o) // return;
Condition0%0/2
$o->{"document"}->get($o) // (return)
l!l
00
MC/DC0%0/1
$o->{"document"}->get($o) // (return)
$o->{"document"}->get($o)
Truth table0%0/2
A
A= $o->{"document"}->get($o)
Aresult
11
00
15702 0 $item->forget;
15703 }
15704  
15705 sub forgetBranch {
15706 0 ▶ my $o = shift;
Subroutine forgetBranch: not called CC=2 SCAR=17.9
15707  
15708 0 for my $child ($o->children) { $child->forgetBranch; }
15709 0 $o->forget;
15710 }
15711  
15712 # Convenience methods (simple interface)
15713  
15714 sub firstValue {
15715 0 ▶ my $o = shift;
Subroutine firstValue: not called CC=2 SCAR=17.9
15716  
15717 0 ▶ my $item = $o->{document}->get($o) // return CDS::Record->new;
Condition0%0/2
$o->{"document"}->get($o) // (return "CDS::Record"->new)
l!l
00
MC/DC0%0/1
$o->{"document"}->get($o) // (return "CDS::Record"->new)
$o->{"document"}->get($o)
Truth table0%0/2
A
A= $o->{"document"}->get($o)
Aresult
11
00
15718 0 return $item->{record}->firstChild;
15719 }
15720  
15721 sub bytesValue {
15722 0 ▶ my $o = shift;
Subroutine bytesValue: not called CC=1 SCAR=6.9
15723 0 $o->firstValue->bytes }
15724 sub hashValue {
15725 0 ▶ my $o = shift;
Subroutine hashValue: not called CC=1 SCAR=6.9
15726 0 $o->firstValue->hash }
15727 sub textValue {
15728 0 ▶ my $o = shift;
Subroutine textValue: not called CC=1 SCAR=6.9
15729 0 $o->firstValue->asText }
15730 sub booleanValue {
15731 0 ▶ my $o = shift;
Subroutine booleanValue: not called CC=1 SCAR=6.9
15732 0 $o->firstValue->asBoolean }
15733 sub integerValue {
15734 0 ▶ my $o = shift;
Subroutine integerValue: not called CC=1 SCAR=6.9
15735 0 $o->firstValue->asInteger }
15736 sub unsignedValue {
15737 0 ▶ my $o = shift;
Subroutine unsignedValue: not called CC=1 SCAR=6.9
15738 0 $o->firstValue->asUnsigned }
15739 sub floatValue {
15740 0 ▶ my $o = shift;
Subroutine floatValue: not called CC=1 SCAR=6.9
15741 0 $o->firstValue->asFloat }
15742 sub hashAndKeyValue {
15743 0 ▶ my $o = shift;
Subroutine hashAndKeyValue: not called CC=1 SCAR=6.9
15744 0 $o->firstValue->asHashAndKey }
15745  
15746 # Sets a new value unless the node has that value already.
15747 sub setBytes {
15748 0 ▶ my $o = shift;
Subroutine setBytes: not called CC=3 SCAR=24.8
15749 0 my $bytes = shift;
15750 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
15751  
15752 0 my $record = CDS::Record->new;
15753 0 $record->add($bytes, $hash);
15754 0 $o->set($record);
15755 }
15756  
15757 sub setHash {
15758 0 ▶ my $o = shift;
Subroutine setHash: not called CC=3 SCAR=24.8
15759 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
15760 0 $o->setBytes('', $hash); };
15761 sub setText {
15762 0 ▶ my $o = shift;
Subroutine setText: not called CC=3 SCAR=24.8
15763 0 my $value = shift;
15764 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
15765 0 $o->setBytes(Encode::encode_utf8($value), $hash); };
15766 sub setBoolean {
15767 0 ▶ my $o = shift;
Subroutine setBoolean: not called CC=3 SCAR=24.8
15768 0 my $value = shift;
15769 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
15770 0 $o->setBytes(CDS->bytesFromBoolean($value), $hash); };
15771 sub setInteger {
15772 0 ▶ my $o = shift;
Subroutine setInteger: not called CC=3 SCAR=24.8
15773 0 my $value = shift;
15774 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
15775 0 $o->setBytes(CDS->bytesFromInteger($value), $hash); };
15776 sub setUnsigned {
15777 0 ▶ my $o = shift;
Subroutine setUnsigned: not called CC=3 SCAR=24.8
15778 0 my $value = shift;
15779 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
15780 0 $o->setBytes(CDS->bytesFromUnsigned($value), $hash); };
15781 sub setFloat32 {
15782 0 ▶ my $o = shift;
Subroutine setFloat32: not called CC=3 SCAR=24.8
15783 0 my $value = shift;
15784 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
15785 0 $o->setBytes(CDS->bytesFromFloat32($value), $hash); };
15786 sub setFloat64 {
15787 0 ▶ my $o = shift;
Subroutine setFloat64: not called CC=3 SCAR=24.8
15788 0 my $value = shift;
15789 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
15790 0 $o->setBytes(CDS->bytesFromFloat64($value), $hash); };
15791 sub setHashAndKey {
15792 0 ▶ my $o = shift;
Subroutine setHashAndKey: not called CC=3 SCAR=24.8
15793 0 ▶ my $hashAndKey = shift; die 'wrong type '.ref($hashAndKey).' for $hashAndKey' if defined $hashAndKey && ref $hashAndKey ne 'CDS::HashAndKey';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hashAndKey and ref $hashAndKey ne "CDS::HashAndKey" 0 0 0
Condition0%0/3
defined $hashAndKey and ref $hashAndKey ne "CDS::HashAndKey"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hashAndKey and ref $hashAndKey ne "CDS::HashAndKey"
defined $hashAndKey ref $hashAndKey ne "CDS::HashAndKey"
Truth table0%0/3
A and B
A= defined $hashAndKeyB= ref $hashAndKey ne "CDS::HashAndKey"
ABresult
0X0
100
111
15794 0 $o->setBytes($hashAndKey->key, $hashAndKey->hash); };
15795  
15796 # Adding objects and merged sources
15797  
15798 sub addObject {
15799 0 ▶ my $o = shift;
Subroutine addObject: not called CC=5 SCAR=34.0
15800 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
15801 0 ▶ my $object = shift; die 'wrong type '.ref($object).' for $object' if defined $object && ref $object ne 'CDS::Object';
Branch: 1 branch
BranchTrueFalseTotal
if defined $object and ref $object ne "CDS::Object" 0 0 0
Condition0%0/3
defined $object and ref $object ne "CDS::Object"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $object and ref $object ne "CDS::Object"
defined $object ref $object ne "CDS::Object"
Truth table0%0/3
A and B
A= defined $objectB= ref $object ne "CDS::Object"
ABresult
0X0
100
111
15802  
15803 0 $o->{document}->{unsaved}->state->addObject($hash, $object);
15804 }
15805  
15806 sub addMergedSource {
15807 0 ▶ my $o = shift;
Subroutine addMergedSource: not called CC=3 SCAR=24.8
15808 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
15809  
15810 0 $o->{document}->{unsaved}->state->addMergedSource($hash);
15811 }
15812  
15813 package CDS::SentItem;
15814  
15815 1 ▶use parent -norequire, 'CDS::UnionList::Item';
Subroutine BEGIN: called CC=1 SCAR=0.0
15816  
15817 sub new {
15818 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
15819 0 my $unionList = shift;
15820 0 my $id = shift;
15821  
15822 0 my $o = $class->SUPER::new($unionList, $id);
15823 0 $o->{validUntil} = 0;
15824 0 $o->{message} = CDS::Record->new;
15825 0 return $o;
15826 }
15827  
15828 0 ▶sub validUntil { shift->{validUntil} }
Subroutine validUntil: not called CC=1 SCAR=6.9
15829 sub envelopeHash {
15830 0 ▶ my $o = shift;
Subroutine envelopeHash: not called CC=1 SCAR=6.9
15831 0 CDS::Hash->fromBytes($o->{message}->bytes) }
15832 sub envelopeHashBytes {
15833 0 ▶ my $o = shift;
Subroutine envelopeHashBytes: not called CC=1 SCAR=6.9
15834 0 $o->{message}->bytes }
15835 0 ▶sub message { shift->{message} }
Subroutine message: not called CC=1 SCAR=6.9
15836  
15837 sub addToRecord {
15838 0 ▶ my $o = shift;
Subroutine addToRecord: not called CC=3 SCAR=24.8
15839 0 ▶ my $record = shift; die 'wrong type '.ref($record).' for $record' if defined $record && ref $record ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $record and ref $record ne "CDS::Record" 0 0 0
Condition0%0/3
defined $record and ref $record ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $record and ref $record ne "CDS::Record"
defined $record ref $record ne "CDS::Record"
Truth table0%0/3
A and B
A= defined $recordB= ref $record ne "CDS::Record"
ABresult
0X0
100
111
15840  
15841 0 $record->add($o->{id})->addInteger($o->{validUntil})->addRecord($o->{message});
15842 }
15843  
15844 sub set {
15845 0 ▶ my $o = shift;
Subroutine set: not called CC=5 SCAR=34.0
15846 0 my $validUntil = shift;
15847 0 ▶ my $envelopeHash = shift; die 'wrong type '.ref($envelopeHash).' for $envelopeHash' if defined $envelopeHash && ref $envelopeHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $envelopeHash and ref $envelopeHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $envelopeHash and ref $envelopeHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $envelopeHash and ref $envelopeHash ne "CDS::Hash"
defined $envelopeHash ref $envelopeHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $envelopeHashB= ref $envelopeHash ne "CDS::Hash"
ABresult
0X0
100
111
15848 0 ▶ my $messageRecord = shift; die 'wrong type '.ref($messageRecord).' for $messageRecord' if defined $messageRecord && ref $messageRecord ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $messageRecord and ref $messageRecord ne "CDS::Record" 0 0 0
Condition0%0/3
defined $messageRecord and ref $messageRecord ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $messageRecord and ref $messageRecord ne "CDS::Record"
defined $messageRecord ref $messageRecord ne "CDS::Record"
Truth table0%0/3
A and B
A= defined $messageRecordB= ref $messageRecord ne "CDS::Record"
ABresult
0X0
100
111
15849  
15850 0 my $message = CDS::Record->new($envelopeHash->bytes);
15851 0 $message->addRecord($messageRecord->children);
15852 0 $o->merge($o->{unionList}->{changes}, CDS->max($validUntil, $o->{validUntil} + 1), $message);
15853 }
15854  
15855 sub clear {
15856 0 ▶ my $o = shift;
Subroutine clear: not called CC=1 SCAR=6.9
15857 0 my $validUntil = shift;
15858  
15859 0 $o->merge($o->{unionList}->{changes}, CDS->max($validUntil, $o->{validUntil} + 1), CDS::Record->new);
15860 }
15861  
15862 sub merge {
15863 0 ▶ my $o = shift;
Subroutine merge: not called CC=4 SCAR=30.0
15864 0 my $part = shift;
15865 0 my $validUntil = shift;
15866 0 my $message = shift;
15867  
15868 0 ▶ return if $o->{validUntil} > $validUntil;
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"validUntil"} > $validUntil 0 0 0
15869 0 ▶ return if $o->{validUntil} == $validUntil && $part->{size} < $o->{part}->{size};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"validUntil"} == $validUntil and $part->{"size"} < $o->{"part"}{"size"} 0 0 0
Condition0%0/3
$o->{"validUntil"} == $validUntil and $part->{"size"} < $o->{"part"}{"size"}
!ll&&!rl&&r
000
MC/DC0%0/2
$o->{"validUntil"} == $validUntil and $part->{"size"} < $o->{"part"}{"size"}
$o->{"validUntil"} == $validUntil $part->{"size"} < $o->{"part"}{"size"}
Truth table0%0/3
A and B
A= $o->{"validUntil"} == $validUntilB= $part->{"size"} < $o->{"part"}{"size"}
ABresult
0X0
100
111
15870 0 $o->{validUntil} = $validUntil;
15871 0 $o->{message} = $message;
15872 0 $o->setPart($part);
15873 }
15874  
15875 package CDS::SentList;
15876  
15877 1 ▶use parent -norequire, 'CDS::UnionList';
Subroutine BEGIN: called CC=1 SCAR=0.0
15878  
15879 sub new {
15880 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
15881 0 my $privateRoot = shift;
15882  
15883 0 return $class->SUPER::new($privateRoot, 'sent list');
15884 }
15885  
15886 sub createItem {
15887 0 ▶ my $o = shift;
Subroutine createItem: not called CC=1 SCAR=6.9
15888 0 my $id = shift;
15889  
15890 0 return CDS::SentItem->new($o, $id);
15891 }
15892  
15893 sub mergeRecord {
15894 0 ▶ my $o = shift;
Subroutine mergeRecord: not called CC=4 SCAR=30.0
15895 0 my $part = shift;
15896 0 ▶ my $record = shift; die 'wrong type '.ref($record).' for $record' if defined $record && ref $record ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $record and ref $record ne "CDS::Record" 0 0 0
Condition0%0/3
defined $record and ref $record ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $record and ref $record ne "CDS::Record"
defined $record ref $record ne "CDS::Record"
Truth table0%0/3
A and B
A= defined $recordB= ref $record ne "CDS::Record"
ABresult
0X0
100
111
15897  
15898 0 my $item = $o->getOrCreate($record->bytes);
15899 0 for my $child ($record->children) {
15900 0 my $validUntil = $child->asInteger;
15901 0 my $message = $child->firstChild;
15902 0 $item->merge($part, $validUntil, $message);
15903 }
15904 }
15905  
15906 sub forgetObsoleteItems {
15907 0 ▶ my $o = shift;
Subroutine forgetObsoleteItems: not called CC=3 SCAR=24.8
15908  
15909 0 my $now = CDS->now;
15910 0 my $toDelete = [];
15911 0 for my $item (values %{$o->{items}}) {
15912 0 ▶ next if $item->{validUntil} >= $now;
Branch: 1 branch
BranchTrueFalseTotal
if $item->{"validUntil"} >= $now 0 0 0
15913 0 $o->forgetItem($item);
15914 }
15915 }
15916  
15917 package CDS::Source;
15918  
15919 sub new {
15920 0 ▶ my $class = shift;
Subroutine new: not called CC=7 SCAR=40.3
15921 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
15922 0 ▶ my $actorOnStore = shift; die 'wrong type '.ref($actorOnStore).' for $actorOnStore' if defined $actorOnStore && ref $actorOnStore ne 'CDS::ActorOnStore';
Branch: 1 branch
BranchTrueFalseTotal
if defined $actorOnStore and ref $actorOnStore ne "CDS::ActorOnStore" 0 0 0
Condition0%0/3
defined $actorOnStore and ref $actorOnStore ne "CDS::ActorOnStore"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $actorOnStore and ref $actorOnStore ne "CDS::ActorOnStore"
defined $actorOnStore ref $actorOnStore ne "CDS::ActorOnStore"
Truth table0%0/3
A and B
A= defined $actorOnStoreB= ref $actorOnStore ne "CDS::ActorOnStore"
ABresult
0X0
100
111
15923 0 my $boxLabel = shift;
15924 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
15925  
15926 0 return bless {
15927 keyPair => $keyPair,
15928 actorOnStore => $actorOnStore,
15929 boxLabel => $boxLabel,
15930 hash => $hash,
15931 referenceCount => 1,
15932 };
15933 }
15934  
15935 0 ▶sub keyPair { shift->{keyPair} }
Subroutine keyPair: not called CC=1 SCAR=6.9
15936 0 ▶sub actorOnStore { shift->{actorOnStore} }
Subroutine actorOnStore: not called CC=1 SCAR=6.9
15937 0 ▶sub boxLabel { shift->{boxLabel} }
Subroutine boxLabel: not called CC=1 SCAR=6.9
15938 0 ▶sub hash { shift->{hash} }
Subroutine hash: not called CC=1 SCAR=6.9
15939 0 ▶sub referenceCount { shift->{referenceCount} }
Subroutine referenceCount: not called CC=1 SCAR=6.9
15940  
15941 sub keep {
15942 0 ▶ my $o = shift;
Subroutine keep: not called CC=2 SCAR=17.9
15943  
15944 0 ▶ if ($o->{referenceCount} < 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"referenceCount"} < 1) 0 0 0
15945 0 warn 'The source '.$o->{actorOnStore}->publicKey->hash->hex.'/'.$o->{boxLabel}.'/'.$o->{hash}->hex.' has already been discarded, and cannot be kept any more.';
15946 0 return;
15947 }
15948  
15949 0 $o->{referenceCount} += 1;
15950 }
15951  
15952 sub discard {
15953 0 ▶ my $o = shift;
Subroutine discard: not called CC=3 SCAR=24.8
15954  
15955 0 ▶ if ($o->{referenceCount} < 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"referenceCount"} < 1) 0 0 0
15956 0 warn 'The source '.$o->{actorOnStore}->publicKey->hash->hex.'/'.$o->{boxLabel}.'/'.$o->{hash}->hex.' has already been discarded, and cannot be discarded again.';
15957 0 return;
15958 }
15959  
15960 0 $o->{referenceCount} -= 1;
15961 0 ▶ return if $o->{referenceCount} > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"referenceCount"} > 0 0 0 0
15962  
15963 0 $o->{actorOnStore}->store->remove($o->{actorOnStore}->publicKey->hash, $o->{boxLabel}, $o->{hash}, $o->{keyPair});
15964 }
15965  
15966 # A store mapping objects and accounts to a group of stores.
15967 package CDS::SplitStore;
15968  
15969 1 ▶use parent -norequire, 'CDS::Store';
Subroutine BEGIN: called CC=1 SCAR=0.0
15970  
15971 sub new {
15972 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
15973 0 my $key = shift;
15974  
15975 0 return bless {
15976 id => 'Split Store\n'.unpack('H*', CDS::C::aesCrypt(CDS->zeroCTR, $key, CDS->zeroCTR)),
15977 key => $key,
15978 accountStores => [],
15979 objectStores => [],
15980 };
15981 }
15982  
15983 0 ▶sub id { shift->{id} }
Subroutine id: not called CC=1 SCAR=6.9
15984  
15985 ### Store configuration
15986  
15987 sub assignAccounts {
15988 0 ▶ my $o = shift;
Subroutine assignAccounts: not called CC=2 SCAR=17.9
15989 0 my $fromIndex = shift;
15990 0 my $toIndex = shift;
15991 0 my $store = shift;
15992  
15993 0 for my $i ($fromIndex .. $toIndex) {
15994 0 $o->{accountStores}->[$i] = $store;
15995 }
15996 }
15997  
15998 sub assignObjects {
15999 0 ▶ my $o = shift;
Subroutine assignObjects: not called CC=2 SCAR=17.9
16000 0 my $fromIndex = shift;
16001 0 my $toIndex = shift;
16002 0 my $store = shift;
16003  
16004 0 for my $i ($fromIndex .. $toIndex) {
16005 0 $o->{objectStores}->[$i] = $store;
16006 }
16007 }
16008  
16009 sub objectStore {
16010 0 ▶ my $o = shift;
Subroutine objectStore: not called CC=1 SCAR=6.9
16011 0 my $index = shift;
16012 0 $o->{objectStores}->[$index] }
16013 sub accountStore {
16014 0 ▶ my $o = shift;
Subroutine accountStore: not called CC=1 SCAR=6.9
16015 0 my $index = shift;
16016 0 $o->{accountStores}->[$index] }
16017  
16018 ### Hash encryption
16019  
16020 1 our $zeroCounter = "\0" x 16;
16021  
16022 sub storeIndex {
16023 0 ▶ my $o = shift;
Subroutine storeIndex: not called CC=3 SCAR=24.8
16024 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
16025  
16026 # To avoid attacks on a single store, the hash is encrypted with a key known to the operator only
16027 0 my $encryptedBytes = CDS::C::aesCrypt(substr($hash->bytes, 0, 16), $o->{key}, $zeroCounter);
16028  
16029 # Use the first byte as store index
16030 0 return ord(substr($encryptedBytes, 0, 1));
16031 }
16032  
16033 ### Store interface
16034  
16035 sub get {
16036 0 ▶ my $o = shift;
Subroutine get: not called CC=6 SCAR=37.4
16037 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
16038 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
16039  
16040 0 ▶ my $store = $o->objectStore($o->storeIndex($hash)) // return undef, 'No store assigned.';
Condition0%0/2
$o->objectStore($o->storeIndex($hash)) // (return undef, "No store assigned.")
l!l
00
MC/DC0%0/1
$o->objectStore($o->storeIndex($hash)) // (return undef, "No store assigned.")
$o->objectStore($o->storeIndex($hash))
Truth table0%0/2
A
A= $o->objectStore($o->storeIndex($hash))
Aresult
11
00
16041 0 return $store->get($hash, $keyPair);
16042 }
16043  
16044 sub put {
16045 0 ▶ my $o = shift;
Subroutine put: not called CC=8 SCAR=42.8
16046 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
16047 0 ▶ my $object = shift; die 'wrong type '.ref($object).' for $object' if defined $object && ref $object ne 'CDS::Object';
Branch: 1 branch
BranchTrueFalseTotal
if defined $object and ref $object ne "CDS::Object" 0 0 0
Condition0%0/3
defined $object and ref $object ne "CDS::Object"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $object and ref $object ne "CDS::Object"
defined $object ref $object ne "CDS::Object"
Truth table0%0/3
A and B
A= defined $objectB= ref $object ne "CDS::Object"
ABresult
0X0
100
111
16048 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
16049  
16050 0 ▶ my $store = $o->objectStore($o->storeIndex($hash)) // return undef, 'No store assigned.';
Condition0%0/2
$o->objectStore($o->storeIndex($hash)) // (return undef, "No store assigned.")
l!l
00
MC/DC0%0/1
$o->objectStore($o->storeIndex($hash)) // (return undef, "No store assigned.")
$o->objectStore($o->storeIndex($hash))
Truth table0%0/2
A
A= $o->objectStore($o->storeIndex($hash))
Aresult
11
00
16051 0 return $store->put($hash, $object, $keyPair);
16052 }
16053  
16054 sub book {
16055 0 ▶ my $o = shift;
Subroutine book: not called CC=6 SCAR=37.4
16056 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
16057 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
16058  
16059 0 ▶ my $store = $o->objectStore($o->storeIndex($hash)) // return undef, 'No store assigned.';
Condition0%0/2
$o->objectStore($o->storeIndex($hash)) // (return undef, "No store assigned.")
l!l
00
MC/DC0%0/1
$o->objectStore($o->storeIndex($hash)) // (return undef, "No store assigned.")
$o->objectStore($o->storeIndex($hash))
Truth table0%0/2
A
A= $o->objectStore($o->storeIndex($hash))
Aresult
11
00
16060 0 return $store->book($hash, $keyPair);
16061 }
16062  
16063 sub list {
16064 0 ▶ my $o = shift;
Subroutine list: not called CC=6 SCAR=37.4
16065 0 ▶ my $accountHash = shift; die 'wrong type '.ref($accountHash).' for $accountHash' if defined $accountHash && ref $accountHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $accountHash and ref $accountHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $accountHash and ref $accountHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $accountHash and ref $accountHash ne "CDS::Hash"
defined $accountHash ref $accountHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $accountHashB= ref $accountHash ne "CDS::Hash"
ABresult
0X0
100
111
16066 0 my $boxLabel = shift;
16067 0 my $timeout = shift;
16068 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
16069  
16070 0 ▶ my $store = $o->accountStore($o->storeIndex($accountHash)) // return undef, 'No store assigned.';
Condition0%0/2
$o->accountStore($o->storeIndex($accountHash)) // (return undef, "No store assigned.")
l!l
00
MC/DC0%0/1
$o->accountStore($o->storeIndex($accountHash)) // (return undef, "No store assigned.")
$o->accountStore($o->storeIndex($accountHash))
Truth table0%0/2
A
A= $o->accountStore($o->storeIndex($accountHash))
Aresult
11
00
16071 0 return $store->list($accountHash, $boxLabel, $timeout, $keyPair);
16072 }
16073  
16074 sub add {
16075 0 ▶ my $o = shift;
Subroutine add: not called CC=8 SCAR=42.8
16076 0 ▶ my $accountHash = shift; die 'wrong type '.ref($accountHash).' for $accountHash' if defined $accountHash && ref $accountHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $accountHash and ref $accountHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $accountHash and ref $accountHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $accountHash and ref $accountHash ne "CDS::Hash"
defined $accountHash ref $accountHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $accountHashB= ref $accountHash ne "CDS::Hash"
ABresult
0X0
100
111
16077 0 my $boxLabel = shift;
16078 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
16079 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
16080  
16081 0 ▶ my $store = $o->accountStore($o->storeIndex($accountHash)) // return 'No store assigned.';
Condition0%0/2
$o->accountStore($o->storeIndex($accountHash)) // (return "No store assigned.")
l!l
00
MC/DC0%0/1
$o->accountStore($o->storeIndex($accountHash)) // (return "No store assigned.")
$o->accountStore($o->storeIndex($accountHash))
Truth table0%0/2
A
A= $o->accountStore($o->storeIndex($accountHash))
Aresult
11
00
16082 0 return $store->add($accountHash, $boxLabel, $hash, $keyPair);
16083 }
16084  
16085 sub remove {
16086 0 ▶ my $o = shift;
Subroutine remove: not called CC=8 SCAR=42.8
16087 0 ▶ my $accountHash = shift; die 'wrong type '.ref($accountHash).' for $accountHash' if defined $accountHash && ref $accountHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $accountHash and ref $accountHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $accountHash and ref $accountHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $accountHash and ref $accountHash ne "CDS::Hash"
defined $accountHash ref $accountHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $accountHashB= ref $accountHash ne "CDS::Hash"
ABresult
0X0
100
111
16088 0 my $boxLabel = shift;
16089 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
16090 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
16091  
16092 0 ▶ my $store = $o->accountStore($o->storeIndex($accountHash)) // return 'No store assigned.';
Condition0%0/2
$o->accountStore($o->storeIndex($accountHash)) // (return "No store assigned.")
l!l
00
MC/DC0%0/1
$o->accountStore($o->storeIndex($accountHash)) // (return "No store assigned.")
$o->accountStore($o->storeIndex($accountHash))
Truth table0%0/2
A
A= $o->accountStore($o->storeIndex($accountHash))
Aresult
11
00
16093 0 return $store->remove($accountHash, $boxLabel, $hash, $keyPair);
16094 }
16095  
16096 sub modify {
16097 0 ▶ my $o = shift;
Subroutine modify: not called CC=11 SCAR=48.8
16098 0 my $modifications = shift;
16099 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
16100  
16101 # Put objects
16102 0 my %objectsByStoreId;
16103 0 for my $entry (values %{$modifications->objects}) {
16104 0 my $store = $o->objectStore($o->storeIndex($entry->{hash}));
16105 0 my $target = $objectsByStoreId{$store->id};
16106 0 $objectsByStoreId{$store->id} = $target = {store => $store, modifications => CDS::StoreModifications->new};
16107 0 $target->modifications->put($entry->{hash}, $entry->{object});
16108 }
16109  
16110 0 for my $item (values %objectsByStoreId) {
16111 0 my $error = $item->{store}->modify($item->{modifications}, $keyPair);
16112 0 ▶ return $error if $error;
Branch: 1 branch
BranchTrueFalseTotal
if $error 0 0 0
16113 }
16114  
16115 # Add box entries
16116 0 my %additionsByStoreId;
16117 0 for my $operation (@{$modifications->additions}) {
16118 0 my $store = $o->accountStore($o->storeIndex($operation->{accountHash}));
16119 0 my $target = $additionsByStoreId{$store->id};
16120 0 $additionsByStoreId{$store->id} = $target = {store => $store, modifications => CDS::StoreModifications->new};
16121 0 $target->modifications->add($operation->{accountHash}, $operation->{boxLabel}, $operation->{hash});
16122 }
16123  
16124 0 for my $item (values %additionsByStoreId) {
16125 0 my $error = $item->{store}->modify($item->{modifications}, $keyPair);
16126 0 ▶ return $error if $error;
Branch: 1 branch
BranchTrueFalseTotal
if $error 0 0 0
16127 }
16128  
16129 # Remove box entries (but ignore errors)
16130 0 my %removalsByStoreId;
16131 0 for my $operation (@$modifications->removals) {
16132 0 my $store = $o->accountStore($o->storeIndex($operation->{accountHash}));
16133 0 my $target = $removalsByStoreId{$store->id};
16134 0 $removalsByStoreId{$store->id} = $target = {store => $store, modifications => CDS::StoreModifications->new};
16135 0 $target->modifications->add($operation->{accountHash}, $operation->{boxLabel}, $operation->{hash});
16136 }
16137  
16138 0 for my $item (values %removalsByStoreId) {
16139 0 $item->{store}->modify($item->{modifications}, $keyPair);
16140 }
16141  
16142 0 return;
16143 }
16144  
16145 # General
16146 # sub id($o) # () => String
16147 package CDS::Store;
16148  
16149 # Object store functions
16150 # sub get($o, $hash, $keyPair) # Hash, KeyPair? => Object?, String?
16151 # sub put($o, $hash, $object, $keyPair) # Hash, Object, KeyPair? => String?
16152 # sub book($o, $hash, $keyPair) # Hash, KeyPair? => 1?, String?
16153  
16154 # Account store functions
16155 # sub list($o, $accountHash, $boxLabel, $timeout, $keyPair) # Hash, String, Duration, KeyPair? => @$Hash, String?
16156 # sub add($o, $accountHash, $boxLabel, $hash, $keyPair) # Hash, String, Hash, KeyPair? => String?
16157 # sub remove($o, $accountHash, $boxLabel, $hash, $keyPair) # Hash, String, Hash, KeyPair? => String?
16158 # sub modify($o, $storeModifications, $keyPair) # StoreModifications, KeyPair? => String?
16159  
16160 package CDS::StoreModifications;
16161  
16162 sub new {
16163 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
16164  
16165 0 return bless {
16166 objects => {},
16167 additions => [],
16168 removals => [],
16169 };
16170 }
16171  
16172 0 ▶sub objects { shift->{objects} }
Subroutine objects: not called CC=1 SCAR=6.9
16173 0 ▶sub additions { shift->{additions} }
Subroutine additions: not called CC=1 SCAR=6.9
16174 0 ▶sub removals { shift->{removals} }
Subroutine removals: not called CC=1 SCAR=6.9
16175  
16176 sub isEmpty {
16177 0 ▶ my $o = shift;
Subroutine isEmpty: not called CC=4 SCAR=30.0
16178  
16179 0 ▶ return if scalar keys %{$o->{objects}};
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %{$$o{"objects"};} 0 0 0
16180 0 ▶ return if scalar @{$o->{additions}};
Branch: 1 branch
BranchTrueFalseTotal
if scalar @{$o->{"additions"};} 0 0 0
16181 0 ▶ return if scalar @{$o->{removals}};
Branch: 1 branch
BranchTrueFalseTotal
if scalar @{$o->{"removals"};} 0 0 0
16182 0 return 1;
16183 }
16184  
16185 sub put {
16186 0 ▶ my $o = shift;
Subroutine put: not called CC=5 SCAR=34.0
16187 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
16188 0 ▶ my $object = shift; die 'wrong type '.ref($object).' for $object' if defined $object && ref $object ne 'CDS::Object';
Branch: 1 branch
BranchTrueFalseTotal
if defined $object and ref $object ne "CDS::Object" 0 0 0
Condition0%0/3
defined $object and ref $object ne "CDS::Object"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $object and ref $object ne "CDS::Object"
defined $object ref $object ne "CDS::Object"
Truth table0%0/3
A and B
A= defined $objectB= ref $object ne "CDS::Object"
ABresult
0X0
100
111
16189  
16190 0 $o->{objects}->{$hash->bytes} = {hash => $hash, object => $object};
16191 }
16192  
16193 sub add {
16194 0 ▶ my $o = shift;
Subroutine add: not called CC=8 SCAR=42.8
16195 0 ▶ my $accountHash = shift; die 'wrong type '.ref($accountHash).' for $accountHash' if defined $accountHash && ref $accountHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $accountHash and ref $accountHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $accountHash and ref $accountHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $accountHash and ref $accountHash ne "CDS::Hash"
defined $accountHash ref $accountHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $accountHashB= ref $accountHash ne "CDS::Hash"
ABresult
0X0
100
111
16196 0 my $boxLabel = shift;
16197 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
16198 0 ▶ my $object = shift; die 'wrong type '.ref($object).' for $object' if defined $object && ref $object ne 'CDS::Object';
Branch: 1 branch
BranchTrueFalseTotal
if defined $object and ref $object ne "CDS::Object" 0 0 0
Condition0%0/3
defined $object and ref $object ne "CDS::Object"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $object and ref $object ne "CDS::Object"
defined $object ref $object ne "CDS::Object"
Truth table0%0/3
A and B
A= defined $objectB= ref $object ne "CDS::Object"
ABresult
0X0
100
111
16199  
16200 0 ▶ $o->put($hash, $object) if $object;
Branch: 1 branch
BranchTrueFalseTotal
if $object 0 0 0
16201 0 push @{$o->{additions}}, {accountHash => $accountHash, boxLabel => $boxLabel, hash => $hash};
16202 }
16203  
16204 sub remove {
16205 0 ▶ my $o = shift;
Subroutine remove: not called CC=5 SCAR=34.0
16206 0 ▶ my $accountHash = shift; die 'wrong type '.ref($accountHash).' for $accountHash' if defined $accountHash && ref $accountHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $accountHash and ref $accountHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $accountHash and ref $accountHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $accountHash and ref $accountHash ne "CDS::Hash"
defined $accountHash ref $accountHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $accountHashB= ref $accountHash ne "CDS::Hash"
ABresult
0X0
100
111
16207 0 my $boxLabel = shift;
16208 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
16209  
16210 0 push @{$o->{removals}}, {accountHash => $accountHash, boxLabel => $boxLabel, hash => $hash};
16211 }
16212  
16213 sub executeIndividually {
16214 0 ▶ my $o = shift;
Subroutine executeIndividually: not called CC=8 SCAR=42.8
16215 0 my $store = shift;
16216 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
16217  
16218 # Process objects
16219 0 for my $entry (values %{$o->{objects}}) {
16220 0 my $error = $store->put($entry->{hash}, $entry->{object}, $keyPair);
16221 0 ▶ return $error if $error;
Branch: 1 branch
BranchTrueFalseTotal
if $error 0 0 0
16222 }
16223  
16224 # Process additions
16225 0 for my $entry (@{$o->{additions}}) {
16226 0 my $error = $store->add($entry->{accountHash}, $entry->{boxLabel}, $entry->{hash}, $keyPair);
16227 0 ▶ return $error if $error;
Branch: 1 branch
BranchTrueFalseTotal
if $error 0 0 0
16228 }
16229  
16230 # Process removals (and ignore errors)
16231 0 for my $entry (@{$o->{removals}}) {
16232 0 $store->remove($entry->{accountHash}, $entry->{boxLabel}, $entry->{hash}, $keyPair);
16233 }
16234  
16235 0 return;
16236 }
16237  
16238 # Returns a text representation of box additions and removals.
16239 sub toRecord {
16240 0 ▶ my $o = shift;
Subroutine toRecord: not called CC=2 SCAR=17.9
16241  
16242 0 my $record = CDS::Record->new;
16243  
16244 # Objects
16245 0 my $objectsRecord = $record->add('put');
16246 0 for my $entry (values %{$o->{objects}}) {
16247 0 $objectsRecord->add($entry->{hash}->bytes)->add($entry->{object}->bytes);
16248 }
16249  
16250 # Box additions and removals
16251 0 &addEntriesToRecord($o->{additions}, $record->add('add'));
16252 0 &addEntriesToRecord($o->{removals}, $record->add('remove'));
16253  
16254 0 return $record;
16255 }
16256  
16257 sub addEntriesToRecord {
16258 0 ▶ my $unsortedEntries = shift;
Subroutine addEntriesToRecord: not called CC=9 SCAR=45.0
16259 0 ▶ my $record = shift; die 'wrong type '.ref($record).' for $record' if defined $record && ref $record ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $record and ref $record ne "CDS::Record" 0 0 0
Condition0%0/3
defined $record and ref $record ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $record and ref $record ne "CDS::Record"
defined $record ref $record ne "CDS::Record"
Truth table0%0/3
A and B
A= defined $recordB= ref $record ne "CDS::Record"
ABresult
0X0
100
111
16260 # private
16261 0 ▶ my @additions = sort { ($a->{accountHash}->bytes cmp $b->{accountHash}->bytes) || ($a->{boxLabel} cmp $b->{boxLabel}) } @$unsortedEntries;
Branch: 1 branch
BranchTrueFalseTotal
$CDS::StoreModifications::a->{"accountHash"}->bytes cmp $CDS::StoreModifications::b->{"accountHash"}->bytes or $CDS::StoreModifications::a->{"boxLabel"} cmp $CDS::StoreModifications::b->{"boxLabel"} 0 0 0
16262 0 my $entry = shift @additions;
16263 0 ▶ while (defined $entry) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $entry) 0 0 0
16264 0 my $accountHash = $entry->{accountHash};
16265 0 my $accountRecord = $record->add($accountHash->bytes);
16266  
16267 0 ▶ while (defined $entry && $entry->{accountHash}->bytes eq $accountHash->bytes) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $entry and $entry->{"accountHash"}->bytes eq $accountHash->bytes) 0 0 0
Condition0%0/3
defined $entry and $entry->{"accountHash"}->bytes eq $accountHash->bytes
!ll&&!rl&&r
000
MC/DC0%0/2
defined $entry and $entry->{"accountHash"}->bytes eq $accountHash->bytes
defined $entry $entry->{"accountHash"}->bytes eq $accountHash->bytes
Truth table0%0/3
A and B
A= defined $entryB= $entry->{"accountHash"}->bytes eq $accountHash->bytes
ABresult
0X0
100
111
16268 0 my $boxLabel = $entry->{boxLabel};
16269 0 my $boxRecord = $accountRecord->add($boxLabel);
16270  
16271 0 ▶ while (defined $entry && $entry->{boxLabel} eq $boxLabel) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $entry and $entry->{"boxLabel"} eq $boxLabel) 0 0 0
Condition0%0/3
defined $entry and $entry->{"boxLabel"} eq $boxLabel
!ll&&!rl&&r
000
MC/DC0%0/2
defined $entry and $entry->{"boxLabel"} eq $boxLabel
defined $entry $entry->{"boxLabel"} eq $boxLabel
Truth table0%0/3
A and B
A= defined $entryB= $entry->{"boxLabel"} eq $boxLabel
ABresult
0X0
100
111
16272 0 $boxRecord->add($entry->{hash}->bytes);
16273 0 $entry = shift @additions;
16274 }
16275 }
16276 }
16277 }
16278  
16279 sub fromBytes {
16280 0 ▶ my $class = shift;
Subroutine fromBytes: not called CC=3 SCAR=24.8
16281 0 my $bytes = shift;
16282  
16283 0 ▶ my $object = CDS::Object->fromBytes($bytes) // return;
Condition0%0/2
"CDS::Object"->fromBytes($bytes) // (return)
l!l
00
MC/DC0%0/1
"CDS::Object"->fromBytes($bytes) // (return)
"CDS::Object"->fromBytes($bytes)
Truth table0%0/2
A
A= "CDS::Object"->fromBytes($bytes)
Aresult
11
00
16284 0 ▶ my $record = CDS::Record->fromObject($object) // return;
Condition0%0/2
"CDS::Record"->fromObject($object) // (return)
l!l
00
MC/DC0%0/1
"CDS::Record"->fromObject($object) // (return)
"CDS::Record"->fromObject($object)
Truth table0%0/2
A
A= "CDS::Record"->fromObject($object)
Aresult
11
00
16285 0 return $class->fromRecord($record);
16286 }
16287  
16288 sub fromRecord {
16289 0 ▶ my $class = shift;
Subroutine fromRecord: not called CC=8 SCAR=42.8
16290 0 ▶ my $record = shift; die 'wrong type '.ref($record).' for $record' if defined $record && ref $record ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $record and ref $record ne "CDS::Record" 0 0 0
Condition0%0/3
defined $record and ref $record ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $record and ref $record ne "CDS::Record"
defined $record ref $record ne "CDS::Record"
Truth table0%0/3
A and B
A= defined $recordB= ref $record ne "CDS::Record"
ABresult
0X0
100
111
16291  
16292 0 my $modifications = $class->new;
16293  
16294 # Read objects (and "envelopes" entries used before 2022-01)
16295 0 for my $objectRecord ($record->child('put')->children, $record->child('envelopes')->children) {
16296 0 ▶ my $hash = CDS::Hash->fromBytes($objectRecord->bytes) // return;
Condition0%0/2
"CDS::Hash"->fromBytes($objectRecord->bytes) // (return)
l!l
00
MC/DC0%0/1
"CDS::Hash"->fromBytes($objectRecord->bytes) // (return)
"CDS::Hash"->fromBytes($objectRecord->bytes)
Truth table0%0/2
A
A= "CDS::Hash"->fromBytes($objectRecord->bytes)
Aresult
11
00
16297 0 ▶ my $object = CDS::Object->fromBytes($objectRecord->firstChild->bytes) // return;
Condition0%0/2
"CDS::Object"->fromBytes($objectRecord->firstChild->bytes) // (return)
l!l
00
MC/DC0%0/1
"CDS::Object"->fromBytes($objectRecord->firstChild->bytes) // (return)
"CDS::Object"->fromBytes($objectRecord->firstChild->bytes)
Truth table0%0/2
A
A= "CDS::Object"->fromBytes($objectRecord->firstChild->bytes)
Aresult
11
00
16298 #return if $o->{checkEnvelopeHash} && ! $object->calculateHash->equals($hash);
16299 0 $modifications->put($hash, $object);
16300 }
16301  
16302 # Read additions and removals
16303 0 ▶ &readEntriesFromRecord($modifications->{additions}, $record->child('add')) // return;
Condition0%0/2
&readEntriesFromRecord($modifications->{"additions"}, $record->child("add")) // (return)
l!l
00
MC/DC0%0/1
&readEntriesFromRecord($modifications->{"additions"}, $record->child("add")) // (return)
&readEntriesFromRecord($modifications->{"additions"}, $record->child("add"))
Truth table0%0/2
A
A= &readEntriesFromRecord($modifications->{"additions"}, $record->child("add"))
Aresult
11
00
16304 0 ▶ &readEntriesFromRecord($modifications->{removals}, $record->child('remove')) // return;
Condition0%0/2
&readEntriesFromRecord($modifications->{"removals"}, $record->child("remove")) // (return)
l!l
00
MC/DC0%0/1
&readEntriesFromRecord($modifications->{"removals"}, $record->child("remove")) // (return)
&readEntriesFromRecord($modifications->{"removals"}, $record->child("remove"))
Truth table0%0/2
A
A= &readEntriesFromRecord($modifications->{"removals"}, $record->child("remove"))
Aresult
11
00
16305  
16306 0 return $modifications;
16307 }
16308  
16309 sub readEntriesFromRecord {
16310 0 ▶ my $entries = shift;
Subroutine readEntriesFromRecord: not called CC=9 SCAR=45.0
16311 0 ▶ my $record = shift; die 'wrong type '.ref($record).' for $record' if defined $record && ref $record ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $record and ref $record ne "CDS::Record" 0 0 0
Condition0%0/3
defined $record and ref $record ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $record and ref $record ne "CDS::Record"
defined $record ref $record ne "CDS::Record"
Truth table0%0/3
A and B
A= defined $recordB= ref $record ne "CDS::Record"
ABresult
0X0
100
111
16312 # private
16313 0 for my $accountHashRecord ($record->children) {
16314 0 ▶ my $accountHash = CDS::Hash->fromBytes($accountHashRecord->bytes) // return;
Condition0%0/2
"CDS::Hash"->fromBytes($accountHashRecord->bytes) // (return)
l!l
00
MC/DC0%0/1
"CDS::Hash"->fromBytes($accountHashRecord->bytes) // (return)
"CDS::Hash"->fromBytes($accountHashRecord->bytes)
Truth table0%0/2
A
A= "CDS::Hash"->fromBytes($accountHashRecord->bytes)
Aresult
11
00
16315 0 for my $boxLabelRecord ($accountHashRecord->children) {
16316 0 my $boxLabel = $boxLabelRecord->bytes;
16317 0 ▶ return if ! CDS->isValidBoxLabel($boxLabel);
Branch: 1 branch
BranchTrueFalseTotal
unless "CDS"->isValidBoxLabel($boxLabel) 0 0 0
16318  
16319 0 for my $hashRecord ($boxLabelRecord->children) {
16320 0 ▶ my $hash = CDS::Hash->fromBytes($hashRecord->bytes) // return;
Condition0%0/2
"CDS::Hash"->fromBytes($hashRecord->bytes) // (return)
l!l
00
MC/DC0%0/1
"CDS::Hash"->fromBytes($hashRecord->bytes) // (return)
"CDS::Hash"->fromBytes($hashRecord->bytes)
Truth table0%0/2
A
A= "CDS::Hash"->fromBytes($hashRecord->bytes)
Aresult
11
00
16321 0 push @$entries, {accountHash => $accountHash, boxLabel => $boxLabel, hash => $hash};
16322 }
16323 }
16324 }
16325  
16326 0 return 1;
16327 }
16328  
16329 package CDS::StreamCache;
16330  
16331 sub new {
16332 0 ▶ my $class = shift;
Subroutine new: not called CC=3 SCAR=24.8
16333 0 my $pool = shift;
16334 0 ▶ my $actorOnStore = shift; die 'wrong type '.ref($actorOnStore).' for $actorOnStore' if defined $actorOnStore && ref $actorOnStore ne 'CDS::ActorOnStore';
Branch: 1 branch
BranchTrueFalseTotal
if defined $actorOnStore and ref $actorOnStore ne "CDS::ActorOnStore" 0 0 0
Condition0%0/3
defined $actorOnStore and ref $actorOnStore ne "CDS::ActorOnStore"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $actorOnStore and ref $actorOnStore ne "CDS::ActorOnStore"
defined $actorOnStore ref $actorOnStore ne "CDS::ActorOnStore"
Truth table0%0/3
A and B
A= defined $actorOnStoreB= ref $actorOnStore ne "CDS::ActorOnStore"
ABresult
0X0
100
111
16335 0 my $timeout = shift;
16336  
16337 0 return bless {
16338 pool => $pool,
16339 actorOnStore => $actorOnStore,
16340 timeout => $timeout,
16341 cache => {},
16342 };
16343 }
16344  
16345 0 ▶sub messageBoxReader { shift->{messageBoxReader} }
Subroutine messageBoxReader: not called CC=1 SCAR=6.9
16346  
16347 sub removeObsolete {
16348 0 ▶ my $o = shift;
Subroutine removeObsolete: not called CC=4 SCAR=30.0
16349  
16350 0 my $limit = CDS->now - $o->{timeout};
16351 0 for my $key (%{$o->{knownStreamHeads}}) {
16352 0 ▶ my $streamHead = $o->{knownStreamHeads}->{$key} // next;
Condition0%0/2
$o->{"knownStreamHeads"}{$key} // (next)
l!l
00
MC/DC0%0/1
$o->{"knownStreamHeads"}{$key} // (next)
$o->{"knownStreamHeads"}{$key}
Truth table0%0/2
A
A= $o->{"knownStreamHeads"}{$key}
Aresult
11
00
16353 0 ▶ next if $streamHead->lastUsed < $limit;
Branch: 1 branch
BranchTrueFalseTotal
if $streamHead->lastUsed < $limit 0 0 0
16354 0 delete $o->{knownStreamHeads}->{$key};
16355 }
16356 }
16357  
16358 sub readStreamHead {
16359 0 ▶ my $o = shift;
Subroutine readStreamHead: not called CC=14 SCAR=53.5
16360 0 my $head = shift;
16361  
16362 0 my $streamHead = $o->{knownStreamHeads}->{$head->hex};
16363 0 ▶ if ($streamHead) {
Branch: 1 branch
BranchTrueFalseTotal
if ($streamHead) 0 0 0
16364 0 $streamHead->stillInUse;
16365 0 return $streamHead;
16366 }
16367  
16368 # Retrieve the head envelope
16369 0 my ($object, $getError) = $o->{actorOnStore}->store->get($head, $o->{pool}->{keyPair});
16370 0 ▶ return if defined $getError;
Branch: 1 branch
BranchTrueFalseTotal
if defined $getError 0 0 0
16371  
16372 # Parse the head envelope
16373 0 my $envelope = CDS::Record->fromObject($object);
16374 0 ▶ return $o->invalid($head, 'Not a record.') if ! $envelope;
Branch: 1 branch
BranchTrueFalseTotal
unless $envelope 0 0 0
16375  
16376 # Read the embedded content object
16377 0 my $encryptedBytes = $envelope->child('content')->bytesValue;
16378 0 ▶ return $o->invalid($head, 'Missing content object.') if ! length $encryptedBytes;
Branch: 1 branch
BranchTrueFalseTotal
unless length $encryptedBytes 0 0 0
16379  
16380 # Decrypt the key
16381 0 my $aesKey = $o->{pool}->{keyPair}->decryptKeyOnEnvelope($envelope);
16382 0 ▶ return $o->invalid($head, 'Not encrypted for us.') if ! $aesKey;
Branch: 1 branch
BranchTrueFalseTotal
unless $aesKey 0 0 0
16383  
16384 # Decrypt the content
16385 0 my $contentObject = CDS::Object->fromBytes(CDS::C::aesCrypt($encryptedBytes, $aesKey, CDS->zeroCTR));
16386 0 ▶ return $o->invalid($head, 'Invalid content object.') if ! $contentObject;
Branch: 1 branch
BranchTrueFalseTotal
unless $contentObject 0 0 0
16387  
16388 0 my $content = CDS::Record->fromObject($contentObject);
16389 0 ▶ return $o->invalid($head, 'Content object is not a record.') if ! $content;
Branch: 1 branch
BranchTrueFalseTotal
unless $content 0 0 0
16390  
16391 # Verify the sender hash
16392 0 my $senderHash = $content->child('sender')->hashValue;
16393 0 ▶ return $o->invalid($head, 'Missing sender hash.') if ! $senderHash;
Branch: 1 branch
BranchTrueFalseTotal
unless $senderHash 0 0 0
16394  
16395 # Verify the sender store
16396 0 my $storeRecord = $content->child('store');
16397 0 ▶ return $o->invalid($head, 'Missing sender store.') if ! scalar $storeRecord->children;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar $storeRecord->children 0 0 0
16398  
16399 0 my $senderStoreUrl = $storeRecord->textValue;
16400 0 my $senderStore = $o->{pool}->{delegate}->onMessageBoxVerifyStore($senderStoreUrl, $head, $envelope, $senderHash);
16401 0 ▶ return $o->invalid($head, 'Invalid sender store.') if ! $senderStore;
Branch: 1 branch
BranchTrueFalseTotal
unless $senderStore 0 0 0
16402  
16403 # Retrieve the sender's public key
16404 0 my ($senderPublicKey, $invalidReason, $publicKeyStoreError) = $o->getPublicKey($senderHash, $senderStore);
16405 0 ▶ return if defined $publicKeyStoreError;
Branch: 1 branch
BranchTrueFalseTotal
if defined $publicKeyStoreError 0 0 0
16406 0 ▶ return $o->invalid($head, 'Failed to retrieve the sender\'s public key: '.$invalidReason) if defined $invalidReason;
Branch: 1 branch
BranchTrueFalseTotal
if defined $invalidReason 0 0 0
16407  
16408 # Verify the signature
16409 0 my $signedHash = CDS::Hash->calculateFor($encryptedBytes);
16410 0 ▶ return $o->invalid($head, 'Invalid signature.') if ! CDS->verifyEnvelopeSignature($envelope, $senderPublicKey, $signedHash);
Branch: 1 branch
BranchTrueFalseTotal
unless "CDS"->verifyEnvelopeSignature($envelope, $senderPublicKey, $signedHash) 0 0 0
16411  
16412 # The envelope is valid
16413 0 my $sender = CDS::ActorOnStore->new($senderPublicKey, $senderStore);
16414 0 my $newStreamHead = CDS::StreamHead->new($head, $envelope, $senderStoreUrl, $sender, $aesKey, $content);
16415 0 $o->{knownStreamHeads}->{$head->hex} = $newStreamHead;
16416 0 return $newStreamHead;
16417 }
16418  
16419 sub invalid {
16420 0 ▶ my $o = shift;
Subroutine invalid: not called CC=1 SCAR=6.9
16421 0 my $head = shift;
16422 0 my $reason = shift;
16423 # private
16424 0 my $newStreamHead = CDS::StreamHead->new($head, undef, undef, undef, undef, undef, $reason);
16425 0 $o->{knownStreamHeads}->{$head->hex} = $newStreamHead;
16426 0 return $newStreamHead;
16427 }
16428  
16429 package CDS::StreamHead;
16430  
16431 sub new {
16432 0 ▶ my $class = shift;
Subroutine new: not called CC=5 SCAR=34.0
16433 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
16434 0 ▶ my $envelope = shift; die 'wrong type '.ref($envelope).' for $envelope' if defined $envelope && ref $envelope ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $envelope and ref $envelope ne "CDS::Record" 0 0 0
Condition0%0/3
defined $envelope and ref $envelope ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $envelope and ref $envelope ne "CDS::Record"
defined $envelope ref $envelope ne "CDS::Record"
Truth table0%0/3
A and B
A= defined $envelopeB= ref $envelope ne "CDS::Record"
ABresult
0X0
100
111
16435 0 my $senderStoreUrl = shift;
16436 0 my $sender = shift;
16437 0 my $content = shift;
16438 0 my $error = shift;
16439  
16440 0 return bless {
16441 hash => $hash,
16442 envelope => $envelope,
16443 senderStoreUrl => $senderStoreUrl,
16444 sender => $sender,
16445 content => $content,
16446 error => $error,
16447 lastUsed => CDS->now,
16448 };
16449 }
16450  
16451 0 ▶sub hash { shift->{hash} }
Subroutine hash: not called CC=1 SCAR=6.9
16452 0 ▶sub envelope { shift->{envelope} }
Subroutine envelope: not called CC=1 SCAR=6.9
16453 0 ▶sub senderStoreUrl { shift->{senderStoreUrl} }
Subroutine senderStoreUrl: not called CC=1 SCAR=6.9
16454 0 ▶sub sender { shift->{sender} }
Subroutine sender: not called CC=1 SCAR=6.9
16455 0 ▶sub content { shift->{content} }
Subroutine content: not called CC=1 SCAR=6.9
16456 0 ▶sub error { shift->{error} }
Subroutine error: not called CC=1 SCAR=6.9
16457 sub isValid {
16458 0 ▶ my $o = shift;
Subroutine isValid: not called CC=1 SCAR=6.9
16459 0 ! defined $o->{error} }
16460 0 ▶sub lastUsed { shift->{lastUsed} }
Subroutine lastUsed: not called CC=1 SCAR=6.9
16461  
16462 sub stillInUse {
16463 0 ▶ my $o = shift;
Subroutine stillInUse: not called CC=1 SCAR=6.9
16464  
16465 0 $o->{lastUsed} = CDS->now;
16466 }
16467  
16468 package CDS::SubDocument;
16469  
16470 1 ▶use parent -norequire, 'CDS::Document';
Subroutine BEGIN: called CC=1 SCAR=0.0
16471  
16472 sub new {
16473 0 ▶ my $class = shift;
Subroutine new: not called CC=3 SCAR=24.8
16474 0 ▶ my $parentSelector = shift; die 'wrong type '.ref($parentSelector).' for $parentSelector' if defined $parentSelector && ref $parentSelector ne 'CDS::Selector';
Branch: 1 branch
BranchTrueFalseTotal
if defined $parentSelector and ref $parentSelector ne "CDS::Selector" 0 0 0
Condition0%0/3
defined $parentSelector and ref $parentSelector ne "CDS::Selector"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $parentSelector and ref $parentSelector ne "CDS::Selector"
defined $parentSelector ref $parentSelector ne "CDS::Selector"
Truth table0%0/3
A and B
A= defined $parentSelectorB= ref $parentSelector ne "CDS::Selector"
ABresult
0X0
100
111
16475  
16476 0 my $o = $class->SUPER::new($parentSelector->document->keyPair, $parentSelector->document->unsaved);
16477 0 $o->{parentSelector} = $parentSelector;
16478 0 return $o;
16479 }
16480  
16481 0 ▶sub parentSelector { shift->{parentSelector} }
Subroutine parentSelector: not called CC=1 SCAR=6.9
16482  
16483 sub partSelector {
16484 0 ▶ my $o = shift;
Subroutine partSelector: not called CC=3 SCAR=24.8
16485 0 ▶ my $hashAndKey = shift; die 'wrong type '.ref($hashAndKey).' for $hashAndKey' if defined $hashAndKey && ref $hashAndKey ne 'CDS::HashAndKey';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hashAndKey and ref $hashAndKey ne "CDS::HashAndKey" 0 0 0
Condition0%0/3
defined $hashAndKey and ref $hashAndKey ne "CDS::HashAndKey"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hashAndKey and ref $hashAndKey ne "CDS::HashAndKey"
defined $hashAndKey ref $hashAndKey ne "CDS::HashAndKey"
Truth table0%0/3
A and B
A= defined $hashAndKeyB= ref $hashAndKey ne "CDS::HashAndKey"
ABresult
0X0
100
111
16486  
16487 0 $o->{parentSelector}->child(substr($hashAndKey->hash->bytes, 0, 16));
16488 }
16489  
16490 sub read {
16491 0 ▶ my $o = shift;
Subroutine read: not called CC=1 SCAR=6.9
16492  
16493 0 $o->merge(map { $_->hashAndKeyValue } $o->{parentSelector}->children);
16494 0 return $o->SUPER::read;
16495 }
16496  
16497 sub savingDone {
16498 0 ▶ my $o = shift;
Subroutine savingDone: not called CC=3 SCAR=24.8
16499 0 my $revision = shift;
16500 0 my $newPart = shift;
16501 0 my $obsoleteParts = shift;
16502  
16503 0 $o->{parentSelector}->document->unsaved->state->merge($o->{unsaved}->savingState);
16504  
16505 # Remove obsolete parts
16506 0 for my $part (@$obsoleteParts) {
16507 0 $o->partSelector($part->{hashAndKey})->merge($revision, CDS::Record->new);
16508 }
16509  
16510 # Add the new part
16511 0 ▶ if ($newPart) {
Branch: 1 branch
BranchTrueFalseTotal
if ($newPart) 0 0 0
16512 0 my $record = CDS::Record->new;
16513 0 $record->addHashAndKey($newPart->{hashAndKey});
16514 0 $o->partSelector($newPart->{hashAndKey})->merge($revision, $record);
16515 }
16516  
16517 0 $o->{unsaved}->savingDone;
16518 }
16519  
16520 # Useful functions to display textual information on the terminal
16521 package CDS::UI;
16522  
16523 sub new {
16524 0 ▶ my $class = shift;
Subroutine new: not called CC=2 SCAR=17.9
16525 0 ▶ my $fileHandle = shift // *STDOUT;
Condition0%0/3
shift() // *STDOUT
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() // *STDOUT
shift() *STDOUT
Truth table0%0/3
A // B
A= shift()B= *STDOUT
ABresult
1X1
011
000
16526 0 my $pure = shift;
16527  
16528 0 binmode $fileHandle, ":utf8";
16529 0 return bless {
16530 fileHandle => $fileHandle,
16531 pure => $pure,
16532 indentCount => 0,
16533 indent => '',
16534 valueIndent => 16,
16535 hasSpace => 0,
16536 hasError => 0,
16537 hasWarning => 0,
16538 };
16539 }
16540  
16541 0 ▶sub fileHandle { shift->{fileHandle} }
Subroutine fileHandle: not called CC=1 SCAR=6.9
16542  
16543 ### Indent
16544  
16545 sub pushIndent {
16546 0 ▶ my $o = shift;
Subroutine pushIndent: not called CC=1 SCAR=6.9
16547  
16548 0 $o->{indentCount} += 1;
16549 0 $o->{indent} = ' ' x $o->{indentCount};
16550 0 return;
16551 }
16552  
16553 sub popIndent {
16554 0 ▶ my $o = shift;
Subroutine popIndent: not called CC=1 SCAR=6.9
16555  
16556 0 $o->{indentCount} -= 1;
16557 0 $o->{indent} = ' ' x $o->{indentCount};
16558 0 return;
16559 }
16560  
16561 sub valueIndent {
16562 0 ▶ my $o = shift;
Subroutine valueIndent: not called CC=1 SCAR=6.9
16563 0 my $width = shift;
16564  
16565 0 $o->{valueIndent} = $width;
16566 }
16567  
16568 ### Low-level (non-semantic) output
16569  
16570 sub print {
16571 0 ▶ my $o = shift;
Subroutine print: not called CC=2 SCAR=17.9
16572  
16573 0 ▶ my $fh = $o->{fileHandle} // return;
Condition0%0/2
$o->{"fileHandle"} // (return)
l!l
00
MC/DC0%0/1
$o->{"fileHandle"} // (return)
$o->{"fileHandle"}
Truth table0%0/2
A
A= $o->{"fileHandle"}
Aresult
11
00
16574 0 print $fh @_;
16575 }
16576  
16577 sub raw {
16578 0 ▶ my $o = shift;
Subroutine raw: not called CC=2 SCAR=17.9
16579  
16580 0 $o->removeProgress;
16581 0 ▶ my $fh = $o->{fileHandle} // return;
Condition0%0/2
$o->{"fileHandle"} // (return)
l!l
00
MC/DC0%0/1
$o->{"fileHandle"} // (return)
$o->{"fileHandle"}
Truth table0%0/2
A
A= $o->{"fileHandle"}
Aresult
11
00
16582 0 binmode $fh, ":bytes";
16583 0 print $fh @_;
16584 0 binmode $fh, ":utf8";
16585 0 $o->{hasSpace} = 0;
16586 0 return;
16587 }
16588  
16589 sub space {
16590 0 ▶ my $o = shift;
Subroutine space: not called CC=2 SCAR=17.9
16591  
16592 0 $o->removeProgress;
16593 0 ▶ return if $o->{hasSpace};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"hasSpace"} 0 0 0
16594 0 $o->{hasSpace} = 1;
16595 0 $o->print("\n");
16596 0 return;
16597 }
16598  
16599 # A line of text (without word-wrap).
16600 sub line {
16601 0 ▶ my $o = shift;
Subroutine line: not called CC=1 SCAR=6.9
16602  
16603 0 $o->removeProgress;
16604 0 my $span = CDS::UI::Span->new(@_);
16605 0 $o->print($o->{indent});
16606 0 $span->printTo($o);
16607 0 $o->print(chr(0x1b), '[0m', "\n");
16608 0 $o->{hasSpace} = 0;
16609 0 return;
16610 }
16611  
16612 # A line of word-wrapped text.
16613 sub p {
16614 0 ▶ my $o = shift;
Subroutine p: not called CC=1 SCAR=6.9
16615  
16616 0 $o->removeProgress;
16617 0 my $span = CDS::UI::Span->new(@_);
16618 0 $span->wordWrap({lineLength => 0, maxLength => 100 - length $o->{indent}, indent => $o->{indent}});
16619 0 $o->print($o->{indent});
16620 0 $span->printTo($o);
16621 0 $o->print(chr(0x1b), '[0m', "\n");
16622 0 $o->{hasSpace} = 0;
16623 0 return;
16624 }
16625  
16626 # Line showing the progress.
16627 sub progress {
16628 0 ▶ my $o = shift;
Subroutine progress: not called CC=4 SCAR=30.0
16629  
16630 0 ▶ return if $o->{pure};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"pure"} 0 0 0
16631 0 $| = 1;
16632 0 $o->{hasProgress} = 1;
16633 0 my $text = ' '.join('', @_);
16634 0 ▶ $text = substr($text, 0, 79).'…' if length $text > 80;
Branch: 1 branch
BranchTrueFalseTotal
if length $text > 80 0 0 0
16635 0 ▶ $text .= ' ' x (80 - length $text) if length $text < 80;
Branch: 1 branch
BranchTrueFalseTotal
if length $text < 80 0 0 0
16636 0 $o->print($text, "\r");
16637 }
16638  
16639 # Progress line removal.
16640 sub removeProgress {
16641 0 ▶ my $o = shift;
Subroutine removeProgress: not called CC=3 SCAR=24.8
16642  
16643 0 ▶ return if $o->{pure};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"pure"} 0 0 0
16644 0 ▶ return if ! $o->{hasProgress};
Branch: 1 branch
BranchTrueFalseTotal
unless $o->{"hasProgress"} 0 0 0
16645 0 $o->print(' ' x 80, "\r");
16646 0 $o->{hasProgress} = 0;
16647 0 $| = 0;
16648 }
16649  
16650 ### Low-level (non-semantic) formatting
16651  
16652 sub span {
16653 0 ▶ my $o = shift;
Subroutine span: not called CC=1 SCAR=6.9
16654 0 CDS::UI::Span->new(@_) }
16655  
16656 sub bold {
16657 0 ▶ my $o = shift;
Subroutine bold: not called CC=1 SCAR=6.9
16658  
16659 0 my $span = CDS::UI::Span->new(@_);
16660 0 $span->{bold} = 1;
16661 0 return $span;
16662 }
16663  
16664 sub underlined {
16665 0 ▶ my $o = shift;
Subroutine underlined: not called CC=1 SCAR=6.9
16666  
16667 0 my $span = CDS::UI::Span->new(@_);
16668 0 $span->{underlined} = 1;
16669 0 return $span;
16670 }
16671  
16672 sub foreground {
16673 0 ▶ my $o = shift;
Subroutine foreground: not called CC=1 SCAR=6.9
16674 0 my $foreground = shift;
16675  
16676 0 my $span = CDS::UI::Span->new(@_);
16677 0 $span->{foreground} = $foreground;
16678 0 return $span;
16679 }
16680  
16681 sub background {
16682 0 ▶ my $o = shift;
Subroutine background: not called CC=1 SCAR=6.9
16683 0 my $background = shift;
16684  
16685 0 my $span = CDS::UI::Span->new(@_);
16686 0 $span->{background} = $background;
16687 0 return $span;
16688 }
16689  
16690 sub red {
16691 0 ▶ my $o = shift;
Subroutine red: not called CC=1 SCAR=6.9
16692 0 $o->foreground(196, @_) } # for failure
16693 sub green {
16694 0 ▶ my $o = shift;
Subroutine green: not called CC=1 SCAR=6.9
16695 0 $o->foreground(40, @_) } # for success
16696 sub orange {
16697 0 ▶ my $o = shift;
Subroutine orange: not called CC=1 SCAR=6.9
16698 0 $o->foreground(166, @_) } # for warnings
16699 sub blue {
16700 0 ▶ my $o = shift;
Subroutine blue: not called CC=1 SCAR=6.9
16701 0 $o->foreground(33, @_) } # to highlight something (selection)
16702 sub violet {
16703 0 ▶ my $o = shift;
Subroutine violet: not called CC=1 SCAR=6.9
16704 0 $o->foreground(93, @_) } # to highlight something (selection)
16705 sub gold {
16706 0 ▶ my $o = shift;
Subroutine gold: not called CC=1 SCAR=6.9
16707 0 $o->foreground(238, @_) } # for commands that can be executed
16708 sub gray {
16709 0 ▶ my $o = shift;
Subroutine gray: not called CC=1 SCAR=6.9
16710 0 $o->foreground(246, @_) } # for additional (less important) information
16711  
16712 sub darkBold {
16713 0 ▶ my $o = shift;
Subroutine darkBold: not called CC=1 SCAR=6.9
16714  
16715 0 my $span = CDS::UI::Span->new(@_);
16716 0 $span->{bold} = 1;
16717 0 $span->{foreground} = 240;
16718 0 return $span;
16719 }
16720  
16721 ### Semantic output
16722  
16723 sub title {
16724 0 ▶ my $o = shift;
Subroutine title: not called CC=1 SCAR=6.9
16725 0 $o->line($o->bold(@_)) }
16726  
16727 sub left {
16728 0 ▶ my $o = shift;
Subroutine left: not called CC=2 SCAR=17.9
16729 0 my $width = shift;
16730 0 my $text = shift;
16731  
16732 0 ▶ return substr($text, 0, $width - 1).'…' if length $text > $width;
Branch: 1 branch
BranchTrueFalseTotal
if length $text > $width 0 0 0
16733 0 return $text . ' ' x ($width - length $text);
16734 }
16735  
16736 sub right {
16737 0 ▶ my $o = shift;
Subroutine right: not called CC=2 SCAR=17.9
16738 0 my $width = shift;
16739 0 my $text = shift;
16740  
16741 0 ▶ return substr($text, 0, $width - 1).'…' if length $text > $width;
Branch: 1 branch
BranchTrueFalseTotal
if length $text > $width 0 0 0
16742 0 return ' ' x ($width - length $text) . $text;
16743 }
16744  
16745 sub keyValue {
16746 0 ▶ my $o = shift;
Subroutine keyValue: not called CC=4 SCAR=30.0
16747 0 my $key = shift;
16748 0 my $firstLine = shift;
16749  
16750 0 my $indent = $o->{valueIndent} - length $o->{indent};
16751 0 ▶ $key = substr($key, 0, $indent - 2).'…' if defined $firstLine && length $key >= $indent;
Branch: 1 branch
BranchTrueFalseTotal
if defined $firstLine and length $key >= $indent 0 0 0
Condition0%0/3
defined $firstLine and length $key >= $indent
!ll&&!rl&&r
000
MC/DC0%0/2
defined $firstLine and length $key >= $indent
defined $firstLine length $key >= $indent
Truth table0%0/3
A and B
A= defined $firstLineB= length $key >= $indent
ABresult
0X0
100
111
16752 0 $key .= ' ' x ($indent - length $key);
16753 0 $o->line($o->gray($key), $firstLine);
16754 0 my $noKey = ' ' x $indent;
16755 0 for my $line (@_) { $o->line($noKey, $line); }
16756 0 return;
16757 }
16758  
16759 sub command {
16760 0 ▶ my $o = shift;
Subroutine command: not called CC=1 SCAR=6.9
16761 0 $o->line($o->bold(@_)) }
16762  
16763 sub verbose {
16764 0 ▶ my $o = shift;
Subroutine verbose: not called CC=2 SCAR=17.9
16765 0 ▶ $o->line($o->foreground(45, @_)) if $o->{verbose} }
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"verbose"} 0 0 0
16766  
16767 sub pGreen {
16768 0 ▶ my $o = shift;
Subroutine pGreen: not called CC=1 SCAR=6.9
16769  
16770 0 $o->p($o->green(@_));
16771 0 return;
16772 }
16773  
16774 sub pOrange {
16775 0 ▶ my $o = shift;
Subroutine pOrange: not called CC=1 SCAR=6.9
16776  
16777 0 $o->p($o->orange(@_));
16778 0 return;
16779 }
16780  
16781 sub pRed {
16782 0 ▶ my $o = shift;
Subroutine pRed: not called CC=1 SCAR=6.9
16783  
16784 0 $o->p($o->red(@_));
16785 0 return;
16786 }
16787  
16788 ### Warnings and errors
16789  
16790 0 ▶sub hasWarning { shift->{hasWarning} }
Subroutine hasWarning: not called CC=1 SCAR=6.9
16791 0 ▶sub hasError { shift->{hasError} }
Subroutine hasError: not called CC=1 SCAR=6.9
16792  
16793 sub warning {
16794 0 ▶ my $o = shift;
Subroutine warning: not called CC=1 SCAR=6.9
16795  
16796 0 $o->{hasWarning} = 1;
16797 0 $o->p($o->orange(@_));
16798 0 return;
16799 }
16800  
16801 sub error {
16802 0 ▶ my $o = shift;
Subroutine error: not called CC=1 SCAR=6.9
16803  
16804 0 $o->{hasError} = 1;
16805 0 my $span = CDS::UI::Span->new(@_);
16806 0 $span->{background} = 196;
16807 0 $span->{foreground} = 15;
16808 0 $span->{bold} = 1;
16809 0 $o->line($span);
16810 0 return;
16811 }
16812  
16813 ### Semantic formatting
16814  
16815 sub a {
16816 0 ▶ my $o = shift;
Subroutine a: not called CC=1 SCAR=6.9
16817 0 $o->underlined(@_) }
16818  
16819 ### Human readable formats
16820  
16821 sub niceBytes {
16822 0 ▶ my $o = shift;
Subroutine niceBytes: not called CC=3 SCAR=24.8
16823 0 my $bytes = shift;
16824 0 my $maxLength = shift;
16825  
16826 0 my $length = length $bytes;
16827 0 ▶ my $text = defined $maxLength && $length > $maxLength ? substr($bytes, 0, $maxLength - 1).'…' : $bytes;
Branch: 1 branch
BranchTrueFalseTotal
defined $maxLength && $length > $maxLength ? : 0 0 0
Condition0%0/3
defined $maxLength and $length > $maxLength
!ll&&!rl&&r
000
MC/DC0%0/2
defined $maxLength and $length > $maxLength
defined $maxLength $length > $maxLength
Truth table0%0/3
A and B
A= defined $maxLengthB= $length > $maxLength
ABresult
0X0
100
111
16828 0 $text =~ s/[\x00-\x1f\x7f-\xff]/./g;
16829 0 return $text;
16830 }
16831  
16832 sub niceFileSize {
16833 0 ▶ my $o = shift;
Subroutine niceFileSize: not called CC=7 SCAR=40.3
16834 0 my $fileSize = shift;
16835  
16836 0 ▶ return $fileSize.' bytes' if $fileSize < 1000;
Branch: 1 branch
BranchTrueFalseTotal
if $fileSize < 1000 0 0 0
16837 0 ▶ return sprintf('%0.1f', $fileSize / 1000).' KB' if $fileSize < 10000;
Branch: 1 branch
BranchTrueFalseTotal
if $fileSize < 10000 0 0 0
16838 0 ▶ return sprintf('%0.0f', $fileSize / 1000).' KB' if $fileSize < 1000000;
Branch: 1 branch
BranchTrueFalseTotal
if $fileSize < 1000000 0 0 0
16839 0 ▶ return sprintf('%0.1f', $fileSize / 1000000).' MB' if $fileSize < 10000000;
Branch: 1 branch
BranchTrueFalseTotal
if $fileSize < 10000000 0 0 0
16840 0 ▶ return sprintf('%0.0f', $fileSize / 1000000).' MB' if $fileSize < 1000000000;
Branch: 1 branch
BranchTrueFalseTotal
if $fileSize < 1000000000 0 0 0
16841 0 ▶ return sprintf('%0.1f', $fileSize / 1000000000).' GB' if $fileSize < 10000000000;
Branch: 1 branch
BranchTrueFalseTotal
if $fileSize < '10000000000' 0 0 0
16842 0 return sprintf('%0.0f', $fileSize / 1000000000).' GB';
16843 }
16844  
16845 sub niceDateTimeLocal {
16846 0 ▶ my $o = shift;
Subroutine niceDateTimeLocal: not called CC=2 SCAR=17.9
16847 0 ▶ my $time = shift // time() * 1000;
Condition0%0/3
shift() // time * 1000
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() // time * 1000
shift() time * 1000
Truth table0%0/3
A // B
A= shift()B= time * 1000
ABresult
1X1
011
000
16848  
16849 0 my @t = localtime($time / 1000);
16850 0 return sprintf('%04d-%02d-%02d %02d:%02d:%02d', $t[5] + 1900, $t[4] + 1, $t[3], $t[2], $t[1], $t[0]);
16851 }
16852  
16853 sub niceDateTime {
16854 0 ▶ my $o = shift;
Subroutine niceDateTime: not called CC=2 SCAR=17.9
16855 0 ▶ my $time = shift // time() * 1000;
Condition0%0/3
shift() // time * 1000
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() // time * 1000
shift() time * 1000
Truth table0%0/3
A // B
A= shift()B= time * 1000
ABresult
1X1
011
000
16856  
16857 0 my @t = gmtime($time / 1000);
16858 0 return sprintf('%04d-%02d-%02d %02d:%02d:%02d UTC', $t[5] + 1900, $t[4] + 1, $t[3], $t[2], $t[1], $t[0]);
16859 }
16860  
16861 sub niceDate {
16862 0 ▶ my $o = shift;
Subroutine niceDate: not called CC=2 SCAR=17.9
16863 0 ▶ my $time = shift // time() * 1000;
Condition0%0/3
shift() // time * 1000
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() // time * 1000
shift() time * 1000
Truth table0%0/3
A // B
A= shift()B= time * 1000
ABresult
1X1
011
000
16864  
16865 0 my @t = gmtime($time / 1000);
16866 0 return sprintf('%04d-%02d-%02d', $t[5] + 1900, $t[4] + 1, $t[3]);
16867 }
16868  
16869 sub niceTime {
16870 0 ▶ my $o = shift;
Subroutine niceTime: not called CC=2 SCAR=17.9
16871 0 ▶ my $time = shift // time() * 1000;
Condition0%0/3
shift() // time * 1000
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() // time * 1000
shift() time * 1000
Truth table0%0/3
A // B
A= shift()B= time * 1000
ABresult
1X1
011
000
16872  
16873 0 my @t = gmtime($time / 1000);
16874 0 return sprintf('%02d:%02d:%02d UTC', $t[2], $t[1], $t[0]);
16875 }
16876  
16877 ### Special output
16878  
16879 sub record {
16880 0 ▶ my $o = shift;
Subroutine record: not called CC=3 SCAR=24.8
16881 0 ▶ my $record = shift; die 'wrong type '.ref($record).' for $record' if defined $record && ref $record ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $record and ref $record ne "CDS::Record" 0 0 0
Condition0%0/3
defined $record and ref $record ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $record and ref $record ne "CDS::Record"
defined $record ref $record ne "CDS::Record"
Truth table0%0/3
A and B
A= defined $recordB= ref $record ne "CDS::Record"
ABresult
0X0
100
111
16882 0 my $storeUrl = shift;
16883 0 CDS::UI::Record->display($o, $record, $storeUrl) }
16884  
16885 sub recordChildren {
16886 0 ▶ my $o = shift;
Subroutine recordChildren: not called CC=4 SCAR=30.0
16887 0 ▶ my $record = shift; die 'wrong type '.ref($record).' for $record' if defined $record && ref $record ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $record and ref $record ne "CDS::Record" 0 0 0
Condition0%0/3
defined $record and ref $record ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $record and ref $record ne "CDS::Record"
defined $record ref $record ne "CDS::Record"
Truth table0%0/3
A and B
A= defined $recordB= ref $record ne "CDS::Record"
ABresult
0X0
100
111
16888 0 my $storeUrl = shift;
16889  
16890 0 for my $child ($record->children) {
16891 0 CDS::UI::Record->display($o, $child, $storeUrl);
16892 }
16893 }
16894  
16895 sub selector {
16896 0 ▶ my $o = shift;
Subroutine selector: not called CC=7 SCAR=40.3
16897 0 ▶ my $selector = shift; die 'wrong type '.ref($selector).' for $selector' if defined $selector && ref $selector ne 'CDS::Selector';
Branch: 1 branch
BranchTrueFalseTotal
if defined $selector and ref $selector ne "CDS::Selector" 0 0 0
Condition0%0/3
defined $selector and ref $selector ne "CDS::Selector"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $selector and ref $selector ne "CDS::Selector"
defined $selector ref $selector ne "CDS::Selector"
Truth table0%0/3
A and B
A= defined $selectorB= ref $selector ne "CDS::Selector"
ABresult
0X0
100
111
16898 0 my $rootLabel = shift;
16899  
16900 0 my $item = $selector->document->get($selector);
16901 0 ▶ my $revision = $item->{revision} ? $o->green(' ', $o->niceDateTime($item->{revision})) : '';
Branch: 1 branch
BranchTrueFalseTotal
$item->{'revision'} ? : 0 0 0
16902  
16903 0 ▶ if ($selector->{id} eq 'ROOT') {
Branch: 1 branch
BranchTrueFalseTotal
if ($selector->{'id'} eq 'ROOT') { } 0 0 0
16904 0 ▶ $o->line($o->bold($rootLabel // 'Data tree'), $revision);
Condition0%0/2
$rootLabel // "Data tree"
l!l
00
MC/DC0%0/1
$rootLabel // "Data tree"
$rootLabel
Truth table0%0/2
A
A= $rootLabel
Aresult
11
00
16905 0 $o->recordChildren($selector->record);
16906 0 $o->selectorChildren($selector);
16907 } else {
16908 0 my $label = $selector->label;
16909 0 ▶ my $labelText = length $label > 64 ? substr($label, 0, 64).'…' : $label;
Branch: 1 branch
BranchTrueFalseTotal
length $label > 64 ? : 0 0 0
16910 0 $labelText =~ s/[\x00-\x1f\x7f-\xff]/·/g;
16911 0 $o->line($o->blue($labelText), $revision);
16912  
16913 0 $o->pushIndent;
16914 0 $o->recordChildren($selector->record);
16915 0 $o->selectorChildren($selector);
16916 0 $o->popIndent;
16917 }
16918 }
16919  
16920 sub selectorChildren {
16921 0 ▶ my $o = shift;
Subroutine selectorChildren: not called CC=4 SCAR=30.0
16922 0 ▶ my $selector = shift; die 'wrong type '.ref($selector).' for $selector' if defined $selector && ref $selector ne 'CDS::Selector';
Branch: 1 branch
BranchTrueFalseTotal
if defined $selector and ref $selector ne "CDS::Selector" 0 0 0
Condition0%0/3
defined $selector and ref $selector ne "CDS::Selector"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $selector and ref $selector ne "CDS::Selector"
defined $selector ref $selector ne "CDS::Selector"
Truth table0%0/3
A and B
A= defined $selectorB= ref $selector ne "CDS::Selector"
ABresult
0X0
100
111
16923  
16924 0 for my $child (sort { $a->{id} cmp $b->{id} } $selector->children) {
16925 0 $o->selector($child);
16926 }
16927 }
16928  
16929 sub hexDump {
16930 0 ▶ my $o = shift;
Subroutine hexDump: not called CC=1 SCAR=6.9
16931 0 my $bytes = shift;
16932 0 CDS::UI::HexDump->new($o, $bytes) }
16933  
16934 package CDS::UI::HexDump;
16935  
16936 sub new {
16937 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
16938 0 my $ui = shift;
16939 0 my $bytes = shift;
16940  
16941 0 return bless {ui => $ui, bytes => $bytes, styleChanges => [], };
16942 }
16943  
16944 0 ▶sub reset { chr(0x1b).'[0m' }
Subroutine reset: not called CC=1 SCAR=6.9
16945 sub foreground {
16946 0 ▶ my $o = shift;
Subroutine foreground: not called CC=1 SCAR=6.9
16947 0 my $color = shift;
16948 0 chr(0x1b).'[0;38;5;'.$color.'m' }
16949  
16950 sub changeStyle {
16951 0 ▶ my $o = shift;
Subroutine changeStyle: not called CC=1 SCAR=6.9
16952  
16953 0 push @{$o->{styleChanges}}, @_;
16954 }
16955  
16956 sub styleHashList {
16957 0 ▶ my $o = shift;
Subroutine styleHashList: not called CC=4 SCAR=30.0
16958 0 my $offset = shift;
16959  
16960 0 my $hashesCount = unpack('L>', substr($o->{bytes}, $offset, 4));
16961 0 my $dataStart = $offset + 4 + $hashesCount * 32;
16962 0 ▶ return $offset if $dataStart > length $o->{bytes};
Branch: 1 branch
BranchTrueFalseTotal
if $dataStart > length $o->{"bytes"} 0 0 0
16963  
16964 # Styles
16965 0 my $darkGreen = $o->foreground(28);
16966 0 my $green0 = $o->foreground(40);
16967 0 my $green1 = $o->foreground(34);
16968  
16969 # Color the hash count
16970 0 my $pos = $offset;
16971 0 $o->changeStyle({at => $pos, style => $darkGreen, breakBefore => 1});
16972 0 $pos += 4;
16973  
16974 # Color the hashes
16975 0 my $alternate = 0;
16976 0 ▶ while ($hashesCount) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hashesCount) 0 0 0
16977 0 ▶ $o->changeStyle({at => $pos, style => $alternate ? $green1 : $green0, breakBefore => 1});
Branch: 1 branch
BranchTrueFalseTotal
$alternate ? : 0 0 0
16978 0 $pos += 32;
16979 0 $alternate = 1 - $alternate;
16980 0 $hashesCount -= 1;
16981 }
16982  
16983 0 return $dataStart;
16984 }
16985  
16986 sub styleRecord {
16987 0 ▶ my $o = shift;
Subroutine styleRecord: not called CC=15 SCAR=54.8
16988 0 my $offset = shift;
16989  
16990 # Styles
16991 0 my $blue = $o->foreground(33);
16992 0 my $black = $o->reset;
16993 0 my $violet = $o->foreground(93);
16994 0 my @styleChanges;
16995  
16996 # Prepare
16997 0 my $pos = $offset;
16998 0 my $hasError = 0;
16999 0 my $level = 0;
17000  
17001 0 ▶ my $use = sub { my $length = shift;
Subroutine __ANON__: not called CC=2 SCAR=17.9
17002 0 my $start = $pos;
17003 0 $pos += $length;
17004 0 ▶ return substr($o->{bytes}, $start, $length) if $pos <= length $o->{bytes};
Branch: 1 branch
BranchTrueFalseTotal
if $pos <= length $o->{"bytes"} 0 0 0
17005 0 $hasError = 1;
17006 0 return;
17007 0 };
17008  
17009 0 ▶ my $readUnsigned8 = sub { unpack('C', &$use(1) // return) };
Subroutine __ANON__: not called CC=2 SCAR=17.9
Condition0%0/2
&$use(1) // (return)
l!l
00
MC/DC0%0/1
&$use(1) // (return)
&$use(1)
Truth table0%0/2
A
A= &$use(1)
Aresult
11
00
17010 0 ▶ my $readUnsigned32 = sub { unpack('L>', &$use(4) // return) };
Subroutine __ANON__: not called CC=2 SCAR=17.9
Condition0%0/2
&$use(4) // (return)
l!l
00
MC/DC0%0/1
&$use(4) // (return)
&$use(4)
Truth table0%0/2
A
A= &$use(4)
Aresult
11
00
17011 0 ▶ my $readUnsigned64 = sub { unpack('Q>', &$use(8) // return) };
Subroutine __ANON__: not called CC=2 SCAR=17.9
Condition0%0/2
&$use(8) // (return)
l!l
00
MC/DC0%0/1
&$use(8) // (return)
&$use(8)
Truth table0%0/2
A
A= &$use(8)
Aresult
11
00
17012  
17013 # Parse all record nodes
17014 0 ▶ while ($level >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($level >= 0) 0 0 0
17015 # Flags
17016 0 push @styleChanges, {at => $pos, style => $blue, breakBefore => 1};
17017 0 ▶ my $flags = &$readUnsigned8 // last;
Condition0%0/2
&$readUnsigned8 // (last)
l!l
00
MC/DC0%0/1
&$readUnsigned8 // (last)
&$readUnsigned8
Truth table0%0/2
A
A= &$readUnsigned8
Aresult
11
00
17018  
17019 # Data
17020 0 my $length = $flags & 0x1f;
17021 0 ▶ my $byteLength = $length == 30 ? 30 + (&$readUnsigned8 // last) : $length == 31 ? (&$readUnsigned64 // last) : $length;
Branch: 2 branches
BranchTrueFalseTotal
$length == 30 ? : 0 0 0
$length == 31 ? : 0 0 0
Condition0%0/4
&$readUnsigned8 // (last)
l!l
00
&$readUnsigned64 // (last)
l!l
00
MC/DC0%0/1
&$readUnsigned8 // (last)
&$readUnsigned8
MC/DC0%0/1
&$readUnsigned64 // (last)
&$readUnsigned64
Truth table0%0/2
A
A= &$readUnsigned8
Aresult
11
00
Truth table0%0/2
A
A= &$readUnsigned64
Aresult
11
00
17022  
17023 0 ▶ if ($byteLength) {
Branch: 1 branch
BranchTrueFalseTotal
if ($byteLength) 0 0 0
17024 0 push @styleChanges, {at => $pos, style => $black};
17025 0 ▶ &$use($byteLength) // last;
Condition0%0/2
&$use($byteLength) // (last)
l!l
00
MC/DC0%0/1
&$use($byteLength) // (last)
&$use($byteLength)
Truth table0%0/2
A
A= &$use($byteLength)
Aresult
11
00
17026 }
17027  
17028 0 ▶ if ($flags & 0x20) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flags & 32) 0 0 0
17029 0 push @styleChanges, {at => $pos, style => $violet};
17030 0 ▶ &$readUnsigned32 // last;
Condition0%0/2
&$readUnsigned32 // (last)
l!l
00
MC/DC0%0/1
&$readUnsigned32 // (last)
&$readUnsigned32
Truth table0%0/2
A
A= &$readUnsigned32
Aresult
11
00
17031 }
17032  
17033 # Children
17034 0 ▶ $level += 1 if $flags & 0x40;
Branch: 1 branch
BranchTrueFalseTotal
if $flags & 64 0 0 0
17035 0 ▶ $level -= 1 if ! ($flags & 0x80);
Branch: 1 branch
BranchTrueFalseTotal
unless $flags & 128 0 0 0
17036 }
17037  
17038 # Don't apply any styles if there are errors
17039 0 ▶ $hasError = 1 if $pos != length $o->{bytes};
Branch: 1 branch
BranchTrueFalseTotal
if $pos != length $o->{"bytes"} 0 0 0
17040 0 ▶ return $offset if $hasError;
Branch: 1 branch
BranchTrueFalseTotal
if $hasError 0 0 0
17041  
17042 0 $o->changeStyle(@styleChanges);
17043 0 return $pos;
17044 }
17045  
17046 sub display {
17047 0 ▶ my $o = shift;
Subroutine display: not called CC=10 SCAR=47.0
17048  
17049 0 $o->{ui}->valueIndent(8);
17050  
17051 0 my $resetStyle = chr(0x1b).'[0m';
17052 0 my $length = length($o->{bytes});
17053 0 my $lineStart = 0;
17054 0 my $currentStyle = '';
17055  
17056 0 my @styleChanges = sort { $a->{at} <=> $b->{at} } @{$o->{styleChanges}};
17057 0 push @styleChanges, {at => $length};
17058 0 my $nextChange = shift(@styleChanges);
17059  
17060 0 $o->{ui}->line($o->{ui}->gray('···· 0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef'));
17061 0 ▶ while ($lineStart < $length) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lineStart < $length) 0 0 0
17062 0 my $hexLine = $currentStyle;
17063 0 my $textLine = $currentStyle;
17064  
17065 0 my $k = 0;
17066 0 ▶ while ($k < 16) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k < 16) 0 0 0
17067 0 my $index = $lineStart + $k;
17068 0 ▶ last if $index >= $length;
Branch: 1 branch
BranchTrueFalseTotal
if $index >= $length 0 0 0
17069  
17070 0 my $break = 0;
17071 0 ▶ while ($index >= $nextChange->{at}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($index >= $nextChange->{"at"}) 0 0 0
17072 0 $currentStyle = $nextChange->{style};
17073 0 ▶ $break = $nextChange->{breakBefore} && $k > 0;
Condition0%0/3
$nextChange->{'breakBefore'} && $k > 0
!ll&&!rl&&r
000
MC/DC0%0/2
$nextChange->{'breakBefore'} && $k > 0
$nextChange->{'breakBefore'} $k > 0
Truth table0%0/3
A && B
A= $nextChange->{'breakBefore'}B= $k > 0
ABresult
0X0
100
111
17074 0 $hexLine .= $currentStyle;
17075 0 $textLine .= $currentStyle;
17076 0 $nextChange = shift @styleChanges;
17077 0 ▶ last if $break;
Branch: 1 branch
BranchTrueFalseTotal
if $break 0 0 0
17078 }
17079  
17080 0 ▶ last if $break;
Branch: 1 branch
BranchTrueFalseTotal
if $break 0 0 0
17081  
17082 0 my $byte = substr($o->{bytes}, $lineStart + $k, 1);
17083 0 $hexLine .= ' '.unpack('H*', $byte);
17084  
17085 0 my $code = ord($byte);
17086 0 ▶ $textLine .= $code >= 32 && $code <= 126 ? $byte : '·';
Branch: 1 branch
BranchTrueFalseTotal
$code >= 32 && $code <= 126 ? : 0 0 0
Condition0%0/3
$code >= 32 and $code <= 126
!ll&&!rl&&r
000
MC/DC0%0/2
$code >= 32 and $code <= 126
$code >= 32 $code <= 126
Truth table0%0/3
A and B
A= $code >= 32B= $code <= 126
ABresult
0X0
100
111
17087  
17088 0 $k += 1;
17089 }
17090  
17091 0 $hexLine .= ' ' x (16 - $k);
17092 0 $textLine .= ' ' x (16 - $k);
17093 0 $o->{ui}->line($o->{ui}->gray(unpack('H4', pack('S>', $lineStart))), ' ', $hexLine, $resetStyle, ' ', $textLine, $resetStyle);
17094  
17095 0 $lineStart += $k;
17096 }
17097 }
17098  
17099 package CDS::UI::ProgressStore;
17100  
17101 1 ▶use parent -norequire, 'CDS::Store';
Subroutine BEGIN: called CC=1 SCAR=0.0
17102  
17103 sub new {
17104 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
17105 0 my $store = shift;
17106 0 my $url = shift;
17107 0 my $ui = shift;
17108  
17109 0 return bless {
17110 store => $store,
17111 url => $url,
17112 ui => $ui,
17113 }
17114 }
17115  
17116 0 ▶sub store { shift->{store} }
Subroutine store: not called CC=1 SCAR=6.9
17117 0 ▶sub url { shift->{url} }
Subroutine url: not called CC=1 SCAR=6.9
17118 0 ▶sub ui { shift->{ui} }
Subroutine ui: not called CC=1 SCAR=6.9
17119  
17120 sub id {
17121 0 ▶ my $o = shift;
Subroutine id: not called CC=1 SCAR=6.9
17122 0 'Progress'."\n ".$o->{store}->id }
17123  
17124 ### Object store functions
17125  
17126 sub get {
17127 0 ▶ my $o = shift;
Subroutine get: not called CC=5 SCAR=34.0
17128 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
17129 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
17130  
17131 0 $o->{ui}->progress('GET ', $hash->shortHex, ' on ', $o->{url});
17132 0 return $o->{store}->get($hash, $keyPair);
17133 }
17134  
17135 sub book {
17136 0 ▶ my $o = shift;
Subroutine book: not called CC=5 SCAR=34.0
17137 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
17138 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
17139  
17140 0 $o->{ui}->progress('BOOK ', $hash->shortHex, ' on ', $o->{url});
17141 0 return $o->{store}->book($hash, $keyPair);
17142 }
17143  
17144 sub put {
17145 0 ▶ my $o = shift;
Subroutine put: not called CC=7 SCAR=40.3
17146 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
17147 0 ▶ my $object = shift; die 'wrong type '.ref($object).' for $object' if defined $object && ref $object ne 'CDS::Object';
Branch: 1 branch
BranchTrueFalseTotal
if defined $object and ref $object ne "CDS::Object" 0 0 0
Condition0%0/3
defined $object and ref $object ne "CDS::Object"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $object and ref $object ne "CDS::Object"
defined $object ref $object ne "CDS::Object"
Truth table0%0/3
A and B
A= defined $objectB= ref $object ne "CDS::Object"
ABresult
0X0
100
111
17148 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
17149  
17150 0 $o->{ui}->progress('PUT ', $hash->shortHex, ' (', $o->{ui}->niceFileSize($object->byteLength), ') on ', $o->{url});
17151 0 return $o->{store}->put($hash, $object, $keyPair);
17152 }
17153  
17154 ### Account store functions
17155  
17156 sub list {
17157 0 ▶ my $o = shift;
Subroutine list: not called CC=6 SCAR=37.4
17158 0 ▶ my $accountHash = shift; die 'wrong type '.ref($accountHash).' for $accountHash' if defined $accountHash && ref $accountHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $accountHash and ref $accountHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $accountHash and ref $accountHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $accountHash and ref $accountHash ne "CDS::Hash"
defined $accountHash ref $accountHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $accountHashB= ref $accountHash ne "CDS::Hash"
ABresult
0X0
100
111
17159 0 my $boxLabel = shift;
17160 0 my $timeout = shift;
17161 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
17162  
17163 0 ▶ $o->{ui}->progress($timeout == 0 ? 'LIST ' : 'WATCH ', $boxLabel, ' of ', $accountHash->shortHex, ' on ', $o->{url});
Branch: 1 branch
BranchTrueFalseTotal
$timeout == 0 ? : 0 0 0
17164 0 return $o->{store}->list($accountHash, $boxLabel, $timeout, $keyPair);
17165 }
17166  
17167 sub add {
17168 0 ▶ my $o = shift;
Subroutine add: not called CC=7 SCAR=40.3
17169 0 ▶ my $accountHash = shift; die 'wrong type '.ref($accountHash).' for $accountHash' if defined $accountHash && ref $accountHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $accountHash and ref $accountHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $accountHash and ref $accountHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $accountHash and ref $accountHash ne "CDS::Hash"
defined $accountHash ref $accountHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $accountHashB= ref $accountHash ne "CDS::Hash"
ABresult
0X0
100
111
17170 0 my $boxLabel = shift;
17171 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
17172 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
17173  
17174 0 $o->{ui}->progress('ADD ', $accountHash->shortHex, ' ', $boxLabel, ' ', $hash->shortHex, ' on ', $o->{url});
17175 0 return $o->{store}->add($accountHash, $boxLabel, $hash, $keyPair);
17176 }
17177  
17178 sub remove {
17179 0 ▶ my $o = shift;
Subroutine remove: not called CC=7 SCAR=40.3
17180 0 ▶ my $accountHash = shift; die 'wrong type '.ref($accountHash).' for $accountHash' if defined $accountHash && ref $accountHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $accountHash and ref $accountHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $accountHash and ref $accountHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $accountHash and ref $accountHash ne "CDS::Hash"
defined $accountHash ref $accountHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $accountHashB= ref $accountHash ne "CDS::Hash"
ABresult
0X0
100
111
17181 0 my $boxLabel = shift;
17182 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
17183 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
17184  
17185 0 $o->{ui}->progress('REMOVE ', $accountHash->shortHex, ' ', $boxLabel, ' ', $hash->shortHex, ' on ', $o->{url});
17186 0 return $o->{store}->remove($accountHash, $boxLabel, $hash, $keyPair);
17187 }
17188  
17189 sub modify {
17190 0 ▶ my $o = shift;
Subroutine modify: not called CC=3 SCAR=24.8
17191 0 my $modifications = shift;
17192 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
17193  
17194 0 $o->{ui}->progress('MODIFY +', scalar @{$modifications->additions}, ' -', scalar @{$modifications->removals}, ' on ', $o->{url});
17195 0 return $o->{store}->modify($modifications, $keyPair);
17196 }
17197  
17198 # Displays a record, and tries to guess the byte interpretation
17199 package CDS::UI::Record;
17200  
17201 sub display {
17202 0 ▶ my $class = shift;
Subroutine display: not called CC=4 SCAR=30.0
17203 0 my $ui = shift;
17204 0 ▶ my $record = shift; die 'wrong type '.ref($record).' for $record' if defined $record && ref $record ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $record and ref $record ne "CDS::Record" 0 0 0
Condition0%0/3
defined $record and ref $record ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $record and ref $record ne "CDS::Record"
defined $record ref $record ne "CDS::Record"
Truth table0%0/3
A and B
A= defined $recordB= ref $record ne "CDS::Record"
ABresult
0X0
100
111
17205 0 my $storeUrl = shift;
17206  
17207 0 ▶ my $o = bless {
Branch: 1 branch
BranchTrueFalseTotal
defined $storeUrl ? : 0 0 0
17208 ui => $ui,
17209 onStore => defined $storeUrl ? $ui->gray(' on ', $storeUrl) : '',
17210 };
17211  
17212 0 $o->record($record, '');
17213 }
17214  
17215 sub record {
17216 0 ▶ my $o = shift;
Subroutine record: not called CC=24 SCAR=64.0
17217 0 ▶ my $record = shift; die 'wrong type '.ref($record).' for $record' if defined $record && ref $record ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $record and ref $record ne "CDS::Record" 0 0 0
Condition0%0/3
defined $record and ref $record ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $record and ref $record ne "CDS::Record"
defined $record ref $record ne "CDS::Record"
Truth table0%0/3
A and B
A= defined $recordB= ref $record ne "CDS::Record"
ABresult
0X0
100
111
17218 0 my $context = shift;
17219  
17220 0 my $bytes = $record->bytes;
17221 0 my $hash = $record->hash;
17222 0 my @children = $record->children;
17223  
17224 # Try to interpret the key / value pair with a set of heuristic rules
17225 my @value =
17226 ! length $bytes && $hash ? ($o->{ui}->gold('cds show record '), $hash->hex, $o->{onStore}) :
17227 ! length $bytes ? $o->{ui}->gray('empty') :
17228 0 ▶ length $bytes == 32 && $hash ? ($o->{ui}->gold('cds show record '), $hash->hex, $o->{onStore}, $o->{ui}->gold(' decrypted with ', unpack('H*', $bytes))) :
Branch: 15 branches
BranchTrueFalseTotal
!length($bytes) && $hash ? : 0 0 0
!length($bytes) ? : 0 0 0
length $bytes == 32 && $hash ? : 0 0 0
$context eq 'e' ? : 0 0 0
$context eq 'n' ? : 0 0 0
$context eq 'p' ? : 0 0 0
$context eq 'q' ? : 0 0 0
$context eq 'encrypted for' ? : 0 0 0
$context eq 'updated by' ? : 0 0 0
$context =~ /(^| )id( |$)/ ? : 0 0 0
$context =~ /(^| )key( |$)/ ? : 0 0 0
$context =~ /(^| )signature( |$)/ ? : 0 0 0
$context =~ /(^| )revision( |$)/ ? : 0 0 0
$context =~ /(^| )date( |$)/ ? : 0 0 0
$context =~ /(^| )expires( |$)/ ? : 0 0 0
Condition0%0/6
not length $bytes and $hash
!ll&&!rl&&r
000
length $bytes == 32 and $hash
!ll&&!rl&&r
000
MC/DC0%0/2
not length $bytes and $hash
not length $bytes $hash
MC/DC0%0/2
length $bytes == 32 and $hash
length $bytes == 32 $hash
Truth table0%0/3
not(A) and B
A= not length $bytesB= $hash
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= length $bytes == 32B= $hash
ABresult
0X0
100
111
17229 $context eq 'e' ? $o->hexValue($bytes) :
17230 $context eq 'n' ? $o->hexValue($bytes) :
17231 $context eq 'p' ? $o->hexValue($bytes) :
17232 $context eq 'q' ? $o->hexValue($bytes) :
17233 $context eq 'encrypted for' ? $o->hexValue($bytes) :
17234 $context eq 'updated by' ? $o->hexValue($bytes) :
17235 $context =~ /(^| )id( |$)/ ? $o->hexValue($bytes) :
17236 $context =~ /(^| )key( |$)/ ? $o->hexValue($bytes) :
17237 $context =~ /(^| )signature( |$)/ ? $o->hexValue($bytes) :
17238 $context =~ /(^| )revision( |$)/ ? $o->revisionValue($bytes) :
17239 $context =~ /(^| )date( |$)/ ? $o->dateValue($bytes) :
17240 $context =~ /(^| )expires( |$)/ ? $o->dateValue($bytes) :
17241 $o->guessValue($bytes);
17242  
17243 0 ▶ push @value, ' ', $o->{ui}->blue($hash->hex), $o->{onStore} if $hash && ($bytes && length $bytes != 32);
Branch: 1 branch
BranchTrueFalseTotal
if $hash and ($bytes and length $bytes != 32) 0 0 0
Condition0%0/6
$hash and ($bytes and length $bytes != 32)
!ll&&!rl&&r
000
$bytes and length $bytes != 32
!ll&&!rl&&r
000
MC/DC0%0/3
$hash and ($bytes and length $bytes != 32)
$hash $bytes length $bytes != 32
Truth table0%0/4
A and B and C
A= $hashB= $bytesC= length $bytes != 32
ABCresult
0XX0
10X0
1100
1111
17244 0 $o->{ui}->line(@value);
17245  
17246 # Children
17247 0 $o->{ui}->pushIndent;
17248 0 for my $child (@children) { $o->record($child, $bytes); }
17249 0 $o->{ui}->popIndent;
17250 }
17251  
17252 sub hexValue {
17253 0 ▶ my $o = shift;
Subroutine hexValue: not called CC=2 SCAR=17.9
17254 0 my $bytes = shift;
17255  
17256 0 my $length = length $bytes;
17257 0 ▶ return '#'.unpack('H*', substr($bytes, 0, $length)) if $length <= 64;
Branch: 1 branch
BranchTrueFalseTotal
if $length <= 64 0 0 0
17258 0 return '#'.unpack('H*', substr($bytes, 0, 64)), '…', $o->{ui}->gray(' (', $length, ' bytes)');
17259 }
17260  
17261 sub guessValue {
17262 0 ▶ my $o = shift;
Subroutine guessValue: not called CC=8 SCAR=42.8
17263 0 my $bytes = shift;
17264  
17265 0 my $length = length $bytes;
17266 0 ▶ my $text = $length > 64 ? substr($bytes, 0, 64).'…' : $bytes;
Branch: 1 branch
BranchTrueFalseTotal
$length > 64 ? : 0 0 0
17267 0 $text =~ s/[\x00-\x1f\x7f-\xff]/·/g;
17268 0 my @value = ($text);
17269  
17270 0 ▶ if ($length <= 8) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length <= 8) 0 0 0
17271 0 my $integer = CDS->integerFromBytes($bytes);
17272 0 ▶ push @value, $o->{ui}->gray(' = ', $integer, $o->looksLikeTimestamp($integer) ? ' = '.$o->{ui}->niceDateTime($integer).' = '.$o->{ui}->niceDateTimeLocal($integer) : '');
Branch: 1 branch
BranchTrueFalseTotal
$o->looksLikeTimestamp($integer) ? : 0 0 0
17273 }
17274  
17275 0 ▶ push @value, $o->{ui}->gray(' = ', CDS->floatFromBytes($bytes)) if $length == 4 || $length == 8;
Branch: 1 branch
BranchTrueFalseTotal
if $length == 4 or $length == 8 0 0 0
Condition0%0/3
$length == 4 or $length == 8
l!l&&r!l&&!r
000
MC/DC0%0/2
$length == 4 or $length == 8
$length == 4 $length == 8
Truth table0%0/3
A or B
A= $length == 4B= $length == 8
ABresult
1X1
011
000
17276 0 ▶ push @value, $o->{ui}->gray(' = ', CDS::Hash->fromBytes($bytes)->hex) if $length == 32;
Branch: 1 branch
BranchTrueFalseTotal
if $length == 32 0 0 0
17277 0 ▶ push @value, $o->{ui}->gray(' (', length $bytes, ' bytes)') if length $bytes > 64;
Branch: 1 branch
BranchTrueFalseTotal
if length $bytes > 64 0 0 0
17278 0 return @value;
17279 }
17280  
17281 sub dateValue {
17282 0 ▶ my $o = shift;
Subroutine dateValue: not called CC=2 SCAR=17.9
17283 0 my $bytes = shift;
17284  
17285 0 my $integer = CDS->integerFromBytes($bytes);
17286 0 ▶ return $integer if ! $o->looksLikeTimestamp($integer);
Branch: 1 branch
BranchTrueFalseTotal
unless $o->looksLikeTimestamp($integer) 0 0 0
17287 0 return $o->{ui}->niceDateTime($integer), ' ', $o->{ui}->gray($o->{ui}->niceDateTimeLocal($integer));
17288 }
17289  
17290 sub revisionValue {
17291 0 ▶ my $o = shift;
Subroutine revisionValue: not called CC=2 SCAR=17.9
17292 0 my $bytes = shift;
17293  
17294 0 my $integer = CDS->integerFromBytes($bytes);
17295 0 ▶ return $integer if ! $o->looksLikeTimestamp($integer);
Branch: 1 branch
BranchTrueFalseTotal
unless $o->looksLikeTimestamp($integer) 0 0 0
17296 0 return $o->{ui}->niceDateTime($integer);
17297 }
17298  
17299 sub looksLikeTimestamp {
17300 0 ▶ my $o = shift;
Subroutine looksLikeTimestamp: not called CC=2 SCAR=17.9
17301 0 my $integer = shift;
17302  
17303 0 ▶ return $integer > 100000000000 && $integer < 10000000000000;
Condition0%0/3
$integer > 100000000000 && $integer < 10000000000000
!ll&&!rl&&r
000
MC/DC0%0/2
$integer > 100000000000 && $integer < 10000000000000
$integer > 100000000000 $integer < 10000000000000
Truth table0%0/3
A && B
A= $integer > 100000000000B= $integer < 10000000000000
ABresult
0X0
100
111
17304 }
17305  
17306 package CDS::UI::Span;
17307  
17308 sub new {
17309 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
17310  
17311 0 return bless {
17312 text => [@_],
17313 };
17314 }
17315  
17316 sub printTo {
17317 0 ▶ my $o = shift;
Subroutine printTo: not called CC=19 SCAR=59.4
17318 0 my $ui = shift;
17319 0 my $parent = shift;
17320  
17321 0 ▶ if ($parent) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parent) { } 0 0 0
17322 0 ▶ $o->{appliedForeground} = $o->{foreground} // $parent->{appliedForeground};
Condition0%0/3
$o->{"foreground"} // $parent->{"appliedForeground"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$o->{"foreground"} // $parent->{"appliedForeground"}
$o->{"foreground"} $parent->{"appliedForeground"}
Truth table0%0/3
A // B
A= $o->{"foreground"}B= $parent->{"appliedForeground"}
ABresult
1X1
011
000
17323 0 ▶ $o->{appliedBackground} = $o->{background} // $parent->{appliedBackground};
Condition0%0/3
$o->{"background"} // $parent->{"appliedBackground"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$o->{"background"} // $parent->{"appliedBackground"}
$o->{"background"} $parent->{"appliedBackground"}
Truth table0%0/3
A // B
A= $o->{"background"}B= $parent->{"appliedBackground"}
ABresult
1X1
011
000
17324 0 ▶ $o->{appliedBold} = $o->{bold} // $parent->{appliedBold} // 0;
Condition0%0/5
($o->{"bold"} // $parent->{"appliedBold"}) // 0
l!l
00
$o->{"bold"} // $parent->{"appliedBold"}
l!l&&r!l&&!r
000
MC/DC0%0/2
($o->{"bold"} // $parent->{"appliedBold"}) // 0
$o->{"bold"} $parent->{"appliedBold"}
Truth table0%0/3
A // B
A= $o->{"bold"}B= $parent->{"appliedBold"}
ABresult
1X1
011
000
17325 0 ▶ $o->{appliedUnderlined} = $o->{underlined} // $parent->{appliedUnderlined} // 0;
Condition0%0/5
($o->{"underlined"} // $parent->{"appliedUnderlined"}) // 0
l!l
00
$o->{"underlined"} // $parent->{"appliedUnderlined"}
l!l&&r!l&&!r
000
MC/DC0%0/2
($o->{"underlined"} // $parent->{"appliedUnderlined"}) // 0
$o->{"underlined"} $parent->{"appliedUnderlined"}
Truth table0%0/3
A // B
A= $o->{"underlined"}B= $parent->{"appliedUnderlined"}
ABresult
1X1
011
000
17326 } else {
17327 0 $o->{appliedForeground} = $o->{foreground};
17328 0 $o->{appliedBackground} = $o->{background};
17329 0 ▶ $o->{appliedBold} = $o->{bold} // 0;
Condition0%0/2
$o->{"bold"} // 0
l!l
00
MC/DC0%0/1
$o->{"bold"} // 0
$o->{"bold"}
Truth table0%0/2
A
A= $o->{"bold"}
Aresult
11
00
17330 0 ▶ $o->{appliedUnderlined} = $o->{underlined} // 0;
Condition0%0/2
$o->{"underlined"} // 0
l!l
00
MC/DC0%0/1
$o->{"underlined"} // 0
$o->{"underlined"}
Truth table0%0/2
A
A= $o->{"underlined"}
Aresult
11
00
17331 }
17332  
17333 0 my $style = chr(0x1b).'[0';
17334 0 ▶ $style .= ';1' if $o->{appliedBold};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"appliedBold"} 0 0 0
17335 0 ▶ $style .= ';4' if $o->{appliedUnderlined};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"appliedUnderlined"} 0 0 0
17336 0 ▶ $style .= ';38;5;'.$o->{appliedForeground} if defined $o->{appliedForeground};
Branch: 1 branch
BranchTrueFalseTotal
if defined $o->{"appliedForeground"} 0 0 0
17337 0 ▶ $style .= ';48;5;'.$o->{appliedBackground} if defined $o->{appliedBackground};
Branch: 1 branch
BranchTrueFalseTotal
if defined $o->{"appliedBackground"} 0 0 0
17338 0 $style .= 'm';
17339  
17340 0 my $needStyle = 1;
17341 0 for my $child (@{$o->{text}}) {
17342 0 my $ref = ref $child;
17343 0 ▶ if ($ref eq 'CDS::UI::Span') {
Branch: 3 branches
BranchTrueFalseTotal
if ($ref eq 'CDS::UI::Span') { } 0 0 0
elsif (length $ref) { } 0 0 0
elsif (not defined $child) { } 0 0 0
17344 0 $child->printTo($ui, $o);
17345 0 $needStyle = 1;
17346 0 next;
17347 } elsif (length $ref) {
17348 0 warn 'Printing REF';
17349 0 $child = $ref;
17350 } elsif (! defined $child) {
17351 0 warn 'Printing UNDEF';
17352 0 $child = 'UNDEF';
17353 }
17354  
17355 0 ▶ if ($needStyle) {
Branch: 1 branch
BranchTrueFalseTotal
if ($needStyle) 0 0 0
17356 0 $ui->print($style);
17357 0 $needStyle = 0;
17358 }
17359  
17360 0 $ui->print($child);
17361 }
17362 }
17363  
17364 sub wordWrap {
17365 0 ▶ my $o = shift;
Subroutine wordWrap: not called CC=13 SCAR=52.0
17366 0 my $state = shift;
17367  
17368 0 my $index = -1;
17369 0 for my $child (@{$o->{text}}) {
17370 0 $index += 1;
17371  
17372 0 ▶ next if ! defined $child;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $child 0 0 0
17373  
17374 0 my $ref = ref $child;
17375 0 ▶ if ($ref eq 'CDS::UI::Span') {
Branch: 3 branches
BranchTrueFalseTotal
if ($ref eq 'CDS::UI::Span') { } 0 0 0
elsif (length $ref) { } 0 0 0
elsif (not defined $child) { } 0 0 0
17376 0 $child->wordWrap($state);
17377 0 next;
17378 } elsif (length $ref) {
17379 0 warn 'Printing REF';
17380 0 $child = $ref;
17381 } elsif (! defined $child) {
17382 0 warn 'Printing UNDEF';
17383 0 $child = 'UNDEF';
17384 }
17385  
17386 0 my $position = -1;
17387 0 for my $char (split //, $child) {
17388 0 $position += 1;
17389 0 $state->{lineLength} += 1;
17390 0 ▶ if ($char eq ' ' || $char eq "\t") {
Branch: 2 branches
BranchTrueFalseTotal
if ($char eq ' ' or $char eq "\t") { } 0 0 0
elsif ($state->{'wrapSpan'} and $state->{'lineLength'} > $state->{'maxLength'}) { } 0 0 0
Condition0%0/3
$char eq " " or $char eq "\t"
l!l&&r!l&&!r
000
MC/DC0%0/2
$char eq " " or $char eq "\t"
$char eq " " $char eq "\t"
Truth table0%0/3
A or B
A= $char eq " "B= $char eq "\t"
ABresult
1X1
011
000
17391 0 $state->{wrapSpan} = $o;
17392 0 $state->{wrapIndex} = $index;
17393 0 $state->{wrapPosition} = $position;
17394 0 $state->{wrapReturn} = $state->{lineLength};
17395 ▶ } elsif ($state->{wrapSpan} && $state->{lineLength} > $state->{maxLength}) {
Condition0%0/3
$state->{"wrapSpan"} and $state->{"lineLength"} > $state->{"maxLength"}
!ll&&!rl&&r
000
MC/DC0%0/2
$state->{"wrapSpan"} and $state->{"lineLength"} > $state->{"maxLength"}
$state->{"wrapSpan"} $state->{"lineLength"} > $state->{"maxLength"}
Truth table0%0/3
A and B
A= $state->{"wrapSpan"}B= $state->{"lineLength"} > $state->{"maxLength"}
ABresult
0X0
100
111
17396 0 my $text = $state->{wrapSpan}->{text}->[$state->{wrapIndex}];
17397 0 $text = substr($text, 0, $state->{wrapPosition})."\n".$state->{indent}.substr($text, $state->{wrapPosition} + 1);
17398 0 $state->{wrapSpan}->{text}->[$state->{wrapIndex}] = $text;
17399 0 $state->{lineLength} -= $state->{wrapReturn};
17400 0 ▶ $position += length $state->{indent} if $state->{wrapSpan} == $o && $state->{wrapIndex} == $index;
Branch: 1 branch
BranchTrueFalseTotal
if $state->{"wrapSpan"} == $o and $state->{"wrapIndex"} == $index 0 0 0
Condition0%0/3
$state->{"wrapSpan"} == $o and $state->{"wrapIndex"} == $index
!ll&&!rl&&r
000
MC/DC0%0/2
$state->{"wrapSpan"} == $o and $state->{"wrapIndex"} == $index
$state->{"wrapSpan"} == $o $state->{"wrapIndex"} == $index
Truth table0%0/3
A and B
A= $state->{"wrapSpan"} == $oB= $state->{"wrapIndex"} == $index
ABresult
0X0
100
111
17401 0 $state->{wrapSpan} = undef;
17402 }
17403 }
17404 }
17405 }
17406  
17407 package CDS::UnionList;
17408  
17409 sub new {
17410 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
17411 0 my $privateRoot = shift;
17412 0 my $label = shift;
17413  
17414 0 my $o = bless {
17415 privateRoot => $privateRoot,
17416 label => $label,
17417 unsaved => CDS::Unsaved->new($privateRoot->unsaved),
17418 items => {},
17419 parts => {},
17420 hasPartsToMerge => 0,
17421 }, $class;
17422  
17423 0 $o->{unused} = CDS::UnionList::Part->new;
17424 0 $o->{changes} = CDS::UnionList::Part->new;
17425 0 $privateRoot->addDataHandler($label, $o);
17426 0 return $o;
17427 }
17428  
17429 0 ▶sub privateRoot { shift->{privateRoot} }
Subroutine privateRoot: not called CC=1 SCAR=6.9
17430 0 ▶sub unsaved { shift->{unsaved} }
Subroutine unsaved: not called CC=1 SCAR=6.9
17431 sub items {
17432 0 ▶ my $o = shift;
Subroutine items: not called CC=1 SCAR=6.9
17433 0 values %{$o->{items}} }
17434 sub parts {
17435 0 ▶ my $o = shift;
Subroutine parts: not called CC=1 SCAR=6.9
17436 0 values %{$o->{parts}} }
17437  
17438 sub get {
17439 0 ▶ my $o = shift;
Subroutine get: not called CC=1 SCAR=6.9
17440 0 my $id = shift;
17441 0 $o->{items}->{$id} }
17442  
17443 sub getOrCreate {
17444 0 ▶ my $o = shift;
Subroutine getOrCreate: not called CC=2 SCAR=17.9
17445 0 my $id = shift;
17446  
17447 0 my $item = $o->{items}->{$id};
17448 0 ▶ return $item if $item;
Branch: 1 branch
BranchTrueFalseTotal
if $item 0 0 0
17449 0 my $newItem = $o->createItem($id);
17450 0 $o->{items}->{$id} = $newItem;
17451 0 return $newItem;
17452 }
17453  
17454 # abstract sub createItem($o, $id)
17455 # abstract sub forgetObsoleteItems($o)
17456  
17457 sub forget {
17458 0 ▶ my $o = shift;
Subroutine forget: not called CC=2 SCAR=17.9
17459 0 my $id = shift;
17460  
17461 0 ▶ my $item = $o->{items}->{$id} // return;
Condition0%0/2
$o->{"items"}{$id} // (return)
l!l
00
MC/DC0%0/1
$o->{"items"}{$id} // (return)
$o->{"items"}{$id}
Truth table0%0/2
A
A= $o->{"items"}{$id}
Aresult
11
00
17462 0 $item->{part}->{count} -= 1;
17463 0 delete $o->{items}->{$id};
17464 }
17465  
17466 sub forgetItem {
17467 0 ▶ my $o = shift;
Subroutine forgetItem: not called CC=1 SCAR=6.9
17468 0 my $item = shift;
17469  
17470 0 $item->{part}->{count} -= 1;
17471 0 delete $o->{items}->{$item->id};
17472 }
17473  
17474 # *** MergeableData interface
17475  
17476 sub addDataTo {
17477 0 ▶ my $o = shift;
Subroutine addDataTo: not called CC=4 SCAR=30.0
17478 0 ▶ my $record = shift; die 'wrong type '.ref($record).' for $record' if defined $record && ref $record ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $record and ref $record ne "CDS::Record" 0 0 0
Condition0%0/3
defined $record and ref $record ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $record and ref $record ne "CDS::Record"
defined $record ref $record ne "CDS::Record"
Truth table0%0/3
A and B
A= defined $recordB= ref $record ne "CDS::Record"
ABresult
0X0
100
111
17479  
17480 0 for my $part (sort { $a->{hashAndKey}->hash->bytes cmp $b->{hashAndKey}->hash->bytes } values %{$o->{parts}}) {
17481 0 $record->addHashAndKey($part->{hashAndKey});
17482 }
17483 }
17484  
17485 sub mergeData {
17486 0 ▶ my $o = shift;
Subroutine mergeData: not called CC=5 SCAR=34.0
17487 0 ▶ my $record = shift; die 'wrong type '.ref($record).' for $record' if defined $record && ref $record ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $record and ref $record ne "CDS::Record" 0 0 0
Condition0%0/3
defined $record and ref $record ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $record and ref $record ne "CDS::Record"
defined $record ref $record ne "CDS::Record"
Truth table0%0/3
A and B
A= defined $recordB= ref $record ne "CDS::Record"
ABresult
0X0
100
111
17488  
17489 0 my @hashesAndKeys;
17490 0 for my $child ($record->children) {
17491 0 ▶ push @hashesAndKeys, $child->asHashAndKey // next;
Condition0%0/2
$child->asHashAndKey // (next)
l!l
00
MC/DC0%0/1
$child->asHashAndKey // (next)
$child->asHashAndKey
Truth table0%0/2
A
A= $child->asHashAndKey
Aresult
11
00
17492 }
17493  
17494 0 $o->merge(@hashesAndKeys);
17495 }
17496  
17497 sub mergeExternalData {
17498 0 ▶ my $o = shift;
Subroutine mergeExternalData: not called CC=11 SCAR=48.8
17499 0 my $store = shift;
17500 0 ▶ my $record = shift; die 'wrong type '.ref($record).' for $record' if defined $record && ref $record ne 'CDS::Record';
Branch: 1 branch
BranchTrueFalseTotal
if defined $record and ref $record ne "CDS::Record" 0 0 0
Condition0%0/3
defined $record and ref $record ne "CDS::Record"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $record and ref $record ne "CDS::Record"
defined $record ref $record ne "CDS::Record"
Truth table0%0/3
A and B
A= defined $recordB= ref $record ne "CDS::Record"
ABresult
0X0
100
111
17501 0 ▶ my $source = shift; die 'wrong type '.ref($source).' for $source' if defined $source && ref $source ne 'CDS::Source';
Branch: 1 branch
BranchTrueFalseTotal
if defined $source and ref $source ne "CDS::Source" 0 0 0
Condition0%0/3
defined $source and ref $source ne "CDS::Source"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $source and ref $source ne "CDS::Source"
defined $source ref $source ne "CDS::Source"
Truth table0%0/3
A and B
A= defined $sourceB= ref $source ne "CDS::Source"
ABresult
0X0
100
111
17502  
17503 0 my @hashes;
17504 my @hashesAndKeys;
17505 0 for my $child ($record->children) {
17506 0 ▶ my $hashAndKey = $child->asHashAndKey // next;
Condition0%0/2
$child->asHashAndKey // (next)
l!l
00
MC/DC0%0/1
$child->asHashAndKey // (next)
$child->asHashAndKey
Truth table0%0/2
A
A= $child->asHashAndKey
Aresult
11
00
17507 0 ▶ next if $o->{parts}->{$hashAndKey->hash->bytes};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"parts"}{$hashAndKey->hash->bytes} 0 0 0
17508 0 push @hashes, $hashAndKey->hash;
17509 0 push @hashesAndKeys, $hashAndKey;
17510 }
17511  
17512 0 my $keyPair = $o->{privateRoot}->privateBoxReader->keyPair;
17513 0 my ($missing, $transferStore, $storeError) = $keyPair->transfer([@hashes], $store, $o->{privateRoot}->unsaved);
17514 0 ▶ return if defined $storeError;
Branch: 1 branch
BranchTrueFalseTotal
if defined $storeError 0 0 0
17515 0 ▶ return if $missing;
Branch: 1 branch
BranchTrueFalseTotal
if $missing 0 0 0
17516  
17517 0 ▶ if ($source) {
Branch: 1 branch
BranchTrueFalseTotal
if ($source) 0 0 0
17518 0 $source->keep;
17519 0 $o->{privateRoot}->unsaved->state->addMergedSource($source);
17520 }
17521  
17522 0 $o->merge(@hashesAndKeys);
17523 0 return 1;
17524 }
17525  
17526 sub merge {
17527 0 ▶ my $o = shift;
Subroutine merge: not called CC=4 SCAR=30.0
17528  
17529 0 for my $hashAndKey (@_) {
17530 0 ▶ next if ! $hashAndKey;
Branch: 1 branch
BranchTrueFalseTotal
unless $hashAndKey 0 0 0
17531 0 ▶ next if $o->{parts}->{$hashAndKey->hash->bytes};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"parts"}{$hashAndKey->hash->bytes} 0 0 0
17532 0 my $part = CDS::UnionList::Part->new;
17533 0 $part->{hashAndKey} = $hashAndKey;
17534 0 $o->{parts}->{$hashAndKey->hash->bytes} = $part;
17535 0 $o->{hasPartsToMerge} = 1;
17536 }
17537 }
17538  
17539 # *** Reading
17540  
17541 sub read {
17542 0 ▶ my $o = shift;
Subroutine read: not called CC=11 SCAR=48.8
17543  
17544 0 ▶ return 1 if ! $o->{hasPartsToMerge};
Branch: 1 branch
BranchTrueFalseTotal
unless $o->{"hasPartsToMerge"} 0 0 0
17545  
17546 # Load the parts
17547 0 for my $part (values %{$o->{parts}}) {
17548 0 ▶ next if $part->{isMerged};
Branch: 1 branch
BranchTrueFalseTotal
if $part->{"isMerged"} 0 0 0
17549 0 ▶ next if $part->{loadedRecord};
Branch: 1 branch
BranchTrueFalseTotal
if $part->{"loadedRecord"} 0 0 0
17550  
17551 0 my ($record, $object, $invalidReason, $storeError) = $o->{privateRoot}->privateBoxReader->keyPair->getAndDecryptRecord($part->{hashAndKey}, $o->{privateRoot}->unsaved);
17552 0 ▶ return if defined $storeError;
Branch: 1 branch
BranchTrueFalseTotal
if defined $storeError 0 0 0
17553  
17554 0 ▶ delete $o->{parts}->{$part->{hashAndKey}->hash->bytes} if defined $invalidReason;
Branch: 1 branch
BranchTrueFalseTotal
if defined $invalidReason 0 0 0
17555 0 $part->{loadedRecord} = $record;
17556 }
17557  
17558 # Merge the loaded parts
17559 0 for my $part (values %{$o->{parts}}) {
17560 0 ▶ next if $part->{isMerged};
Branch: 1 branch
BranchTrueFalseTotal
if $part->{"isMerged"} 0 0 0
17561 0 ▶ next if ! $part->{loadedRecord};
Branch: 1 branch
BranchTrueFalseTotal
unless $part->{"loadedRecord"} 0 0 0
17562  
17563 # Merge
17564 0 for my $child ($part->{loadedRecord}->children) {
17565 0 $o->mergeRecord($part, $child);
17566 }
17567  
17568 0 delete $part->{loadedRecord};
17569 0 $part->{isMerged} = 1;
17570 }
17571  
17572 0 $o->{hasPartsToMerge} = 0;
17573 0 return 1;
17574 }
17575  
17576 # abstract sub mergeRecord($o, $part, $record)
17577  
17578 # *** Saving
17579  
17580 sub hasChanges {
17581 0 ▶ my $o = shift;
Subroutine hasChanges: not called CC=1 SCAR=6.9
17582 0 $o->{changes}->{count} > 0 }
17583  
17584 sub save {
17585 0 ▶ my $o = shift;
Subroutine save: not called CC=14 SCAR=53.5
17586  
17587 0 $o->forgetObsoleteItems;
17588 0 $o->{unsaved}->startSaving;
17589  
17590 0 ▶ if ($o->{changes}->{count}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"changes"}{"count"}) 0 0 0
17591 # Take the changes
17592 0 my $newPart = $o->{changes};
17593 0 $o->{changes} = CDS::UnionList::Part->new;
17594  
17595 # Add all changes
17596 0 my $record = CDS::Record->new;
17597 0 for my $item (values %{$o->{items}}) {
17598 0 ▶ next if $item->{part} != $newPart;
Branch: 1 branch
BranchTrueFalseTotal
if $item->{"part"} != $newPart 0 0 0
17599 0 $item->addToRecord($record);
17600 }
17601  
17602 # Select all parts smaller than 2 * count elements
17603 0 my $count = $newPart->{count};
17604 0 while (1) {
17605 0 my $addedPart = 0;
17606 0 for my $part (values %{$o->{parts}}) {
17607 0 ▶ next if ! $part->{isMerged} || $part->{selected} || $part->{count} >= $count * 2;
Branch: 1 branch
BranchTrueFalseTotal
if not $part->{"isMerged"} or $part->{"selected"} or $part->{"count"} >= $count * 2 0 0 0
Condition0%0/6
not $part->{"isMerged"} or $part->{"selected"} or $part->{"count"} >= $count * 2
l!l&&r!l&&!r
000
not $part->{"isMerged"} or $part->{"selected"}
l!l&&r!l&&!r
000
MC/DC0%0/3
not $part->{"isMerged"} or $part->{"selected"} or $part->{"count"} >= $count * 2
not $part->{"isMerged"} $part->{"selected"} $part->{"count"} >= $count * 2
Truth table0%0/4
not(A) or B or C
A= not $part->{"isMerged"}B= $part->{"selected"}C= $part->{"count"} >= $count * 2
ABCresult
1XX1
01X1
0011
0000
17608 0 $count += $part->{count};
17609 0 $part->{selected} = 1;
17610 0 $addedPart = 1;
17611 }
17612  
17613 0 ▶ last if ! $addedPart;
Branch: 1 branch
BranchTrueFalseTotal
unless $addedPart 0 0 0
17614 }
17615  
17616 # Include the selected items
17617 0 for my $item (values %{$o->{items}}) {
17618 0 ▶ next if ! $item->{part}->{selected};
Branch: 1 branch
BranchTrueFalseTotal
unless $item->{"part"}{"selected"} 0 0 0
17619 0 $item->setPart($newPart);
17620 0 $item->addToRecord($record);
17621 }
17622  
17623 # Serialize the new part
17624 0 my $key = CDS->randomKey;
17625 0 my $newObject = $record->toObject->crypt($key);
17626 0 my $newHash = $newObject->calculateHash;
17627 0 $newPart->{hashAndKey} = CDS::HashAndKey->new($newHash, $key);
17628 0 $newPart->{isMerged} = 1;
17629 0 $o->{parts}->{$newHash->bytes} = $newPart;
17630 0 $o->{privateRoot}->unsaved->state->addObject($newHash, $newObject);
17631 0 $o->{privateRoot}->dataChanged;
17632 }
17633  
17634 # Remove obsolete parts
17635 0 for my $part (values %{$o->{parts}}) {
17636 0 ▶ next if ! $part->{isMerged};
Branch: 1 branch
BranchTrueFalseTotal
unless $part->{"isMerged"} 0 0 0
17637 0 ▶ next if $part->{count};
Branch: 1 branch
BranchTrueFalseTotal
if $part->{"count"} 0 0 0
17638 0 delete $o->{parts}->{$part->{hashAndKey}->hash->bytes};
17639 0 $o->{privateRoot}->dataChanged;
17640 }
17641  
17642 # Propagate the unsaved state
17643 0 $o->{privateRoot}->unsaved->state->merge($o->{unsaved}->savingState);
17644 0 $o->{unsaved}->savingDone;
17645 0 return 1;
17646 }
17647  
17648 package CDS::UnionList::Item;
17649  
17650 sub new {
17651 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
17652 0 my $unionList = shift;
17653 0 my $id = shift;
17654  
17655 0 $unionList->{unused}->{count} += 1;
17656 return bless {
17657 unionList => $unionList,
17658 id => $id,
17659 part => $unionList->{unused},
17660 0 }, $class;
17661 }
17662  
17663 0 ▶sub unionList { shift->{unionList} }
Subroutine unionList: not called CC=1 SCAR=6.9
17664 0 ▶sub id { shift->{id} }
Subroutine id: not called CC=1 SCAR=6.9
17665  
17666 sub setPart {
17667 0 ▶ my $o = shift;
Subroutine setPart: not called CC=1 SCAR=6.9
17668 0 my $part = shift;
17669  
17670 0 $o->{part}->{count} -= 1;
17671 0 $o->{part} = $part;
17672 0 $o->{part}->{count} += 1;
17673 }
17674  
17675 # abstract sub addToRecord($o, $record)
17676  
17677 package CDS::UnionList::Part;
17678  
17679 sub new {
17680 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
17681  
17682 0 return bless {
17683 isMerged => 0,
17684 hashAndKey => undef,
17685 size => 0,
17686 count => 0,
17687 selected => 0,
17688 };
17689 }
17690  
17691 package CDS::Unsaved;
17692  
17693 1 ▶use parent -norequire, 'CDS::Store';
Subroutine BEGIN: called CC=1 SCAR=0.0
17694  
17695 sub new {
17696 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
17697 0 my $store = shift;
17698  
17699 0 return bless {
17700 state => CDS::Unsaved::State->new,
17701 savingState => undef,
17702 store => $store,
17703 };
17704 }
17705  
17706 0 ▶sub state { shift->{state} }
Subroutine state: not called CC=1 SCAR=6.9
17707 0 ▶sub savingState { shift->{savingState} }
Subroutine savingState: not called CC=1 SCAR=6.9
17708  
17709 # *** Saving, state propagation
17710  
17711 sub isSaving {
17712 0 ▶ my $o = shift;
Subroutine isSaving: not called CC=1 SCAR=6.9
17713 0 defined $o->{savingState} }
17714  
17715 sub startSaving {
17716 0 ▶ my $o = shift;
Subroutine startSaving: not called CC=2 SCAR=17.9
17717  
17718 0 ▶ die 'Start saving, but already saving' if $o->{savingState};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"savingState"} 0 0 0
17719 0 $o->{savingState} = $o->{state};
17720 0 $o->{state} = CDS::Unsaved::State->new;
17721 }
17722  
17723 sub savingDone {
17724 0 ▶ my $o = shift;
Subroutine savingDone: not called CC=2 SCAR=17.9
17725  
17726 0 ▶ die 'Not in saving state' if ! $o->{savingState};
Branch: 1 branch
BranchTrueFalseTotal
unless $o->{"savingState"} 0 0 0
17727 0 $o->{savingState} = undef;
17728 }
17729  
17730 sub savingFailed {
17731 0 ▶ my $o = shift;
Subroutine savingFailed: not called CC=2 SCAR=17.9
17732  
17733 0 ▶ die 'Not in saving state' if ! $o->{savingState};
Branch: 1 branch
BranchTrueFalseTotal
unless $o->{"savingState"} 0 0 0
17734 0 $o->{state}->merge($o->{savingState});
17735 0 $o->{savingState} = undef;
17736 }
17737  
17738 # *** Store interface
17739  
17740 sub id {
17741 0 ▶ my $o = shift;
Subroutine id: not called CC=1 SCAR=6.9
17742 0 'Unsaved'."\n".unpack('H*', CDS->randomBytes(16))."\n".$o->{store}->id }
17743  
17744 sub get {
17745 0 ▶ my $o = shift;
Subroutine get: not called CC=8 SCAR=42.8
17746 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
17747 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
17748  
17749 0 my $stateObject = $o->{state}->{objects}->{$hash->bytes};
17750 0 ▶ return $stateObject->{object} if $stateObject;
Branch: 1 branch
BranchTrueFalseTotal
if $stateObject 0 0 0
17751  
17752 0 ▶ if ($o->{savingState}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"savingState"}) 0 0 0
17753 0 my $savingStateObject = $o->{savingState}->{objects}->{$hash->bytes};
17754 0 ▶ return $savingStateObject->{object} if $savingStateObject;
Branch: 1 branch
BranchTrueFalseTotal
if $savingStateObject 0 0 0
17755 }
17756  
17757 0 return $o->{store}->get($hash, $keyPair);
17758 }
17759  
17760 sub book {
17761 0 ▶ my $o = shift;
Subroutine book: not called CC=5 SCAR=34.0
17762 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
17763 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
17764  
17765 0 return $o->{store}->book($hash, $keyPair);
17766 }
17767  
17768 sub put {
17769 0 ▶ my $o = shift;
Subroutine put: not called CC=7 SCAR=40.3
17770 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
17771 0 ▶ my $object = shift; die 'wrong type '.ref($object).' for $object' if defined $object && ref $object ne 'CDS::Object';
Branch: 1 branch
BranchTrueFalseTotal
if defined $object and ref $object ne "CDS::Object" 0 0 0
Condition0%0/3
defined $object and ref $object ne "CDS::Object"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $object and ref $object ne "CDS::Object"
defined $object ref $object ne "CDS::Object"
Truth table0%0/3
A and B
A= defined $objectB= ref $object ne "CDS::Object"
ABresult
0X0
100
111
17772 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
17773  
17774 0 return $o->{store}->put($hash, $object, $keyPair);
17775 }
17776  
17777 sub list {
17778 0 ▶ my $o = shift;
Subroutine list: not called CC=5 SCAR=34.0
17779 0 ▶ my $accountHash = shift; die 'wrong type '.ref($accountHash).' for $accountHash' if defined $accountHash && ref $accountHash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $accountHash and ref $accountHash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $accountHash and ref $accountHash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $accountHash and ref $accountHash ne "CDS::Hash"
defined $accountHash ref $accountHash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $accountHashB= ref $accountHash ne "CDS::Hash"
ABresult
0X0
100
111
17780 0 my $boxLabel = shift;
17781 0 my $timeout = shift;
17782 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
17783  
17784 0 return $o->{store}->list($accountHash, $boxLabel, $timeout, $keyPair);
17785 }
17786  
17787 sub modify {
17788 0 ▶ my $o = shift;
Subroutine modify: not called CC=3 SCAR=24.8
17789 0 my $additions = shift;
17790 0 my $removals = shift;
17791 0 ▶ my $keyPair = shift; die 'wrong type '.ref($keyPair).' for $keyPair' if defined $keyPair && ref $keyPair ne 'CDS::KeyPair';
Branch: 1 branch
BranchTrueFalseTotal
if defined $keyPair and ref $keyPair ne "CDS::KeyPair" 0 0 0
Condition0%0/3
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyPair and ref $keyPair ne "CDS::KeyPair"
defined $keyPair ref $keyPair ne "CDS::KeyPair"
Truth table0%0/3
A and B
A= defined $keyPairB= ref $keyPair ne "CDS::KeyPair"
ABresult
0X0
100
111
17792  
17793 0 return $o->{store}->modify($additions, $removals, $keyPair);
17794 }
17795  
17796 package CDS::Unsaved::State;
17797  
17798 sub new {
17799 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
17800  
17801 0 return bless {
17802 objects => {},
17803 mergedSources => [],
17804 dataSavedHandlers => [],
17805 };
17806 }
17807  
17808 0 ▶sub objects { shift->{objects} }
Subroutine objects: not called CC=1 SCAR=6.9
17809 sub mergedSources {
17810 0 ▶ my $o = shift;
Subroutine mergedSources: not called CC=1 SCAR=6.9
17811 0 @{$o->{mergedSources}} }
17812 sub dataSavedHandlers {
17813 0 ▶ my $o = shift;
Subroutine dataSavedHandlers: not called CC=1 SCAR=6.9
17814 0 @{$o->{dataSavedHandlers}} }
17815  
17816 sub addObject {
17817 0 ▶ my $o = shift;
Subroutine addObject: not called CC=5 SCAR=34.0
17818 0 ▶ my $hash = shift; die 'wrong type '.ref($hash).' for $hash' if defined $hash && ref $hash ne 'CDS::Hash';
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash and ref $hash ne "CDS::Hash" 0 0 0
Condition0%0/3
defined $hash and ref $hash ne "CDS::Hash"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash and ref $hash ne "CDS::Hash"
defined $hash ref $hash ne "CDS::Hash"
Truth table0%0/3
A and B
A= defined $hashB= ref $hash ne "CDS::Hash"
ABresult
0X0
100
111
17819 0 ▶ my $object = shift; die 'wrong type '.ref($object).' for $object' if defined $object && ref $object ne 'CDS::Object';
Branch: 1 branch
BranchTrueFalseTotal
if defined $object and ref $object ne "CDS::Object" 0 0 0
Condition0%0/3
defined $object and ref $object ne "CDS::Object"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $object and ref $object ne "CDS::Object"
defined $object ref $object ne "CDS::Object"
Truth table0%0/3
A and B
A= defined $objectB= ref $object ne "CDS::Object"
ABresult
0X0
100
111
17820  
17821 0 $o->{objects}->{$hash->bytes} = {hash => $hash, object => $object};
17822 }
17823  
17824 sub addMergedSource {
17825 0 ▶ my $o = shift;
Subroutine addMergedSource: not called CC=1 SCAR=6.9
17826  
17827 0 push @{$o->{mergedSources}}, @_;
17828 }
17829  
17830 sub addDataSavedHandler {
17831 0 ▶ my $o = shift;
Subroutine addDataSavedHandler: not called CC=1 SCAR=6.9
17832  
17833 0 push @{$o->{dataSavedHandlers}}, @_;
17834 }
17835  
17836 sub merge {
17837 0 ▶ my $o = shift;
Subroutine merge: not called CC=2 SCAR=17.9
17838 0 my $state = shift;
17839  
17840 0 for my $key (keys %{$state->{objects}}) {
17841 0 $o->{objects}->{$key} = $state->{objects}->{$key};
17842 }
17843  
17844 0 push @{$o->{mergedSources}}, @{$state->{mergedSources}};
17845 0 push @{$o->{dataSavedHandlers}}, @{$state->{dataSavedHandlers}};
17846 }
↑ Summary CDS/C.pm »