| 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 Socket; | ||||||||||||||||||||||||||||||||
|
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
| |||||||||||||||||||||||||||||||||||
| 13 | } | ||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||
| 15 | # Largest single read, so the buffer perl allocates tracks the data | ||||||||||||||||||||||||||||||||||
| 16 | # received and not the length an element declares | ||||||||||||||||||||||||||||||||||
| 17 | 32 | my $MAX_READ = 65536; | |||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||
| 19 | 15 | ▶ | sub asn_recv { # $socket, $buffer, $flags | ||||||||||||||||||||||||||||||||
|
Subroutine
asn_recv: called CC=30 SCAR=42.2
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||
| 21 | 15 | my $peer; | |||||||||||||||||||||||||||||||||
| 22 | my $buf; | ||||||||||||||||||||||||||||||||||
| 23 | 15 | my $n = 128; | |||||||||||||||||||||||||||||||||
| 24 | 15 | my $pos = 0; | |||||||||||||||||||||||||||||||||
| 25 | 15 | my $depth = 0; | |||||||||||||||||||||||||||||||||
| 26 | 15 | my $len = 0; | |||||||||||||||||||||||||||||||||
| 27 | 15 | my($tmp,$tb,$lb); | |||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||
| 29 | MORE: | ||||||||||||||||||||||||||||||||||
| 30 | 15 | ▶ | for( | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 31 | $peer = recv($_[0],$buf,$n,MSG_PEEK); | ||||||||||||||||||||||||||||||||||
| 32 | defined $peer; | ||||||||||||||||||||||||||||||||||
| 33 | $peer = recv($_[0],$buf,$n<<=1,MSG_PEEK) | ||||||||||||||||||||||||||||||||||
| 34 | ) { | ||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||
| 36 | 15 | ▶ | if ($depth) { # Are we searching of "\0\0" | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | unless (2+$pos <= length $buf) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | next MORE if $n == length $buf; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 40 | 0 | last MORE; | |||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | if(substr($buf,$pos,2) eq "\0\0") { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | unless (--$depth) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 45 | 0 | $len = $pos + 2; | |||||||||||||||||||||||||||||||||
| 46 | 0 | last MORE; | |||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||
| 51 | # If we can decode a tag and length we can determine the length | ||||||||||||||||||||||||||||||||||
| 52 | 15 | ($tb,$tmp) = asn_decode_tag(substr($buf,$pos)); | |||||||||||||||||||||||||||||||||
| 53 | 15 | ▶ | unless ($tb && ($pos+$tb < length $buf)) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$tb and $pos + $tb < length $buf
MC/DC50%1/2
$tb and $pos + $tb < length $buf
$tb
$pos + $tb < length $buf
Truth table66%2/3
A and B
A= $tbB= $pos + $tb < length $buf
| |||||||||||||||||||||||||||||||||||
| 54 | 4 | ▶ | next MORE if $n == length $buf; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 55 | 4 | last MORE; | |||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||
| 58 | 11 | ▶ | if (unpack("C",substr($buf,$pos+$tb,1)) == 0x80) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 59 | # indefinite length, grrr! | ||||||||||||||||||||||||||||||||||
| 60 | 0 | $depth++; | |||||||||||||||||||||||||||||||||
| 61 | 0 | $pos += $tb + 1; | |||||||||||||||||||||||||||||||||
| 62 | 0 | redo MORE; | |||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||
| 65 | 11 | ($lb,$len) = asn_decode_length(substr($buf,$pos+$tb)); | |||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||
| 67 | 11 | ▶ | if ($lb) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 68 | 9 | ▶ | if ($depth) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 69 | 0 | $pos += $tb + $lb + $len; | |||||||||||||||||||||||||||||||||
| 70 | 0 | redo MORE; | |||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||
| 72 | else { | ||||||||||||||||||||||||||||||||||
| 73 | 9 | $len += $tb + $lb + $pos; | |||||||||||||||||||||||||||||||||
| 74 | 9 | last MORE; | |||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||
| 77 | else { | ||||||||||||||||||||||||||||||||||
| 78 | 2 | ▶ | next MORE if $n == length $buf; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 79 | 2 | last MORE; | |||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||
| 83 | 15 | ▶ | if (defined $peer) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 84 | 15 | my $type = getsockopt($_[0], SOL_SOCKET, SO_TYPE); | |||||||||||||||||||||||||||||||||
| 85 | 15 | ▶ | my $discard = defined $type && unpack('i', $type) == SOCK_DGRAM | ||||||||||||||||||||||||||||||||
|
Condition50%3/6
defined $type && unpack('i', $type) == 2 && !($_[2] & 2)
defined $type and unpack("i", $type) == 2
MC/DC33%1/3
defined $type && unpack('i', $type) == 2 && !($_[2] & 2)
defined $type
unpack("i", $type) == 2
!($_[2] & 2)
Truth table50%2/4
A and B && not(C)
A= defined $typeB= unpack("i", $type) == 2C= !($_[2] & 2)
| |||||||||||||||||||||||||||||||||||
| 86 | && !($_[2] & MSG_PEEK); | ||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||
| 88 | 15 | ▶ | if ($len > length $buf) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 89 | # Check we can read the whole element. Peek in doubling steps so the | ||||||||||||||||||||||||||||||||||
| 90 | # buffer perl allocates is bounded by the data available, not by the | ||||||||||||||||||||||||||||||||||
| 91 | # declared length | ||||||||||||||||||||||||||||||||||
| 92 | 3 | ▶ | my $ask = length($buf) || 64; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
length $buf || 64
MC/DC0%0/1
length $buf || 64
length $buf
Truth table50%1/2
A
A= length $buf
| |||||||||||||||||||||||||||||||||||
| 93 | 3 | ▶ | while ($len > length $buf) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 94 | 9 | $ask *= 2; | |||||||||||||||||||||||||||||||||
| 95 | 9 | ▶ | $ask = $len if $ask > $len; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 96 | goto error | ||||||||||||||||||||||||||||||||||
| 97 | 9 | ▶ | unless defined($peer = recv($_[0],$buf,$ask,MSG_PEEK)); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 98 | 9 | ▶ | last if length($buf) < $ask; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||
| 101 | 3 | ▶ | if ($len > length $buf) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 102 | # Cannot get whole element; discard the datagram so it doesn't wedge the queue | ||||||||||||||||||||||||||||||||||
| 103 | 2 | ▶ | recv($_[0], my $junk, length $buf, 0) if $discard; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 104 | 2 | $_[1]=''; | |||||||||||||||||||||||||||||||||
| 105 | 2 | return $peer; | |||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||
| 108 | elsif ($len == 0) { | ||||||||||||||||||||||||||||||||||
| 109 | # Discard the datagram so it doesn't wedge the queue | ||||||||||||||||||||||||||||||||||
| 110 | 6 | ▶ | recv($_[0], my $junk, length($buf) || 1, 0) if $discard; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
length $buf || 1
MC/DC0%0/1
length $buf || 1
length $buf
Truth table50%1/2
A
A= length $buf
| |||||||||||||||||||||||||||||||||||
| 111 | 6 | $_[1] = ''; | |||||||||||||||||||||||||||||||||
| 112 | 6 | return $peer; | |||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||
| 115 | 7 | ▶ | if ($_[2] & MSG_PEEK) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 116 | 0 | $_[1] = substr($buf,0,$len); | |||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||
| 118 | elsif (!defined($peer = recv($_[0],$_[1],$len,0))) { | ||||||||||||||||||||||||||||||||||
| 119 | 0 | goto error; | |||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||
| 122 | 7 | return $peer; | |||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||
| 125 | error: | ||||||||||||||||||||||||||||||||||
| 126 | 0 | $_[1] = undef; | |||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||
| 129 | 5 | ▶ | sub asn_read { # $fh, $buffer, $offset | ||||||||||||||||||||||||||||||||
|
Subroutine
asn_read: called CC=29 SCAR=36.5
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||
| 131 | # We need to read one packet, and exactly only one packet. | ||||||||||||||||||||||||||||||||||
| 132 | # So we have to read the first few bytes one at a time, until | ||||||||||||||||||||||||||||||||||
| 133 | # we have enough to decode a tag and a length. We then know | ||||||||||||||||||||||||||||||||||
| 134 | # how many more bytes to read | ||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||
| 136 | 5 | ▶ | if ($_[2]) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | if ($_[2] > length $_[1]) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 138 | 0 | require Carp; | |||||||||||||||||||||||||||||||||
| 139 | 0 | Carp::carp("Offset beyond end of buffer"); | |||||||||||||||||||||||||||||||||
| 140 | 0 | return; | |||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||
| 142 | 0 | substr($_[1],$_[2]) = ''; | |||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||
| 144 | else { | ||||||||||||||||||||||||||||||||||
| 145 | 5 | $_[1] = ''; | |||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||
| 148 | 5 | my $pos = 0; | |||||||||||||||||||||||||||||||||
| 149 | 5 | my $need = 0; | |||||||||||||||||||||||||||||||||
| 150 | 5 | my $depth = 0; | |||||||||||||||||||||||||||||||||
| 151 | 5 | my $ch; | |||||||||||||||||||||||||||||||||
| 152 | my $n; | ||||||||||||||||||||||||||||||||||
| 153 | 5 | my $e; | |||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||
| 156 | 5 | while(1) { | |||||||||||||||||||||||||||||||||
| 157 | 269 | ▶ | $need = ($pos + ($depth * 2)) || 2; | ||||||||||||||||||||||||||||||||
|
Condition100%2/2
$pos + $depth * 2 || 2
MC/DC100%1/1
$pos + $depth * 2 || 2
$pos + $depth * 2
Truth table100%2/2
A
A= $pos + $depth * 2
| |||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||
| 159 | 269 | ▶ | while(($n = $need - length $_[1]) > 0) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 160 | 199 | ▶ | $e = sysread($_[0],$_[1],($n > $MAX_READ ? $MAX_READ : $n),length $_[1]) or | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 161 | goto READ_ERR; | ||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||
| 164 | 269 | my $tch = unpack("C",substr($_[1],$pos++,1)); | |||||||||||||||||||||||||||||||||
| 165 | # Tag may be multi-byte | ||||||||||||||||||||||||||||||||||
| 166 | 269 | ▶ | if(($tch & 0x1f) == 0x1f) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 167 | 175 | my $ch; | |||||||||||||||||||||||||||||||||
| 168 | 175 | ▶ | do { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 169 | 273 | $need++; | |||||||||||||||||||||||||||||||||
| 170 | 273 | ▶ | while(($n = $need - length $_[1]) > 0) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 171 | 273 | ▶ | $e = sysread($_[0],$_[1],($n > $MAX_READ ? $MAX_READ : $n),length $_[1]) or | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 172 | goto READ_ERR; | ||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||
| 174 | 273 | $ch = unpack("C",substr($_[1],$pos++,1)); | |||||||||||||||||||||||||||||||||
| 175 | } while($ch & 0x80); | ||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||
| 178 | 269 | $need = $pos + 1; | |||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||
| 180 | 269 | ▶ | while(($n = $need - length $_[1]) > 0) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 181 | 0 | ▶ | $e = sysread($_[0],$_[1],($n > $MAX_READ ? $MAX_READ : $n),length $_[1]) or | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 182 | goto READ_ERR; | ||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||
| 185 | 269 | my $len = unpack("C",substr($_[1],$pos++,1)); | |||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||
| 187 | 269 | ▶ | if($len & 0x80) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 188 | 73 | ▶ | unless ($len &= 0x7f) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 189 | 71 | $depth++; | |||||||||||||||||||||||||||||||||
| 190 | 71 | next; | |||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||
| 192 | 2 | $need = $pos + $len; | |||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||
| 194 | 2 | ▶ | while(($n = $need - length $_[1]) > 0) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 195 | 2 | ▶ | $e = sysread($_[0],$_[1],($n > $MAX_READ ? $MAX_READ : $n),length $_[1]) or | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 196 | goto READ_ERR; | ||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||
| 199 | 2 | $pos += $len + unpack("N", "\0" x (4 - $len) . substr($_[1],$pos,$len)); | |||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||
| 201 | ▶ | elsif (!$len && !$tch) { | |||||||||||||||||||||||||||||||||
|
Condition66%2/3
$len || $tch
MC/DC50%1/2
$len || $tch
$len
$tch
Truth table66%2/3
A || B
A= $lenB= $tch
| |||||||||||||||||||||||||||||||||||
| 202 | 71 | ▶ | die "Bad ASN PDU" unless $depth; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 203 | 71 | ▶ | unless (--$depth) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 204 | 1 | last; | |||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||
| 207 | else { | ||||||||||||||||||||||||||||||||||
| 208 | 125 | $pos += $len; | |||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||
| 211 | 197 | ▶ | last unless $depth; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||
| 214 | 5 | ▶ | while(($n = $pos - length $_[1]) > 0) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 215 | 8 | ▶ | $e = sysread($_[0],$_[1],($n > $MAX_READ ? $MAX_READ : $n),length $_[1]) or | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 216 | goto READ_ERR; | ||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||
| 219 | 4 | return length $_[1]; | |||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||
| 221 | 1 | ▶ | READ_ERR: | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 222 | $@ = defined($e) ? "Unexpected EOF" : "I/O Error $!"; # . CORE::unpack("H*",$_[1]); | ||||||||||||||||||||||||||||||||||
| 223 | 1 | return undef; | |||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||
| 226 | 1 | ▶ | sub asn_send { # $sock, $buffer, $flags, $to | ||||||||||||||||||||||||||||||||
|
Subroutine
asn_send: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||
| 228 | 1 | ▶ | @_ == 4 | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 229 | ? send($_[0],$_[1],$_[2],$_[3]) | ||||||||||||||||||||||||||||||||||
| 230 | : send($_[0],$_[1],$_[2]); | ||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||
| 233 | 2 | ▶ | sub asn_write { # $sock, $buffer | ||||||||||||||||||||||||||||||||
|
Subroutine
asn_write: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||
| 235 | 2 | syswrite($_[0],$_[1], length $_[1]); | |||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||
| 238 | 6 | ▶ | sub asn_get { # $fh | ||||||||||||||||||||||||||||||||
|
Subroutine
asn_get: called CC=12 SCAR=24.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||
| 240 | 6 | ▶ | my $fh = ref($_[0]) ? $_[0] : \($_[0]); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 241 | 6 | my $href = \%{*$fh}; | |||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||
| 243 | 6 | ▶ | $href->{'asn_buffer'} = '' unless exists $href->{'asn_buffer'}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||
| 245 | 6 | ▶ | my $need = delete $href->{'asn_need'} || 0; | ||||||||||||||||||||||||||||||||
|
Condition100%2/2
delete $href->{'asn_need'} || 0
MC/DC100%1/1
delete $href->{'asn_need'} || 0
delete $href->{'asn_need'}
Truth table100%2/2
A
A= delete $href->{'asn_need'}
| |||||||||||||||||||||||||||||||||||
| 246 | 6 | while(1) { | |||||||||||||||||||||||||||||||||
| 247 | 13 | ▶ | next if $need; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 248 | 8 | ▶ | my($tb,$tag) = asn_decode_tag($href->{'asn_buffer'}) or next; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 249 | 4 | ▶ | my($lb,$len) = asn_decode_length(substr($href->{'asn_buffer'},$tb,8)) or next; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 250 | 4 | $need = $tb + $lb + $len; | |||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||
| 252 | continue { | ||||||||||||||||||||||||||||||||||
| 253 | 13 | ▶ | if ($need && $need <= length $href->{'asn_buffer'}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$need and $need <= length $href->{"asn_buffer"}
MC/DC100%2/2
$need and $need <= length $href->{"asn_buffer"}
$need
$need <= length $href->{"asn_buffer"}
Truth table100%3/3
A and B
A= $needB= $need <= length $href->{"asn_buffer"}
| |||||||||||||||||||||||||||||||||||
| 254 | 4 | my $ret = substr($href->{'asn_buffer'},0,$need); | |||||||||||||||||||||||||||||||||
| 255 | 4 | substr($href->{'asn_buffer'},0,$need) = ''; | |||||||||||||||||||||||||||||||||
| 256 | 4 | return $ret; | |||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||
| 259 | 9 | ▶ | my $get = $need > 1024 ? $need : 1024; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 260 | 9 | ▶ | $get = $MAX_READ if $get > $MAX_READ; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||
| 262 | 9 | ▶ | sysread($_[0], $href->{'asn_buffer'}, $get, length $href->{'asn_buffer'}) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 263 | or return undef; | ||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||
| 267 | 2 | ▶ | sub asn_ready { # $fh | ||||||||||||||||||||||||||||||||
|
Subroutine
asn_ready: called CC=6 SCAR=18.5
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||
| 269 | 2 | ▶ | my $fh = ref($_[0]) ? $_[0] : \($_[0]); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 270 | 2 | my $href = \%{*$fh}; | |||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||
| 272 | 2 | ▶ | return 0 unless exists $href->{'asn_buffer'}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||
| 274 | return $href->{'asn_need'} <= length $href->{'asn_buffer'} | ||||||||||||||||||||||||||||||||||
| 275 | 2 | ▶ | if exists $href->{'asn_need'}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||
| 277 | 2 | ▶ | my($tb,$tag) = asn_decode_tag($href->{'asn_buffer'}) or return 0; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 278 | 1 | ▶ | my($lb,$len) = asn_decode_length(substr($href->{'asn_buffer'},$tb,8)) or return 0; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||
| 280 | 1 | $href->{'asn_need'} = $tb + $lb + $len; | |||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||
| 282 | 1 | $href->{'asn_need'} <= length $href->{'asn_buffer'}; | |||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||
| 285 | 32 | 1; | |||||||||||||||||||||||||||||||||