lib/Mail/DKIM2/Chain.pm

filter: Statementstmt 89.7% 158 / 176 Branchbran 83.8% 52 / 62 Conditioncond 81.6% 58 / 71 MC/DCmcdc 64.8% 24 / 37 Subroutinesub 89.7% 35 / 39 Podpod 100% 26 / 26 totaltotal 85.8% 353 / 411 CC 123 SCAR 22.5
CC
123
Cov
87%
add_field
18.1
add_field
18.1
structure_error
17.0
CRAP 9.5
« lib/Mail/DKIM2/Signature.pm ↑ Summary lib/Mail/DKIM2/TagValueList.pm »
1 package Mail::DKIM2::Chain;
2 197 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 197 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 197 our $VERSION = '0.35';
6  
7 197 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 197 ▶use Mail::DKIM2::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 197 ▶use Mail::DKIM2::Common qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
10 MI_MISSING_M_ERROR
11 MAX_CHAIN_LENGTH
12 chain_length_error
13 chain_number_error
14 duplicate_number_error
15 extract_mi_version
16 mi_version_tag
17 unkeyable_signature_error
18 valid_sequence
19 197 );
20 197 ▶use Mail::DKIM2::HeaderParser;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 197 ▶use Mail::DKIM2::Signature;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 197 ▶use Mail::DKIM2::MessageInstance;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 # The Message-Instance and DKIM2-Signature fields of one message, numbered:
25 # what the Verifier, the Signer and the Gate each need to know about a chain
26 # before any of them looks at the content. Fields are added as the header is
27 # read; nothing here hashes, fetches a key or checks a signature.
28  
29 2107 ▶sub new {
Subroutine new: called CC=1 SCAR=1.2
Pod documented
30 0 ▶ my ($class) = @_;
Subroutine new: not called CC=1 SCAR=1.2
Pod documented
31 0 return bless {
32 instance => {}, # m => the raw field
33 signature => {}, # i => { raw => the raw field, sig => Signature }
34 count => {}, # lower-cased field name => how many there were
35 numbers => { 'message-instance' => [], 'dkim2-signature' => [] },
36 parsed => {}, # m => [MessageInstance or undef, error]
37 }, $class;
38 }
39  
40 # from_fields(\@fields): a chain from header fields given whole, name and
41 # value, as Mail::DKIM2::HeaderParser keeps them. Other fields are ignored.
42 1 ▶sub from_fields {
Subroutine from_fields: called CC=3 SCAR=15.1
Pod documented
43 0 ▶ my ($class, $fields) = @_;
Subroutine from_fields: not called CC=3 SCAR=15.1
Pod documented
44 0 my $self = $class->new;
45 0 for my $raw (@$fields) {
46 0 ▶ my ($name, $value) = $raw =~ /\A([^\s:]+)[ \t]*:[ \t]*(.*)\z/s or next;
Branch: 2 branches
BranchTrueFalseTotal
() = $raw =~ /\A([^\s:]+)[ \t]*:[ \t]*(.*)\z/s or next 3 0 3
() = $raw =~ /\A([^\s:]+)[ \t]*:[ \t]*(.*)\z/s or next 0 0 0
47 0 $value =~ s/\r?\n\z//;
48 0 $self->add_field($name, $value, $raw);
49 }
50 0 return $self;
51 }
52  
53 # from_message($text): a chain from a message, or from its header block
54 # alone, as a string. Only the header fields are read.
55 422 ▶sub from_message {
Subroutine from_message: called CC=2 SCAR=10.0
Pod documented
56 0 ▶ my ($class, $text) = @_;
Subroutine from_message: not called CC=2 SCAR=10.0
Pod documented
57 0 ▶ Carp::croak("from_message needs a message") unless defined $text;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $text 0 422 422
unless defined $text 0 0 0
58 0 my $reader = Mail::DKIM2::Chain::_Reader->new;
59 0 $reader->PRINT($text);
60 0 $reader->CLOSE;
61 0 return $reader->{chain};
62 }
63  
64 {
65 # The header fields of a message, as the Signer and the Verifier split
66 # them, straight into a chain; the body is not read.
67 package Mail::DKIM2::Chain::_Reader;
68 197 ▶ use parent -norequire, 'Mail::DKIM2::HeaderParser';
Subroutine BEGIN: called CC=1 SCAR=0.0
69 422 ▶ sub init {
Subroutine init: called CC=1 SCAR=1.2
70 0 ▶ my $self = shift;
Subroutine init: not called CC=1 SCAR=1.2
71 0 $self->SUPER::init;
72 0 $self->{chain} = Mail::DKIM2::Chain->new;
73 }
74 3634 ▶ sub handle_header { $_[0]{chain}->add_field(@_[1 .. 3]) }
Subroutine handle_header: called CC=1 SCAR=0.0
75 422 ▶ sub finish_header { $_[0]->stop }
Subroutine finish_header: called CC=1 SCAR=0.0
76 }
77  
78 # add_field($name, $value, $raw): take one header field -- its name, its
79 # value without the line break, and the whole field as it is in the
80 # message. True if it was a Message-Instance or DKIM2-Signature field.
81 #
82 # A field that cannot be placed in the chain is remembered as the chain's
83 # fault (numbering_error), never skipped: a DKIM2-Signature that does not
84 # parse, or has no i=, or an i= or m= that is not a chain number (1*DIGIT,
85 # at most two digits, no more than MAX_CHAIN_LENGTH); a Message-Instance
86 # without a usable m=. Past MAX_CHAIN_LENGTH fields of either kind the rest
87 # are counted and not read: the count alone is the fault.
88 197 ▶sub add_field {
Subroutine add_field: called CC=17 SCAR=28.9
Pod documented
89 23332 my ($self, $name, $value, $raw) = @_;
90 23332 my $lc = lc $name;
91 23332 $lc =~ s/[ \t]+\z//;
92 23332 ▶ return 0 unless $lc eq 'message-instance' || $lc eq 'dkim2-signature';
Branch: 1 branch
BranchTrueFalseTotal
unless $lc eq "message-instance" or $lc eq "dkim2-signature" 16089 7243 23332
Condition100%3/3
$lc eq "message-instance" or $lc eq "dkim2-signature"
l!l&&r!l&&!r
3463378016089
MC/DC100%2/2
$lc eq "message-instance" or $lc eq "dkim2-signature"
$lc eq "message-instance" $lc eq "dkim2-signature"
Truth table100%3/3
A or B
A= $lc eq "message-instance"B= $lc eq "dkim2-signature"
ABresult
1X1
011
000
93 7243 ▶ return 1 if ++$self->{count}{$lc} > MAX_CHAIN_LENGTH;
Branch: 1 branch
BranchTrueFalseTotal
if ++$self->{"count"}{$lc} > 32 1011 6232 7243
94 6232 ▶ $raw //= "$name:$value";
Condition50%1/2
$raw //= "${name}:$value"
l!l
62320
MC/DC0%0/1
$raw //= "${name}:$value"
$raw
Truth table50%1/2
A
A= $raw
Aresult
11
00
95  
96 6232 ▶ if ($lc eq 'message-instance') {
Branch: 1 branch
BranchTrueFalseTotal
if ($lc eq "message-instance") 3461 2771 6232
97 3461 my $tag = mi_version_tag($value);
98 3461 ▶ if (!defined $tag) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $tag) { } 3 3458 3461
elsif (my $e = chain_number_error('Message-Instance', 'm', $tag)) { } 17 3441 3458
99 3 ▶ $self->{instance_unusable} //= MI_MISSING_M_ERROR;
Condition50%1/2
$self->{"instance_unusable"} //= "PERMERROR: Message-Instance m= tag=m missing"
l!l
03
MC/DC0%0/1
$self->{"instance_unusable"} //= "PERMERROR: Message-Instance m= tag=m missing"
$self->{"instance_unusable"}
Truth table50%1/2
A
A= $self->{"instance_unusable"}
Aresult
11
00
100 }
101 elsif (my $e = chain_number_error('Message-Instance', 'm', $tag)) {
102 17 ▶ $self->{instance_unusable} //= $e;
Condition33%1/3
$self->{"instance_unusable"} //= $e
l!l&&r!l&&!r
0170
MC/DC0%0/2
$self->{"instance_unusable"} //= $e
$self->{"instance_unusable"} $e
Truth table33%1/3
A //= B
A= $self->{"instance_unusable"}B= $e
ABresult
1X1
011
000
103 }
104 else {
105 3441 my $m = extract_mi_version($value); # numeric: m=01 is m=1
106 3441 push @{ $self->{numbers}{$lc} }, $m;
107 3441 $self->{instance}{$m} = $raw;
108 }
109 3461 return 1;
110 }
111  
112 2771 my $sig = eval { Mail::DKIM2::Signature->parse($value) };
113 2771 ▶ die $@ if ref $@;
Branch: 1 branch
BranchTrueFalseTotal
if ref $@ 0 2771 2771
114 2771 ▶ my $i = $sig ? $sig->sequence : undef;
Branch: 1 branch
BranchTrueFalseTotal
$sig ? : 2771 0 2771
115 2771 ▶ if (!valid_sequence($i)) {
Branch: 2 branches
BranchTrueFalseTotal
if (not valid_sequence($i)) { } 62 2709 2771
elsif (my $e = chain_number_error('DKIM2-Signature', 'i', $i) // chain_number_error('DKIM2-Signature', 'm', $sig->version, $i)) { } 24 2685 2709
116 62 ▶ $self->{signature_unusable} //= unkeyable_signature_error($value);
Condition33%1/3
$self->{"signature_unusable"} //= unkeyable_signature_error($value)
l!l&&r!l&&!r
0620
MC/DC0%0/2
$self->{"signature_unusable"} //= unkeyable_signature_error($value)
$self->{"signature_unusable"} unkeyable_signature_error($value)
Truth table33%1/3
A //= B
A= $self->{"signature_unusable"}B= unkeyable_signature_error($value)
ABresult
1X1
011
000
117 }
118 ▶ elsif (my $e = chain_number_error('DKIM2-Signature', 'i', $i)
Condition100%3/3
chain_number_error("DKIM2-Signature", "i", $i) // chain_number_error("DKIM2-Signature", "m", $sig->version, $i)
l!l&&r!l&&!r
14102685
MC/DC100%2/2
chain_number_error("DKIM2-Signature", "i", $i) // chain_number_error("DKIM2-Signature", "m", $sig->version, $i)
chain_number_error("DKIM2-Signature", "i", $i) chain_number_error("DKIM2-Signature", "m", $sig->version, $i)
Truth table100%3/3
A // B
A= chain_number_error("DKIM2-Signature", "i", $i)B= chain_number_error("DKIM2-Signature", "m", $sig->version, $i)
ABresult
1X1
011
000
119 // chain_number_error('DKIM2-Signature', 'm', $sig->version, $i)) {
120 24 ▶ $self->{signature_unusable} //= $e;
Condition33%1/3
$self->{"signature_unusable"} //= $e
l!l&&r!l&&!r
0240
MC/DC0%0/2
$self->{"signature_unusable"} //= $e
$self->{"signature_unusable"} $e
Truth table33%1/3
A //= B
A= $self->{"signature_unusable"}B= $e
ABresult
1X1
011
000
121 }
122 else {
123 2685 push @{ $self->{numbers}{$lc} }, $i;
124 2685 $self->{signature}{ $i + 0 } = { raw => $raw, sig => $sig };
125 }
126 2771 return 1;
127 }
128  
129 # --- What is in the chain ---
130  
131 540 ▶sub count {
Subroutine count: called CC=2 SCAR=6.9
Pod documented
132 540 my ($self, $field) = @_;
133 540 ▶ return $self->{count}{ lc $field } // 0;
Condition100%2/2
$self->{"count"}{lc $field} // 0
l!l
341199
MC/DC100%1/1
$self->{"count"}{lc $field} // 0
$self->{"count"}{lc $field}
Truth table100%2/2
A
A= $self->{"count"}{lc $field}
Aresult
11
00
134 }
135  
136 2 ▶sub is_empty {
Subroutine is_empty: called CC=1 SCAR=0.0
Pod documented
137 2 my ($self) = @_;
138 2 return !%{ $self->{count} };
139 }
140  
141 # (Through an array: sort in scalar context returns nothing useful, and
142 # "unless $chain->instance_numbers" should count them.)
143 7045 ▶sub instance_numbers { my @n = sort { $a <=> $b } keys %{ $_[0]{instance} }; return @n }
Subroutine instance_numbers: called CC=1 SCAR=0.0
Pod documented
144 5640 ▶sub signature_numbers { my @n = sort { $a <=> $b } keys %{ $_[0]{signature} }; return @n }
Subroutine signature_numbers: called CC=1 SCAR=0.0
Pod documented
145  
146 2953 ▶sub top_instance { return ($_[0]->instance_numbers)[-1] }
Subroutine top_instance: called CC=1 SCAR=0.0
Pod documented
147 2641 ▶sub top_signature_number { return ($_[0]->signature_numbers)[-1] }
Subroutine top_signature_number: called CC=1 SCAR=0.0
Pod documented
148  
149 1226 ▶sub instance_field { return $_[0]{instance}{ $_[1] } }
Subroutine instance_field: called CC=1 SCAR=0.0
Pod documented
150  
151 # The chain's own maps, for a caller that walks all of it: m => the raw
152 # field, and i => { raw => the raw field, sig => the Signature }.
153 1109 ▶sub instance_fields { return $_[0]{instance} }
Subroutine instance_fields: called CC=1 SCAR=0.0
Pod documented
154 1109 ▶sub signature_entries { return $_[0]{signature} }
Subroutine signature_entries: called CC=1 SCAR=0.0
Pod documented
155  
156 1764 ▶sub signature {
Subroutine signature: called CC=2 SCAR=7.1
Pod documented
157 1764 my ($self, $i) = @_;
158 1764 ▶ my $entry = $self->{signature}{$i} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $entry = $self->{"signature"}{$i} or return 1764 0 1764
159 1764 return $entry->{sig};
160 }
161  
162 727 ▶sub signature_field {
Subroutine signature_field: called CC=2 SCAR=6.9
Pod documented
163 727 my ($self, $i) = @_;
164 727 ▶ my $entry = $self->{signature}{$i} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $entry = $self->{"signature"}{$i} or return 725 2 727
165 725 return $entry->{raw};
166 }
167  
168 1889 ▶sub signatures {
Subroutine signatures: called CC=1 SCAR=0.0
Pod documented
169 1889 my ($self) = @_;
170 1889 return map { $self->{signature}{$_}{sig} } $self->signature_numbers;
171 }
172  
173 215 ▶sub top_signature {
Subroutine top_signature: called CC=2 SCAR=6.9
Pod documented
174 215 my ($self) = @_;
175 215 ▶ my $i = $self->top_signature_number // return;
Condition100%2/2
$self->top_signature_number // (return)
l!l
14768
MC/DC100%1/1
$self->top_signature_number // (return)
$self->top_signature_number
Truth table100%2/2
A
A= $self->top_signature_number
Aresult
11
00
176 147 return $self->{signature}{$i}{sig};
177 }
178  
179 # instance($m): the parsed Message-Instance m=, or (undef, $error) when it
180 # is not there or does not parse -- $error in the words the Verifier
181 # reports. Parsed once, however many callers ask.
182 3853 ▶sub instance {
Subroutine instance: called CC=6 SCAR=18.0
Pod documented
183 3853 my ($self, $m) = @_;
184 3853 ▶ my $cached = $self->{parsed}{$m} //= do {
Condition66%2/3
$self->{"parsed"}{$m} //= do { my $raw = $self->{"instance"}{$m}; if (not defined $raw) { [undef, "PERMERROR: Message-Instance m=$m missing"]; } else { (my $value = $raw) =~ s/\A[^:]*:[ \t]*//; my $obj = eval { do { "Mail::DKIM2::MessageInstance"->parse($value) } }; die $@ if ref $@; $obj ? [$obj] : [undef, Mail::DKIM2::MessageInstance::_parse_error($@)]; } }
l!l&&r!l&&!r
197918740
MC/DC0%0/2
$self->{"parsed"}{$m} //= do { my $raw = $self->{"instance"}{$m}; if (not defined $raw) { [undef, "PERMERROR: Message-Instance m=$m missing"]; } else { (my $value = $raw) =~ s/\A[^:]*:[ \t]*//; my $obj = eval { do { "Mail::DKIM2::MessageInstance"->parse($value) } }; die $@ if ref $@; $obj ? [$obj] : [undef, Mail::DKIM2::MessageInstance::_parse_error($@)]; } }
$self->{"parsed"}{$m} do { my $raw = $self->{"instance"}{$m}; if (not defined $raw) { [undef, "PERMERROR: Message-Instance m=$m missing"]; } else { (my $value = $raw) =~ s/\A[^:]*:[ \t]*//; my $obj = eval { do { "Mail::DKIM2::MessageInstance"->parse($value) } }; die $@ if ref $@; $obj ? [$obj] : [undef, Mail::DKIM2::MessageInstance::_parse_error($@)]; } }
Truth table66%2/3
A //= B
A= $self->{"parsed"}{$m}B= do { my $raw = $self->{"instance"}{$m}; if (not defined $raw) { [undef, "PERMERROR: Message-Instance m=$m missing"]; } else { (my $value = $raw) =~ s/\A[^:]*:[ \t]*//; my $obj = eval { do { "Mail::DKIM2::MessageInstance"->parse($value) } }; die $@ if ref $@; $obj ? [$obj] : [undef, Mail::DKIM2::MessageInstance::_parse_error($@)]; } }
ABresult
1X1
011
000
185 1874 my $raw = $self->{instance}{$m};
186 1874 ▶ if (!defined $raw) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $raw) { } 1 1873 1874
187 1 [undef, "PERMERROR: Message-Instance m=$m missing"];
188 } else {
189 1873 (my $value = $raw) =~ s/\A[^:]*:[ \t]*//;
190 1873 my $obj = eval { Mail::DKIM2::MessageInstance->parse($value) };
191 1873 ▶ die $@ if ref $@;
Branch: 1 branch
BranchTrueFalseTotal
if ref $@ 0 1873 1873
192 1873 ▶ $obj ? [$obj] : [undef, Mail::DKIM2::MessageInstance::_parse_error($@)];
Branch: 1 branch
BranchTrueFalseTotal
$obj ? : 1729 144 1873
193 }
194 };
195 3853 ▶ return wantarray ? @$cached : $cached->[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 2873 980 3853
196 }
197  
198 # covered_m(): the highest m= any signature names, or 0. A DKIM2-Signature
199 # with m=k covers instances 1 to k (-09 section 10.2), so every instance
200 # above this is one nobody has signed yet.
201 1886 ▶sub covered_m {
Subroutine covered_m: called CC=4 SCAR=13.9
Pod documented
202 1886 my ($self) = @_;
203 1886 my $covered = 0;
204 1886 for my $sig ($self->signatures) {
205 3293 ▶ my $m = $sig->version // next;
Condition50%1/2
$sig->version // (next)
l!l
32930
MC/DC0%0/1
$sig->version // (next)
$sig->version
Truth table50%1/2
A
A= $sig->version
Aresult
11
00
206 3293 ▶ $covered = 0 + $m if $m > $covered;
Branch: 1 branch
BranchTrueFalseTotal
if $m > $covered 3051 242 3293
207 }
208 1886 return $covered;
209 }
210  
211 # unsigned_instances(): the m= of every instance above covered_m, ascending.
212 1 ▶sub unsigned_instances {
Subroutine unsigned_instances: called CC=1 SCAR=0.0
Pod documented
213 1 my ($self) = @_;
214 1 my $covered = $self->covered_m;
215 1 my @above = grep { $_ > $covered } $self->instance_numbers;
216 1 return @above;
217 }
218  
219 # instances_changing($name, $above, $upto): the m= of every instance with
220 # $above < m <= $upto that has a header Recipe for the field named $name --
221 # the hops, between two signatures, that say they changed that field. One
222 # that does not parse says nothing. m=1 is never in it: its Recipes record
223 # what happened to the message before DKIM2, which no signature answers for.
224 958 ▶sub instances_changing {
Subroutine instances_changing: called CC=8 SCAR=20.8
Pod documented
225 958 my ($self, $name, $above, $upto) = @_;
226 958 ▶ $above //= 0;
Condition50%1/2
$above //= 0
l!l
9580
MC/DC0%0/1
$above //= 0
$above
Truth table50%1/2
A
A= $above
Aresult
11
00
227 958 ▶ $upto //= $self->top_instance // 0;
Condition75%3/4
$upto //= $self->top_instance // 0
l!l
741217
$self->top_instance // 0
l!l
2170
MC/DC100%1/1
$upto //= $self->top_instance // 0
$upto
Truth table100%2/2
A
A= $upto
Aresult
11
00
228 my @changing = grep {
229 958 ▶ my $mi = $_ >= 2 && $_ > $above && $_ <= $upto ? $self->instance($_) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$_ >= 2 && $_ > $above && $_ <= $upto ? : 727 4193 4920
Condition100%6/6
$_ >= 2 and $_ > $above and $_ <= $upto
!ll&&!rl&&r
28851308727
$_ >= 2 and $_ > $above
!ll&&!rl&&r
95819272035
MC/DC100%3/3
$_ >= 2 and $_ > $above and $_ <= $upto
$_ >= 2 $_ > $above $_ <= $upto
Truth table100%4/4
A and B and C
A= $_ >= 2B= $_ > $aboveC= $_ <= $upto
ABCresult
0XX0
10X0
1100
1111
230 4920 ▶ $mi && $mi->changes_header($name);
Condition100%3/3
$mi && $mi->changes_header($name)
!ll&&!rl&&r
4305451164
MC/DC100%2/2
$mi && $mi->changes_header($name)
$mi $mi->changes_header($name)
Truth table100%3/3
A && B
A= $miB= $mi->changes_header($name)
ABresult
0X0
100
111
231 } $self->instance_numbers;
232 958 return @changing;
233 }
234  
235 # --- Whether it is a chain ---
236  
237 # numbering_error(%opts): the PERMERROR for a chain whose fields cannot be
238 # numbered, or undef -- too many fields, a field with no usable number, a
239 # number given twice. In the interop contract's order (C9, a to e), so every
240 # verifier names the same fault first. Signatures => 0 leaves the
241 # DKIM2-Signature fields out of it, but for their count.
242 2779 ▶sub numbering_error {
Subroutine numbering_error: called CC=8 SCAR=20.8
Pod documented
243 2779 my ($self, %o) = @_;
244 2779 ▶ my $sigs = $o{Signatures} // 1;
Condition100%2/2
$o{"Signatures"} // 1
l!l
2212567
MC/DC100%1/1
$o{"Signatures"} // 1
$o{"Signatures"}
Truth table100%2/2
A
A= $o{"Signatures"}
Aresult
11
00
245 2779 my $n = $self->{numbers};
246 return chain_length_error($self->{count}) # a
247 // $self->{instance_unusable} # b
248 2754 ▶ // duplicate_number_error('Message-Instance', 'm', @{ $n->{'message-instance'} }) # c
Branch: 2 branches
BranchTrueFalseTotal
$sigs ? : 2497 248 2745
$sigs ? : 2444 248 2692
249 // ($sigs ? $self->{signature_unusable} : undef) # d
250 // ($sigs ? duplicate_number_error('DKIM2-Signature', 'i', # e
251 2779 ▶ @{ $n->{'dkim2-signature'} }) : undef);
Condition100%12/12
(((chain_length_error($self->{"count"}) // $self->{"instance_unusable"}) // duplicate_number_error("Message-Instance", "m", @{$$n{"message-instance"};})) // ($sigs ? $self->{"signature_unusable"} : undef)) // ($sigs ? duplicate_number_error("DKIM2-Signature", "i", @{$$n{"dkim2-signature"};}) : undef)
l!l&&r!l&&!r
8762686
((chain_length_error($self->{"count"}) // $self->{"instance_unusable"}) // duplicate_number_error("Message-Instance", "m", @{$$n{"message-instance"};})) // ($sigs ? $self->{"signature_unusable"} : undef)
l!l&&r!l&&!r
34532692
(chain_length_error($self->{"count"}) // $self->{"instance_unusable"}) // duplicate_number_error("Message-Instance", "m", @{$$n{"message-instance"};})
l!l&&r!l&&!r
2592745
chain_length_error($self->{"count"}) // $self->{"instance_unusable"}
l!l&&r!l&&!r
5202754
MC/DC100%5/5
(((chain_length_error($self->{"count"}) // $self->{"instance_unusable"}) // duplicate_number_error("Message-Instance", "m", @{$$n{"message-instance"};})) // ($sigs ? $self->{"signature_unusable"} : undef)) // ($sigs ? duplicate_number_error("DKIM2-Signature", "i", @{$$n{"dkim2-signature"};}) : undef)
chain_length_error($self->{"count"}) $self->{"instance_unusable"} duplicate_number_error("Message-Instance", "m", @{$$n{"message-instance"};}) ($sigs ? $self->{"signature_unusable"} : undef) ($sigs ? duplicate_number_error("DKIM2-Signature", "i", @{$$n{"dkim2-signature"};}) : undef)
Truth table100%6/6
A // B // C // D // E
A= chain_length_error($self->{"count"})B= $self->{"instance_unusable"}C= duplicate_number_error("Message-Instance", "m", @{$$n{"message-instance"};})D= ($sigs ? $self->{"signature_unusable"} : undef)E= ($sigs ? duplicate_number_error("DKIM2-Signature", "i", @{$$n{"dkim2-signature"};}) : undef)
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
252 }
253  
254 # structure_error(%opts): numbering_error, then the gaps and the coverage
255 # the numbers give (-09 section 14.2; C9, f to h): every instance from m=1
256 # to the highest there is or the highest the top signature names; no
257 # instance above every signature's m= (unless AllowUnsigned: a signer holds
258 # the instance it is about to sign); every signature from i=1 to the
259 # highest. Signatures => 0 checks the instances alone.
260 2072 ▶sub structure_error {
Subroutine structure_error: called CC=17 SCAR=28.3
Pod documented
261 2072 my ($self, %o) = @_;
262 2072 Mail::DKIM2::Util::check_options('structure_error', \%o, qw(Signatures AllowUnsigned));
263 2072 ▶ my $sigs = $o{Signatures} // 1;
Condition100%2/2
$o{"Signatures"} // 1
l!l
205814
MC/DC100%1/1
$o{"Signatures"} // 1
$o{"Signatures"}
Truth table100%2/2
A
A= $o{"Signatures"}
Aresult
11
00
264 2072 ▶ if (my $error = $self->numbering_error(Signatures => $sigs)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $error = $self->numbering_error("Signatures", $sigs)) 68 2004 2072
265 68 return $error;
266 }
267  
268 2004 my $top_m = $self->top_instance;
269 2004 ▶ my $top_i = $sigs ? $self->top_signature_number : undef;
Branch: 1 branch
BranchTrueFalseTotal
$sigs ? : 1859 145 2004
270 2004 ▶ my $named = defined $top_i ? ($self->signature($top_i)->version || 0) : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $top_i ? : 1764 240 2004
Condition50%1/2
$self->signature($top_i)->version or 0
l!l
17640
MC/DC0%0/1
$self->signature($top_i)->version or 0
$self->signature($top_i)->version
Truth table50%1/2
A
A= $self->signature($top_i)->version
Aresult
11
00
271 2004 ▶ my $upto = ($top_m // 0) > $named ? $top_m : $named;
Branch: 1 branch
BranchTrueFalseTotal
($top_m // 0) > $named ? : 269 1735 2004
Condition100%2/2
$top_m // 0
l!l
193767
MC/DC100%1/1
$top_m // 0
$top_m
Truth table100%2/2
A
A= $top_m
Aresult
11
00
272 2004 for my $m (1 .. $upto) { # f
273 2993 ▶ return "PERMERROR: Message-Instance m=$m missing" unless $self->{instance}{$m};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"instance"}{$m} 8 2985 2993
274 }
275  
276 1996 ▶ if (defined $top_m && $sigs && !$o{AllowUnsigned}) { # g
Branch: 1 branch
BranchTrueFalseTotal
if (defined $top_m and $sigs and not $o{"AllowUnsigned"}) 1465 531 1996
Condition100%6/6
defined $top_m and $sigs and not $o{"AllowUnsigned"}
!ll&&!rl&&r
2123191465
defined $top_m and $sigs
!ll&&!rl&&r
671451784
MC/DC100%3/3
defined $top_m and $sigs and not $o{"AllowUnsigned"}
defined $top_m $sigs not $o{"AllowUnsigned"}
Truth table100%4/4
A and B and not(C)
A= defined $top_mB= $sigsC= not $o{"AllowUnsigned"}
ABCresult
0XX0
10X0
1100
1111
277 1465 ▶ return "PERMERROR: Message-Instance m=$top_m is not signed"
Branch: 1 branch
BranchTrueFalseTotal
if $top_m > $self->covered_m 12 1453 1465
278 if $top_m > $self->covered_m;
279 }
280  
281 1984 ▶ for my $i (1 .. ($top_i // 0)) { # h
Condition100%2/2
$top_i // 0
l!l
1754230
MC/DC100%1/1
$top_i // 0
$top_i
Truth table100%2/2
A
A= $top_i
Aresult
11
00
282 2805 ▶ return "PERMERROR: DKIM2-Signature i=$i missing" unless $self->{signature}{$i};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"signature"}{$i} 4 2801 2805
283 }
284 1980 return;
285 }
286  
287 197 1;
288  
289 __END__
« lib/Mail/DKIM2/Signature.pm ↑ Summary lib/Mail/DKIM2/TagValueList.pm »