lib/Mail/DKIM2/Signer.pm

filter: Statementstmt 96.5% 141 / 146 Branchbran 91.6% 55 / 60 Conditioncond 82.7% 48 / 58 MC/DCmcdc 62.5% 20 / 32 Subroutinesub 94.2% 33 / 35 Podpod 100% 13 / 13 totaltotal 90.1% 310 / 344 CC 54 SCAR 20.2
CC
54
Cov
92%
_new_signature
15.1
finish_header
13.0
init
12.3
CRAP 7.6
« lib/Mail/DKIM2/TagValueList.pm ↑ Summary lib/Mail/DKIM2/Canon.pm »
1 package Mail::DKIM2::Signer;
2 142 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 142 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 142 our $VERSION = '0.33';
6  
7 142 ▶use base 'Mail::DKIM2::HeaderParser';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 142 ▶use MIME::Base64 qw(encode_base64);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 142 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 142 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 142 ▶use Mail::DKIM2::Address ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 142 ▶use Mail::DKIM2::Common qw(chain_length_error);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 142 ▶use Mail::DKIM2::Canon qw(build_signing_input);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 142 ▶use Mail::DKIM2::Key qw(load_private_key signature_algorithm signature_algorithm_for_key);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 142 ▶use Mail::DKIM2::Chain;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 142 ▶use Mail::DKIM2::Signature;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 142 ▶use Mail::DKIM2::MessageInstance;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 142 ▶use Mail::DKIM2::HeaderPlan;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 577 ▶sub known_options {
Subroutine known_options: called CC=1 SCAR=0.0
Pod documented
22 577 return qw(Domain Selector KeyFile Key Algorithm MailFrom RcptTo
23 Nonce Flags Exploded Timestamp NextDomain ParentFromCallback
24 PolicyCallback Resolver);
25 }
26  
27 575 ▶sub init {
Subroutine init: called CC=12 SCAR=25.1
Pod documented
28 575 my $self = shift;
29 575 $self->SUPER::init;
30 575 ▶ croak "Domain required" unless $self->{Domain};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"Domain"} 1 574 575
31 574 ▶ croak "Selector required" unless $self->{Selector};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"Selector"} 0 574 574
32 574 ▶ croak "KeyFile or Key required" unless $self->{KeyFile} || $self->{Key};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"KeyFile"} or $self->{"Key"} 0 574 574
Condition66%2/3
$self->{"KeyFile"} or $self->{"Key"}
l!l&&r!l&&!r
345400
MC/DC0%0/2
$self->{"KeyFile"} or $self->{"Key"}
$self->{"KeyFile"} $self->{"Key"}
Truth table66%2/3
A or B
A= $self->{"KeyFile"}B= $self->{"Key"}
ABresult
1X1
011
000
33  
34 574 ▶ if ($self->{KeyFile} && !$self->{Key}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"KeyFile"} and not $self->{"Key"}) 34 540 574
Condition66%2/3
$self->{"KeyFile"} and not $self->{"Key"}
!ll&&!rl&&r
540034
MC/DC50%1/2
$self->{"KeyFile"} and not $self->{"Key"}
$self->{"KeyFile"} not $self->{"Key"}
Truth table66%2/3
A and not(B)
A= $self->{"KeyFile"}B= not $self->{"Key"}
ABresult
0X0
100
111
35 34 $self->{Key} = load_private_key($self->{KeyFile});
36 }
37  
38 # The algorithm is the key's unless the caller names one; a name this
39 # library does not implement, or one the key cannot sign with, is a
40 # mistake in the call -- never a signature labelled as something it is
41 # not, or an exception from inside CLOSE.
42 574 ▶ $self->{Algorithm} ||= signature_algorithm_for_key($self->{Key}) || 'rsa-sha256';
Condition80%4/5
$self->{"Algorithm"} ||= signature_algorithm_for_key($self->{"Key"}) || "rsa-sha256"
l!l&&r!l&&!r
275470
signature_algorithm_for_key($self->{'Key'}) || 'rsa-sha256'
l!l
5461
MC/DC0%0/2
$self->{"Algorithm"} ||= signature_algorithm_for_key($self->{"Key"}) || "rsa-sha256"
$self->{"Algorithm"} signature_algorithm_for_key($self->{'Key'})
Truth table66%2/3
A ||= B
A= $self->{"Algorithm"}B= signature_algorithm_for_key($self->{'Key'})
ABresult
1X1
011
000
43 my $alg = signature_algorithm($self->{Algorithm})
44 574 ▶ or croak "unsupported Algorithm $self->{Algorithm}";
Branch: 1 branch
BranchTrueFalseTotal
my $alg = signature_algorithm($self->{"Algorithm"}) or croak(qq[unsupported Algorithm $self->{"Algorithm"}]) 570 4 574
45 croak "Algorithm $self->{Algorithm} needs a $alg->{key_class} key"
46 570 ▶ unless Scalar::Util::blessed($self->{Key}) && $self->{Key}->isa($alg->{key_class});
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($self->{"Key"}) and $self->{"Key"}->isa($alg->{"key_class"}) 3 567 570
Condition100%3/3
builtin::blessed($self->{"Key"}) and $self->{"Key"}->isa($alg->{"key_class"})
!ll&&!rl&&r
12567
MC/DC100%2/2
builtin::blessed($self->{"Key"}) and $self->{"Key"}->isa($alg->{"key_class"})
builtin::blessed($self->{"Key"}) $self->{"Key"}->isa($alg->{"key_class"})
Truth table100%3/3
A and B
A= builtin::blessed($self->{"Key"})B= $self->{"Key"}->isa($alg->{"key_class"})
ABresult
0X0
100
111
47 567 $self->{_alg} = $alg;
48 567 $self->{_chain} = Mail::DKIM2::Chain->new;
49 }
50  
51 5185 ▶sub handle_header {
Subroutine handle_header: called CC=1 SCAR=0.0
Pod documented
52 5185 my ($self, $field_name, $contents, $line) = @_;
53 5185 $self->{_chain}->add_field($field_name, $contents, $line);
54 }
55  
56 # The message's Message-Instance and DKIM2-Signature fields, numbered
57 # (Mail::DKIM2::Chain). Complete once the header block has been read.
58 0 ▶sub chain { return $_[0]->{_chain} }
Subroutine chain: not called CC=1 SCAR=6.9
Pod documented
59  
60 558 ▶sub finish_header {
Subroutine finish_header: called CC=13 SCAR=25.7
Pod documented
61 558 my $self = shift;
62  
63 558 my $chain = $self->{_chain};
64 558 ▶ my $next_i = ($chain->top_signature_number // 0) + 1;
Condition100%2/2
$chain->top_signature_number // 0
l!l
232326
MC/DC100%1/1
$chain->top_signature_number // 0
$chain->top_signature_number
Truth table100%2/2
A
A= $chain->top_signature_number
Aresult
11
00
65  
66 # A chain no verifier can number is a PERMERROR to all of them, and so
67 # is one a signature would take past the limit: do not sign over it.
68 # Whether the chain is otherwise worth extending -- its signatures, its
69 # instances against the content -- is Mail::DKIM2::Gate's to decide.
70 558 ▶ my $error = $chain->numbering_error
Condition100%3/3
$chain->numbering_error // chain_length_error({"dkim2-signature", $next_i})
l!l&&r!l&&!r
232533
MC/DC100%2/2
$chain->numbering_error // chain_length_error({"dkim2-signature", $next_i})
$chain->numbering_error chain_length_error({"dkim2-signature", $next_i})
Truth table100%3/3
A // B
A= $chain->numbering_errorB= chain_length_error({"dkim2-signature", $next_i})
ABresult
1X1
011
000
71 // chain_length_error({ 'dkim2-signature' => $next_i });
72 # A signature names the Message-Instance it covers in m=, and a verifier
73 # rejects one that names none (tag=m missing), so a message with no
74 # instance cannot be signed: compute one first (dkim2sign does).
75 558 ▶ $error //= 'no Message-Instance field to sign over' unless $chain->instance_numbers;
Branch: 1 branch
BranchTrueFalseTotal
unless $chain->instance_numbers 6 552 558
Condition100%2/2
$error //= "no Message-Instance field to sign over"
l!l
51
MC/DC100%1/1
$error //= "no Message-Instance field to sign over"
$error
Truth table100%2/2
A
A= $error
Aresult
11
00
76 # -09 section 3.2: a Signer MUST use an RSA key of at least 1024 bits,
77 # and every verifier calls a shorter one "too short".
78 558 ▶ if (my $min = $self->{_alg}{min_bits}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $min = $self->{"_alg"}{"min_bits"}) 556 2 558
79 $error //= "signing key is shorter than $min bits"
80 556 ▶ if $self->{Key}->size * 8 < $min;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Key"}->size * 8 < $min 1 555 556
Condition50%1/2
$error //= "signing key is shorter than $min bits"
l!l
01
MC/DC0%0/1
$error //= "signing key is shorter than $min bits"
$error
Truth table50%1/2
A
A= $error
Aresult
11
00
81 }
82 # -09 sections 11 and 12.4: a hop that originates the message, or whose
83 # instances changed From, signs with a d= the From is Authentic for.
84 # -09 contract E3.4: d= may also be below the From domain when the
85 # caller says this d= may sign for it (ParentFromCallback), or, as an
86 # explicit opt-in, when that domain's Domain Policy Record allows it.
87 # Without either the upward case is refused: no live DNS by default.
88 558 ▶ if (!$error && $self->_from_must_match) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $error and $self->_from_must_match) 336 222 558
Condition100%3/3
not $error and $self->_from_must_match
!ll&&!rl&&r
27195336
MC/DC100%2/2
not $error and $self->_from_must_match
not $error $self->_from_must_match
Truth table100%3/3
not(A) and B
A= not $errorB= $self->_from_must_match
ABresult
0X0
100
111
89 my $e = Mail::DKIM2::Address::from_pair_error($self->{Domain},
90 14 ▶ sub { $self->_parent_policy(@_) },
Subroutine __ANON__: called CC=1 SCAR=0.0
91 338 map { $_->[1] } grep { lc $_->[0] eq 'from' }
92 336 @{ Mail::DKIM2::HeaderPlan::fields($self->{headers}) });
93 336 ▶ $error = "From header field is not Authentic for d=$self->{Domain}" if $e;
Branch: 1 branch
BranchTrueFalseTotal
if $e 13 323 336
94 }
95 558 ▶ if ($error) {
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 40 518 558
96 # A protocol outcome, not a programming error: reported through
97 # result/details like the Verifier's, so a streaming host is not
98 # handed an exception from inside PRINT. The body is discarded.
99 40 $self->{result} = 'fail';
100 40 $self->{details} = $error;
101 40 $self->stop;
102 40 return;
103 }
104 518 $self->{_mi_version} = $chain->top_instance;
105 518 ▶ $self->{_timestamp} = $self->{Timestamp} || time();
Condition100%2/2
$self->{'Timestamp'} || time
l!l
323195
MC/DC100%1/1
$self->{'Timestamp'} || time
$self->{'Timestamp'}
Truth table100%2/2
A
A= $self->{'Timestamp'}
Aresult
11
00
106 518 $self->{_next_i} = $next_i;
107 518 $self->{_signature} = $self->_new_signature($self->{RcptTo});
108 # Section 12.8 signs the Message-Instance and DKIM2-Signature fields
109 # alone, so the body is not kept.
110 518 ▶ $self->{_body_sink} = sub {};
Subroutine __ANON__: called CC=1 SCAR=0.0
111 }
112  
113 # The signature object for this hop with rt= set to $rcpt (an arrayref, or
114 # undef for none). -09 §12.3: when NextDomain is set this is an
115 # imaginary forwarding hop -- emit nd= and omit mf=/rt= (Signature->new
116 # enforces the exclusion).
117 #
118 # f= (-09 section 12.5): "exploded" MUST be set by a hop sending the message
119 # to more than one address and MUST NOT be set at i=1. So it is set when
120 # i > 1 and the caller asked for it (Exploded, or "exploded" among its
121 # Flags) or rt= holds more than one address, and dropped at i=1 whatever
122 # the caller said. Built afresh for each recipient set, since the flag
123 # depends on rt=.
124 528 ▶sub _new_signature {
Subroutine _new_signature: called CC=15 SCAR=27.1
125 528 my ($self, $rcpt) = @_;
126 528 my $i = $self->{_next_i};
127 528 ▶ my @rcpt = !defined $rcpt ? () : ref $rcpt eq 'ARRAY' ? @$rcpt : ($rcpt);
Branch: 2 branches
BranchTrueFalseTotal
!defined($rcpt) ? : 30 498 528
ref $rcpt eq 'ARRAY' ? : 498 0 498
128 528 ▶ my @flags = grep { $_ ne 'exploded' } @{ $self->{Flags} || [] };
Condition100%2/2
$self->{'Flags'} || []
l!l
1527
MC/DC100%1/1
$self->{'Flags'} || []
$self->{'Flags'}
Truth table100%2/2
A
A= $self->{'Flags'}
Aresult
11
00
129 my $asked = $self->{Exploded}
130 528 ▶ || grep { $_ eq 'exploded' } @{ $self->{Flags} || [] };
Condition100%5/5
$self->{'Exploded'} || grep({$_ eq 'exploded';} @{$self->{'Flags'} or [];})
l!l&&r!l&&!r
151512
$self->{'Flags'} || []
l!l
1512
MC/DC100%2/2
$self->{'Exploded'} || grep({$_ eq 'exploded';} @{$self->{'Flags'} or [];})
$self->{'Exploded'} grep({$_ eq 'exploded';} @{$self->{'Flags'} or [];})
MC/DC100%1/1
$self->{'Flags'} || []
$self->{'Flags'}
Truth table100%3/3
A || B
A= $self->{'Exploded'}B= grep({$_ eq 'exploded';} @{$self->{'Flags'} or [];})
ABresult
1X1
011
000
Truth table100%2/2
A
A= $self->{'Flags'}
Aresult
11
00
131 push @flags, 'exploded'
132 528 ▶ if $i > 1 && ($asked || (!$self->{NextDomain} && @rcpt > 1));
Branch: 1 branch
BranchTrueFalseTotal
if $i > 1 and $asked || !$self->{"NextDomain"} && @rcpt > 1 13 515 528
Condition100%9/9
$i > 1 and $asked || !$self->{"NextDomain"} && @rcpt > 1
!ll&&!rl&&r
31320213
$asked or not $self->{"NextDomain"} and @rcpt > 1
l!l&&r!l&&!r
112202
not $self->{"NextDomain"} and @rcpt > 1
!ll&&!rl&&r
111912
MC/DC100%4/4
$i > 1 and $asked || !$self->{"NextDomain"} && @rcpt > 1
$i > 1 $asked not $self->{"NextDomain"} @rcpt > 1
Truth table100%5/5
A and B or not(C) and D
A= $i > 1B= $askedC= not $self->{"NextDomain"}D= @rcpt > 1
ABCDresult
0XXX0
100X0
10100
11XX1
10111
133 return Mail::DKIM2::Signature->new(
134 Sequence => $i,
135 Version => $self->{_mi_version} || undef,
136 Timestamp => $self->{_timestamp},
137 Domain => $self->{Domain},
138 ($self->{NextDomain}
139 ? (NextDomain => $self->{NextDomain})
140 : (MailFrom => $self->{MailFrom},
141 (defined $rcpt ? (RcptTo => \@rcpt) : ()))),
142 Signatures => [[ $self->{Selector}, $self->{Algorithm}, '' ]],
143 528 ▶ ($self->{Nonce} ? (Nonce => $self->{Nonce}) : ()),
Branch: 4 branches
BranchTrueFalseTotal
$self->{'NextDomain'} ? : 28 500 528
defined $rcpt ? : 498 2 500
$self->{'Nonce'} ? : 0 528 528
@flags ? : 14 514 528
Condition50%1/2
$self->{'_mi_version'} || undef
l!l
5280
MC/DC0%0/1
$self->{'_mi_version'} || undef
$self->{'_mi_version'}
Truth table50%1/2
A
A= $self->{'_mi_version'}
Aresult
11
00
144 (@flags ? (Flags => \@flags) : ()),
145 );
146 }
147  
148 # For from_pair_error: whether this d= may make a From in parent domain
149 # $dom Authentic ('open') or not ('strict').
150 14 ▶sub _parent_policy {
Subroutine _parent_policy: called CC=5 SCAR=16.1
151 14 my ($self, $dom) = @_;
152 14 ▶ if (my $cb = $self->{ParentFromCallback}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cb = $self->{"ParentFromCallback"}) 8 6 14
153 8 ▶ return $cb->($dom, $self) ? 'open' : 'strict';
Branch: 1 branch
BranchTrueFalseTotal
&$cb($dom, $self) ? : 4 4 8
154 }
155 6 ▶ return 'strict' unless $self->{PolicyCallback} || $self->{Resolver};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"PolicyCallback"} or $self->{"Resolver"} 1 5 6
Condition100%3/3
$self->{"PolicyCallback"} or $self->{"Resolver"}
l!l&&r!l&&!r
321
MC/DC100%2/2
$self->{"PolicyCallback"} or $self->{"Resolver"}
$self->{"PolicyCallback"} $self->{"Resolver"}
Truth table100%3/3
A or B
A= $self->{"PolicyCallback"}B= $self->{"Resolver"}
ABresult
1X1
011
000
156 my ($p) = Mail::DKIM2::Key::policy_from_source($dom,
157 5 ▶ $self->{PolicyCallback}, sub { $self->_resolver }, $self);
Subroutine __ANON__: called CC=1 SCAR=0.0
158 5 return $p;
159 }
160  
161 # fetch_domain_policy($domain): the TXT records at _domainkey.$domain
162 # through the Resolver, as Mail::DKIM2::Verifier's: for a PolicyCallback
163 # to fall back to.
164 0 ▶sub fetch_domain_policy {
Subroutine fetch_domain_policy: not called CC=1 SCAR=6.9
Pod documented
165 0 my ($self, $dom) = @_;
166 0 return Mail::DKIM2::Key::query_domain_policy($self->_resolver, $dom);
167 }
168  
169 # The Resolver for the Domain Policy Record lookup: the caller's, else a
170 # default Net::DNS::Resolver, made only when a lookup is needed.
171 2 ▶sub _resolver {
Subroutine _resolver: called CC=2 SCAR=10.1
172 2 my ($self) = @_;
173 2 ▶ return $self->{Resolver} //= do {
Condition33%1/3
$self->{"Resolver"} //= do { require Net::DNS::Resolver; "Net::DNS::Resolver"->new }
l!l&&r!l&&!r
200
MC/DC0%0/2
$self->{"Resolver"} //= do { require Net::DNS::Resolver; "Net::DNS::Resolver"->new }
$self->{"Resolver"} do { require Net::DNS::Resolver; "Net::DNS::Resolver"->new }
Truth table33%1/3
A //= B
A= $self->{"Resolver"}B= do { require Net::DNS::Resolver; "Net::DNS::Resolver"->new }
ABresult
1X1
011
000
174 0 require Net::DNS::Resolver;
175 0 Net::DNS::Resolver->new;
176 };
177 }
178  
179 # True when this signature answers for the From the message carries: there
180 # is no signature yet (this hop is i=1), or a Message-Instance no existing
181 # signature covers (m= above every signature's m=) has a header Recipe that
182 # names From -- this hop, or a list manager on its host, changed it. One
183 # that does not parse is left to the verifiers (and Mail::DKIM2::Gate),
184 # which refuse it: the Signer checks only what it needs to sign.
185 531 ▶sub _from_must_match {
Subroutine _from_must_match: called CC=3 SCAR=11.0
186 531 my ($self) = @_;
187 531 my $chain = $self->{_chain};
188 531 ▶ return 1 unless $chain->signature_numbers;
Branch: 1 branch
BranchTrueFalseTotal
unless $chain->signature_numbers 316 215 531
189 215 ▶ return $chain->instances_changing('From', $chain->covered_m) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$chain->instances_changing('From', $chain->covered_m) ? : 20 195 215
190 }
191  
192 518 ▶sub finish_body {
Subroutine finish_body: called CC=1 SCAR=0.0
Pod documented
193 518 my $self = shift;
194 518 $self->_compute_signature;
195 518 $self->{result} = 'signed';
196 }
197  
198 # Re-sign the same message for a different envelope recipient, returning the
199 # folded DKIM2-Signature header to prepend for that recipient.
200 #
201 # This is the cheap half of signing. §12.8 signs solely the Message-Instance and
202 # DKIM2-Signature header fields, so everything expensive -- the body hash and
203 # the hash of every other header field -- lives in the Message-Instance and is
204 # identical for every recipient. Only rt= changes, so an additional recipient
205 # costs one signature over a few hundred bytes rather than another pass over
206 # the message.
207 #
208 # Feed the message through PRINT/CLOSE once, then call this per recipient:
209 #
210 # $signer->PRINT($message); $signer->CLOSE; # once
211 # for my $rcpt (@rcpts) {
212 # my $header = $signer->sign_for_recipient($rcpt);
213 # }
214 #
215 # Takes one address or an arrayref of them. Not usable on a signature carrying
216 # nd=, which excludes rt= by §10.7; Signature::rcpt_to croaks in that case.
217 12 ▶sub sign_for_recipient {
Subroutine sign_for_recipient: called CC=6 SCAR=18.0
Pod documented
218 12 my ($self, $rcpt) = @_;
219 croak "sign_for_recipient: no signature: " . ($self->{details} // 'CLOSE has not run')
220 12 ▶ unless $self->{_signature};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_signature"} 1 11 12
Condition50%1/2
$self->{"details"} // "CLOSE has not run"
l!l
10
MC/DC0%0/1
$self->{"details"} // "CLOSE has not run"
$self->{"details"}
Truth table50%1/2
A
A= $self->{"details"}
Aresult
11
00
221 croak "cannot set rt= on a signature carrying nd= (-09 §10.7)"
222 11 ▶ if $self->{NextDomain};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"NextDomain"} 1 10 11
223 10 ▶ my @list = ref $rcpt eq 'ARRAY' ? @$rcpt : ($rcpt);
Branch: 1 branch
BranchTrueFalseTotal
ref $rcpt eq 'ARRAY' ? : 1 9 10
224 10 ▶ croak "rcpt_to requires at least one recipient" unless @list;
Branch: 1 branch
BranchTrueFalseTotal
unless @list 0 10 10
225 10 $self->{_signature} = $self->_new_signature(\@list);
226 10 $self->_compute_signature;
227 10 $self->{result} = 'signed';
228 10 return $self->as_string;
229 }
230  
231 528 ▶sub _compute_signature {
Subroutine _compute_signature: called CC=1 SCAR=0.0
232 528 my $self = shift;
233  
234 528 my $signature = $self->{_signature};
235 528 my $chain = $self->{_chain};
236  
237 # Reset s= to the empty placeholder before building the signing input.
238 # Without this a second call would sign an input containing the FIRST
239 # call's signature bytes, which no verifier can reproduce -- the signing
240 # input must always carry an empty s= value (§12.8).
241 528 $signature->set_tag('s', join(':', $self->{Selector}, $self->{Algorithm}, ''));
242  
243 my $signing_input = build_signing_input(
244 1152 instances => [ map { $chain->instance_field($_) } $chain->instance_numbers ],
245 528 signatures => [ map { $chain->signature_field($_) } $chain->signature_numbers ],
246 signing => $signature->as_folded_string, # as it will be sent
247 );
248  
249 528 my $sig_raw = $self->{_alg}{sign}->($self->{Key}, $signing_input);
250 528 my $signb64 = encode_base64($sig_raw, '');
251  
252 # Update the signature object with the actual signature
253 # Format: sel:alg:sig
254 528 $signature->set_tag('s', join(':', $self->{Selector}, $self->{Algorithm}, $signb64));
255 }
256  
257 10 ▶sub signature {
Subroutine signature: called CC=1 SCAR=0.0
Pod documented
258 10 my $self = shift;
259 10 return $self->{_signature};
260 }
261  
262 # No signature (before CLOSE, or a refused message) croaks: an empty string
263 # prepended to the message by a caller that did not check result() is a
264 # blank line that ends its header block.
265 510 ▶sub as_string {
Subroutine as_string: called CC=3 SCAR=11.1
Pod documented
266 510 my $self = shift;
267 croak 'no signature: ' . ($self->{details} // 'the message has not been signed') . "\n"
268 510 ▶ unless $self->{_signature};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_signature"} 2 508 510
Condition50%1/2
$self->{"details"} // "the message has not been signed"
l!l
20
MC/DC0%0/1
$self->{"details"} // "the message has not been signed"
$self->{"details"}
Truth table50%1/2
A
A= $self->{"details"}
Aresult
11
00
269 508 return $self->{_signature}->as_folded_string();
270 }
271  
272 # undef until CLOSE; then 'signed', or 'fail' with the reason in details().
273 245 ▶sub result {
Subroutine result: called CC=1 SCAR=0.0
Pod documented
274 245 my $self = shift;
275 245 return $self->{result};
276 }
277  
278 17 ▶sub details {
Subroutine details: called CC=1 SCAR=0.0
Pod documented
279 17 my $self = shift;
280 17 return $self->{details};
281 }
282  
283 57 ▶sub result_detail {
Subroutine result_detail: called CC=3 SCAR=11.1
Pod documented
284 57 my $self = shift;
285 57 ▶ my $result = $self->result // return;
Condition50%1/2
$self->result // (return)
l!l
570
MC/DC0%0/1
$self->result // (return)
$self->result
Truth table50%1/2
A
A= $self->result
Aresult
11
00
286 57 ▶ return $self->{details} ? "$result ($self->{details})" : $result;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'details'} ? : 29 28 57
287 }
288  
289 142 1;
290  
291 __END__
« lib/Mail/DKIM2/TagValueList.pm ↑ Summary lib/Mail/DKIM2/Canon.pm »