ASN1/_encode.pm

filter: Statementstmt 88.2% 187 / 212 Branchbran 89.3% 109 / 122 Conditioncond 61.5% 24 / 39 MC/DCmcdc 40.9% 9 / 22 Subroutinesub 94.7% 18 / 19 Podpod n/a totaltotal 83.8% 347 / 414 CC 79 SCAR 24.1
CC
79
Cov
86%
_enc_integer
23.8
_enc_time
12.8
_encode
10.0
CRAP 11.2
« ASN1/IO.pm ↑ Summary ASN1.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 32 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 32 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
12 32 unless (CHECK_UTF8) {
13 local $SIG{__DIE__};
14 eval { require bytes } and 'bytes'->import
15 }
16 }
17  
18 # These are the subs which do the encoding, they are called with
19 # 0 1 2 3 4 5
20 # $opt, $op, $stash, $var, $buf, $loop
21 # The order in the array must match the op definitions above
22  
23 my @encode = (
24 0 ▶ sub { die "internal error\n" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
25 32 \&_enc_boolean,
26 \&_enc_integer,
27 \&_enc_bitstring,
28 \&_enc_string,
29 \&_enc_null,
30 \&_enc_object_id,
31 \&_enc_real,
32 \&_enc_sequence,
33 \&_enc_sequence, # EXPLICIT is the same encoding as sequence
34 \&_enc_sequence, # SET is the same encoding as sequence
35 \&_enc_time,
36 \&_enc_time,
37 \&_enc_utf8,
38 \&_enc_any,
39 \&_enc_choice,
40 \&_enc_object_id,
41 \&_enc_bcd,
42 );
43  
44  
45 175 ▶sub _encode {
Subroutine _encode: called CC=10 SCAR=23.0
46 175 my ($optn, $ops, $stash, $path) = @_;
47 175 my $var;
48  
49 175 foreach my $op (@{$ops}) {
50 222 ▶ next if $op->[cTYPE] == opEXTENSIONS;
Branch: 1 branch
BranchTrueFalseTotal
if $op->[1] == 18 5 217 222
51 217 ▶ if (defined(my $opt = $op->[cOPT])) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $opt = $op->[4])) 5 212 217
52 5 ▶ next unless defined $stash->{$opt};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $stash->{$opt} 2 3 5
53 }
54 215 ▶ if (defined($var = $op->[cVAR])) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($var = $op->[2])) 178 37 215
55 178 push @$path, $var;
56 178 ▶ require Carp, Carp::croak(join(".", @$path)," is undefined") unless defined $stash->{$var};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $stash->{$var} 3 175 178
57 }
58 212 $_[4] .= $op->[cTAG];
59  
60 212 &{$encode[$op->[cTYPE]]}(
61 $optn,
62 $op,
63 (UNIVERSAL::isa($stash, 'HASH')
64 212 ▶ ? ($stash, defined($var) ? $stash->{$var} : undef)
Branch: 2 branches
BranchTrueFalseTotal
UNIVERSAL::isa($stash, 'HASH') ? : 202 10 212
defined $var ? : 175 27 202
65 : ({}, $stash)),
66 $_[4],
67 $op->[cLOOP],
68 $path,
69 );
70  
71 200 ▶ pop @$path if defined $var;
Branch: 1 branch
BranchTrueFalseTotal
if defined $var 165 35 200
72 }
73  
74 160 $_[4];
75 }
76  
77  
78 15 ▶sub _enc_boolean {
Subroutine _enc_boolean: called CC=2 SCAR=6.9
79 # 0 1 2 3 4 5 6
80 # $optn, $op, $stash, $var, $buf, $loop, $path
81  
82 15 ▶ $_[4] .= pack("CC",1, $_[3] ? 0xff : 0);
Branch: 1 branch
BranchTrueFalseTotal
$_[3] ? : 3 12 15
83 }
84  
85  
86 87 ▶sub _enc_integer {
Subroutine _enc_integer: called CC=23 SCAR=31.7
87 # 0 1 2 3 4 5 6
88 # $optn, $op, $stash, $var, $buf, $loop, $path
89 87 ▶ if (abs($_[3]) >= 2**31) {
Branch: 1 branch
BranchTrueFalseTotal
if (abs $_[3] >= 2147483648) { } 27 60 87
90 27 ▶ my $biclass = $_[0]->{encode_bigint} || 'Math::BigInt';
Condition50%1/2
$_[0]{'encode_bigint'} || 'Math::BigInt'
l!l
027
MC/DC0%0/1
$_[0]{'encode_bigint'} || 'Math::BigInt'
$_[0]{'encode_bigint'}
Truth table50%1/2
A
A= $_[0]{'encode_bigint'}
Aresult
11
00
91 27 my $digits;
92 27 ▶ if (blessed($_[3]) && $_[3]->isa($biclass)) {
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::blessed($_[3]) and $_[3]->isa($biclass)) { } 10 17 27
elsif ("$_[3]" =~ /\A\s*[+-]?0*(\d*)(?:\.(\d*))?(?:[eE]([+-]?\d+))?\s*\z/ and length $1 || defined $2 && length $2) { } 16 1 17
Condition66%2/3
builtin::blessed($_[3]) and $_[3]->isa($biclass)
!ll&&!rl&&r
17010
MC/DC50%1/2
builtin::blessed($_[3]) and $_[3]->isa($biclass)
builtin::blessed($_[3]) $_[3]->isa($biclass)
Truth table66%2/3
A and B
A= builtin::blessed($_[3])B= $_[3]->isa($biclass)
ABresult
0X0
100
111
93 10 ($digits = "$_[3]") =~ s/^[+-]//;
94 10 $digits = length $digits;
95 }
96 # size exponent-form strings before the bigint class expands them
97 ▶ elsif ("$_[3]" =~ /\A\s*[+-]?0*(\d*)(?:\.(\d*))?(?:[eE]([+-]?\d+))?\s*\z/
Condition33%3/9
"$_[3]" =~ /\A\s*[+-]?0*(\d*)(?:\.(\d*))?(?:[eE]([+-]?\d+))?\s*\z/ and length $1 || defined $2 && length $2
!ll&&!rl&&r
1016
length $1 or defined $2 and length $2
l!l&&r!l&&!r
1600
defined $2 and length $2
!ll&&!rl&&r
000
MC/DC25%1/4
"$_[3]" =~ /\A\s*[+-]?0*(\d*)(?:\.(\d*))?(?:[eE]([+-]?\d+))?\s*\z/ and length $1 || defined $2 && length $2
"$_[3]" =~ /\A\s*[+-]?0*(\d*)(?:\.(\d*))?(?:[eE]([+-]?\d+))?\s*\z/ length $1 defined $2 length $2
Truth table40%2/5
A and B or C and D
A= "$_[3]" =~ /\A\s*[+-]?0*(\d*)(?:\.(\d*))?(?:[eE]([+-]?\d+))?\s*\z/B= length $1C= defined $2D= length $2
ABCDresult
0XXX0
100X0
10100
11XX1
10111
98 && (length($1) || (defined($2) && length($2)))) {
99 16 ▶ $digits = length($1) + ($3 || 0);
Condition100%2/2
$3 || 0
l!l
412
MC/DC100%1/1
$3 || 0
$3
Truth table100%2/2
A
A= $3
Aresult
11
00
100 }
101 else {
102 1 die "INTEGER value is not an integer\n";
103 }
104 my $max = exists $_[0]->{encode_max_int_len}
105 ? $_[0]->{encode_max_int_len}
106 26 ▶ : 1025;
Branch: 1 branch
BranchTrueFalseTotal
exists $_[0]{'encode_max_int_len'} ? : 3 23 26
107 26 ▶ die "encode: max_int_len must not be negative\n" if $max < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $max < 0 1 25 26
108 25 ▶ if ($max) {
Branch: 1 branch
BranchTrueFalseTotal
if ($max) 24 1 25
109 # estimate byte size 0.415 = log(10) / log(256)
110 24 ▶ die "INTEGER too large\n" if int(($digits - 1) * 0.415) > $max + 1;
Branch: 1 branch
BranchTrueFalseTotal
if int(($digits - 1) * "0.415") > $max + 1 1 23 24
111 }
112 24 ▶ my $os = i2osp($_[3], blessed($_[3]) || $biclass);
Condition66%2/3
builtin::blessed($_[3]) || $biclass
l!l&&r!l&&!r
9150
MC/DC0%0/2
builtin::blessed($_[3]) || $biclass
builtin::blessed($_[3]) $biclass
Truth table66%2/3
A || B
A= builtin::blessed($_[3])B= $biclass
ABresult
1X1
011
000
113 23 my $len = length $os;
114 23 ▶ my $msb = (vec($os, 0, 8) & 0x80) ? 0 : 255;
Branch: 1 branch
BranchTrueFalseTotal
vec($os, 0, 8) & 128 ? : 8 15 23
115 23 ▶ $len++, $os = pack("C",$msb) . $os if $msb xor $_[3] > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $msb xor $_[3] > 0 4 19 23
Condition100%4/4
$msb xor $_[3] > 0
l&&rl&&!r!l&&r!l&&!r
13226
MC/DC100%2/2
$msb xor $_[3] > 0
$msb $_[3] > 0
Truth table100%4/4
A xor B
A= $msbB= $_[3] > 0
ABresult
110
101
011
000
116 23 ▶ die "INTEGER too large (length $len exceeds max_int_len $max)\n"
Branch: 1 branch
BranchTrueFalseTotal
if $max and $len > $max 1 22 23
Condition100%3/3
$max and $len > $max
!ll&&!rl&&r
1211
MC/DC100%2/2
$max and $len > $max
$max $len > $max
Truth table100%3/3
A and B
A= $maxB= $len > $max
ABresult
0X0
100
111
117 if $max && $len > $max;
118 22 $_[4] .= asn_encode_length($len);
119 22 $_[4] .= $os;
120 }
121 else {
122 60 my $val = int($_[3]);
123 60 my $neg = ($val < 0);
124 60 ▶ my $len = num_length($neg ? ~$val : $val);
Branch: 1 branch
BranchTrueFalseTotal
$neg ? : 10 50 60
125 60 my $msb = $val & (0x80 << (($len - 1) * 8));
126  
127 60 ▶ $len++ if $neg ? !$msb : $msb;
Branch: 2 branches
BranchTrueFalseTotal
if $neg ? !$msb : $msb 2 58 60
$neg ? : 10 50 60
128  
129 60 $_[4] .= asn_encode_length($len);
130 60 $_[4] .= substr(pack("N",$val), -$len);
131 }
132 }
133  
134  
135 4 ▶sub _enc_bitstring {
Subroutine _enc_bitstring: called CC=6 SCAR=18.6
136 # 0 1 2 3 4 5 6
137 # $optn, $op, $stash, $var, $buf, $loop, $path
138 4 ▶ my $vref = ref($_[3]) ? \($_[3]->[0]) : \$_[3];
Branch: 1 branch
BranchTrueFalseTotal
ref $_[3] ? : 3 1 4
139  
140 4 ▶ if (CHECK_UTF8 and Encode::is_utf8($$vref)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&Encode::is_utf8($$vref)) 0 4 4
141 0 utf8::encode(my $tmp = $$vref);
142 0 $vref = \$tmp;
143 }
144  
145 4 ▶ if (ref($_[3])) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[3]) { } 3 1 4
146 3 my $less = (8 - ($_[3]->[1] & 7)) & 7;
147 3 my $len = ($_[3]->[1] + 7) >> 3;
148 3 $_[4] .= asn_encode_length(1+$len);
149 3 $_[4] .= pack("C",$less);
150 3 $_[4] .= substr($$vref, 0, $len);
151 3 ▶ if ($less && $len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($less and $len) 3 0 3
Condition33%1/3
$less and $len
!ll&&!rl&&r
003
MC/DC0%0/2
$less and $len
$less $len
Truth table33%1/3
A and B
A= $lessB= $len
ABresult
0X0
100
111
152 3 substr($_[4],-1) &= pack("C",(0xff << $less) & 0xff);
153 }
154 }
155 else {
156 1 $_[4] .= asn_encode_length(1+length $$vref);
157 1 $_[4] .= pack("C",0);
158 1 $_[4] .= $$vref;
159 }
160 }
161  
162  
163 41 ▶sub _enc_string {
Subroutine _enc_string: called CC=2 SCAR=6.9
164 # 0 1 2 3 4 5 6
165 # $optn, $op, $stash, $var, $buf, $loop, $path
166  
167 41 ▶ if (CHECK_UTF8 and Encode::is_utf8($_[3])) {
Branch: 1 branch
BranchTrueFalseTotal
if (&Encode::is_utf8($_[3])) { } 1 40 41
168 1 utf8::encode(my $tmp = $_[3]);
169 1 $_[4] .= asn_encode_length(length $tmp);
170 1 $_[4] .= $tmp;
171 }
172 else {
173 40 $_[4] .= asn_encode_length(length $_[3]);
174 40 $_[4] .= $_[3];
175 }
176 }
177  
178  
179 2 ▶sub _enc_null {
Subroutine _enc_null: called CC=1 SCAR=0.0
180 # 0 1 2 3 4 5 6
181 # $optn, $op, $stash, $var, $buf, $loop, $path
182  
183 2 $_[4] .= pack("C",0);
184 }
185  
186  
187 19 ▶sub _enc_object_id {
Subroutine _enc_object_id: called CC=7 SCAR=19.5
188 # 0 1 2 3 4 5 6
189 # $optn, $op, $stash, $var, $buf, $loop, $path
190  
191 19 my @data = ($_[3] =~ /(\d+)/g);
192  
193 # pack "w" is quadratic in arc length, so bound each arc first
194 my $max = exists $_[0]->{encode_max_oid_arc_len}
195 ? $_[0]->{encode_max_oid_arc_len}
196 19 ▶ : 32;
Branch: 1 branch
BranchTrueFalseTotal
exists $_[0]{'encode_max_oid_arc_len'} ? : 4 15 19
197 19 ▶ die "encode: max_oid_arc_len must not be negative\n" if $max < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $max < 0 1 18 19
198 18 ▶ if ($max) {
Branch: 1 branch
BranchTrueFalseTotal
if ($max) 17 1 18
199 # any arc of this many digits fits in $max bytes: 2.107 < 7 * log10(2)
200 17 my $digits = int($max * 2.107);
201 die "OBJECT IDENTIFIER arc too large\n"
202 17 ▶ if grep { length > $digits } @data;
Branch: 1 branch
BranchTrueFalseTotal
if grep {length $_ > $digits;} @data 4 13 17
203 }
204  
205 14 ▶ if ($_[1]->[cTYPE] == opOBJID) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[1][1] == 6) 11 3 14
206 11 ▶ if(@data < 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@data < 2) { } 0 11 11
207 0 @data = (0);
208 }
209 else {
210 11 my $first = $data[1] + ($data[0] * 40);
211 11 splice(@data,0,2,$first);
212 }
213 }
214  
215 14 my $l = length $_[4];
216 14 $_[4] .= pack("cw*", 0, @data);
217 14 substr($_[4],$l,1) = asn_encode_length(length($_[4]) - $l - 1);
218 }
219  
220  
221 7 ▶sub _enc_real {
Subroutine _enc_real: called CC=9 SCAR=22.6
222 # 0 1 2 3 4 5 6
223 # $optn, $op, $stash, $var, $buf, $loop, $path
224  
225 # Zero
226 7 ▶ unless ($_[3]) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($_[3]) 1 6 7
227 1 $_[4] .= pack("C",0);
228 1 return;
229 }
230  
231 6 require POSIX;
232  
233 # +oo (well we use HUGE_VAL as Infinity is not available to perl)
234 6 ▶ if ($_[3] >= POSIX::HUGE_VAL()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[3] >= &POSIX::HUGE_VAL()) 1 5 6
235 1 $_[4] .= pack("C*",0x01,0x40);
236 1 return;
237 }
238  
239 # -oo (well we use HUGE_VAL as Infinity is not available to perl)
240 5 ▶ if ($_[3] <= - POSIX::HUGE_VAL()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[3] <= -&POSIX::HUGE_VAL()) 1 4 5
241 1 $_[4] .= pack("C*",0x01,0x41);
242 1 return;
243 }
244  
245 4 ▶ if (exists $_[0]->{'encode_real'} && $_[0]->{'encode_real'} ne 'binary') {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $_[0]{"encode_real"} and $_[0]{"encode_real"} ne "binary") 0 4 4
Condition33%1/3
exists $_[0]{"encode_real"} and $_[0]{"encode_real"} ne "binary"
!ll&&!rl&&r
400
MC/DC0%0/2
exists $_[0]{"encode_real"} and $_[0]{"encode_real"} ne "binary"
exists $_[0]{"encode_real"} $_[0]{"encode_real"} ne "binary"
Truth table33%1/3
A and B
A= exists $_[0]{"encode_real"}B= $_[0]{"encode_real"} ne "binary"
ABresult
0X0
100
111
246 0 my $tmp = sprintf("%g",$_[3]);
247 0 $_[4] .= asn_encode_length(1+length $tmp);
248 0 $_[4] .= pack("C",1); # NR1?
249 0 $_[4] .= $tmp;
250 0 return;
251 }
252  
253 # We have a real number.
254 4 my $first = 0x80;
255 4 my($mantissa, $exponent) = POSIX::frexp($_[3]);
256  
257 4 ▶ if ($mantissa < 0.0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mantissa < 0) 1 3 4
258 1 $mantissa = -$mantissa;
259 1 $first |= 0x40;
260 }
261 4 my($eMant,$eExp);
262  
263 4 ▶ while($mantissa > 0.0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mantissa > 0) 5 4 9
264 5 ($mantissa, my $int) = POSIX::modf($mantissa * (1<<8));
265 5 $eMant .= pack("C",$int);
266 }
267 4 $exponent -= 8 * length $eMant;
268  
269 4 _enc_integer(undef, undef, undef, $exponent, $eExp);
270  
271 # $eExp will be prefixed by a length byte
272
273 4 ▶ if (5 > length $eExp) {
Branch: 1 branch
BranchTrueFalseTotal
if (5 > length $eExp) { } 4 0 4
274 4 $eExp =~ s/\A.//s;
275 4 $first |= length($eExp)-1;
276 }
277 else {
278 0 $first |= 0x3;
279 }
280  
281 4 $_[4] .= asn_encode_length(1 + length($eMant) + length($eExp));
282 4 $_[4] .= pack("C",$first);
283 4 $_[4] .= $eExp;
284 4 $_[4] .= $eMant;
285 }
286  
287  
288 45 ▶sub _enc_sequence {
Subroutine _enc_sequence: called CC=5 SCAR=16.2
289 # 0 1 2 3 4 5 6
290 # $optn, $op, $stash, $var, $buf, $loop, $path
291  
292 45 ▶ if (my $ops = $_[1]->[cCHILD]) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ops = $_[1][6]) { } 45 0 45
293 45 my $l = length $_[4];
294 45 $_[4] .= "\0\0"; # guess
295 45 ▶ if (defined $_[5]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[5]) { } 11 34 45
296 11 my $op = $ops->[0]; # there should only be one
297 11 my $enc = $encode[$op->[cTYPE]];
298 11 my $tag = $op->[cTAG];
299 11 my $loop = $op->[cLOOP];
300  
301 11 push @{$_[6]}, -1;
302  
303 11 foreach my $var (@{$_[3]}) {
304 32 $_[6]->[-1]++;
305 32 $_[4] .= $tag;
306  
307 32 &{$enc}(
308 $_[0], # $optn
309 $op, # $op
310 $_[2], # $stash
311 $var, # $var
312 $_[4], # $buf
313 $loop, # $loop
314 $_[6], # $path
315 );
316 }
317 11 pop @{$_[6]};
318 }
319 else {
320 34 ▶ _encode($_[0],$_[1]->[cCHILD], defined($_[3]) ? $_[3] : $_[2], $_[6], $_[4]);
Branch: 1 branch
BranchTrueFalseTotal
defined $_[3] ? : 11 23 34
321 }
322 43 substr($_[4],$l,2) = asn_encode_length(length($_[4]) - $l - 2);
323 }
324 else {
325 0 $_[4] .= asn_encode_length(length $_[3]);
326 0 $_[4] .= $_[3];
327 }
328 }
329  
330  
331 32 my %_enc_time_opt = ( utctime => 1, withzone => 0, raw => 2);
332  
333 6 ▶sub _enc_time {
Subroutine _enc_time: called CC=11 SCAR=25.5
334 # 0 1 2 3 4 5 6
335 # $optn, $op, $stash, $var, $buf, $loop, $path
336  
337 6 ▶ my $mode = $_enc_time_opt{$_[0]->{'encode_time'} || ''} || 0;
Condition100%4/4
$_enc_time_opt{$_[0]{'encode_time'} or ''} || 0
l!l
15
$_[0]{'encode_time'} || ''
l!l
15
MC/DC100%1/1
$_enc_time_opt{$_[0]{'encode_time'} or ''} || 0
$_enc_time_opt{$_[0]{'encode_time'} or ''}
MC/DC100%1/1
$_[0]{'encode_time'} || ''
$_[0]{'encode_time'}
Truth table100%2/2
A
A= $_enc_time_opt{$_[0]{'encode_time'} or ''}
Aresult
11
00
Truth table100%2/2
A
A= $_[0]{'encode_time'}
Aresult
11
00
338  
339 6 ▶ if ($mode == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode == 2) 0 6 6
340 0 $_[4] .= asn_encode_length(length $_[3]);
341 0 $_[4] .= $_[3];
342 0 return;
343 }
344  
345 6 my $time;
346 my @time;
347 6 my $offset;
348 6 my $isgen = $_[1]->[cTYPE] == opGTIME;
349  
350 6 ▶ if (ref($_[3])) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $_[3]) { } 0 6 6
elsif ($mode == 0) { } 5 1 6
351 0 $offset = int($_[3]->[1] / 60);
352 0 $time = $_[3]->[0] + $_[3]->[1];
353 }
354 elsif ($mode == 0) {
355 5 ▶ if (exists $_[0]->{'encode_timezone'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $_[0]{'encode_timezone'}) { } 5 0 5
356 5 $offset = int($_[0]->{'encode_timezone'} / 60);
357 5 $time = $_[3] + $_[0]->{'encode_timezone'};
358 }
359 else {
360 0 @time = localtime($_[3]);
361 0 my @g = gmtime($_[3]);
362
363 0 $offset = ($time[1] - $g[1]) + ($time[2] - $g[2]) * 60;
364 0 $time = $_[3] + $offset*60;
365 }
366 }
367 else {
368 1 $time = $_[3];
369 }
370 6 @time = gmtime($time);
371 6 $time[4] += 1;
372 6 ▶ $time[5] = $isgen ? ($time[5] + 1900) : ($time[5] % 100);
Branch: 1 branch
BranchTrueFalseTotal
$isgen ? : 3 3 6
373  
374 6 my $tmp = sprintf("%02d"x6, @time[5,4,3,2,1,0]);
375 6 ▶ if ($isgen) {
Branch: 1 branch
BranchTrueFalseTotal
if ($isgen) 3 3 6
376 3 my $sp = sprintf("%.03f",$time);
377 3 ▶ $tmp .= substr($sp,-4) unless $sp =~ /\.000$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $sp =~ /\.000$/ 1 2 3
378 }
379 6 ▶ $tmp .= $offset ? sprintf("%+03d%02d",$offset / 60, abs($offset % 60)) : 'Z';
Branch: 1 branch
BranchTrueFalseTotal
$offset ? : 5 1 6
380 6 $_[4] .= asn_encode_length(length $tmp);
381 6 $_[4] .= $tmp;
382 }
383  
384  
385 2 ▶sub _enc_utf8 {
Subroutine _enc_utf8: called CC=2 SCAR=6.9
386 # 0 1 2 3 4 5 6
387 # $optn, $op, $stash, $var, $buf, $loop, $path
388  
389 2 if (CHECK_UTF8) {
390 2 my $tmp = $_[3];
391 2 ▶ utf8::upgrade($tmp) unless Encode::is_utf8($tmp);
Branch: 1 branch
BranchTrueFalseTotal
unless &Encode::is_utf8($tmp) 1 1 2
392 2 utf8::encode($tmp);
393 2 $_[4] .= asn_encode_length(length $tmp);
394 2 $_[4] .= $tmp;
395 }
396 else {
397 $_[4] .= asn_encode_length(length $_[3]);
398 $_[4] .= $_[3];
399 }
400 }
401  
402  
403 2 ▶sub _enc_any {
Subroutine _enc_any: called CC=5 SCAR=18.4
404 # 0 1 2 3 4 5 6
405 # $optn, $op, $stash, $var, $buf, $loop, $path
406  
407 2 my $handler;
408 2 ▶ if ($_[1]->[cDEFINE] && $_[2]->{$_[1]->[cDEFINE]}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[1][7] and $_[2]{$_[1][7]}) 2 0 2
Condition33%1/3
$_[1][7] and $_[2]{$_[1][7]}
!ll&&!rl&&r
002
MC/DC0%0/2
$_[1][7] and $_[2]{$_[1][7]}
$_[1][7] $_[2]{$_[1][7]}
Truth table33%1/3
A and B
A= $_[1][7]B= $_[2]{$_[1][7]}
ABresult
0X0
100
111
409 2 $handler=$_[0]->{oidtable}{$_[2]->{$_[1]->[cDEFINE]}};
410 2 ▶ $handler=$_[0]->{handlers}{$_[1]->[cVAR]}{$_[2]->{$_[1]->[cDEFINE]}} unless $handler;
Branch: 1 branch
BranchTrueFalseTotal
unless $handler 0 2 2
411 }
412 2 ▶ if ($handler) {
Branch: 1 branch
BranchTrueFalseTotal
if ($handler) { } 2 0 2
413 2 $_[4] .= $handler->encode($_[3]);
414 } else {
415 0 $_[4] .= $_[3];
416 }
417 }
418  
419  
420 10 ▶sub _enc_choice {
Subroutine _enc_choice: called CC=6 SCAR=18.2
421 # 0 1 2 3 4 5 6
422 # $optn, $op, $stash, $var, $buf, $loop, $path
423  
424 10 ▶ my $stash = defined($_[3]) ? $_[3] : $_[2];
Branch: 1 branch
BranchTrueFalseTotal
defined $_[3] ? : 6 4 10
425 10 for my $op (@{$_[1]->[cCHILD]}) {
426 16 ▶ next if $op->[cTYPE] == opEXTENSIONS;
Branch: 1 branch
BranchTrueFalseTotal
if $op->[1] == 18 1 15 16
427 15 ▶ my $var = defined $op->[cVAR] ? $op->[cVAR] : $op->[cCHILD]->[0]->[cVAR];
Branch: 1 branch
BranchTrueFalseTotal
defined $op->[2] ? : 15 0 15
428  
429 15 ▶ if (exists $stash->{$var}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $stash->{$var}) 10 5 15
430 10 push @{$_[6]}, $var;
431 10 _encode($_[0],[$op], $stash, $_[6], $_[4]);
432 10 pop @{$_[6]};
433 10 return;
434 }
435 }
436 0 require Carp;
437 0 Carp::croak("No value found for CHOICE " . join(".", @{$_[6]}));
438 }
439  
440  
441 8 ▶sub _enc_bcd {
Subroutine _enc_bcd: called CC=3 SCAR=11.0
442 # 0 1 2 3 4 5 6
443 # $optn, $op, $stash, $var, $buf, $loop, $path
444 8 ▶ my $str = ("$_[3]" =~ /^(\d+)/) ? $1 : "";
Branch: 1 branch
BranchTrueFalseTotal
"$_[3]" =~ /^(\d+)/ ? : 6 2 8
445 8 ▶ $str .= "F" if length($str) & 1;
Branch: 1 branch
BranchTrueFalseTotal
if length $str & 1 3 5 8
446 8 $_[4] .= asn_encode_length(length($str) / 2);
447 8 $_[4] .= pack("H*", $str);
448 }
449 32 1;
450  
« ASN1/IO.pm ↑ Summary ASN1.pm »