lib/Mail/DKIM2/Chain.pm

filter: Statementstmt 89.7% 158 / 176 Branchbran 82.2% 51 / 62 Conditioncond 81.6% 58 / 71 MC/DCmcdc 64.8% 24 / 37 Subroutinesub 89.7% 35 / 39 Podpod 100% 26 / 26 totaltotal 85.6% 352 / 411 CC 123 SCAR 22.5
CC
123
Cov
86%
add_field
18.1
add_field
18.1
structure_error
17.0
CRAP 9.5
« lib/Mail/DKIM2/Signature.pm ↑ Summary lib/Mail/Milter/Authentication/Handler/DKIM2Verify.pm »
1 package Mail::DKIM2::Chain;
2 181 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 181 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 181 our $VERSION = '0.33';
6  
7 181 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 181 ▶use Mail::DKIM2::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 181 ▶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 181 );
20 181 ▶use Mail::DKIM2::HeaderParser;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 181 ▶use Mail::DKIM2::Signature;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 181 ▶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 2027 ▶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 379 ▶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 379 379
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 181 ▶ use parent -norequire, 'Mail::DKIM2::HeaderParser';
Subroutine BEGIN: called CC=1 SCAR=0.0
69 379 ▶ 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 3253 ▶ sub handle_header { $_[0]{chain}->add_field(@_[1 .. 3]) }
Subroutine handle_header: called CC=1 SCAR=0.0
75 379 ▶ 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 181 ▶sub add_field {
Subroutine add_field: called CC=17 SCAR=28.9
Pod documented
89 22604 my ($self, $name, $value, $raw) = @_;
90 22604 my $lc = lc $name;
91 22604 $lc =~ s/[ \t]+\z//;
92 22604 ▶ 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" 15544 7060 22604
Condition100%3/3
$lc eq "message-instance" or $lc eq "dkim2-signature"
l!l&&r!l&&!r
3367369315544
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 7060 ▶ return 1 if ++$self->{count}{$lc} > MAX_CHAIN_LENGTH;
Branch: 1 branch
BranchTrueFalseTotal
if ++$self->{"count"}{$lc} > 32 1003 6057 7060
94 6057 ▶ $raw //= "$name:$value";
Condition50%1/2
$raw //= "${name}:$value"
l!l
60570
MC/DC0%0/1
$raw //= "${name}:$value"
$raw
Truth table50%1/2
A
A= $raw
Aresult
11
00
95  
96 6057 ▶ if ($lc eq 'message-instance') {
Branch: 1 branch
BranchTrueFalseTotal
if ($lc eq "message-instance") 3365 2692 6057
97 3365 my $tag = mi_version_tag($value);
98 3365 ▶ if (!defined $tag) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $tag) { } 3 3362 3365
elsif (my $e = chain_number_error('Message-Instance', 'm', $tag)) { } 20 3342 3362
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 20 ▶ $self->{instance_unusable} //= $e;
Condition33%1/3
$self->{"instance_unusable"} //= $e
l!l&&r!l&&!r
0200
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 3342 my $m = extract_mi_version($value); # numeric: m=01 is m=1
106 3342 push @{ $self->{numbers}{$lc} }, $m;
107 3342 $self->{instance}{$m} = $raw;
108 }
109 3365 return 1;
110 }
111  
112 2692 my $sig = eval { Mail::DKIM2::Signature->parse($value) };
113 2692 ▶ die $@ if ref $@;
Branch: 1 branch
BranchTrueFalseTotal
if ref $@ 0 2692 2692
114 2692 ▶ my $i = $sig ? $sig->sequence : undef;
Branch: 1 branch
BranchTrueFalseTotal
$sig ? : 2692 0 2692
115 2692 ▶ if (!valid_sequence($i)) {
Branch: 2 branches
BranchTrueFalseTotal
if (not valid_sequence($i)) { } 63 2629 2692
elsif (my $e = chain_number_error('DKIM2-Signature', 'i', $i) // chain_number_error('DKIM2-Signature', 'm', $sig->version, $i)) { } 24 2605 2629
116 63 ▶ $self->{signature_unusable} //= unkeyable_signature_error($value);
Condition33%1/3
$self->{"signature_unusable"} //= unkeyable_signature_error($value)
l!l&&r!l&&!r
0630
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
14102605
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 2605 push @{ $self->{numbers}{$lc} }, $i;
124 2605 $self->{signature}{ $i + 0 } = { raw => $raw, sig => $sig };
125 }
126 2692 return 1;
127 }
128  
129 # --- What is in the chain ---
130  
131 532 ▶sub count {
Subroutine count: called CC=2 SCAR=6.9
Pod documented
132 532 my ($self, $field) = @_;
133 532 ▶ return $self->{count}{ lc $field } // 0;
Condition100%2/2
$self->{"count"}{lc $field} // 0
l!l
339193
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 6931 ▶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 5522 ▶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 2908 ▶sub top_instance { return ($_[0]->instance_numbers)[-1] }
Subroutine top_instance: called CC=1 SCAR=0.0
Pod documented
147 2608 ▶sub top_signature_number { return ($_[0]->signature_numbers)[-1] }
Subroutine top_signature_number: called CC=1 SCAR=0.0
Pod documented
148  
149 1201 ▶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 1080 ▶sub instance_fields { return $_[0]{instance} }
Subroutine instance_fields: called CC=1 SCAR=0.0
Pod documented
154 1080 ▶sub signature_entries { return $_[0]{signature} }
Subroutine signature_entries: called CC=1 SCAR=0.0
Pod documented
155  
156 1752 ▶sub signature {
Subroutine signature: called CC=2 SCAR=7.1
Pod documented
157 1752 my ($self, $i) = @_;
158 1752 ▶ my $entry = $self->{signature}{$i} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $entry = $self->{"signature"}{$i} or return 1752 0 1752
159 1752 return $entry->{sig};
160 }
161  
162 703 ▶sub signature_field {
Subroutine signature_field: called CC=2 SCAR=7.1
Pod documented
163 703 my ($self, $i) = @_;
164 703 ▶ my $entry = $self->{signature}{$i} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $entry = $self->{"signature"}{$i} or return 703 0 703
165 703 return $entry->{raw};
166 }
167  
168 1854 ▶sub signatures {
Subroutine signatures: called CC=1 SCAR=0.0
Pod documented
169 1854 my ($self) = @_;
170 1854 return map { $self->{signature}{$_}{sig} } $self->signature_numbers;
171 }
172  
173 212 ▶sub top_signature {
Subroutine top_signature: called CC=2 SCAR=6.9
Pod documented
174 212 my ($self) = @_;
175 212 ▶ my $i = $self->top_signature_number // return;
Condition100%2/2
$self->top_signature_number // (return)
l!l
14567
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 145 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 3807 ▶sub instance {
Subroutine instance: called CC=6 SCAR=18.0
Pod documented
183 3807 my ($self, $m) = @_;
184 3807 ▶ 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
195818490
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 1849 my $raw = $self->{instance}{$m};
186 1849 ▶ if (!defined $raw) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $raw) { } 1 1848 1849
187 1 [undef, "PERMERROR: Message-Instance m=$m missing"];
188 } else {
189 1848 (my $value = $raw) =~ s/\A[^:]*:[ \t]*//;
190 1848 my $obj = eval { Mail::DKIM2::MessageInstance->parse($value) };
191 1848 ▶ die $@ if ref $@;
Branch: 1 branch
BranchTrueFalseTotal
if ref $@ 0 1848 1848
192 1848 ▶ $obj ? [$obj] : [undef, Mail::DKIM2::MessageInstance::_parse_error($@)];
Branch: 1 branch
BranchTrueFalseTotal
$obj ? : 1704 144 1848
193 }
194 };
195 3807 ▶ return wantarray ? @$cached : $cached->[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 2839 968 3807
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 1851 ▶sub covered_m {
Subroutine covered_m: called CC=4 SCAR=13.9
Pod documented
202 1851 my ($self) = @_;
203 1851 my $covered = 0;
204 1851 for my $sig ($self->signatures) {
205 3262 ▶ my $m = $sig->version // next;
Condition50%1/2
$sig->version // (next)
l!l
32620
MC/DC0%0/1
$sig->version // (next)
$sig->version
Truth table50%1/2
A
A= $sig->version
Aresult
11
00
206 3262 ▶ $covered = 0 + $m if $m > $covered;
Branch: 1 branch
BranchTrueFalseTotal
if $m > $covered 3020 242 3262
207 }
208 1851 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 952 ▶sub instances_changing {
Subroutine instances_changing: called CC=8 SCAR=20.8
Pod documented
225 952 my ($self, $name, $above, $upto) = @_;
226 952 ▶ $above //= 0;
Condition50%1/2
$above //= 0
l!l
9520
MC/DC0%0/1
$above //= 0
$above
Truth table50%1/2
A
A= $above
Aresult
11
00
227 952 ▶ $upto //= $self->top_instance // 0;
Condition75%3/4
$upto //= $self->top_instance // 0
l!l
737215
$self->top_instance // 0
l!l
2150
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 952 ▶ my $mi = $_ >= 2 && $_ > $above && $_ <= $upto ? $self->instance($_) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$_ >= 2 && $_ > $above && $_ <= $upto ? : 721 4187 4908
Condition100%6/6
$_ >= 2 and $_ > $above and $_ <= $upto
!ll&&!rl&&r
28791308721
$_ >= 2 and $_ > $above
!ll&&!rl&&r
95219272029
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 4908 ▶ $mi && $mi->changes_header($name);
Condition100%3/3
$mi && $mi->changes_header($name)
!ll&&!rl&&r
4299445164
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 952 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 2704 ▶sub numbering_error {
Subroutine numbering_error: called CC=8 SCAR=20.8
Pod documented
243 2704 my ($self, %o) = @_;
244 2704 ▶ my $sigs = $o{Signatures} // 1;
Condition100%2/2
$o{"Signatures"} // 1
l!l
2144560
MC/DC100%1/1
$o{"Signatures"} // 1
$o{"Signatures"}
Truth table100%2/2
A
A= $o{"Signatures"}
Aresult
11
00
245 2704 my $n = $self->{numbers};
246 return chain_length_error($self->{count}) # a
247 // $self->{instance_unusable} # b
248 2677 ▶ // duplicate_number_error('Message-Instance', 'm', @{ $n->{'message-instance'} }) # c
Branch: 2 branches
BranchTrueFalseTotal
$sigs ? : 2432 236 2668
$sigs ? : 2379 236 2615
249 // ($sigs ? $self->{signature_unusable} : undef) # d
250 // ($sigs ? duplicate_number_error('DKIM2-Signature', 'i', # e
251 2704 ▶ @{ $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
8962609
((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
36532615
(chain_length_error($self->{"count"}) // $self->{"instance_unusable"}) // duplicate_number_error("Message-Instance", "m", @{$$n{"message-instance"};})
l!l&&r!l&&!r
2792668
chain_length_error($self->{"count"}) // $self->{"instance_unusable"}
l!l&&r!l&&!r
4232677
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 2039 ▶sub structure_error {
Subroutine structure_error: called CC=17 SCAR=28.3
Pod documented
261 2039 my ($self, %o) = @_;
262 2039 Mail::DKIM2::Util::check_options('structure_error', \%o, qw(Signatures AllowUnsigned));
263 2039 ▶ my $sigs = $o{Signatures} // 1;
Condition100%2/2
$o{"Signatures"} // 1
l!l
202514
MC/DC100%1/1
$o{"Signatures"} // 1
$o{"Signatures"}
Truth table100%2/2
A
A= $o{"Signatures"}
Aresult
11
00
264 2039 ▶ if (my $error = $self->numbering_error(Signatures => $sigs)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $error = $self->numbering_error("Signatures", $sigs)) 67 1972 2039
265 67 return $error;
266 }
267  
268 1972 my $top_m = $self->top_instance;
269 1972 ▶ my $top_i = $sigs ? $self->top_signature_number : undef;
Branch: 1 branch
BranchTrueFalseTotal
$sigs ? : 1837 135 1972
270 1972 ▶ my $named = defined $top_i ? ($self->signature($top_i)->version || 0) : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $top_i ? : 1752 220 1972
Condition50%1/2
$self->signature($top_i)->version or 0
l!l
17520
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 1972 ▶ my $upto = ($top_m // 0) > $named ? $top_m : $named;
Branch: 1 branch
BranchTrueFalseTotal
($top_m // 0) > $named ? : 259 1713 1972
Condition100%2/2
$top_m // 0
l!l
191359
MC/DC100%1/1
$top_m // 0
$top_m
Truth table100%2/2
A
A= $top_m
Aresult
11
00
272 1972 for my $m (1 .. $upto) { # f
273 2959 ▶ return "PERMERROR: Message-Instance m=$m missing" unless $self->{instance}{$m};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"instance"}{$m} 8 2951 2959
274 }
275  
276 1964 ▶ if (defined $top_m && $sigs && !$o{AllowUnsigned}) { # g
Branch: 1 branch
BranchTrueFalseTotal
if (defined $top_m and $sigs and not $o{"AllowUnsigned"}) 1449 515 1964
Condition100%6/6
defined $top_m and $sigs and not $o{"AllowUnsigned"}
!ll&&!rl&&r
1943211449
defined $top_m and $sigs
!ll&&!rl&&r
591351770
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 1449 ▶ return "PERMERROR: Message-Instance m=$top_m is not signed"
Branch: 1 branch
BranchTrueFalseTotal
if $top_m > $self->covered_m 12 1437 1449
278 if $top_m > $self->covered_m;
279 }
280  
281 1952 ▶ for my $i (1 .. ($top_i // 0)) { # h
Condition100%2/2
$top_i // 0
l!l
1742210
MC/DC100%1/1
$top_i // 0
$top_i
Truth table100%2/2
A
A= $top_i
Aresult
11
00
282 2789 ▶ return "PERMERROR: DKIM2-Signature i=$i missing" unless $self->{signature}{$i};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"signature"}{$i} 4 2785 2789
283 }
284 1948 return;
285 }
286  
287 181 1;
288  
289 __END__
« lib/Mail/DKIM2/Signature.pm ↑ Summary lib/Mail/Milter/Authentication/Handler/DKIM2Verify.pm »