ASN1.pm

filter: Statementstmt 81.2% 204 / 251 Branchbran 69.0% 69 / 100 Conditioncond 62.5% 15 / 24 MC/DCmcdc 53.3% 8 / 15 Subroutinesub 84.7% 39 / 46 Podpod 78.9% 15 / 19 totaltotal 76.9% 350 / 455 CC 65 SCAR 20.2
CC
65
Cov
77%
AUTOLOAD
42.0
asn_decode_tag2
30.0
decode
9.0
CRAP 7.5
« ASN1/_encode.pm ↑ Summary
1 # Copyright (c) 2000-2002 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 5.004;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 32 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 32 ▶use vars qw($VERSION @ISA @EXPORT_OK %EXPORT_TAGS @opParts @opName $AUTOLOAD);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 32 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 32 ▶use constant CHECK_UTF8 => $] > 5.007;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 32 ▶BEGIN {
Subroutine BEGIN: called CC=4 SCAR=13.9
15 32 local $SIG{__DIE__};
16 32 ▶ eval { require bytes and 'bytes'->import };
Branch: 1 branch
BranchTrueFalseTotal
require bytes and "bytes"->import 32 0 32
17  
18 32 if (CHECK_UTF8) {
19 32 require Encode;
20 32 require utf8;
21 }
22  
23 32 @ISA = qw(Exporter);
24  
25 32 %EXPORT_TAGS = (
26 io => [qw(asn_recv asn_send asn_read asn_write asn_get asn_ready)],
27  
28 debug => [qw(asn_dump asn_hexdump)],
29  
30 const => [qw(ASN_BOOLEAN ASN_INTEGER ASN_BIT_STR ASN_OCTET_STR
31 ASN_NULL ASN_OBJECT_ID ASN_REAL ASN_ENUMERATED
32 ASN_SEQUENCE ASN_SET ASN_PRINT_STR ASN_IA5_STR
33 ASN_UTC_TIME ASN_GENERAL_TIME ASN_RELATIVE_OID
34 ASN_UNIVERSAL ASN_APPLICATION ASN_CONTEXT ASN_PRIVATE
35 ASN_PRIMITIVE ASN_CONSTRUCTOR ASN_LONG_LEN ASN_EXTENSION_ID ASN_BIT)],
36  
37 tag => [qw(asn_tag asn_decode_tag2 asn_decode_tag asn_encode_tag asn_decode_length asn_encode_length)]
38 );
39  
40 32 @EXPORT_OK = map { @$_ } values %EXPORT_TAGS;
41 32 $EXPORT_TAGS{all} = \@EXPORT_OK;
42  
43 32 @opParts = qw(
44 cTAG cTYPE cVAR cLOOP cOPT cEXT cCHILD cDEFINE
45 );
46  
47 32 @opName = qw(
48 opUNKNOWN opBOOLEAN opINTEGER opBITSTR opSTRING opNULL opOBJID opREAL
49 opSEQUENCE opEXPLICIT opSET opUTIME opGTIME opUTF8 opANY opCHOICE opROID opBCD
50 opEXTENSIONS
51 );
52  
53 32 foreach my $l (\@opParts, \@opName) {
54 64 my $i = 0;
55 64 foreach my $name (@$l) {
56 864 my $j = $i++;
57 32 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
58 0 ▶ *{__PACKAGE__ . '::' . $name} = sub () { $j }
Subroutine __ANON__: not called CC=1 SCAR=1.2
59 864 }
60 }
61 }
62  
63 32 ▶sub _internal_syms {
Subroutine _internal_syms: called CC=2 SCAR=6.9
64 32 my $pkg = caller;
65 32 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
66 32 for my $sub (@opParts,@opName,'dump_op') {
67 896 *{$pkg . '::' . $sub} = \&{__PACKAGE__ . '::' . $sub};
68 }
69 }
70  
71 sub ASN_BOOLEAN () { 0x01 }
72 sub ASN_INTEGER () { 0x02 }
73 sub ASN_BIT_STR () { 0x03 }
74 sub ASN_OCTET_STR () { 0x04 }
75 sub ASN_NULL () { 0x05 }
76 sub ASN_OBJECT_ID () { 0x06 }
77 sub ASN_REAL () { 0x09 }
78 sub ASN_ENUMERATED () { 0x0A }
79 sub ASN_RELATIVE_OID () { 0x0D }
80 sub ASN_SEQUENCE () { 0x10 }
81 sub ASN_SET () { 0x11 }
82 sub ASN_PRINT_STR () { 0x13 }
83 sub ASN_IA5_STR () { 0x16 }
84 sub ASN_UTC_TIME () { 0x17 }
85 sub ASN_GENERAL_TIME () { 0x18 }
86  
87 sub ASN_UNIVERSAL () { 0x00 }
88 sub ASN_APPLICATION () { 0x40 }
89 sub ASN_CONTEXT () { 0x80 }
90 sub ASN_PRIVATE () { 0xC0 }
91  
92 sub ASN_PRIMITIVE () { 0x00 }
93 sub ASN_CONSTRUCTOR () { 0x20 }
94  
95 sub ASN_LONG_LEN () { 0x80 }
96 sub ASN_EXTENSION_ID () { 0x1F }
97 sub ASN_BIT () { 0x80 }
98  
99  
100 47 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
101 47 my $pkg = shift;
102 47 my $self = bless {}, $pkg;
103  
104 47 $self->configure(@_);
105 47 $self;
106 }
107  
108  
109 74 ▶sub configure {
Subroutine configure: called CC=8 SCAR=21.6
Pod documented
110 74 my $self = shift;
111 74 my %opt = @_;
112  
113 74 ▶ $self->{options}{encoding} = uc($opt{encoding} || 'BER');
Condition100%2/2
$opt{'encoding'} || 'BER'
l!l
272
MC/DC100%1/1
$opt{'encoding'} || 'BER'
$opt{'encoding'}
Truth table100%2/2
A
A= $opt{'encoding'}
Aresult
11
00
114  
115 74 ▶ unless ($self->{options}{encoding} =~ /^[BD]ER$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"options"}{"encoding"} =~ /^[BD]ER$/) 0 74 74
116 0 require Carp;
117 0 Carp::croak("Unsupported encoding format '$opt{encoding}'");
118 }
119  
120 # IMPLICIT as default for backwards compatibility, even though it's wrong.
121 74 ▶ $self->{options}{tagdefault} = uc($opt{tagdefault} || 'IMPLICIT');
Condition100%2/2
$opt{'tagdefault'} || 'IMPLICIT'
l!l
173
MC/DC100%1/1
$opt{'tagdefault'} || 'IMPLICIT'
$opt{'tagdefault'}
Truth table100%2/2
A
A= $opt{'tagdefault'}
Aresult
11
00
122  
123 74 ▶ unless ($self->{options}{tagdefault} =~ /^(?:EXPLICIT|IMPLICIT)$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"options"}{"tagdefault"} =~ /^(?:EXPLICIT|IMPLICIT)$/) 0 74 74
124 0 require Carp;
125 0 Carp::croak("Default tagging must be EXPLICIT/IMPLICIT. Not $opt{tagdefault}");
126 }
127  
128  
129 74 for my $type (qw(encode decode)) {
130 148 ▶ if (exists $opt{$type}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opt{$type}) 32 116 148
131 32 ▶ while(my($what,$value) = each %{$opt{$type}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$opt{$type};}) 37 32 69
132 37 $self->{options}{"${type}_${what}"} = $value;
133 }
134 }
135 }
136 }
137  
138  
139  
140 19 ▶sub find {
Subroutine find: called CC=2 SCAR=7.0
Pod documented
141 19 my $self = shift;
142 19 my $what = shift;
143 19 ▶ return unless exists $self->{tree}{$what};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"tree"}{$what} 0 19 19
144 19 my %new = %$self;
145 19 $new{script} = $new{tree}->{$what};
146 19 bless \%new, ref($self);
147 }
148  
149  
150 116 ▶sub prepare {
Subroutine prepare: called CC=4 SCAR=15.9
Pod documented
151 116 my $self = shift;
152 116 my $asn = shift;
153  
154 116 ▶ $self = $self->new unless ref($self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 116 116
155 116 my $tree;
156 116 ▶ if( ref($asn) eq 'GLOB' ){
Branch: 1 branch
BranchTrueFalseTotal
if (ref $asn eq 'GLOB') { } 0 116 116
157 0 local $/ = undef;
158 0 my $txt = <$asn>;
159 0 $tree = Convert::ASN1::parser::parse($txt,$self->{options}{tagdefault});
160 } else {
161 116 $tree = Convert::ASN1::parser::parse($asn,$self->{options}{tagdefault});
162 }
163  
164 116 ▶ unless ($tree) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tree) 0 116 116
165 0 $self->{error} = $@;
166 0 return;
167 ### If $self has been set to a new object, not returning
168 ### this object here will destroy the object, so the caller
169 ### won't be able to get at the error.
170 }
171  
172 116 $self->{tree} = _pack_struct($tree);
173 116 $self->{script} = (values %$tree)[0];
174 116 $self;
175 }
176  
177 0 ▶sub prepare_file {
Subroutine prepare_file: not called CC=2 SCAR=17.9
Pod documented
178 0 my $self = shift;
179 0 my $asnp = shift;
180  
181 0 local *ASN;
182 open( ASN, $asnp )
183 0 ▶ or do{ $self->{error} = $@; return; };
Branch: 1 branch
BranchTrueFalseTotal
open ASN, $asnp or do { $self->{"error"} = $@; return } 0 0 0
184 0 my $ret = $self->prepare( \*ASN );
185 0 close( ASN );
186 0 $ret;
187 }
188  
189 2 ▶sub registeroid {
Subroutine registeroid: called CC=1 SCAR=0.0
Pod documented
190 2 my $self = shift;
191 2 my $oid = shift;
192 2 my $handler = shift;
193  
194 2 $self->{options}{oidtable}{$oid}=$handler;
195 2 $self->{oidtable}{$oid}=$handler;
196 }
197  
198 0 ▶sub registertype {
Subroutine registertype: not called CC=1 SCAR=6.9
Pod documented
199 0 my $self = shift;
200 0 my $def = shift;
201 0 my $type = shift;
202 0 my $handler = shift;
203  
204 0 $self->{options}{handlers}{$def}{$type}=$handler;
205 }
206  
207 # In XS the will convert the tree between perl and C structs
208  
209 116 ▶sub _pack_struct { $_[0] }
Subroutine _pack_struct: called CC=1 SCAR=0.0
210 0 ▶sub _unpack_struct { $_[0] }
Subroutine _unpack_struct: not called CC=1 SCAR=6.9
211  
212 ##
213 ## Encoding
214 ##
215  
216 131 ▶sub encode {
Subroutine encode: called CC=3 SCAR=11.0
Pod documented
217 131 my $self = shift;
218 131 ▶ my $stash = @_ == 1 ? shift : { @_ };
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 11 120 131
219 131 my $buf = '';
220 131 local $SIG{__DIE__};
221 131 eval { _encode($self->{options}, $self->{script}, $stash, [], $buf) }
222 131 ▶ or do { $self->{error} = $@; undef }
Branch: 1 branch
BranchTrueFalseTotal
eval { do { _encode($self->{"options"}, $self->{"script"}, $stash, scalar [], $buf) } } or do { $self->{"error"} = $@; undef } 118 13 131
223 }
224  
225  
226  
227 # Encode tag value for encoding.
228 # We assume that the tag has been correctly generated with asn_tag()
229  
230 1122 ▶sub asn_encode_tag {
Subroutine asn_encode_tag: called CC=4 SCAR=14.0
Pod documented
231 1122 ▶ $_[0] >> 8
Branch: 3 branches
BranchTrueFalseTotal
$_[0] >> 8 ? : 6 1116 1122
$_[0] & 32768 ? : 3 3 6
$_[0] & 8388608 ? : 0 3 3
232 ? $_[0] & 0x8000
233 ? $_[0] & 0x800000
234 ? pack("V",$_[0])
235 : substr(pack("V",$_[0]),0,3)
236 : pack("v", $_[0])
237 : pack("C",$_[0]);
238 }
239  
240  
241 # Encode a length. If < 0x80 then encode as a byte. Otherwise encode
242 # 0x80 | num_bytes followed by the bytes for the number. top end
243 # bytes of all zeros are not encoded
244  
245 246 ▶sub asn_encode_length {
Subroutine asn_encode_length: called CC=2 SCAR=6.9
Pod documented
246  
247 246 ▶ if($_[0] >> 7) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] >> 7) 16 230 246
248 16 my $lenlen = &num_length;
249  
250 16 return pack("Ca*", $lenlen | 0x80, substr(pack("N",$_[0]), -$lenlen));
251 }
252  
253 230 return pack("C", $_[0]);
254 }
255  
256  
257 ##
258 ## Decoding
259 ##
260  
261 183 ▶sub decode {
Subroutine decode: called CC=9 SCAR=22.0
Pod documented
262 183 my $self = shift;
263 183 my $ret;
264  
265 183 local $SIG{__DIE__};
266 eval {
267 183 my (%stash, $result);
268 183 my $script = $self->{script};
269 183 my $stash = \$result;
270  
271 183 ▶ while ($script) {
Branch: 1 branch
BranchTrueFalseTotal
if ($script) 230 7 237
272 230 ▶ my $child = $script->[0] or last;
Branch: 1 branch
BranchTrueFalseTotal
my $child = $script->[0] or last 230 0 230
273 230 ▶ if (@$script > 1 or defined $child->[cVAR]) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$script > 1 or defined $child->[2]) 162 68 230
Condition100%3/3
@$script > 1 or defined $child->[2]
l!l&&r!l&&!r
4311968
MC/DC100%2/2
@$script > 1 or defined $child->[2]
@$script > 1 defined $child->[2]
Truth table100%3/3
A or B
A= @$script > 1B= defined $child->[2]
ABresult
1X1
011
000
274 162 $result = $stash = \%stash;
275 162 last;
276 }
277 68 ▶ last if $child->[cTYPE] == opCHOICE or $child->[cLOOP];
Branch: 1 branch
BranchTrueFalseTotal
if $child->[1] == 15 or $child->[3] 14 54 68
Condition100%3/3
$child->[1] == 15 or $child->[3]
l!l&&r!l&&!r
7754
MC/DC100%2/2
$child->[1] == 15 or $child->[3]
$child->[1] == 15 $child->[3]
Truth table100%3/3
A or B
A= $child->[1] == 15B= $child->[3]
ABresult
1X1
011
000
278 54 $script = $child->[cCHILD];
279 }
280  
281 _decode(
282 $self->{options},
283 $self->{script},
284 183 $stash,
285 0,
286 length $_[0],
287 undef,
288 {},
289 $_[0]);
290  
291 164 $ret = $result;
292 164 ▶ 1;
Condition50%1/2
$@ || 'Unknown error'
l!l
190
MC/DC0%0/1
$@ || 'Unknown error'
$@
Truth table50%1/2
A
A= $@
Aresult
11
00
293 183 ▶ } or $self->{'error'} = $@ || 'Unknown error';
Branch: 1 branch
BranchTrueFalseTotal
eval { do { my(%stash, $result); my $script = $self->{"script"}; my $stash = \$result; while ($script) { my $child = $script->[0] or last; if (@$script > 1 or defined $child->[2]) { $result = ($stash = \%stash); last; } ; last if $child->[1] == 15 or $child->[3]; $script = $child->[6]; } ; _decode($self->{"options"}, $self->{"script"}, $stash, 0, length $_[0], undef, scalar {}, $_[0]); $ret = $result; 1 } } or $self->{"error"} = $@ || "Unknown error" 164 19 183
294  
295 183 $ret;
296 }
297  
298  
299 22 ▶sub asn_decode_length {
Subroutine asn_decode_length: called CC=5 SCAR=16.2
Pod documented
300 22 ▶ return unless length $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless length $_[0] 0 22 22
301  
302 22 my $len = unpack("C",$_[0]);
303  
304 22 ▶ if($len & 0x80) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len & 128) 11 11 22
305 11 ▶ $len &= 0x7f or return (1,-1);
Branch: 1 branch
BranchTrueFalseTotal
$len &= 127 or return 1, -1 11 0 11
306  
307 11 ▶ return if $len >= length $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if $len >= length $_[0] 2 9 11
308  
309 9 return (1+$len, unpack("N", "\0" x (4 - $len) . substr($_[0],1,$len)));
310 }
311 11 return (1, $len);
312 }
313  
314  
315 31 ▶sub asn_decode_tag {
Subroutine asn_decode_tag: called CC=5 SCAR=16.1
Pod documented
316 31 ▶ return unless length $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless length $_[0] 5 26 31
317  
318 26 my $tag = unpack("C", $_[0]);
319 26 my $n = 1;
320  
321 26 ▶ if(($tag & 0x1f) == 0x1f) {
Branch: 1 branch
BranchTrueFalseTotal
if (($tag & 31) == 31) 4 22 26
322 4 my $b;
323 4 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$b & 128 and do { do { return if $n >= length $_[0]; $b = unpack("C", substr($_[0], $n, 1)); $tag |= $b << 8 * $n++ } } 2 4 6
324 6 ▶ return if $n >= length $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if $n >= length $_[0] 0 6 6
325 6 $b = unpack("C",substr($_[0],$n,1));
326 6 $tag |= $b << (8 * $n++);
327 } while($b & 0x80);
328 }
329 26 ($n, $tag);
330 }
331  
332  
333 0 ▶sub asn_decode_tag2 {
Subroutine asn_decode_tag2: not called CC=5 SCAR=34.0
Pod undocumented
334 0 ▶ return unless length $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless length $_[0] 0 0 0
335  
336 0 my $tag = unpack("C",$_[0]);
337 0 my $num = $tag & 0x1f;
338 0 my $len = 1;
339  
340 0 ▶ if($num == 0x1f) {
Branch: 1 branch
BranchTrueFalseTotal
if ($num == 31) 0 0 0
341 0 $num = 0;
342 0 my $b;
343 0 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$b & 128 and do { do { return if $len >= length $_[0]; $b = unpack("C", substr($_[0], $len++, 1)); $num = ($num << 7) + ($b & 127) } } 0 0 0
344 0 ▶ return if $len >= length $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if $len >= length $_[0] 0 0 0
345 0 $b = unpack("C",substr($_[0],$len++,1));
346 0 $num = ($num << 7) + ($b & 0x7f);
347 } while($b & 0x80);
348 }
349 0 ($len, $tag, $num);
350 }
351  
352  
353 ##
354 ## Utilities
355 ##
356  
357 # How many bytes are needed to encode a number
358  
359 76 ▶sub num_length {
Subroutine num_length: called CC=4 SCAR=13.9
Pod undocumented
360 76 ▶ $_[0] >> 8
Branch: 3 branches
BranchTrueFalseTotal
$_[0] >> 8 ? : 20 56 76
$_[0] >> 16 ? : 6 14 20
$_[0] >> 24 ? : 4 2 6
361 ? $_[0] >> 16
362 ? $_[0] >> 24
363 ? 4
364 : 3
365 : 2
366 : 1
367 }
368  
369 # Convert from a bigint to an octet string
370  
371 24 ▶sub i2osp {
Subroutine i2osp: called CC=6 SCAR=17.9
Pod undocumented
372 24 my($num, $biclass) = @_;
373 24 ▶ eval "use $biclass";
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
374 24 $num = $biclass->new($num);
375 24 ▶ die "INTEGER value is not an integer\n"
Branch: 1 branch
BranchTrueFalseTotal
if $num->can("is_nan") and $num->is_nan 1 23 24
Condition66%2/3
$num->can("is_nan") and $num->is_nan
!ll&&!rl&&r
0231
MC/DC50%1/2
$num->can("is_nan") and $num->is_nan
$num->can("is_nan") $num->is_nan
Truth table66%2/3
A and B
A= $num->can("is_nan")B= $num->is_nan
ABresult
0X0
100
111
376 if $num->can('is_nan') && $num->is_nan;
377 23 ▶ my $neg = $num < 0
Branch: 1 branch
BranchTrueFalseTotal
my $neg = $num < 0 and $num = abs $num + 1 8 15 23
378 and $num = abs($num+1);
379 23 my $base = $biclass->new(256);
380 23 my $result = '';
381 23 ▶ while($num != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($num != 0) 3243 23 3266
382 3243 my $r = $num % $base;
383 3243 $num = ($num-$r) / $base;
384 3243 $result .= pack("C",$r);
385 }
386 23 ▶ $result ^= pack("C",255) x length($result) if $neg;
Branch: 1 branch
BranchTrueFalseTotal
if $neg 8 15 23
387 23 return scalar reverse $result;
388 }
389  
390 # Convert from an octet string to a bigint
391  
392 24 ▶sub os2ip {
Subroutine os2ip: called CC=4 SCAR=13.9
Pod undocumented
393 24 my($os, $biclass) = @_;
394 24 eval "require $biclass";
395 24 my $base = $biclass->new(256);
396 24 my $result = $biclass->new(0);
397 24 ▶ my $neg = unpack("C",$os) >= 0x80
Branch: 1 branch
BranchTrueFalseTotal
my $neg = unpack("C", $os) >= 128 and $os ^= "\377" x length($os) 6 18 24
398 and $os ^= pack("C",255) x length($os);
399 24 for (unpack("C*",$os)) {
400 3766 $result = ($result * $base) + $_;
401 }
402 24 ▶ return $neg ? ($result + 1) * -1 : $result;
Branch: 1 branch
BranchTrueFalseTotal
$neg ? : 6 18 24
403 }
404  
405 # Given a class and a tag, calculate an integer which when encoded
406 # will become the tag. This means that the class bits are always
407 # in the bottom byte, so are the tag bits if tag < 30. Otherwise
408 # the tag is in the upper 3 bytes. The upper bytes are encoded
409 # with bit8 representing that there is another byte. This
410 # means the max tag we can do is 0x1fffff
411  
412 98 ▶sub asn_tag {
Subroutine asn_tag: called CC=6 SCAR=18.1
Pod documented
413 98 my($class,$value) = @_;
414  
415 98 ▶ die sprintf "Bad tag class 0x%x",$class
Branch: 1 branch
BranchTrueFalseTotal
if $class & '18446744073709551391' 0 98 98
416 if $class & ~0xe0;
417  
418 98 ▶ unless ($value & ~0x1f or $value == 0x1f) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($value & '18446744073709551584' or $value == 31) 92 6 98
Condition66%2/3
$value & '18446744073709551584' or $value == 31
l!l&&r!l&&!r
6092
MC/DC50%1/2
$value & '18446744073709551584' or $value == 31
$value & '18446744073709551584' $value == 31
Truth table66%2/3
A or B
A= $value & '18446744073709551584'B= $value == 31
ABresult
1X1
011
000
419 92 return (($class & 0xe0) | $value);
420 }
421  
422 6 ▶ die sprintf "Tag value 0x%08x too big\n",$value
Branch: 1 branch
BranchTrueFalseTotal
if $value & 4292870144 0 6 6
423 if $value & 0xffe00000;
424  
425 6 $class = ($class | 0x1f) & 0xff;
426  
427 6 my @t = ($value & 0x7f);
428 6 ▶ unshift @t, (0x80 | ($value & 0x7f)) while $value >>= 7;
Branch: 1 branch
BranchTrueFalseTotal
$value >>= 7 and do { unshift @t, 128 | $value & 127 } 3 6 9
429 6 unpack("V",pack("C4",$class,@t,0,0));
430 }
431  
432  
433 32 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=7.0
434 # When we have XS &_encode will be defined by the XS code
435 # so will all the subs in these required packages
436 32 ▶ unless (defined &_encode) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined &Convert::ASN1::_encode) 32 0 32
437 32 require Convert::ASN1::_decode;
438 32 require Convert::ASN1::_encode;
439 32 require Convert::ASN1::IO;
440 }
441  
442 32 require Convert::ASN1::parser;
443 }
444  
445 0 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: not called CC=6 SCAR=37.4
446 0 ▶ require Convert::ASN1::Debug if $AUTOLOAD =~ /dump/;
Branch: 1 branch
BranchTrueFalseTotal
if $Convert::ASN1::AUTOLOAD =~ /dump/ 0 0 0
447 0 ▶ goto &{$AUTOLOAD} if defined &{$AUTOLOAD};
Branch: 1 branch
BranchTrueFalseTotal
if defined &{$Convert::ASN1::AUTOLOAD;} 0 0 0
448 0 require Carp;
449 0 ▶ my $pkg = ref($_[0]) || ($_[0] =~ /^[\w\d]+(?:::[\w\d]+)*$/)[0];
Condition0%0/3
ref $_[0] || ($_[0] =~ /^[\w\d]+(?:::[\w\d]+)*$/)[0]
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $_[0] || ($_[0] =~ /^[\w\d]+(?:::[\w\d]+)*$/)[0]
ref $_[0] ($_[0] =~ /^[\w\d]+(?:::[\w\d]+)*$/)[0]
Truth table0%0/3
A || B
A= ref $_[0]B= ($_[0] =~ /^[\w\d]+(?:::[\w\d]+)*$/)[0]
ABresult
1X1
011
000
450 0 ▶ if ($pkg and UNIVERSAL::isa($pkg, __PACKAGE__)) { # guess it was a method call
Branch: 1 branch
BranchTrueFalseTotal
if ($pkg and UNIVERSAL::isa($pkg, __PACKAGE__)) { } 0 0 0
Condition0%0/3
$pkg and UNIVERSAL::isa($pkg, __PACKAGE__)
!ll&&!rl&&r
000
MC/DC0%0/2
$pkg and UNIVERSAL::isa($pkg, __PACKAGE__)
$pkg UNIVERSAL::isa($pkg, __PACKAGE__)
Truth table0%0/3
A and B
A= $pkgB= UNIVERSAL::isa($pkg, __PACKAGE__)
ABresult
0X0
100
111
451 0 $AUTOLOAD =~ s/.*:://;
452 0 Carp::croak(sprintf q{Can't locate object method "%s" via package "%s"},$AUTOLOAD,$pkg);
453 }
454 else {
455 0 Carp::croak(sprintf q{Undefined subroutine &%s called}, $AUTOLOAD);
456 }
457 }
458  
459 0 ▶sub DESTROY {}
Subroutine DESTROY: not called CC=1 SCAR=0.0
460  
461 25 ▶sub error { $_[0]->{error} }
Subroutine error: called CC=1 SCAR=0.0
Pod documented
462 32 1;
« ASN1/_encode.pm ↑ Summary