Blossom/_CashuPaymentRequest.pm

filter: Statementstmt 98.5% 203 / 206 Branchbran 80.0% 120 / 150 Conditioncond 65.2% 92 / 141 MC/DCmcdc 46.3% 38 / 82 Subroutinesub 100% 23 / 23 Podpod 0.0% 0 / 1 totaltotal 78.9% 476 / 603 CC 127 SCAR 28.8
CC
127
Cov
84%
_valid_request
32.6
_valid_tlv
30.0
_valid_cbor_transport
22.6
CRAP 17.8
↑ Summary Blossom/URI.pm »
1 package Net::Blossom::_CashuPaymentRequest;
2  
3 1 ▶use strictures 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use B ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use CBOR::Free::Decoder ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Encode qw(decode FB_CROAK);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use MIME::Base64 qw(decode_base64);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Net::Blossom::_Bech32 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Net::Blossom::_URL ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 my $BECH32M_CHECKSUM = 0x2bc830a3;
13  
14 53 ▶sub valid {
Subroutine valid: called CC=6 SCAR=19.3
Pod undocumented
15 53 my ($payload) = @_;
16 53 ▶ return 0 unless defined $payload && !ref($payload) && length $payload;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $payload and not ref $payload and length $payload 0 53 53
Condition33%2/6
defined $payload and not ref $payload and length $payload
!ll&&!rl&&r
0053
defined $payload and not ref $payload
!ll&&!rl&&r
0053
MC/DC0%0/3
defined $payload and not ref $payload and length $payload
defined $payload not ref $payload length $payload
Truth table25%1/4
A and not(B) and C
A= defined $payloadB= not ref $payloadC= length $payload
ABCresult
0XX0
10X0
1100
1111
17  
18 53 ▶ return _valid_cbor(substr($payload, 5))
Branch: 1 branch
BranchTrueFalseTotal
if substr($payload, 0, 5) =~ /\Acreqa\z/i 16 37 53
19 if substr($payload, 0, 5) =~ /\Acreqa\z/i;
20 37 ▶ return _valid_tlv($payload)
Branch: 1 branch
BranchTrueFalseTotal
if substr($payload, 0, 6) =~ /\Acreqb1\z/i 36 1 37
21 if substr($payload, 0, 6) =~ /\Acreqb1\z/i;
22 1 return 0;
23 }
24  
25 16 ▶sub _valid_cbor {
Subroutine _valid_cbor: called CC=7 SCAR=19.8
26 16 my ($encoded) = @_;
27 16 my $bytes = _decode_base64url($encoded);
28 16 ▶ return 0 unless defined $bytes && length $bytes;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bytes and length $bytes 0 16 16
Condition33%1/3
defined $bytes and length $bytes
!ll&&!rl&&r
0016
MC/DC0%0/2
defined $bytes and length $bytes
defined $bytes length $bytes
Truth table33%1/3
A and B
A= defined $bytesB= length $bytes
ABresult
0X0
100
111
29  
30 16 my (@warnings, $request);
31 16 my $ok = eval {
32 16 ▶ local $SIG{__WARN__} = sub { push @warnings, @_ };
Subroutine __ANON__: called CC=1 SCAR=0.0
33 16 my $decoder = CBOR::Free::Decoder->new();
34 16 $decoder->reject_duplicate_keys();
35 16 $request = $decoder->decode($bytes);
36 15 1;
37 };
38 16 ▶ return 0 unless $ok && !@warnings && ref($request) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless $ok and not @warnings and ref $request eq "HASH" 2 14 16
Condition83%5/6
$ok and not @warnings and ref $request eq "HASH"
!ll&&!rl&&r
2014
$ok and not @warnings
!ll&&!rl&&r
1114
MC/DC66%2/3
$ok and not @warnings and ref $request eq "HASH"
$ok not @warnings ref $request eq "HASH"
Truth table75%3/4
A and not(B) and C
A= $okB= not @warningsC= ref $request eq "HASH"
ABCresult
0XX0
10X0
1100
1111
39 14 ▶ return 0 if grep { !_text($_) } keys %$request;
Branch: 1 branch
BranchTrueFalseTotal
if grep {not _text($_);} keys %$request 0 14 14
40 14 return _valid_request($request);
41 }
42  
43 36 ▶sub _valid_tlv {
Subroutine _valid_tlv: called CC=30 SCAR=34.0
44 36 my ($payload) = @_;
45 36 my ($hrp, $words) = Net::Blossom::_Bech32::decode($payload, $BECH32M_CHECKSUM);
46 36 ▶ return 0 unless defined $hrp && $hrp eq 'creqb';
Branch: 1 branch
BranchTrueFalseTotal
unless defined $hrp and $hrp eq "creqb" 3 33 36
Condition66%2/3
defined $hrp and $hrp eq "creqb"
!ll&&!rl&&r
3033
MC/DC50%1/2
defined $hrp and $hrp eq "creqb"
defined $hrp $hrp eq "creqb"
Truth table66%2/3
A and B
A= defined $hrpB= $hrp eq "creqb"
ABresult
0X0
100
111
47  
48 33 my $bytes = Net::Blossom::_Bech32::convert_5_to_8($words);
49 33 ▶ return 0 unless defined $bytes;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bytes 0 33 33
50 33 my $entries = _tlv_entries($bytes);
51 33 ▶ return 0 unless defined $entries;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $entries 2 31 33
52  
53 31 my @amount = grep { $_->[0] == 0x02 } @$entries;
54 31 ▶ return 0 unless @amount == 1 && length($amount[0][1]) == 8;
Branch: 1 branch
BranchTrueFalseTotal
unless @amount == 1 and length $amount[0][1] == 8 3 28 31
Condition100%3/3
@amount == 1 and length $amount[0][1] == 8
!ll&&!rl&&r
2128
MC/DC100%2/2
@amount == 1 and length $amount[0][1] == 8
@amount == 1 length $amount[0][1] == 8
Truth table100%3/3
A and B
A= @amount == 1B= length $amount[0][1] == 8
ABresult
0X0
100
111
55 28 ▶ return 0 unless grep { $_ ne "\0" } split //, $amount[0][1];
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ ne "\0";} split(//, $amount[0][1], 0) 1 27 28
56  
57 27 my @unit = grep { $_->[0] == 0x03 } @$entries;
58 27 ▶ return 0 unless @unit == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @unit == 1 2 25 27
59 25 ▶ if ($unit[0][1] ne "\0") {
Branch: 1 branch
BranchTrueFalseTotal
if ($unit[0][1] ne "\0") 2 23 25
60 2 my $unit = _utf8($unit[0][1]);
61 2 ▶ return 0 unless defined $unit && length $unit;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $unit and length $unit 2 0 2
Condition66%2/3
defined $unit and length $unit
!ll&&!rl&&r
110
MC/DC0%0/2
defined $unit and length $unit
defined $unit length $unit
Truth table66%2/3
A and B
A= defined $unitB= length $unit
ABresult
0X0
100
111
62 }
63  
64 23 my @mints = grep { $_->[0] == 0x05 } @$entries;
65 23 ▶ return 0 unless @mints;
Branch: 1 branch
BranchTrueFalseTotal
unless @mints 1 22 23
66 22 for my $entry (@mints) {
67 23 my $mint = _utf8($entry->[1]);
68 23 ▶ return 0 unless defined $mint && Net::Blossom::_URL::http_base_url($mint);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $mint and Net::Blossom::_URL::http_base_url($mint) 2 21 23
Condition100%3/3
defined $mint and Net::Blossom::_URL::http_base_url($mint)
!ll&&!rl&&r
1121
MC/DC100%2/2
defined $mint and Net::Blossom::_URL::http_base_url($mint)
defined $mint Net::Blossom::_URL::http_base_url($mint)
Truth table100%3/3
A and B
A= defined $mintB= Net::Blossom::_URL::http_base_url($mint)
ABresult
0X0
100
111
69 }
70  
71 20 my @id = grep { $_->[0] == 0x01 } @$entries;
72 20 ▶ return 0 if @id > 1 || @id && !defined _utf8($id[0][1]);
Branch: 1 branch
BranchTrueFalseTotal
if @id > 1 or @id and not defined _utf8($id[0][1]) 2 18 20
Condition100%6/6
@id > 1 or @id and not defined _utf8($id[0][1])
l!l&&r!l&&!r
1118
@id and not defined _utf8($id[0][1])
!ll&&!rl&&r
1711
MC/DC100%3/3
@id > 1 or @id and not defined _utf8($id[0][1])
@id > 1 @id not defined _utf8($id[0][1])
Truth table100%4/4
A or B and not(C)
A= @id > 1B= @idC= not defined _utf8($id[0][1])
ABCresult
1XX1
0111
00X0
0100
73  
74 18 my @single_use = grep { $_->[0] == 0x04 } @$entries;
75 18 ▶ return 0 if @single_use > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @single_use > 1 1 17 18
76 17 ▶ return 0 if @single_use
Branch: 1 branch
BranchTrueFalseTotal
if @single_use and length $single_use[0][1] != 1 || ord $single_use[0][1] > 1 2 15 17
Condition100%6/6
@single_use and length $single_use[0][1] != 1 || ord $single_use[0][1] > 1
!ll&&!rl&&r
1412
length $single_use[0][1] != 1 or ord $single_use[0][1] > 1
l!l&&r!l&&!r
111
MC/DC100%3/3
@single_use and length $single_use[0][1] != 1 || ord $single_use[0][1] > 1
@single_use length $single_use[0][1] != 1 ord $single_use[0][1] > 1
Truth table100%4/4
A and B or C
A= @single_useB= length $single_use[0][1] != 1C= ord $single_use[0][1] > 1
ABCresult
0XX0
1000
11X1
1011
77 && (length($single_use[0][1]) != 1 || ord($single_use[0][1]) > 1);
78  
79 15 my @description = grep { $_->[0] == 0x06 } @$entries;
80 15 ▶ return 0 if @description > 1 || @description && !defined _utf8($description[0][1]);
Branch: 1 branch
BranchTrueFalseTotal
if @description > 1 or @description and not defined _utf8($description[0][1]) 2 13 15
Condition100%6/6
@description > 1 or @description and not defined _utf8($description[0][1])
l!l&&r!l&&!r
1113
@description and not defined _utf8($description[0][1])
!ll&&!rl&&r
1211
MC/DC100%3/3
@description > 1 or @description and not defined _utf8($description[0][1])
@description > 1 @description not defined _utf8($description[0][1])
Truth table100%4/4
A or B and not(C)
A= @description > 1B= @descriptionC= not defined _utf8($description[0][1])
ABCresult
1XX1
0111
00X0
0100
81  
82 13 my @transport = grep { $_->[0] == 0x07 } @$entries;
83 13 ▶ return 0 if grep { !_valid_tlv_transport($_->[1]) } @transport;
Branch: 1 branch
BranchTrueFalseTotal
if grep {not _valid_tlv_transport($_->[1]);} @transport 4 9 13
84  
85 9 my @nut10 = grep { $_->[0] == 0x08 } @$entries;
86 9 ▶ return 0 if @nut10 > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @nut10 > 1 1 8 9
87 8 ▶ return 0 if @nut10 && !_valid_tlv_nut10($nut10[0][1]);
Branch: 1 branch
BranchTrueFalseTotal
if @nut10 and not _valid_tlv_nut10($nut10[0][1]) 2 6 8
Condition100%3/3
@nut10 and not _valid_tlv_nut10($nut10[0][1])
!ll&&!rl&&r
512
MC/DC100%2/2
@nut10 and not _valid_tlv_nut10($nut10[0][1])
@nut10 not _valid_tlv_nut10($nut10[0][1])
Truth table100%3/3
A and not(B)
A= @nut10B= not _valid_tlv_nut10($nut10[0][1])
ABresult
0X0
100
111
88 6 return 1;
89 }
90  
91 14 ▶sub _valid_request {
Subroutine _valid_request: called CC=24 SCAR=34.9
92 14 my ($request) = @_;
93 14 ▶ return 0 unless exists $request->{a} && _integer($request->{a}) && $request->{a} > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless exists $request->{"a"} and _integer($request->{"a"}) and $request->{"a"} > 0 0 14 14
Condition33%2/6
exists $request->{"a"} and _integer($request->{"a"}) and $request->{"a"} > 0
!ll&&!rl&&r
0014
exists $request->{"a"} and _integer($request->{"a"})
!ll&&!rl&&r
0014
MC/DC0%0/3
exists $request->{"a"} and _integer($request->{"a"}) and $request->{"a"} > 0
exists $request->{"a"} _integer($request->{"a"}) $request->{"a"} > 0
Truth table25%1/4
A and B and C
A= exists $request->{"a"}B= _integer($request->{"a"})C= $request->{"a"} > 0
ABCresult
0XX0
10X0
1100
1111
94 14 ▶ return 0 unless exists $request->{u} && _text($request->{u}) && length $request->{u};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $request->{"u"} and _text($request->{"u"}) and length $request->{"u"} 0 14 14
Condition33%2/6
exists $request->{"u"} and _text($request->{"u"}) and length $request->{"u"}
!ll&&!rl&&r
0014
exists $request->{"u"} and _text($request->{"u"})
!ll&&!rl&&r
0014
MC/DC0%0/3
exists $request->{"u"} and _text($request->{"u"}) and length $request->{"u"}
exists $request->{"u"} _text($request->{"u"}) length $request->{"u"}
Truth table25%1/4
A and B and C
A= exists $request->{"u"}B= _text($request->{"u"})C= length $request->{"u"}
ABCresult
0XX0
10X0
1100
1111
95 14 ▶ return 0 unless exists $request->{m} && ref($request->{m}) eq 'ARRAY' && @{$request->{m}};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $request->{"m"} and ref $request->{"m"} eq "ARRAY" and @{$request->{"m"};} 0 14 14
Condition33%2/6
exists $request->{"m"} and ref $request->{"m"} eq "ARRAY" and @{$request->{"m"};}
!ll&&!rl&&r
0014
exists $request->{"m"} and ref $request->{"m"} eq "ARRAY"
!ll&&!rl&&r
0014
MC/DC0%0/3
exists $request->{"m"} and ref $request->{"m"} eq "ARRAY" and @{$request->{"m"};}
exists $request->{"m"} ref $request->{"m"} eq "ARRAY" @{$request->{"m"};}
Truth table25%1/4
A and B and C
A= exists $request->{"m"}B= ref $request->{"m"} eq "ARRAY"C= @{$request->{"m"};}
ABCresult
0XX0
10X0
1100
1111
96  
97 14 for my $mint (@{$request->{m}}) {
98 14 ▶ return 0 unless _text($mint) && Net::Blossom::_URL::http_base_url($mint);
Branch: 1 branch
BranchTrueFalseTotal
unless _text($mint) and Net::Blossom::_URL::http_base_url($mint) 0 14 14
Condition33%1/3
_text($mint) and Net::Blossom::_URL::http_base_url($mint)
!ll&&!rl&&r
0014
MC/DC0%0/2
_text($mint) and Net::Blossom::_URL::http_base_url($mint)
_text($mint) Net::Blossom::_URL::http_base_url($mint)
Truth table33%1/3
A and B
A= _text($mint)B= Net::Blossom::_URL::http_base_url($mint)
ABresult
0X0
100
111
99 }
100  
101 14 ▶ return 0 if exists $request->{i} && !_text($request->{i});
Branch: 1 branch
BranchTrueFalseTotal
if exists $request->{"i"} and not _text($request->{"i"}) 1 13 14
Condition100%3/3
exists $request->{"i"} and not _text($request->{"i"})
!ll&&!rl&&r
1211
MC/DC100%2/2
exists $request->{"i"} and not _text($request->{"i"})
exists $request->{"i"} not _text($request->{"i"})
Truth table100%3/3
A and not(B)
A= exists $request->{"i"}B= not _text($request->{"i"})
ABresult
0X0
100
111
102 13 ▶ return 0 if exists $request->{s} && !_boolean($request->{s});
Branch: 1 branch
BranchTrueFalseTotal
if exists $request->{"s"} and not _boolean($request->{"s"}) 1 12 13
Condition100%3/3
exists $request->{"s"} and not _boolean($request->{"s"})
!ll&&!rl&&r
1111
MC/DC100%2/2
exists $request->{"s"} and not _boolean($request->{"s"})
exists $request->{"s"} not _boolean($request->{"s"})
Truth table100%3/3
A and not(B)
A= exists $request->{"s"}B= not _boolean($request->{"s"})
ABresult
0X0
100
111
103 12 ▶ return 0 if exists $request->{d} && !_text($request->{d});
Branch: 1 branch
BranchTrueFalseTotal
if exists $request->{"d"} and not _text($request->{"d"}) 1 11 12
Condition100%3/3
exists $request->{"d"} and not _text($request->{"d"})
!ll&&!rl&&r
1011
MC/DC100%2/2
exists $request->{"d"} and not _text($request->{"d"})
exists $request->{"d"} not _text($request->{"d"})
Truth table100%3/3
A and not(B)
A= exists $request->{"d"}B= not _text($request->{"d"})
ABresult
0X0
100
111
104  
105 11 ▶ if (exists $request->{t}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $request->{"t"}) 4 7 11
106 4 ▶ return 0 unless ref($request->{t}) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $request->{"t"} eq "ARRAY" 1 3 4
107 3 ▶ return 0 if grep { !_valid_cbor_transport($_) } @{$request->{t}};
Branch: 1 branch
BranchTrueFalseTotal
if grep {not _valid_cbor_transport($_);} @{$$request{"t"};} 2 1 3
108 }
109  
110 8 ▶ return 0 if exists $request->{nut10} && !_valid_cbor_nut10($request->{nut10});
Branch: 1 branch
BranchTrueFalseTotal
if exists $request->{"nut10"} and not _valid_cbor_nut10($request->{"nut10"}) 6 2 8
Condition100%3/3
exists $request->{"nut10"} and not _valid_cbor_nut10($request->{"nut10"})
!ll&&!rl&&r
116
MC/DC100%2/2
exists $request->{"nut10"} and not _valid_cbor_nut10($request->{"nut10"})
exists $request->{"nut10"} not _valid_cbor_nut10($request->{"nut10"})
Truth table100%3/3
A and not(B)
A= exists $request->{"nut10"}B= not _valid_cbor_nut10($request->{"nut10"})
ABresult
0X0
100
111
111 2 return 1;
112 }
113  
114 3 ▶sub _valid_cbor_transport {
Subroutine _valid_cbor_transport: called CC=13 SCAR=31.2
115 3 my ($transport) = @_;
116 3 ▶ return 0 unless ref($transport) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $transport eq "HASH" 0 3 3
117 3 ▶ return 0 if grep { !_text($_) } keys %$transport;
Branch: 1 branch
BranchTrueFalseTotal
if grep {not _text($_);} keys %$transport 0 3 3
118 3 ▶ return 0 unless exists $transport->{t} && _text($transport->{t});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $transport->{"t"} and _text($transport->{"t"}) 0 3 3
Condition33%1/3
exists $transport->{"t"} and _text($transport->{"t"})
!ll&&!rl&&r
003
MC/DC0%0/2
exists $transport->{"t"} and _text($transport->{"t"})
exists $transport->{"t"} _text($transport->{"t"})
Truth table33%1/3
A and B
A= exists $transport->{"t"}B= _text($transport->{"t"})
ABresult
0X0
100
111
119 3 ▶ return 0 unless exists $transport->{a} && _text($transport->{a});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $transport->{"a"} and _text($transport->{"a"}) 1 2 3
Condition66%2/3
exists $transport->{"a"} and _text($transport->{"a"})
!ll&&!rl&&r
102
MC/DC50%1/2
exists $transport->{"a"} and _text($transport->{"a"})
exists $transport->{"a"} _text($transport->{"a"})
Truth table66%2/3
A and B
A= exists $transport->{"a"}B= _text($transport->{"a"})
ABresult
0X0
100
111
120 2 ▶ return 1 unless exists $transport->{g};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $transport->{"g"} 1 1 2
121 1 ▶ return 0 unless ref($transport->{g}) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $transport->{"g"} eq "ARRAY" 0 1 1
122  
123 1 for my $tag (@{$transport->{g}}) {
124 1 ▶ return 0 unless ref($tag) eq 'ARRAY' && @$tag >= 2;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $tag eq "ARRAY" and @$tag >= 2 1 0 1
Condition33%1/3
ref $tag eq "ARRAY" and @$tag >= 2
!ll&&!rl&&r
010
MC/DC0%0/2
ref $tag eq "ARRAY" and @$tag >= 2
ref $tag eq "ARRAY" @$tag >= 2
Truth table33%1/3
A and B
A= ref $tag eq "ARRAY"B= @$tag >= 2
ABresult
0X0
100
111
125 0 ▶ return 0 if grep { !_text($_) } @$tag;
Branch: 1 branch
BranchTrueFalseTotal
if grep {not _text($_);} @$tag 0 0 0
126 }
127  
128 0 return 1;
129 }
130  
131 7 ▶sub _valid_cbor_nut10 {
Subroutine _valid_cbor_nut10: called CC=16 SCAR=28.5
132 7 my ($nut10) = @_;
133 7 ▶ return 0 unless ref($nut10) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $nut10 eq "HASH" 1 6 7
134 6 ▶ return 0 if grep { !_text($_) } keys %$nut10;
Branch: 1 branch
BranchTrueFalseTotal
if grep {not _text($_);} keys %$nut10 0 6 6
135 6 ▶ return 0 unless exists $nut10->{k} && _text($nut10->{k}) && length $nut10->{k};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $nut10->{"k"} and _text($nut10->{"k"}) and length $nut10->{"k"} 1 5 6
Condition66%4/6
exists $nut10->{"k"} and _text($nut10->{"k"}) and length $nut10->{"k"}
!ll&&!rl&&r
105
exists $nut10->{"k"} and _text($nut10->{"k"})
!ll&&!rl&&r
105
MC/DC33%1/3
exists $nut10->{"k"} and _text($nut10->{"k"}) and length $nut10->{"k"}
exists $nut10->{"k"} _text($nut10->{"k"}) length $nut10->{"k"}
Truth table50%2/4
A and B and C
A= exists $nut10->{"k"}B= _text($nut10->{"k"})C= length $nut10->{"k"}
ABCresult
0XX0
10X0
1100
1111
136 5 ▶ return 0 unless exists $nut10->{d} && _text($nut10->{d}) && length $nut10->{d};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $nut10->{"d"} and _text($nut10->{"d"}) and length $nut10->{"d"} 1 4 5
Condition66%4/6
exists $nut10->{"d"} and _text($nut10->{"d"}) and length $nut10->{"d"}
!ll&&!rl&&r
104
exists $nut10->{"d"} and _text($nut10->{"d"})
!ll&&!rl&&r
104
MC/DC33%1/3
exists $nut10->{"d"} and _text($nut10->{"d"}) and length $nut10->{"d"}
exists $nut10->{"d"} _text($nut10->{"d"}) length $nut10->{"d"}
Truth table50%2/4
A and B and C
A= exists $nut10->{"d"}B= _text($nut10->{"d"})C= length $nut10->{"d"}
ABCresult
0XX0
10X0
1100
1111
137 4 ▶ return 1 unless exists $nut10->{t};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $nut10->{"t"} 0 4 4
138 4 ▶ return 0 unless ref($nut10->{t}) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $nut10->{"t"} eq "ARRAY" 1 3 4
139  
140 3 for my $tag (@{$nut10->{t}}) {
141 3 ▶ return 0 unless ref($tag) eq 'ARRAY' && @$tag == 2;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $tag eq "ARRAY" and @$tag == 2 1 2 3
Condition66%2/3
ref $tag eq "ARRAY" and @$tag == 2
!ll&&!rl&&r
012
MC/DC50%1/2
ref $tag eq "ARRAY" and @$tag == 2
ref $tag eq "ARRAY" @$tag == 2
Truth table66%2/3
A and B
A= ref $tag eq "ARRAY"B= @$tag == 2
ABresult
0X0
100
111
142 2 ▶ return 0 unless _text($tag->[0]) && _text($tag->[1]);
Branch: 1 branch
BranchTrueFalseTotal
unless _text($tag->[0]) and _text($tag->[1]) 1 1 2
Condition66%2/3
_text($tag->[0]) and _text($tag->[1])
!ll&&!rl&&r
011
MC/DC50%1/2
_text($tag->[0]) and _text($tag->[1])
_text($tag->[0]) _text($tag->[1])
Truth table66%2/3
A and B
A= _text($tag->[0])B= _text($tag->[1])
ABresult
0X0
100
111
143 }
144  
145 1 return 1;
146 }
147  
148 3 ▶sub _valid_tlv_nut10 {
Subroutine _valid_tlv_nut10: called CC=8 SCAR=21.2
149 3 my ($bytes) = @_;
150 3 my $entries = _tlv_entries($bytes);
151 3 ▶ return 0 unless defined $entries;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $entries 0 3 3
152  
153 3 my @kind = grep { $_->[0] == 0x01 } @$entries;
154 3 my @data = grep { $_->[0] == 0x02 } @$entries;
155 3 ▶ return 0 unless @kind == 1 && length($kind[0][1]) == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @kind == 1 and length $kind[0][1] == 1 0 3 3
Condition33%1/3
@kind == 1 and length $kind[0][1] == 1
!ll&&!rl&&r
003
MC/DC0%0/2
@kind == 1 and length $kind[0][1] == 1
@kind == 1 length $kind[0][1] == 1
Truth table33%1/3
A and B
A= @kind == 1B= length $kind[0][1] == 1
ABresult
0X0
100
111
156 3 ▶ return 0 unless @data == 1 && defined _utf8($data[0][1]);
Branch: 1 branch
BranchTrueFalseTotal
unless @data == 1 and defined _utf8($data[0][1]) 1 2 3
Condition66%2/3
@data == 1 and defined _utf8($data[0][1])
!ll&&!rl&&r
102
MC/DC50%1/2
@data == 1 and defined _utf8($data[0][1])
@data == 1 defined _utf8($data[0][1])
Truth table66%2/3
A and B
A= @data == 1B= defined _utf8($data[0][1])
ABresult
0X0
100
111
157 2 ▶ return 0 if grep { $_->[0] == 0x03 && !_valid_tag_tuple($_->[1]) } @$entries;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_->[0] == 3 and not _valid_tag_tuple($_->[1]);} @$entries 1 1 2
Condition100%3/3
$_->[0] == 3 && !_valid_tag_tuple($_->[1])
!ll&&!rl&&r
411
MC/DC100%2/2
$_->[0] == 3 && !_valid_tag_tuple($_->[1])
$_->[0] == 3 !_valid_tag_tuple($_->[1])
Truth table100%3/3
A && not(B)
A= $_->[0] == 3B= !_valid_tag_tuple($_->[1])
ABresult
0X0
100
111
158 1 return 1;
159 }
160  
161 6 ▶sub _valid_tlv_transport {
Subroutine _valid_tlv_transport: called CC=9 SCAR=22.1
162 6 my ($bytes) = @_;
163 6 my $entries = _tlv_entries($bytes);
164 6 ▶ return 0 unless defined $entries;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $entries 0 6 6
165  
166 6 my @kind = grep { $_->[0] == 0x01 } @$entries;
167 6 my @target = grep { $_->[0] == 0x02 } @$entries;
168 6 ▶ return 0 unless @kind == 1 && length($kind[0][1]) == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @kind == 1 and length $kind[0][1] == 1 0 6 6
Condition33%1/3
@kind == 1 and length $kind[0][1] == 1
!ll&&!rl&&r
006
MC/DC0%0/2
@kind == 1 and length $kind[0][1] == 1
@kind == 1 length $kind[0][1] == 1
Truth table33%1/3
A and B
A= @kind == 1B= length $kind[0][1] == 1
ABresult
0X0
100
111
169 6 ▶ return 0 unless @target == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @target == 1 1 5 6
170 5 ▶ return 0 if grep { $_->[0] == 0x03 && !_valid_tag_tuple($_->[1]) } @$entries;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_->[0] == 3 and not _valid_tag_tuple($_->[1]);} @$entries 1 4 5
Condition100%3/3
$_->[0] == 3 && !_valid_tag_tuple($_->[1])
!ll&&!rl&&r
1011
MC/DC100%2/2
$_->[0] == 3 && !_valid_tag_tuple($_->[1])
$_->[0] == 3 !_valid_tag_tuple($_->[1])
Truth table100%3/3
A && not(B)
A= $_->[0] == 3B= !_valid_tag_tuple($_->[1])
ABresult
0X0
100
111
171  
172 4 my $kind = ord $kind[0][1];
173 4 ▶ return length($target[0][1]) == 32 if $kind == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $kind == 0 1 3 4
174 3 ▶ return defined _utf8($target[0][1]) if $kind == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $kind == 1 2 1 3
175 1 return 0;
176 }
177  
178 4 ▶sub _valid_tag_tuple {
Subroutine _valid_tag_tuple: called CC=7 SCAR=19.9
179 4 my ($bytes) = @_;
180 4 ▶ return 0 unless length $bytes;
Branch: 1 branch
BranchTrueFalseTotal
unless length $bytes 0 4 4
181  
182 4 my $position = 0;
183 4 my $key_length = ord substr($bytes, $position++, 1);
184 4 ▶ return 0 if $position + $key_length > length $bytes;
Branch: 1 branch
BranchTrueFalseTotal
if $position + $key_length > length $bytes 0 4 4
185 4 ▶ return 0 unless defined _utf8(substr($bytes, $position, $key_length));
Branch: 1 branch
BranchTrueFalseTotal
unless defined _utf8(substr($bytes, $position, $key_length)) 0 4 4
186 4 $position += $key_length;
187  
188 4 my $values = 0;
189 4 ▶ while ($position < length $bytes) {
Branch: 1 branch
BranchTrueFalseTotal
if ($position < length $bytes) 2 4 6
190 2 my $length = ord substr($bytes, $position++, 1);
191 2 ▶ return 0 if $position + $length > length $bytes;
Branch: 1 branch
BranchTrueFalseTotal
if $position + $length > length $bytes 0 2 2
192 2 ▶ return 0 unless defined _utf8(substr($bytes, $position, $length));
Branch: 1 branch
BranchTrueFalseTotal
unless defined _utf8(substr($bytes, $position, $length)) 0 2 2
193 2 $position += $length;
194 2 $values++;
195 }
196  
197 4 return $values > 0;
198 }
199  
200 42 ▶sub _tlv_entries {
Subroutine _tlv_entries: called CC=4 SCAR=13.9
201 42 my ($bytes) = @_;
202 42 my @entries;
203 42 my $position = 0;
204  
205 42 ▶ while ($position < length $bytes) {
Branch: 1 branch
BranchTrueFalseTotal
if ($position < length $bytes) 146 40 186
206 146 ▶ return if length($bytes) - $position < 3;
Branch: 1 branch
BranchTrueFalseTotal
if length($bytes) - $position < 3 1 145 146
207 145 my $type = ord substr($bytes, $position, 1);
208 145 my $length = unpack 'n', substr($bytes, $position + 1, 2);
209 145 $position += 3;
210 145 ▶ return if $position + $length > length $bytes;
Branch: 1 branch
BranchTrueFalseTotal
if $position + $length > length $bytes 1 144 145
211 144 push @entries, [$type, substr($bytes, $position, $length)];
212 144 $position += $length;
213 }
214  
215 40 return \@entries;
216 }
217  
218 14 ▶sub _integer {
Subroutine _integer: called CC=3 SCAR=12.0
219 14 my ($value) = @_;
220 14 ▶ return 0 if ref($value);
Branch: 1 branch
BranchTrueFalseTotal
if ref $value 0 14 14
221 14 my $flags = B::svref_2object(\$value)->FLAGS;
222 14 ▶ return ($flags & B::SVp_IOK()) && !($flags & (B::SVp_NOK() | B::SVp_POK()));
Condition33%1/3
$flags & 4096 && !($flags & 24576)
!ll&&!rl&&r
0014
MC/DC0%0/2
$flags & 4096 && !($flags & 24576)
$flags & 4096 !($flags & 24576)
Truth table33%1/3
A && not(B)
A= $flags & 4096B= !($flags & 24576)
ABresult
0X0
100
111
223 }
224  
225 2 ▶sub _boolean {
Subroutine _boolean: called CC=3 SCAR=11.0
226 2 my ($value) = @_;
227 2 ▶ return ref($value) && eval { $value->isa('Types::Serialiser::Boolean') } ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
ref $value && eval { do { $value->isa('Types::Serialiser::Boolean') } } ? : 1 1 2
Condition66%2/3
ref $value and eval { do { $value->isa("Types::Serialiser::Boolean") } }
!ll&&!rl&&r
101
MC/DC50%1/2
ref $value and eval { do { $value->isa("Types::Serialiser::Boolean") } }
ref $value eval { do { $value->isa("Types::Serialiser::Boolean") } }
Truth table66%2/3
A and B
A= ref $valueB= eval { do { $value->isa("Types::Serialiser::Boolean") } }
ABresult
0X0
100
111
228 }
229  
230 129 ▶sub _text {
Subroutine _text: called CC=3 SCAR=12.5
231 129 my ($value) = @_;
232 129 ▶ return defined $value && !ref($value) && utf8::is_utf8($value);
Condition50%3/6
defined $value && !ref($value) && utf8::is_utf8($value)
!ll&&!rl&&r
03126
defined $value and not ref $value
!ll&&!rl&&r
00129
MC/DC33%1/3
defined $value && !ref($value) && utf8::is_utf8($value)
defined $value not ref $value utf8::is_utf8($value)
Truth table50%2/4
A and not(B) && C
A= defined $valueB= not ref $valueC= utf8::is_utf8($value)
ABCresult
0XX0
10X0
1100
1111
233 }
234  
235 39 ▶sub _utf8 {
Subroutine _utf8: called CC=2 SCAR=6.9
236 39 my ($bytes) = @_;
237 39 my $text = eval { decode('UTF-8', $bytes, FB_CROAK) };
238 39 ▶ return if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 5 34 39
239 34 return $text;
240 }
241  
242 16 ▶sub _decode_base64url {
Subroutine _decode_base64url: called CC=6 SCAR=19.6
243 16 my ($encoded) = @_;
244 16 ▶ return unless defined $encoded && !ref($encoded) && $encoded =~ /\A[A-Za-z0-9_-]+={0,2}\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $encoded and not ref $encoded and $encoded =~ /\A[A-Za-z0-9_-]+={0,2}\z/ 0 16 16
Condition33%2/6
defined $encoded and not ref $encoded and $encoded =~ /\A[A-Za-z0-9_-]+={0,2}\z/
!ll&&!rl&&r
0016
defined $encoded and not ref $encoded
!ll&&!rl&&r
0016
MC/DC0%0/3
defined $encoded and not ref $encoded and $encoded =~ /\A[A-Za-z0-9_-]+={0,2}\z/
defined $encoded not ref $encoded $encoded =~ /\A[A-Za-z0-9_-]+={0,2}\z/
Truth table25%1/4
A and not(B) and C
A= defined $encodedB= not ref $encodedC= $encoded =~ /\A[A-Za-z0-9_-]+={0,2}\z/
ABCresult
0XX0
10X0
1100
1111
245  
246 16 $encoded =~ s/=+\z//;
247 16 ▶ return if length($encoded) % 4 == 1;
Branch: 1 branch
BranchTrueFalseTotal
if length($encoded) % 4 == 1 0 16 16
248 16 $encoded =~ tr{-_}{+/};
249 16 ▶ $encoded .= '=' while length($encoded) % 4;
Branch: 1 branch
BranchTrueFalseTotal
length($encoded) % 4 and do { $encoded .= '=' } 18 16 34
250 16 return decode_base64($encoded);
251 }
252  
253 1 1;
↑ Summary Blossom/URI.pm »