ASN1/_decode.pm

filter: Statementstmt 84.6% 265 / 313 Branchbran 70.8% 197 / 278 Conditioncond 57.2% 67 / 117 MC/DCmcdc 36.6% 26 / 71 Subroutinesub 95.6% 22 / 23 Podpod n/a totaltotal 71.9% 577 / 802 CC 188 SCAR 49.3
CC
188
Cov
75%
_decode
273.2
_dec_set
175.1
_scan_indef
15.1
CRAP 138.1
↑ Summary ASN1/Debug.pm »
1 # Copyright (c) 2000-2005 Graham Barr <gbarr@pobox.com>. All rights reserved.
2 # This program is free software; you can redistribute it and/or
3 # modify it under the same terms as Perl itself.
4  
5 package Convert::ASN1;
6 32 $Convert::ASN1::VERSION = '0.37';
7 32 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 32 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 32 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=7.1
11 32 local $SIG{__DIE__};
12 32 ▶ eval { require bytes and 'bytes'->import };
Branch: 1 branch
BranchTrueFalseTotal
require bytes and "bytes"->import 32 0 32
13 }
14  
15 # These are the subs that do the decode, they are called with
16 # 0 1 2 3 4
17 # $optn, $op, $stash, $var, $buf
18 # The order must be the same as the op definitions above
19  
20 my @decode = (
21 0 ▶ sub { die "internal error\n" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
22 32 \&_dec_boolean,
23 \&_dec_integer,
24 \&_dec_bitstring,
25 \&_dec_string,
26 \&_dec_null,
27 \&_dec_object_id,
28 \&_dec_real,
29 \&_dec_sequence,
30 \&_dec_explicit,
31 \&_dec_set,
32 \&_dec_time,
33 \&_dec_time,
34 \&_dec_utf8,
35 undef, # ANY
36 undef, # CHOICE
37 \&_dec_object_id,
38 \&_dec_bcd,
39 );
40  
41 32 my @ctr;
42 32 @ctr[opBITSTR, opSTRING, opUTF8] = (\&_ctr_bitstring,\&_ctr_string,\&_ctr_string);
43  
44  
45 641 ▶sub _decode {
Subroutine _decode: called CC=81 SCAR=56.1
46 641 my ($optn, $ops, $stash, $pos, $end, $seqof, $larr) = @_;
47  
48 641 ▶ my $max_depth = exists $optn->{decode_max_depth} ? $optn->{decode_max_depth} : 99;
Branch: 1 branch
BranchTrueFalseTotal
exists $optn->{'decode_max_depth'} ? : 42 599 641
49 641 ▶ local $optn->{_decode_depth} = ($optn->{_decode_depth} || 0) + 1;
Condition100%2/2
$optn->{'_decode_depth'} || 0
l!l
460181
MC/DC100%1/1
$optn->{'_decode_depth'} || 0
$optn->{'_decode_depth'}
Truth table100%2/2
A
A= $optn->{'_decode_depth'}
Aresult
11
00
50 641 ▶ die "decode: max_depth must not be negative\n" if $max_depth < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $max_depth < 0 1 640 641
51 die "decode error (nesting depth limit exceeded)\n"
52 640 ▶ if $max_depth > 0 && $optn->{_decode_depth} > $max_depth;
Branch: 1 branch
BranchTrueFalseTotal
if $max_depth > 0 and $optn->{"_decode_depth"} > $max_depth 2 638 640
Condition100%3/3
$max_depth > 0 and $optn->{"_decode_depth"} > $max_depth
!ll&&!rl&&r
46342
MC/DC100%2/2
$max_depth > 0 and $optn->{"_decode_depth"} > $max_depth
$max_depth > 0 $optn->{"_decode_depth"} > $max_depth
Truth table100%3/3
A and B
A= $max_depth > 0B= $optn->{"_decode_depth"} > $max_depth
ABresult
0X0
100
111
53  
54 638 my $idx = 0;
55  
56 # we try not to copy the input buffer at any time
57 638 foreach my $buf ($_[-1]) {
58 OP:
59 638 foreach my $op (@{$ops}) {
60 1110 my $var = $op->[cVAR];
61  
62 1110 ▶ if (length $op->[cTAG]) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $op->[0]) { } 844 266 1110
63  
64 TAGLOOP: {
65 844 my($tag,$len,$npos,$indef) = _decode_tl($buf,$pos,$end,$larr)
66 1462 ▶ or do {
Branch: 1 branch
BranchTrueFalseTotal
() = _decode_tl($buf, $pos, $end, $larr) or do { next OP if $pos == $end and $seqof || defined $op->[5]; die "decode error" } 1437 25 1462
67 25 ▶ next OP if $pos==$end and ($seqof || defined $op->[cEXT]);
Branch: 1 branch
BranchTrueFalseTotal
if $pos == $end and $seqof || defined $op->[5] 23 2 25
Condition50%3/6
$pos == $end and $seqof || defined $op->[5]
!ll&&!rl&&r
2023
$seqof or defined $op->[5]
l!l&&r!l&&!r
0230
MC/DC33%1/3
$pos == $end and $seqof || defined $op->[5]
$pos == $end $seqof defined $op->[5]
Truth table50%2/4
A and B or C
A= $pos == $endB= $seqofC= defined $op->[5]
ABCresult
0XX0
1000
11X1
1011
68 2 die "decode error";
69 };
70  
71 1437 ▶ if ($tag eq $op->[cTAG]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag eq $op->[0]) 1370 67 1437
72  
73 1370 &{$decode[$op->[cTYPE]]}(
74 $optn,
75 $op,
76 $stash,
77 # We send 1 if there is not var as if there is the decode
78 # should be getting undef. So if it does not get undef
79 # it knows it has no variable
80 1370 ▶ ($seqof ? $seqof->[$idx++] : defined($var) ? $stash->{$var} : ref($stash) eq 'SCALAR' ? $$stash : 1),
Branch: 3 branches
BranchTrueFalseTotal
$seqof ? : 740 630 1370
defined $var ? : 546 84 630
ref $stash eq 'SCALAR' ? : 16 68 84
81 $buf,$npos,$len, $larr
82 );
83  
84 1354 $pos = $npos+$len+$indef;
85  
86 1354 ▶ redo TAGLOOP if $seqof && $pos < $end;
Branch: 1 branch
BranchTrueFalseTotal
if $seqof and $pos < $end 618 736 1354
Condition100%3/3
$seqof and $pos < $end
!ll&&!rl&&r
614122618
MC/DC100%2/2
$seqof and $pos < $end
$seqof $pos < $end
Truth table100%3/3
A and B
A= $seqofB= $pos < $end
ABresult
0X0
100
111
87 736 next OP;
88 }
89  
90 67 ▶ if ($tag eq ($op->[cTAG] | pack("C",ASN_CONSTRUCTOR))
Branch: 1 branch
BranchTrueFalseTotal
if ($tag eq ($op->[0] | " ") and my $ctr = $ctr[$op->[1]]) 2 65 67
Condition66%2/3
$tag eq ($op->[0] | " ") and my $ctr = $ctr[$op->[1]]
!ll&&!rl&&r
6502
MC/DC50%1/2
$tag eq ($op->[0] | " ") and my $ctr = $ctr[$op->[1]]
$tag eq ($op->[0] | " ") my $ctr = $ctr[$op->[1]]
Truth table66%2/3
A and B
A= $tag eq ($op->[0] | " ")B= my $ctr = $ctr[$op->[1]]
ABresult
0X0
100
111
91 and my $ctr = $ctr[$op->[cTYPE]])
92 {
93 2 _decode(
94 $optn,
95 [$op],
96 undef,
97 $npos,
98 $npos+$len,
99 (\my @ctrlist),
100 $larr,
101 $buf,
102 );
103  
104 ($seqof
105 ? $seqof->[$idx++] # = &{$ctr}(@ctrlist);
106 : defined($var)
107 ? $stash->{$var} # = &{$ctr}(@ctrlist);
108 : ref($stash) eq 'SCALAR'
109 ? $$stash # = &{$ctr}(@ctrlist);
110 : my $any ) # = &{$ctr}(@ctrlist) FIX #43
111 2 ▶ = &{$ctr}(@ctrlist);
Branch: 3 branches
BranchTrueFalseTotal
$seqof ? : 0 2 2
defined $var ? : 2 0 2
ref $stash eq 'SCALAR' ? : 0 0 0
112  
113 2 $pos = $npos+$len+$indef;
114  
115 2 ▶ redo TAGLOOP if $seqof && $pos < $end;
Branch: 1 branch
BranchTrueFalseTotal
if $seqof and $pos < $end 0 2 2
Condition33%1/3
$seqof and $pos < $end
!ll&&!rl&&r
200
MC/DC0%0/2
$seqof and $pos < $end
$seqof $pos < $end
Truth table33%1/3
A and B
A= $seqofB= $pos < $end
ABresult
0X0
100
111
116 2 next OP;
117  
118 }
119  
120 65 ▶ if ($seqof || defined $op->[cEXT]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seqof or defined $op->[5]) 65 0 65
Condition33%1/3
$seqof or defined $op->[5]
l!l&&r!l&&!r
0650
MC/DC0%0/2
$seqof or defined $op->[5]
$seqof defined $op->[5]
Truth table33%1/3
A or B
A= $seqofB= defined $op->[5]
ABresult
1X1
011
000
121 65 next OP;
122 }
123  
124 0 ▶ die "decode error " . unpack("H*",$tag) ."<=>" . unpack("H*",$op->[cTAG]), " ",$pos," ",$op->[cTYPE]," ",$op->[cVAR]||'';
Condition0%0/2
$op->[2] || ''
l!l
00
MC/DC0%0/1
$op->[2] || ''
$op->[2]
Truth table0%0/2
A
A= $op->[2]
Aresult
11
00
125 }
126 }
127 else { # opTag length is zero, so it must be an ANY, CHOICE or EXTENSIONS
128
129 266 ▶ if ($op->[cTYPE] == opANY) {
Branch: 3 branches
BranchTrueFalseTotal
if ($op->[1] == 14) { } 83 183 266
elsif ($op->[1] == 15) { } 179 4 183
elsif ($op->[1] == 18) { } 4 0 4
130  
131 ANYLOOP: {
132  
133 83 my($tag,$len,$npos,$indef) = _decode_tl($buf,$pos,$end,$larr)
134 84 ▶ or do {
Branch: 1 branch
BranchTrueFalseTotal
() = _decode_tl($buf, $pos, $end, $larr) or do { next OP if $pos == $end and $seqof || defined $op->[5]; die "decode error" } 82 2 84
135 2 ▶ next OP if $pos==$end and ($seqof || defined $op->[cEXT]);
Branch: 1 branch
BranchTrueFalseTotal
if $pos == $end and $seqof || defined $op->[5] 2 0 2
Condition33%2/6
$pos == $end and $seqof || defined $op->[5]
!ll&&!rl&&r
002
$seqof or defined $op->[5]
l!l&&r!l&&!r
020
MC/DC0%0/3
$pos == $end and $seqof || defined $op->[5]
$pos == $end $seqof defined $op->[5]
Truth table25%1/4
A and B or C
A= $pos == $endB= $seqofC= defined $op->[5]
ABCresult
0XX0
1000
11X1
1011
136 0 die "decode error";
137 };
138  
139 82 $len += $npos - $pos + $indef;
140  
141 82 my $handler;
142 82 ▶ if ($op->[cDEFINE]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op->[7]) 2 80 82
143 2 ▶ $handler = $optn->{oidtable} && $optn->{oidtable}{$stash->{$op->[cDEFINE]}};
Condition33%1/3
$optn->{'oidtable'} && $optn->{'oidtable'}{$$stash{$op->[7]}}
!ll&&!rl&&r
002
MC/DC0%0/2
$optn->{'oidtable'} && $optn->{'oidtable'}{$$stash{$op->[7]}}
$optn->{'oidtable'} $optn->{'oidtable'}{$$stash{$op->[7]}}
Truth table33%1/3
A && B
A= $optn->{'oidtable'}B= $optn->{'oidtable'}{$$stash{$op->[7]}}
ABresult
0X0
100
111
144 2 ▶ $handler ||= $optn->{handlers}{$op->[cVAR]}{$stash->{$op->[cDEFINE]}};
Condition33%1/3
$handler ||= $optn->{"handlers"}{$op->[2]}{$$stash{$op->[7]}}
l!l&&r!l&&!r
200
MC/DC0%0/2
$handler ||= $optn->{"handlers"}{$op->[2]}{$$stash{$op->[7]}}
$handler $optn->{"handlers"}{$op->[2]}{$$stash{$op->[7]}}
Truth table33%1/3
A ||= B
A= $handlerB= $optn->{"handlers"}{$op->[2]}{$$stash{$op->[7]}}
ABresult
1X1
011
000
145 }
146  
147 82 ▶ if ($handler) {
Branch: 1 branch
BranchTrueFalseTotal
if ($handler) { } 2 80 82
148 2 local $handler->{options}{_decode_depth} = $optn->{_decode_depth};
149 local $handler->{options}{decode_max_depth} = $max_depth
150 2 ▶ unless exists $handler->{options}{decode_max_depth};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $handler->{"options"}{"decode_max_depth"} 2 0 2
151 2 ▶ ($seqof ? $seqof->[$idx++] : ref($stash) eq 'SCALAR' ? $$stash : $stash->{$var})
Branch: 2 branches
BranchTrueFalseTotal
$seqof ? : 0 2 2
ref $stash eq 'SCALAR' ? : 0 2 2
152 = $handler->decode(substr($buf,$pos,$len));
153 } else {
154 80 ▶ ($seqof ? $seqof->[$idx++] : ref($stash) eq 'SCALAR' ? $$stash : $stash->{$var})
Branch: 2 branches
BranchTrueFalseTotal
$seqof ? : 2 78 80
ref $stash eq 'SCALAR' ? : 1 77 78
155 = substr($buf,$pos,$len);
156 }
157  
158 82 $pos += $len;
159  
160 82 ▶ redo ANYLOOP if $seqof && $pos < $end;
Branch: 1 branch
BranchTrueFalseTotal
if $seqof and $pos < $end 1 81 82
Condition100%3/3
$seqof and $pos < $end
!ll&&!rl&&r
8011
MC/DC100%2/2
$seqof and $pos < $end
$seqof $pos < $end
Truth table100%3/3
A and B
A= $seqofB= $pos < $end
ABresult
0X0
100
111
161 }
162 }
163 elsif ($op->[cTYPE] == opCHOICE) {
164  
165 CHOICELOOP: {
166 179 my($tag,$len,$npos,$indef) = _decode_tl($buf,$pos,$end,$larr)
167 182 ▶ or do {
Branch: 1 branch
BranchTrueFalseTotal
() = _decode_tl($buf, $pos, $end, $larr) or do { next OP if $pos == $end and $seqof || defined $op->[5]; die "decode error" } 182 0 182
168 0 ▶ next OP if $pos==$end and ($seqof || defined $op->[cEXT]);
Branch: 1 branch
BranchTrueFalseTotal
if $pos == $end and $seqof || defined $op->[5] 0 0 0
Condition0%0/6
$pos == $end and $seqof || defined $op->[5]
!ll&&!rl&&r
000
$seqof or defined $op->[5]
l!l&&r!l&&!r
000
MC/DC0%0/3
$pos == $end and $seqof || defined $op->[5]
$pos == $end $seqof defined $op->[5]
Truth table0%0/4
A and B or C
A= $pos == $endB= $seqofC= defined $op->[5]
ABCresult
0XX0
1000
11X1
1011
169 0 die "decode error";
170 };
171 182 my $extensions;
172 182 foreach my $cop (@{$op->[cCHILD]}) {
173  
174 323 ▶ if ($tag eq $cop->[cTAG]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag eq $cop->[0]) 157 166 323
175  
176 my $nstash = $seqof
177 ? ($seqof->[$idx++]={})
178 : defined($var)
179 157 ▶ ? ($stash->{$var}={})
Branch: 3 branches
BranchTrueFalseTotal
$seqof ? : 8 149 157
defined $var ? : 137 12 149
ref $stash eq 'SCALAR' ? : 5 7 12
180 : ref($stash) eq 'SCALAR'
181 ? ($$stash={}) : $stash;
182  
183 157 &{$decode[$cop->[cTYPE]]}(
184 $optn,
185 $cop,
186 $nstash,
187 157 ▶ ($cop->[cVAR] ? $nstash->{$cop->[cVAR]} : undef),
Branch: 1 branch
BranchTrueFalseTotal
$cop->[2] ? : 157 0 157
188 $buf,$npos,$len,$larr,
189 );
190  
191 157 $pos = $npos+$len+$indef;
192  
193 157 ▶ redo CHOICELOOP if $seqof && $pos < $end;
Branch: 1 branch
BranchTrueFalseTotal
if $seqof and $pos < $end 2 155 157
Condition100%3/3
$seqof and $pos < $end
!ll&&!rl&&r
14962
MC/DC100%2/2
$seqof and $pos < $end
$seqof $pos < $end
Truth table100%3/3
A and B
A= $seqofB= $pos < $end
ABresult
0X0
100
111
194 155 next OP;
195 }
196  
197 166 ▶ if ($cop->[cTYPE] == opEXTENSIONS) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cop->[1] == 18) 2 164 166
198 2 $extensions = 1;
199 2 next;
200 }
201  
202 164 ▶ unless (length $cop->[cTAG]) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length $cop->[0]) 24 140 164
203 eval {
204 24 _decode(
205 $optn,
206 [$cop],
207 (\my %tmp_stash),
208 $pos,
209 $npos+$len+$indef,
210 undef,
211 $larr,
212 $buf,
213 );
214  
215 my $nstash = $seqof
216 ? ($seqof->[$idx++]={})
217 : defined($var)
218 2 ▶ ? ($stash->{$var}={})
Branch: 3 branches
BranchTrueFalseTotal
$seqof ? : 2 0 2
defined $var ? : 0 0 0
ref $stash eq 'SCALAR' ? : 0 0 0
219 : ref($stash) eq 'SCALAR'
220 ? ($$stash={}) : $stash;
221  
222 2 @{$nstash}{keys %tmp_stash} = values %tmp_stash;
223  
224 24 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { _decode($optn, [$cop], \my %tmp_stash, $pos, $npos + $len + $indef, undef, $larr, $buf); my $nstash = $seqof ? $$seqof[$idx++] = {} : (defined $var ? $stash->{$var} = {} : (ref $stash eq "SCALAR" ? $$stash = {} : $stash)); @{$nstash;}{keys %tmp_stash} = values %tmp_stash } } or do { die $@ if $@ =~ /nesting depth limit exceeded/; next } 2 22 24
225 22 ▶ die $@ if $@ =~ /nesting depth limit exceeded/;
Branch: 1 branch
BranchTrueFalseTotal
if $@ =~ /nesting depth limit exceeded/ 22 0 22
226 0 next;
227 };
228  
229  
230 2 $pos = $npos+$len+$indef;
231  
232 2 ▶ redo CHOICELOOP if $seqof && $pos < $end;
Branch: 1 branch
BranchTrueFalseTotal
if $seqof and $pos < $end 1 1 2
Condition66%2/3
$seqof and $pos < $end
!ll&&!rl&&r
011
MC/DC50%1/2
$seqof and $pos < $end
$seqof $pos < $end
Truth table66%2/3
A and B
A= $seqofB= $pos < $end
ABresult
0X0
100
111
233 1 next OP;
234 }
235  
236 140 ▶ if ($tag eq ($cop->[cTAG] | pack("C",ASN_CONSTRUCTOR))
Branch: 1 branch
BranchTrueFalseTotal
if ($tag eq ($cop->[0] | " ") and my $ctr = $ctr[$cop->[1]]) 0 140 140
Condition33%1/3
$tag eq ($cop->[0] | " ") and my $ctr = $ctr[$cop->[1]]
!ll&&!rl&&r
14000
MC/DC0%0/2
$tag eq ($cop->[0] | " ") and my $ctr = $ctr[$cop->[1]]
$tag eq ($cop->[0] | " ") my $ctr = $ctr[$cop->[1]]
Truth table33%1/3
A and B
A= $tag eq ($cop->[0] | " ")B= my $ctr = $ctr[$cop->[1]]
ABresult
0X0
100
111
237 and my $ctr = $ctr[$cop->[cTYPE]])
238 {
239 my $nstash = $seqof
240 ? ($seqof->[$idx++]={})
241 : defined($var)
242 0 ▶ ? ($stash->{$var}={})
Branch: 3 branches
BranchTrueFalseTotal
$seqof ? : 0 0 0
defined $var ? : 0 0 0
ref $stash eq 'SCALAR' ? : 0 0 0
243 : ref($stash) eq 'SCALAR'
244 ? ($$stash={}) : $stash;
245  
246 0 _decode(
247 $optn,
248 [$cop],
249 undef,
250 $npos,
251 $npos+$len,
252 (\my @ctrlist),
253 $larr,
254 $buf,
255 );
256  
257 0 $nstash->{$cop->[cVAR]} = &{$ctr}(@ctrlist);
258 0 $pos = $npos+$len+$indef;
259  
260 0 ▶ redo CHOICELOOP if $seqof && $pos < $end;
Branch: 1 branch
BranchTrueFalseTotal
if $seqof and $pos < $end 0 0 0
Condition0%0/3
$seqof and $pos < $end
!ll&&!rl&&r
000
MC/DC0%0/2
$seqof and $pos < $end
$seqof $pos < $end
Truth table0%0/3
A and B
A= $seqofB= $pos < $end
ABresult
0X0
100
111
261 0 next OP;
262 }
263 }
264  
265 1 ▶ if ($pos < $end && $extensions) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos < $end and $extensions) 1 0 1
Condition33%1/3
$pos < $end and $extensions
!ll&&!rl&&r
001
MC/DC0%0/2
$pos < $end and $extensions
$pos < $end $extensions
Truth table33%1/3
A and B
A= $pos < $endB= $extensions
ABresult
0X0
100
111
266 1 $pos = $npos+$len+$indef;
267  
268 1 ▶ redo CHOICELOOP if $seqof && $pos < $end;
Branch: 1 branch
BranchTrueFalseTotal
if $seqof and $pos < $end 0 1 1
Condition33%1/3
$seqof and $pos < $end
!ll&&!rl&&r
100
MC/DC0%0/2
$seqof and $pos < $end
$seqof $pos < $end
Truth table33%1/3
A and B
A= $seqofB= $pos < $end
ABresult
0X0
100
111
269 1 next OP;
270 }
271 }
272 0 ▶ die "decode error" unless $op->[cEXT];
Branch: 1 branch
BranchTrueFalseTotal
unless $op->[5] 0 0 0
273 }
274 elsif ($op->[cTYPE] == opEXTENSIONS) {
275 4 $pos = $end; # Skip over the rest
276 }
277 else {
278 0 die "this point should never be reached";
279 }
280 }
281 }
282 }
283 598 ▶ die "decode error $pos $end" unless $pos == $end;
Branch: 1 branch
BranchTrueFalseTotal
unless $pos == $end 1 597 598
284 }
285  
286  
287 26 ▶sub _dec_boolean {
Subroutine _dec_boolean: called CC=2 SCAR=6.9
288 # 0 1 2 3 4 5 6
289 # $optn, $op, $stash, $var, $buf, $pos, $len
290  
291 26 ▶ $_[3] = unpack("C",substr($_[4],$_[5],1)) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
unpack('C', substr($_[4], $_[5], 1)) ? : 10 16 26
292 26 1;
293 }
294  
295  
296 128 ▶sub _dec_integer {
Subroutine _dec_integer: called CC=10 SCAR=23.1
297 # 0 1 2 3 4 5 6
298 # $optn, $op, $stash, $var, $buf, $pos, $len
299  
300 128 my $buf = substr($_[4],$_[5],$_[6]);
301 128 ▶ my $tmp = unpack("C",$buf) & 0x80 ? pack("C",255) : pack("C",0);
Branch: 1 branch
BranchTrueFalseTotal
unpack('C', $buf) & 128 ? : 17 111 128
302 128 ▶ if ($_[6] > 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[6] > 4) { } 28 100 128
303 my $max = ($_[0] && exists $_[0]->{decode_max_int_len})
304 ? $_[0]->{decode_max_int_len}
305 28 ▶ : 1025;
Branch: 1 branch
BranchTrueFalseTotal
$_[0] && exists $_[0]{'decode_max_int_len'} ? : 7 21 28
Condition66%2/3
$_[0] and exists $_[0]{"decode_max_int_len"}
!ll&&!rl&&r
0217
MC/DC50%1/2
$_[0] and exists $_[0]{"decode_max_int_len"}
$_[0] exists $_[0]{"decode_max_int_len"}
Truth table66%2/3
A and B
A= $_[0]B= exists $_[0]{"decode_max_int_len"}
ABresult
0X0
100
111
306 28 ▶ die "decode: max_int_len must not be negative\n" if $max < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $max < 0 1 27 28
307 27 ▶ die "INTEGER too large (length $_[6] exceeds max_int_len $max)\n"
Branch: 1 branch
BranchTrueFalseTotal
if $max and $_[6] > $max 3 24 27
Condition100%3/3
$max and $_[6] > $max
!ll&&!rl&&r
1233
MC/DC100%2/2
$max and $_[6] > $max
$max $_[6] > $max
Truth table100%3/3
A and B
A= $maxB= $_[6] > $max
ABresult
0X0
100
111
308 if $max && $_[6] > $max;
309 24 ▶ $_[3] = os2ip($buf, ($_[0] && $_[0]->{decode_bigint}) || 'Math::BigInt');
Condition80%4/5
$_[0] && $_[0]{'decode_bigint'} || 'Math::BigInt'
l!l
195
$_[0] and $_[0]{"decode_bigint"}
!ll&&!rl&&r
0519
MC/DC50%1/2
$_[0] && $_[0]{'decode_bigint'} || 'Math::BigInt'
$_[0] $_[0]{"decode_bigint"}
Truth table66%2/3
A and B
A= $_[0]B= $_[0]{"decode_bigint"}
ABresult
111
0X0
100
310 } else {
311 # N unpacks an unsigned value
312 100 $_[3] = unpack("l",pack("l",unpack("N", $tmp x (4-$_[6]) . $buf)));
313 }
314 124 1;
315 }
316  
317  
318 535 ▶sub _dec_bitstring {
Subroutine _dec_bitstring: called CC=3 SCAR=11.0
319 # 0 1 2 3 4 5 6
320 # $optn, $op, $stash, $var, $buf, $pos, $len
321  
322 535 ▶ if ($_[6] < 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[6] < 1) 501 34 535
323 501 $_[3] = ["", 0];
324 501 return 1;
325 }
326 34 ▶ die "BIT STRING decode error\n" if unpack("C", substr($_[4],$_[5],1)) > 7;
Branch: 1 branch
BranchTrueFalseTotal
if unpack("C", substr($_[4], $_[5], 1)) > 7 1 33 34
327 33 $_[3] = [ substr($_[4],$_[5]+1,$_[6]-1), ($_[6]-1)*8-unpack("C",substr($_[4],$_[5],1)) ];
328 33 1;
329 }
330  
331  
332 187 ▶sub _dec_string {
Subroutine _dec_string: called CC=1 SCAR=0.0
333 # 0 1 2 3 4 5 6
334 # $optn, $op, $stash, $var, $buf, $pos, $len
335  
336 187 $_[3] = substr($_[4],$_[5],$_[6]);
337 187 1;
338 }
339  
340  
341 2 ▶sub _dec_null {
Subroutine _dec_null: called CC=2 SCAR=7.2
342 # 0 1 2 3 4 5 6
343 # $optn, $op, $stash, $var, $buf, $pos, $len
344  
345 2 ▶ $_[3] = exists($_[0]->{decode_null}) ? $_[0]->{decode_null} : 1;
Branch: 1 branch
BranchTrueFalseTotal
exists $_[0]{'decode_null'} ? : 0 2 2
346 2 1;
347 }
348  
349  
350 174 ▶sub _dec_object_id {
Subroutine _dec_object_id: called CC=10 SCAR=23.0
351 # 0 1 2 3 4 5 6
352 # $optn, $op, $stash, $var, $buf, $pos, $len
353  
354 # unpack "w" is quadratic in arc length, so bound each arc first
355 my $max = exists $_[0]->{decode_max_oid_arc_len}
356 ? $_[0]->{decode_max_oid_arc_len}
357 174 ▶ : 32;
Branch: 1 branch
BranchTrueFalseTotal
exists $_[0]{'decode_max_oid_arc_len'} ? : 5 169 174
358 174 ▶ die "decode: max_oid_arc_len must not be negative\n" if $max < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $max < 0 1 173 174
359 173 ▶ if ($max) {
Branch: 1 branch
BranchTrueFalseTotal
if ($max) 172 1 173
360 172 my $oid = substr($_[4],$_[5],$_[6]);
361 # every byte of an arc except its last has the high bit set
362 172 ▶ while ($oid =~ /[\x80-\xff]+/g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($oid =~ /[\x80-\xff]+/g) 95 167 262
363 95 ▶ die "OBJECT IDENTIFIER decode error (arc too large)\n"
Branch: 1 branch
BranchTrueFalseTotal
if $+[0] - $-[0] >= $max 5 90 95
364 if $+[0] - $-[0] >= $max;
365 }
366 }
367  
368 168 my @data = unpack("w*",substr($_[4],$_[5],$_[6]));
369 168 ▶ if ($_[1]->[cTYPE] == opOBJID and @data > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[1][1] == 6 and @data > 1) 165 3 168
Condition66%2/3
$_[1][1] == 6 and @data > 1
!ll&&!rl&&r
30165
MC/DC50%1/2
$_[1][1] == 6 and @data > 1
$_[1][1] == 6 @data > 1
Truth table66%2/3
A and B
A= $_[1][1] == 6B= @data > 1
ABresult
0X0
100
111
370 165 ▶ if ($data[0] < 40) {
Branch: 2 branches
BranchTrueFalseTotal
if ($data[0] < 40) { } 4 161 165
elsif ($data[0] < 80) { } 41 120 161
371 4 splice(@data, 0, 1, 0, $data[0]);
372 }
373 elsif ($data[0] < 80) {
374 41 splice(@data, 0, 1, 1, $data[0] - 40);
375 }
376 else {
377 120 splice(@data, 0, 1, 2, $data[0] - 80);
378 }
379 }
380 168 $_[3] = join(".", @data);
381 168 1;
382 }
383  
384  
385 32 my @_dec_real_base = (2,8,16);
386  
387 13 ▶sub _dec_real {
Subroutine _dec_real: called CC=12 SCAR=25.2
388 # 0 1 2 3 4 5 6
389 # $optn, $op, $stash, $var, $buf, $pos, $len
390  
391 13 ▶ $_[3] = 0.0, return unless $_[6];
Branch: 1 branch
BranchTrueFalseTotal
unless $_[6] 2 11 13
392  
393 11 my $first = unpack("C",substr($_[4],$_[5],1));
394 11 ▶ if ($first & 0x80) {
Branch: 3 branches
BranchTrueFalseTotal
if ($first & 128) { } 9 2 11
elsif ($first & 64) { } 2 0 2
elsif (substr($_[4], $_[5], $_[6]) =~ /^.([-+]?)0*(\d+(?:\.\d+(?:[Ee][-+]?\d+)?)?)$/s) { } 0 0 0
395 # A real number
396  
397 9 require POSIX;
398  
399 9 my $exp;
400 9 my $expLen = $first & 0x3;
401 9 my $estart = $_[5]+1;
402  
403 9 ▶ if($expLen == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expLen == 3) { } 3 6 9
404 3 $estart++;
405 3 $expLen = unpack("C",substr($_[4],$_[5]+1,1));
406 }
407 else {
408 6 $expLen++;
409 }
410  
411 9 my $overhead = $estart - $_[5]; # 1 short-form, 2 long-form
412 # an exponent over 4 bytes would become a bigint and make pow() run unbounded
413 9 ▶ die "REAL decode error\n" if $expLen > 4 || $expLen > $_[6] - $overhead;
Branch: 1 branch
BranchTrueFalseTotal
if $expLen > 4 or $expLen > $_[6] - $overhead 2 7 9
Condition100%3/3
$expLen > 4 or $expLen > $_[6] - $overhead
l!l&&r!l&&!r
117
MC/DC100%2/2
$expLen > 4 or $expLen > $_[6] - $overhead
$expLen > 4 $expLen > $_[6] - $overhead
Truth table100%3/3
A or B
A= $expLen > 4B= $expLen > $_[6] - $overhead
ABresult
1X1
011
000
414  
415 7 _dec_integer(undef, undef, undef, $exp, $_[4],$estart,$expLen);
416  
417 7 my $mant = 0.0;
418 7 for (reverse unpack("C*",substr($_[4],$estart+$expLen,$_[6]-$overhead-$expLen))) {
419 8 $exp +=8, $mant = (($mant+$_) / 256) ;
420 }
421  
422 7 $mant *= 1 << (($first >> 2) & 0x3);
423 7 ▶ $mant = - $mant if $first & 0x40;
Branch: 1 branch
BranchTrueFalseTotal
if $first & 64 1 6 7
424  
425 7 $_[3] = $mant * POSIX::pow($_dec_real_base[($first >> 4) & 0x3], $exp);
426 7 return;
427 }
428 elsif($first & 0x40) {
429 2 ▶ $_[3] = POSIX::HUGE_VAL(),return if $first == 0x40;
Branch: 1 branch
BranchTrueFalseTotal
if $first == 64 1 1 2
430 1 ▶ $_[3] = - POSIX::HUGE_VAL(),return if $first == 0x41;
Branch: 1 branch
BranchTrueFalseTotal
if $first == 65 1 0 1
431 }
432 elsif(substr($_[4],$_[5],$_[6]) =~ /^.([-+]?)0*(\d+(?:\.\d+(?:[Ee][-+]?\d+)?)?)$/s) {
433 0 $_[3] = eval "$1$2";
434 0 return;
435 }
436  
437 0 die "REAL decode error\n";
438 }
439  
440  
441 30 ▶sub _dec_explicit {
Subroutine _dec_explicit: called CC=2 SCAR=6.9
442 # 0 1 2 3 4 5 6 7
443 # $optn, $op, $stash, $var, $buf, $pos, $len, $larr
444  
445 30 ▶ local $_[1][cCHILD][0][cVAR] = $_[1][cVAR] unless $_[1][cCHILD][0][cVAR];
Branch: 1 branch
BranchTrueFalseTotal
unless $_[1][6][0][2] 4 26 30
446  
447 30 _decode(
448 $_[0], #optn
449 $_[1]->[cCHILD], #ops
450 $_[2], #stash
451 $_[5], #pos
452 $_[5]+$_[6], #end
453 undef, #loop
454 $_[7],
455 $_[4], #buf
456 );
457 30 1;
458 }
459 402 ▶sub _dec_sequence {
Subroutine _dec_sequence: called CC=5 SCAR=16.3
460 # 0 1 2 3 4 5 6 7
461 # $optn, $op, $stash, $var, $buf, $pos, $len, $larr
462  
463 402 ▶ if (defined( my $ch = $_[1]->[cCHILD])) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $ch = $_[1][6])) { } 402 0 402
464 402 ▶ _decode(
Branch: 1 branch
BranchTrueFalseTotal
defined $_[3] || $_[1][3] ? : 162 240 402
Condition100%5/5
defined $_[3] or $_[1][3]
l!l&&r!l&&!r
34128240
$_[1][3] && ($_[3] = [])
!ll
274128
MC/DC100%2/2
defined $_[3] or $_[1][3]
defined $_[3] $_[1][3]
MC/DC100%1/1
$_[1][3] && ($_[3] = [])
$_[1][3]
Truth table100%3/3
A or B
A= defined $_[3]B= $_[1][3]
ABresult
1X1
011
000
Truth table100%2/2
A
A= $_[1][3]
Aresult
00
11
465 $_[0], #optn
466 $ch, #ops
467 (defined($_[3]) || $_[1]->[cLOOP]) ? $_[2] : ($_[3]= {}), #stash
468 $_[5], #pos
469 $_[5]+$_[6], #end
470 $_[1]->[cLOOP] && ($_[3]=[]), #loop
471 $_[7],
472 $_[4], #buf
473 );
474 }
475 else {
476 0 $_[3] = substr($_[4],$_[5],$_[6]);
477 }
478 399 1;
479 }
480  
481  
482 8 ▶sub _dec_set {
Subroutine _dec_set: called CC=34 SCAR=51.7
483 # 0 1 2 3 4 5 6 7
484 # $optn, $op, $stash, $var, $buf, $pos, $len, $larr
485  
486 # decode SET OF the same as SEQUENCE OF
487 8 my $ch = $_[1]->[cCHILD];
488 8 ▶ goto &_dec_sequence if $_[1]->[cLOOP] or !defined($ch);
Branch: 1 branch
BranchTrueFalseTotal
if $_[1][3] or not defined $ch 0 8 8
Condition33%1/3
$_[1][3] or not defined $ch
l!l&&r!l&&!r
008
MC/DC0%0/2
$_[1][3] or not defined $ch
$_[1][3] not defined $ch
Truth table33%1/3
A or not(B)
A= $_[1][3]B= not defined $ch
ABresult
1X1
011
000
489  
490 8 my ($optn, $pos, $larr) = @_[0,5,7];
491 8 ▶ my $stash = defined($_[3]) ? $_[2] : ($_[3]={});
Branch: 1 branch
BranchTrueFalseTotal
defined $_[3] ? : 8 0 8
492 8 my $end = $pos + $_[6];
493 8 my @done;
494 my $extensions;
495  
496 8 ▶ while ($pos < $end) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos < $end) 26 8 34
497 26 ▶ my($tag,$len,$npos,$indef) = _decode_tl($_[4],$pos,$end,$larr)
Branch: 1 branch
BranchTrueFalseTotal
() = _decode_tl($_[4], $pos, $end, $larr) or die "decode error" 26 0 26
498 or die "decode error";
499  
500 26 my ($idx, $any, $done) = (-1);
501  
502 SET_OP:
503 26 foreach my $op (@$ch) {
504 69 $idx++;
505 69 ▶ if (length($op->[cTAG])) {
Branch: 4 branches
BranchTrueFalseTotal
if (length $op->[0]) { } 55 14 69
elsif ($op->[1] == 14) { } 0 14 14
elsif ($op->[1] == 15) { } 0 14 14
elsif ($op->[1] == 18) { } 14 0 14
506 55 ▶ if ($tag eq $op->[cTAG]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag eq $op->[0]) 25 30 55
507 25 my $var = $op->[cVAR];
508 25 &{$decode[$op->[cTYPE]]}(
509 $optn,
510 $op,
511 $stash,
512 # We send 1 if there is not var as if there is the decode
513 # should be getting undef. So if it does not get undef
514 # it knows it has no variable
515 25 ▶ (defined($var) ? $stash->{$var} : 1),
Branch: 1 branch
BranchTrueFalseTotal
defined $var ? : 25 0 25
516 $_[4],$npos,$len,$larr,
517 );
518 25 $done = $idx;
519 25 last SET_OP;
520 }
521 30 ▶ if ($tag eq ($op->[cTAG] | pack("C",ASN_CONSTRUCTOR))
Branch: 1 branch
BranchTrueFalseTotal
if ($tag eq ($op->[0] | " ") and my $ctr = $ctr[$op->[1]]) 0 30 30
Condition33%1/3
$tag eq ($op->[0] | " ") and my $ctr = $ctr[$op->[1]]
!ll&&!rl&&r
3000
MC/DC0%0/2
$tag eq ($op->[0] | " ") and my $ctr = $ctr[$op->[1]]
$tag eq ($op->[0] | " ") my $ctr = $ctr[$op->[1]]
Truth table33%1/3
A and B
A= $tag eq ($op->[0] | " ")B= my $ctr = $ctr[$op->[1]]
ABresult
0X0
100
111
522 and my $ctr = $ctr[$op->[cTYPE]])
523 {
524 0 _decode(
525 $optn,
526 [$op],
527 undef,
528 $npos,
529 $npos+$len,
530 (\my @ctrlist),
531 $larr,
532 $_[4],
533 );
534  
535 0 ▶ $stash->{$op->[cVAR]} = &{$ctr}(@ctrlist)
Branch: 1 branch
BranchTrueFalseTotal
if defined $op->[2] 0 0 0
536 if defined $op->[cVAR];
537 0 $done = $idx;
538 0 last SET_OP;
539 }
540 30 next SET_OP;
541 }
542 elsif ($op->[cTYPE] == opANY) {
543 0 $any = $idx;
544 }
545 elsif ($op->[cTYPE] == opCHOICE) {
546 0 my $var = $op->[cVAR];
547 0 foreach my $cop (@{$op->[cCHILD]}) {
548 0 ▶ if ($tag eq $cop->[cTAG]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag eq $cop->[0]) 0 0 0
549 0 ▶ my $nstash = defined($var) ? ($stash->{$var}={}) : $stash;
Branch: 1 branch
BranchTrueFalseTotal
defined $var ? : 0 0 0
550  
551 0 &{$decode[$cop->[cTYPE]]}(
552 $optn,
553 $cop,
554 $nstash,
555 0 $nstash->{$cop->[cVAR]},
556 $_[4],$npos,$len,$larr,
557 );
558 0 $done = $idx;
559 0 last SET_OP;
560 }
561 0 ▶ if ($tag eq ($cop->[cTAG] | pack("C",ASN_CONSTRUCTOR))
Branch: 1 branch
BranchTrueFalseTotal
if ($tag eq ($cop->[0] | " ") and my $ctr = $ctr[$cop->[1]]) 0 0 0
Condition0%0/3
$tag eq ($cop->[0] | " ") and my $ctr = $ctr[$cop->[1]]
!ll&&!rl&&r
000
MC/DC0%0/2
$tag eq ($cop->[0] | " ") and my $ctr = $ctr[$cop->[1]]
$tag eq ($cop->[0] | " ") my $ctr = $ctr[$cop->[1]]
Truth table0%0/3
A and B
A= $tag eq ($cop->[0] | " ")B= my $ctr = $ctr[$cop->[1]]
ABresult
0X0
100
111
562 and my $ctr = $ctr[$cop->[cTYPE]])
563 {
564 0 ▶ my $nstash = defined($var) ? ($stash->{$var}={}) : $stash;
Branch: 1 branch
BranchTrueFalseTotal
defined $var ? : 0 0 0
565  
566 0 _decode(
567 $optn,
568 [$cop],
569 undef,
570 $npos,
571 $npos+$len,
572 (\my @ctrlist),
573 $larr,
574 $_[4],
575 );
576  
577 0 $nstash->{$cop->[cVAR]} = &{$ctr}(@ctrlist);
578 0 $done = $idx;
579 0 last SET_OP;
580 }
581 }
582 }
583 elsif ($op->[cTYPE] == opEXTENSIONS) {
584 14 $extensions = $idx;
585 }
586 else {
587 0 die "internal error";
588 }
589 }
590  
591 26 ▶ if (!defined($done) and defined($any)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $done and defined $any) 0 26 26
Condition66%2/3
not defined $done and defined $any
!ll&&!rl&&r
2510
MC/DC0%0/2
not defined $done and defined $any
not defined $done defined $any
Truth table66%2/3
not(A) and B
A= not defined $doneB= defined $any
ABresult
0X0
100
111
592 0 my $var = $ch->[$any][cVAR];
593 0 ▶ $stash->{$var} = substr($_[4],$pos,$len+$npos-$pos) if defined $var;
Branch: 1 branch
BranchTrueFalseTotal
if defined $var 0 0 0
594 0 $done = $any;
595 }
596  
597 26 ▶ if( !defined($done) && defined($extensions) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $done and defined $extensions) 1 25 26
Condition66%2/3
not defined $done and defined $extensions
!ll&&!rl&&r
2501
MC/DC50%1/2
not defined $done and defined $extensions
not defined $done defined $extensions
Truth table66%2/3
not(A) and B
A= not defined $doneB= defined $extensions
ABresult
0X0
100
111
598 1 $done = $extensions;
599 }
600  
601 26 ▶ die "decode error" if !defined($done) or $done[$done]++;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $done or $done[$done]++ 0 26 26
Condition33%1/3
not defined $done or $done[$done]++
l!l&&r!l&&!r
0026
MC/DC0%0/2
not defined $done or $done[$done]++
not defined $done $done[$done]++
Truth table33%1/3
not(A) or B
A= not defined $doneB= $done[$done]++
ABresult
1X1
011
000
602  
603 26 $pos = $npos + $len + $indef;
604 }
605  
606 8 ▶ die "decode error" unless $end == $pos;
Branch: 1 branch
BranchTrueFalseTotal
unless $end == $pos 0 8 8
607  
608 8 foreach my $idx (0..$#{$ch}) {
609 30 ▶ die "decode error" unless $done[$idx] or $ch->[$idx][cEXT] or $ch->[$idx][cTYPE] == opEXTENSIONS;
Branch: 1 branch
BranchTrueFalseTotal
unless $done[$idx] or $ch->[$idx][5] or $ch->[$idx][1] == 18 0 30 30
Condition83%5/6
$done[$idx] or $ch->[$idx][5] or $ch->[$idx][1] == 18
l!l&&r!l&&!r
2730
$done[$idx] or $ch->[$idx][5]
l!l&&r!l&&!r
2613
MC/DC0%0/3
$done[$idx] or $ch->[$idx][5] or $ch->[$idx][1] == 18
$done[$idx] $ch->[$idx][5] $ch->[$idx][1] == 18
Truth table75%3/4
A or B or C
A= $done[$idx]B= $ch->[$idx][5]C= $ch->[$idx][1] == 18
ABCresult
1XX1
01X1
0011
0000
610 }
611  
612 8 1;
613 }
614  
615  
616 32 my %_dec_time_opt = ( unixtime => 0, withzone => 1, raw => 2);
617  
618 44 ▶sub _dec_time {
Subroutine _dec_time: called CC=12 SCAR=24.9
619 # 0 1 2 3 4 5 6
620 # $optn, $op, $stash, $var, $buf, $pos, $len
621  
622 44 ▶ my $mode = $_dec_time_opt{$_[0]->{'decode_time'} || ''} || 0;
Condition100%4/4
$_dec_time_opt{$_[0]{'decode_time'} or ''} || 0
l!l
1034
$_[0]{'decode_time'} || ''
l!l
1034
MC/DC100%1/1
$_dec_time_opt{$_[0]{'decode_time'} or ''} || 0
$_dec_time_opt{$_[0]{'decode_time'} or ''}
MC/DC100%1/1
$_[0]{'decode_time'} || ''
$_[0]{'decode_time'}
Truth table100%2/2
A
A= $_dec_time_opt{$_[0]{'decode_time'} or ''}
Aresult
11
00
Truth table100%2/2
A
A= $_[0]{'decode_time'}
Aresult
11
00
623  
624 44 ▶ if ($mode == 2 or $_[6] == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode == 2 or $_[6] == 0) 10 34 44
Condition66%2/3
$mode == 2 or $_[6] == 0
l!l&&r!l&&!r
10034
MC/DC50%1/2
$mode == 2 or $_[6] == 0
$mode == 2 $_[6] == 0
Truth table66%2/3
A or B
A= $mode == 2B= $_[6] == 0
ABresult
1X1
011
000
625 10 $_[3] = substr($_[4],$_[5],$_[6]);
626 10 return;
627 }
628  
629 34 ▶ my @bits = (substr($_[4],$_[5],$_[6])
Branch: 1 branch
BranchTrueFalseTotal
my(@bits) = substr($_[4], $_[5], $_[6]) =~ /^((?:\d\d)?\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)((?:\.\d{1,3})?)(([-+])(\d\d)(\d\d)|Z)/ or die "bad time format" 34 0 34
630 =~ /^((?:\d\d)?\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)((?:\.\d{1,3})?)(([-+])(\d\d)(\d\d)|Z)/)
631 or die "bad time format";
632  
633 # two digit year (UTCTime), RFC 5280 4.1.2.5.1: 50 - 99 is 19YY, 00 - 49 is 20YY
634 34 ▶ if (length $bits[0] == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $bits[0] == 2) 25 9 34
635 25 ▶ $bits[0] += ($bits[0] < 50) ? 2000 : 1900;
Branch: 1 branch
BranchTrueFalseTotal
$bits[0] < 50 ? : 21 4 25
636 }
637 34 $bits[1] -= 1;
638 34 require Time::Local;
639 34 my $time = Time::Local::timegm_modern(@bits[5,4,3,2,1,0]);
640 34 ▶ $time += $bits[6] if length $bits[6];
Branch: 1 branch
BranchTrueFalseTotal
if length $bits[6] 1 33 34
641 34 my $offset = 0;
642 34 ▶ if ($bits[7] ne 'Z') {
Branch: 1 branch
BranchTrueFalseTotal
if ($bits[7] ne "Z") 5 29 34
643 5 $offset = $bits[9] * 3600 + $bits[10] * 60;
644 5 ▶ $offset = -$offset if $bits[8] eq '-';
Branch: 1 branch
BranchTrueFalseTotal
if $bits[8] eq "-" 1 4 5
645 5 $time -= $offset;
646 }
647 34 ▶ $_[3] = $mode ? [$time,$offset] : $time;
Branch: 1 branch
BranchTrueFalseTotal
$mode ? : 0 34 34
648 }
649  
650  
651 2 ▶sub _dec_utf8 {
Subroutine _dec_utf8: called CC=1 SCAR=0.0
652 # 0 1 2 3 4 5 6
653 # $optn, $op, $stash, $var, $buf, $pos, $len
654  
655 32 ▶ BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
656 32 unless (CHECK_UTF8) {
657 local $SIG{__DIE__};
658 eval { require bytes } and 'bytes'->unimport;
659 eval { require utf8 } and 'utf8'->import;
660 }
661 }
662  
663 2 if (CHECK_UTF8) {
664 2 $_[3] = Encode::decode('utf8', substr($_[4],$_[5],$_[6]));
665 }
666 else {
667 $_[3] = (substr($_[4],$_[5],$_[6]) =~ /(.*)/s)[0];
668 }
669  
670 2 1;
671 }
672  
673  
674 1754 ▶sub _decode_tl {
Subroutine _decode_tl: called CC=13 SCAR=25.8
675 1754 my($pos,$end,$larr) = @_[1,2,3];
676  
677 1754 ▶ return if $pos >= $end;
Branch: 1 branch
BranchTrueFalseTotal
if $pos >= $end 25 1729 1754
678  
679 1729 my $indef = 0;
680  
681 1729 my $tag = substr($_[0], $pos++, 1);
682  
683 1729 ▶ if((unpack("C",$tag) & 0x1f) == 0x1f) {
Branch: 1 branch
BranchTrueFalseTotal
if ((unpack("C", $tag) & 31) == 31) 1 1728 1729
684 1 my $b;
685 1 my $n=1;
686 1 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$b & 128 and do { do { return if $pos >= $end; $tag .= substr($_[0], $pos++, 1); $b = ord substr($tag, -1) } } 4 0 4
687 5 ▶ return if $pos >= $end;
Branch: 1 branch
BranchTrueFalseTotal
if $pos >= $end 1 4 5
688 4 $tag .= substr($_[0],$pos++,1);
689 4 $b = ord substr($tag,-1);
690 } while($b & 0x80);
691 }
692 1728 ▶ return if $pos >= $end;
Branch: 1 branch
BranchTrueFalseTotal
if $pos >= $end 0 1728 1728
693  
694 1728 my $len = ord substr($_[0],$pos++,1);
695  
696 1728 ▶ if($len & 0x80) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len & 128) 141 1587 1728
697 141 $len &= 0x7f;
698  
699 141 ▶ if ($len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len) { } 131 10 141
700 131 ▶ return if $pos+$len > $end ;
Branch: 1 branch
BranchTrueFalseTotal
if $pos + $len > $end 0 131 131
701  
702 131 ▶ my $padding = $len < 4 ? "\0" x (4 - $len) : "";
Branch: 1 branch
BranchTrueFalseTotal
$len < 4 ? : 131 0 131
703 131 ($len,$pos) = (unpack("N", $padding . substr($_[0],$pos,$len)), $pos+$len);
704 }
705 else {
706 10 ▶ unless (exists $larr->{$pos}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $larr->{$pos}) 5 5 10
707 5 ▶ _scan_indef($_[0],$pos,$end,$larr) or return;
Branch: 1 branch
BranchTrueFalseTotal
_scan_indef($_[0], $pos, $end, $larr) or return 4 1 5
708 }
709 9 $indef = 2;
710 9 $len = $larr->{$pos};
711 }
712 }
713  
714 1727 ▶ return if $pos+$len+$indef > $end;
Branch: 1 branch
BranchTrueFalseTotal
if $pos + $len + $indef > $end 0 1727 1727
715  
716 # return the tag, the length of the data, the position of the data
717 # and the number of extra bytes for indefinite encoding
718  
719 1727 ($tag, $len, $pos, $indef);
720 }
721  
722 5 ▶sub _scan_indef {
Subroutine _scan_indef: called CC=13 SCAR=27.1
723 5 my($pos,$end,$larr) = @_[1,2,3];
724 5 my @depth = ( $pos );
725  
726 5 ▶ while(@depth) {
Branch: 1 branch
BranchTrueFalseTotal
if (@depth) 27 4 31
727 27 ▶ return if $pos+2 > $end;
Branch: 1 branch
BranchTrueFalseTotal
if $pos + 2 > $end 0 27 27
728  
729 27 ▶ if (substr($_[0],$pos,2) eq "\0\0") {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($_[0], $pos, 2) eq "\0\0") 10 17 27
730 10 my $end = $pos;
731 10 my $stref = shift @depth;
732 # replace pos with length = end - pos
733 10 $larr->{$stref} = $end - $stref;
734 10 $pos += 2;
735 10 next;
736 }
737 17 ▶ return if $pos >= $end;
Branch: 1 branch
BranchTrueFalseTotal
if $pos >= $end 0 17 17
738  
739 17 my $tag = substr($_[0], $pos++, 1);
740  
741 17 ▶ if((unpack("C",$tag) & 0x1f) == 0x1f) {
Branch: 1 branch
BranchTrueFalseTotal
if ((unpack("C", $tag) & 31) == 31) 1 16 17
742 1 my $b;
743 1 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$b & 128 and do { do { return if $pos >= $end; $tag .= substr($_[0], $pos++, 1); $b = ord substr($tag, -1) } } 2 0 2
744 3 ▶ return if $pos >= $end;
Branch: 1 branch
BranchTrueFalseTotal
if $pos >= $end 1 2 3
745 2 $tag .= substr($_[0],$pos++,1);
746 2 $b = ord substr($tag,-1);
747 } while($b & 0x80);
748 }
749 16 ▶ return if $pos >= $end;
Branch: 1 branch
BranchTrueFalseTotal
if $pos >= $end 0 16 16
750  
751 16 my $len = ord substr($_[0],$pos++,1);
752  
753 16 ▶ if($len & 0x80) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len & 128) { } 6 10 16
754 6 ▶ if ($len &= 0x7f) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len &= 127) { } 0 6 6
755 0 ▶ return if $pos+$len > $end ;
Branch: 1 branch
BranchTrueFalseTotal
if $pos + $len > $end 0 0 0
756  
757 0 ▶ my $padding = $len < 4 ? "\0" x (4 - $len) : "";
Branch: 1 branch
BranchTrueFalseTotal
$len < 4 ? : 0 0 0
758 0 $pos += $len + unpack("N", $padding . substr($_[0],$pos,$len));
759 }
760 else {
761 # reserve another list element
762 6 unshift @depth, $pos;
763 }
764 }
765 else {
766 10 $pos += $len;
767 }
768 }
769  
770 4 1;
771 }
772  
773 1 ▶sub _ctr_string { join '', @_ }
Subroutine _ctr_string: called CC=1 SCAR=0.0
774  
775 1 ▶sub _ctr_bitstring {
Subroutine _ctr_bitstring: called CC=1 SCAR=0.0
776 1 [ join('', map { $_->[0] } @_), $_[-1]->[1] ]
777 }
778  
779 8 ▶sub _dec_bcd {
Subroutine _dec_bcd: called CC=1 SCAR=0.0
780 # 0 1 2 3 4 5 6
781 # $optn, $op, $stash, $var, $buf, $pos, $len
782  
783 8 ($_[3] = unpack("H*", substr($_[4],$_[5],$_[6]))) =~ s/[fF]$//;
784 8 1;
785 }
786 32 1;
787  
↑ Summary ASN1/Debug.pm »