| 1 | package Data::Radius::Encode; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use bytes; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Socket qw(inet_pton AF_INET AF_INET6); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | use constant { | ||||||||||||||||||||||||||||
| 9 | 2 | MAX_STRING_SIZE => 253, | |||||||||||||||||||||||||||
| 10 | MAX_VSA_STRING_SIZE => 247, | ||||||||||||||||||||||||||||
| 11 | ATTR_CISCO_AVPAIR => 'Cisco-AVPair', | ||||||||||||||||||||||||||||
| 12 | ATTR_CISCO_AVPAIR_ID => 1, | ||||||||||||||||||||||||||||
| 13 | VENDOR_CISCO => 'Cisco', | ||||||||||||||||||||||||||||
| 14 | 2 | ▶ | }; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use Exporter qw(import); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 2 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||
| 19 | encode | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | encode_string | ||||||||||||||||||||||||||||
| 22 | encode_int | ||||||||||||||||||||||||||||
| 23 | encode_byte | ||||||||||||||||||||||||||||
| 24 | encode_short | ||||||||||||||||||||||||||||
| 25 | encode_signed | ||||||||||||||||||||||||||||
| 26 | encode_ipaddr | ||||||||||||||||||||||||||||
| 27 | encode_ipv6addr | ||||||||||||||||||||||||||||
| 28 | encode_combo_ip | ||||||||||||||||||||||||||||
| 29 | encode_octets | ||||||||||||||||||||||||||||
| 30 | encode_avpair | ||||||||||||||||||||||||||||
| 31 | encode_tlv | ||||||||||||||||||||||||||||
| 32 | ); | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 2 | ▶ | use Data::Radius::Util qw(is_enum_type); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | # type encoders | ||||||||||||||||||||||||||||
| 37 | # $coderef->($value, $attr, $dictionary) | ||||||||||||||||||||||||||||
| 38 | 2 | my %encode_map = ( | |||||||||||||||||||||||||||
| 39 | string => \&encode_string, | ||||||||||||||||||||||||||||
| 40 | string_tag => \&encode_string_tag, | ||||||||||||||||||||||||||||
| 41 | integer => \&encode_int, | ||||||||||||||||||||||||||||
| 42 | integer_tag => \&encode_int_tag, | ||||||||||||||||||||||||||||
| 43 | byte => \&encode_byte, | ||||||||||||||||||||||||||||
| 44 | short => \&encode_short, | ||||||||||||||||||||||||||||
| 45 | signed => \&encode_signed, | ||||||||||||||||||||||||||||
| 46 | ipaddr => \&encode_ipaddr, | ||||||||||||||||||||||||||||
| 47 | ipv6addr => \&encode_ipv6addr, | ||||||||||||||||||||||||||||
| 48 | avpair => \&encode_avpair, | ||||||||||||||||||||||||||||
| 49 | 'combo-ip' => \&encode_combo_ip, | ||||||||||||||||||||||||||||
| 50 | octets => \&encode_octets, | ||||||||||||||||||||||||||||
| 51 | tlv => \&encode_tlv, | ||||||||||||||||||||||||||||
| 52 | # Unix timestamp | ||||||||||||||||||||||||||||
| 53 | date => \&encode_int, | ||||||||||||||||||||||||||||
| 54 | #TODO Ascend binary encoding | ||||||||||||||||||||||||||||
| 55 | # abinary => ... | ||||||||||||||||||||||||||||
| 56 | ); | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 2 | ▶ | if (!defined inet_pton(AF_INET6, '::1')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 0 | require Net::IP; | |||||||||||||||||||||||||||
| 60 | 0 | $encode_map{ipv6addr} = \&encode_ipv6addr_pp, | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | # value limits for numeric types | ||||||||||||||||||||||||||||
| 64 | 2 | my %limits_map = ( | |||||||||||||||||||||||||||
| 65 | integer => [0, 2**32 - 1], | ||||||||||||||||||||||||||||
| 66 | integer_tag => [0, 2**24 - 1], | ||||||||||||||||||||||||||||
| 67 | byte => [0, 2**8 - 1], | ||||||||||||||||||||||||||||
| 68 | short => [0, 2**16 - 1], | ||||||||||||||||||||||||||||
| 69 | signed => [-2**31, 2**31 - 1], | ||||||||||||||||||||||||||||
| 70 | # unix timestamp | ||||||||||||||||||||||||||||
| 71 | date => [0, 2**32 - 1], | ||||||||||||||||||||||||||||
| 72 | ); | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | sub encode_string { | ||||||||||||||||||||||||||||
| 75 | 13 | ▶ | my ($value, $attr, $dict) = @_; | ||||||||||||||||||||||||||
|
Subroutine
encode_string: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 76 | 13 | ▶ | my $max_size = ($attr && $attr->{vendor}) ? MAX_VSA_STRING_SIZE : MAX_STRING_SIZE; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$attr and $attr->{"vendor"}
MC/DC50%1/2
$attr and $attr->{"vendor"}
$attr
$attr->{"vendor"}
Truth table66%2/3
A and B
A= $attrB= $attr->{"vendor"}
| |||||||||||||||||||||||||||||
| 77 | 13 | ▶ | if (length($value) > $max_size) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | 2 | warn "Too long value of ".$attr->{name}; | |||||||||||||||||||||||||||
| 79 | 2 | return undef; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | 11 | return $value; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | sub encode_string_tag { | ||||||||||||||||||||||||||||
| 85 | 0 | ▶ | my ($value, $attr, $dict, $tag) = @_; | ||||||||||||||||||||||||||
|
Subroutine
encode_string_tag: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 86 | 0 | ▶ | my $max_size = ($attr && $attr->{vendor}) ? MAX_VSA_STRING_SIZE : MAX_STRING_SIZE; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$attr and $attr->{"vendor"}
MC/DC0%0/2
$attr and $attr->{"vendor"}
$attr
$attr->{"vendor"}
Truth table0%0/3
A and B
A= $attrB= $attr->{"vendor"}
| |||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 0 | ▶ | if (defined $tag) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 0 | ▶ | if ($tag > 31) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 0 | warn sprintf('Too big tag value %d for %s', $tag, $attr->{name}); | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | 0 | $max_size--; | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 0 | ▶ | if (length($value) > $max_size) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | 0 | warn "Too long value of ".$attr->{name}; | |||||||||||||||||||||||||||
| 97 | 0 | return undef; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 0 | ▶ | if (defined $tag) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | 0 | $value = pack('C', $tag) . $value; | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 0 | return $value; | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 2 | ▶ | sub encode_int { pack('N', int($_[0])) } | ||||||||||||||||||||||||||
|
Subroutine
encode_int: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 108 | 2 | ▶ | sub encode_byte { pack('C', int($_[0])) } | ||||||||||||||||||||||||||
|
Subroutine
encode_byte: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 109 | 1 | ▶ | sub encode_short { pack('S>', int($_[0])) } | ||||||||||||||||||||||||||
|
Subroutine
encode_short: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 110 | 2 | ▶ | sub encode_signed { pack('l>', int($_[0])) } | ||||||||||||||||||||||||||
|
Subroutine
encode_signed: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | sub encode_int_tag { | ||||||||||||||||||||||||||||
| 113 | 0 | ▶ | my ($value, $attr, $dict, $tag) = @_; | ||||||||||||||||||||||||||
|
Subroutine
encode_int_tag: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 114 | 0 | $value = pack('N', int($value)); | |||||||||||||||||||||||||||
| 115 | 0 | ▶ | if (defined $tag) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | 0 | ▶ | if ($tag > 31) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | 0 | warn sprintf('Too big tag value %d for %s', $tag, $attr->{name}); | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | # tag added to 1st byte, not extending the value length | ||||||||||||||||||||||||||||
| 120 | 0 | substr($value, 0, 1, pack('C', $tag) ); | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | 0 | return $value; | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 3 | ▶ | sub encode_ipaddr { inet_pton(AF_INET, $_[0]) } | ||||||||||||||||||||||||||
|
Subroutine
encode_ipaddr: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 126 | 3 | ▶ | sub encode_ipv6addr { inet_pton(AF_INET6, $_[0]) } | ||||||||||||||||||||||||||
|
Subroutine
encode_ipv6addr: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | sub encode_ipv6addr_pp { | ||||||||||||||||||||||||||||
| 129 | 0 | ▶ | my $value = shift; | ||||||||||||||||||||||||||
|
Subroutine
encode_ipv6addr_pp: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 130 | 0 | my $expanded_value = Net::IP::ip_expand_address( $value, 6 ); | |||||||||||||||||||||||||||
| 131 | 0 | ▶ | return undef if (! $expanded_value); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 132 | 0 | my $bin_value = Net::IP::ip_iptobin( $expanded_value, 6 ); | |||||||||||||||||||||||||||
| 133 | 0 | ▶ | return undef if (! defined $bin_value); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | 0 | return pack( 'B*', $bin_value ); | |||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | sub encode_octets { | ||||||||||||||||||||||||||||
| 138 | 2 | ▶ | my ($value, $attr, $dict) = @_; | ||||||||||||||||||||||||||
|
Subroutine
encode_octets: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 2 | ▶ | if ($value !~ /^0x(?:[0-9A-Fa-f]{2})+$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 141 | 1 | warn 'Invalid octet string for '.$attr->{name}; | |||||||||||||||||||||||||||
| 142 | 1 | return undef; | |||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | 1 | $value =~ s/^0x//; | |||||||||||||||||||||||||||
| 146 | 1 | return pack("H*", $value); | |||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | sub encode_combo_ip { | ||||||||||||||||||||||||||||
| 150 | 2 | ▶ | my $ip = shift; | ||||||||||||||||||||||||||
|
Subroutine
encode_combo_ip: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 2 | ▶ | if ($ip =~ /^\d+\.\d+.\d+.\d+$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 153 | 1 | return $encode_map{ipaddr}->($ip); | |||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 1 | return $encode_map{ipv6addr}->($ip); | |||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | sub encode_avpair { | ||||||||||||||||||||||||||||
| 160 | 4 | ▶ | my ($value, $attr, $dict) = @_; | ||||||||||||||||||||||||||
|
Subroutine
encode_avpair: called CC=6 SCAR=18.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 161 | 4 | ▶ | if ( ($attr->{vendor} // '') eq VENDOR_CISCO ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$attr->{"vendor"} // ""
MC/DC0%0/1
$attr->{"vendor"} // ""
$attr->{"vendor"}
Truth table50%1/2
A
A= $attr->{"vendor"}
| |||||||||||||||||||||||||||||
| 162 | # Looks like it afects only requests from Cisco NAS | ||||||||||||||||||||||||||||
| 163 | # and probably not required in requests to it | ||||||||||||||||||||||||||||
| 164 | # Do not applied to Cisco-AVPair attribute itself | ||||||||||||||||||||||||||||
| 165 | 4 | ▶ | if ($attr->{id} == ATTR_CISCO_AVPAIR_ID && $attr->{name} ne ATTR_CISCO_AVPAIR) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$attr->{"id"} == 1 and $attr->{"name"} ne "Cisco-AVPair"
MC/DC50%1/2
$attr->{"id"} == 1 and $attr->{"name"} ne "Cisco-AVPair"
$attr->{"id"} == 1
$attr->{"name"} ne "Cisco-AVPair"
Truth table66%2/3
A and B
A= $attr->{"id"} == 1B= $attr->{"name"} ne "Cisco-AVPair"
| |||||||||||||||||||||||||||||
| 166 | 2 | $value = $attr->{name} . '=' . $value; | |||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | 4 | ▶ | if (length($value) > MAX_VSA_STRING_SIZE) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 171 | 2 | warn "Too long value of ".$attr->{name}; | |||||||||||||||||||||||||||
| 172 | 2 | return undef; | |||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | 2 | return $value; | |||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | # TODO continuation field is not supported for WiMAX VSA | ||||||||||||||||||||||||||||
| 179 | sub encode_tlv { | ||||||||||||||||||||||||||||
| 180 | 2 | ▶ | my ($value, $parent, $dict) = @_; | ||||||||||||||||||||||||||
|
Subroutine
encode_tlv: called CC=7 SCAR=21.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | 2 | my @list = (); | |||||||||||||||||||||||||||
| 183 | 2 | foreach my $v (@{$value}) { | |||||||||||||||||||||||||||
| 184 | 3 | my $attr = $dict->attribute($v->{Name}); | |||||||||||||||||||||||||||
| 185 | 3 | ▶ | if (! $attr) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 186 | 0 | warn "Unknown tlv-attribute ".$v->{Name}; | |||||||||||||||||||||||||||
| 187 | 0 | next; | |||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | # no vendor for sub-attributes | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | # verify that corrent sub-attribute is used | ||||||||||||||||||||||||||||
| 193 | 3 | ▶ | if ( ($attr->{parent} // '') ne $parent->{name}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$attr->{"parent"} // ""
MC/DC0%0/1
$attr->{"parent"} // ""
$attr->{"parent"}
Truth table50%1/2
A
A= $attr->{"parent"}
| |||||||||||||||||||||||||||||
| 194 | 0 | warn "Attribute $v->{Name} cannot be used with $parent->{name}"; | |||||||||||||||||||||||||||
| 195 | 0 | next; | |||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | # constant to its value | ||||||||||||||||||||||||||||
| 199 | 3 | my $value; | |||||||||||||||||||||||||||
| 200 | 3 | ▶ | if (is_enum_type($attr->{type})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 201 | 1 | ▶ | $value = $dict->value($attr->{name}, $v->{Value}) // $v->{Value}; | ||||||||||||||||||||||||||
|
Condition33%1/3
$dict->value($attr->{"name"}, $v->{"Value"}) // $v->{"Value"}
MC/DC0%0/2
$dict->value($attr->{"name"}, $v->{"Value"}) // $v->{"Value"}
$dict->value($attr->{"name"}, $v->{"Value"})
$v->{"Value"}
Truth table33%1/3
A // B
A= $dict->value($attr->{"name"}, $v->{"Value"})B= $v->{"Value"}
| |||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||
| 203 | else { | ||||||||||||||||||||||||||||
| 204 | 2 | $value = $v->{Value}; | |||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | 3 | my $encoded = encode($attr, $value, $dict); | |||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | 3 | push @list, pack('C C', $attr->{id}, length($encoded) + 2) . $encoded; | |||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | 2 | return join('', @list); | |||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | # main exported function | ||||||||||||||||||||||||||||
| 216 | sub encode { | ||||||||||||||||||||||||||||
| 217 | 44 | ▶ | my ($attr, $value, $dict, $tag) = @_; | ||||||||||||||||||||||||||
|
Subroutine
encode: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | 44 | ▶ | if (! defined $value) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 220 | 1 | warn "Value is not defined for " . $attr->{name}; | |||||||||||||||||||||||||||
| 221 | 1 | return undef; | |||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | 43 | ▶ | my $encoder = $attr->{type} . ($attr->{has_tag} ? '_tag' : ''); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | 43 | my $limits = $limits_map{ $encoder }; | |||||||||||||||||||||||||||
| 227 | 43 | ▶ | if ($limits) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 228 | # integer types | ||||||||||||||||||||||||||||
| 229 | 16 | ▶ | if ($value !~ /^-?\d+$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 230 | 1 | warn "Value is not number for " . $attr->{name}; | |||||||||||||||||||||||||||
| 231 | 1 | return undef; | |||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | 15 | my ($min, $max) = @$limits; | |||||||||||||||||||||||||||
| 235 | 15 | ▶ | if ($value < $min || $value > $max) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$value < $min or $value > $max
MC/DC100%2/2
$value < $min or $value > $max
$value < $min
$value > $max
Truth table100%3/3
A or B
A= $value < $minB= $value > $max
| |||||||||||||||||||||||||||||
| 236 | 8 | warn "Value out of range for " . $attr->{name}; | |||||||||||||||||||||||||||
| 237 | 8 | return undef; | |||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | 34 | my $encoded = $encode_map{ $encoder }->($value, $attr, $dict, $tag); | |||||||||||||||||||||||||||
| 242 | 34 | return $encoded; | |||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | 2 | 1; | |||||||||||||||||||||||||||