DKIM/Signature.pm

filter: Statementstmt 87.0% 229 / 263 Branchbran 78.5% 110 / 140 Conditioncond 80.0% 16 / 20 MC/DCmcdc 66.6% 8 / 12 Subroutinesub 88.4% 46 / 52 Podpod 62.5% 25 / 40 totaltotal 82.3% 434 / 527 CC 82 SCAR 15.2
CC
82
Cov
84%
wantheader
20.0
method
12.0
new
9.0
CRAP 4.6
« DKIM/MessageParser.pm ↑ Summary DKIM/PrivateKey.pm »
1 package Mail::DKIM::Signature;
2 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 15 our $VERSION = '1.20240923'; # VERSION
5 # ABSTRACT: represents a DKIM-Signature header
6  
7 # Copyright 2005-2007 Messiah College. All rights reserved.
8 # Jason Long <jlong@messiah.edu>
9  
10 # Copyright (c) 2004 Anthony D. Urso. All rights reserved.
11 # This program is free software; you can redistribute it and/or
12 # modify it under the same terms as Perl itself.
13  
14 15 ▶use Mail::DKIM::PublicKey;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 15 ▶use Mail::DKIM::Algorithm::rsa_sha1;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 15 ▶use Mail::DKIM::Algorithm::rsa_sha256;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 15 ▶use Mail::DKIM::Algorithm::ed25519_sha256;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 15 ▶use base 'Mail::DKIM::KeyValueList';
Subroutine BEGIN: called CC=1 SCAR=0.0
20 15 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22  
23 171 ▶sub new {
Subroutine new: called CC=9 SCAR=22.0
Pod documented
24 171 my $class = shift;
25 171 my %prms = @_;
26 171 my $self = {};
27 171 bless $self, $class;
28  
29 171 $self->version('1');
30 171 ▶ $self->algorithm( $prms{'Algorithm'} || 'rsa-sha1' );
Condition100%2/2
$prms{'Algorithm'} || 'rsa-sha1'
l!l
17154
MC/DC100%1/1
$prms{'Algorithm'} || 'rsa-sha1'
$prms{'Algorithm'}
Truth table100%2/2
A
A= $prms{'Algorithm'}
Aresult
11
00
31 171 $self->signature( $prms{'Signature'} );
32 171 ▶ $self->canonicalization( $prms{'Method'} ) if exists $prms{'Method'};
Branch: 1 branch
BranchTrueFalseTotal
if exists $prms{"Method"} 17 154 171
33 171 $self->domain( $prms{'Domain'} );
34 171 $self->headerlist( $prms{'Headers'} );
35 171 ▶ $self->protocol( $prms{'Query'} ) if exists $prms{'Query'};
Branch: 1 branch
BranchTrueFalseTotal
if exists $prms{"Query"} 0 171 171
36 171 $self->selector( $prms{'Selector'} );
37 171 ▶ $self->identity( $prms{'Identity'} ) if exists $prms{'Identity'};
Branch: 1 branch
BranchTrueFalseTotal
if exists $prms{"Identity"} 2 169 171
38 171 ▶ $self->timestamp( $prms{'Timestamp'} ) if defined $prms{'Timestamp'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $prms{"Timestamp"} 5 166 171
39 171 ▶ $self->expiration( $prms{'Expiration'} ) if defined $prms{'Expiration'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $prms{"Expiration"} 3 168 171
40 171 ▶ $self->tags( $prms{'Tags'} ) if defined $prms{'Tags'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $prms{"Tags"} 0 171 171
41 171 ▶ $self->key( $prms{'Key'} ) if defined $prms{'Key'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $prms{"Key"} 15 156 171
42 171 return $self;
43 }
44  
45  
46 886 ▶sub parse {
Subroutine parse: called CC=3 SCAR=11.1
Pod documented
47 886 my $class = shift;
48 886 ▶ croak 'wrong number of arguments' unless ( @_ == 1 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 1 0 886 886
49 886 my ($string) = @_;
50  
51 # remove line terminator, if present
52 886 $string =~ s/\015\012\z//;
53  
54 # remove field name, if present
55 886 my $prefix = $class->prefix();
56 886 ▶ if ( $string =~ s/^($prefix)//i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ s/^($prefix)//i) 886 0 886
57  
58 # save the field name (capitalization), so that it can be
59 # restored later
60 886 $prefix = $1;
61 }
62  
63 886 my $self = $class->SUPER::parse($string);
64 884 $self->{prefix} = $prefix;
65  
66 884 return $self;
67 }
68  
69  
70 # deprecated
71 0 ▶sub wantheader {
Subroutine wantheader: not called CC=4 SCAR=30.0
Pod undocumented
72 0 my $self = shift;
73 0 my $attr = shift;
74  
75 0 ▶ $self->headerlist
Branch: 1 branch
BranchTrueFalseTotal
$self->headerlist or return 1 0 0 0
76 or return 1;
77  
78 0 foreach my $key ( $self->headerlist ) {
79 0 ▶ lc $attr eq lc $key
Branch: 1 branch
BranchTrueFalseTotal
lc $attr eq lc $key and return 1 0 0 0
80 and return 1;
81 }
82  
83 0 return;
84 }
85  
86  
87 2992 ▶sub algorithm {
Subroutine algorithm: called CC=3 SCAR=11.0
Pod documented
88 2992 my $self = shift;
89  
90 2992 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 943 2049 2992
91 943 $self->set_tag( 'a', shift );
92 }
93  
94 2992 my $a = $self->get_tag('a');
95 2992 ▶ return defined $a ? lc $a : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $a ? : 2988 4 2992
96 }
97  
98  
99 939 ▶sub as_string {
Subroutine as_string: called CC=1 SCAR=0.0
Pod documented
100 939 my $self = shift;
101  
102 939 return $self->prefix() . $self->SUPER::as_string;
103 }
104  
105 # undocumented method
106 0 ▶sub as_string_debug {
Subroutine as_string_debug: not called CC=1 SCAR=6.9
Pod undocumented
107 0 my $self = shift;
108  
109 return $self->prefix()
110 0 . join( ';', map { '>' . $_->{raw} . '<' } @{ $self->{tags} } );
111 }
112  
113  
114 421 ▶sub as_string_without_data {
Subroutine as_string_without_data: called CC=2 SCAR=7.0
Pod documented
115 421 my $self = shift;
116 421 ▶ croak 'wrong number of arguments' unless ( @_ == 0 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 0 0 421 421
117  
118 421 my $alt = $self->clone;
119 421 $alt->signature('');
120  
121 421 return $alt->as_string;
122 }
123  
124  
125 262 ▶sub body_count {
Subroutine body_count: called CC=2 SCAR=7.1
Pod documented
126 262 my $self = shift;
127  
128 # set new body count if provided
129 262 ▶ (@_)
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->set_tag("l", shift()) 0 262 262
130 and $self->set_tag( 'l', shift );
131  
132 262 return $self->get_tag('l');
133 }
134  
135  
136 188 ▶sub body_hash {
Subroutine body_hash: called CC=3 SCAR=11.0
Pod documented
137 188 my $self = shift;
138  
139 # set new body hash if provided
140 188 ▶ (@_)
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->set_tag("bh", shift()) 38 150 188
141 and $self->set_tag( 'bh', shift );
142  
143 188 my $result = $self->get_tag('bh');
144 188 ▶ if ( defined $result ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $result) 188 0 188
145 188 $result =~ s/\s+//gs;
146 }
147 188 return $result;
148 }
149  
150  
151 551 ▶sub canonicalization {
Subroutine canonicalization: called CC=6 SCAR=17.9
Pod documented
152 551 my $self = shift;
153  
154 551 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 38 513 551
155 38 $self->set_tag( 'c', join( '/', @_ ) );
156 }
157  
158 551 my $c = $self->get_tag('c');
159 551 ▶ $c = lc $c if defined $c;
Branch: 1 branch
BranchTrueFalseTotal
if defined $c 549 2 551
160 551 ▶ if ( not $c ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($c) 4 547 551
161 4 $c = 'simple/simple';
162 }
163 551 my ( $c1, $c2 ) = split( /\//, $c, 2 );
164 551 ▶ if ( not defined $c2 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $c2) 149 402 551
165  
166 # default body canonicalization is "simple"
167 149 $c2 = 'simple';
168 }
169  
170 551 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 505 46 551
171 505 return ( $c1, $c2 );
172 }
173 else {
174 46 return "$c1/$c2";
175 }
176 }
177  
178 15 ▶use MIME::Base64;
Subroutine BEGIN: called CC=1 SCAR=0.0
179  
180 # checks whether this signature specifies a legal canonicalization method
181 # returns true if the canonicalization is acceptable, false otherwise
182 #
183 424 ▶sub check_canonicalization {
Subroutine check_canonicalization: called CC=3 SCAR=11.0
Pod undocumented
184 424 my $self = shift;
185  
186 424 my ( $c1, $c2 ) = $self->canonicalization;
187  
188 424 my @known = ( 'nowsp', 'simple', 'relaxed', 'seal' );
189 424 ▶ return undef unless ( grep { $_ eq $c1 } @known );
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $c1;} @known 3 421 424
190 421 ▶ return undef unless ( grep { $_ eq $c2 } @known );
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $c2;} @known 0 421 421
191 421 return 1;
192 }
193  
194 1 ▶sub set_verify_time {
Subroutine set_verify_time: called CC=1 SCAR=0.0
Pod undocumented
195 1 my ( $self, $verify_time ) = @_;
196 1 $self->{_verify_time} = $verify_time;
197 }
198  
199 # checks whether the expiration time on this signature is acceptable
200 # returns a true value if acceptable, false otherwise
201 #
202 434 ▶sub check_expiration {
Subroutine check_expiration: called CC=3 SCAR=11.0
Pod undocumented
203 434 my $self = shift;
204 434 my $x = $self->expiration;
205 434 ▶ return 1 if not defined $x;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $x 429 5 434
206 5 ▶ $self->{_verify_time} ||= time();
Condition66%2/3
$self->{"_verify_time"} ||= time
l!l&&r!l&&!r
140
MC/DC0%0/2
$self->{"_verify_time"} ||= time
$self->{"_verify_time"} time
Truth table66%2/3
A ||= B
A= $self->{"_verify_time"}B= time
ABresult
1X1
011
000
207 5 return ( $self->{_verify_time} <= $x );
208 }
209  
210 # Returns a filtered list of protocols that can be used to fetch the
211 # public key corresponding to this signature. An empty list means that
212 # all designated protocols are unrecognized.
213 # Note: at this time, the only recognized protocol is "dns/txt".
214 #
215 830 ▶sub check_protocol {
Subroutine check_protocol: called CC=7 SCAR=19.5
Pod undocumented
216 830 my $self = shift;
217  
218 830 my $v = $self->version;
219  
220 830 foreach my $prot ( split /:/, $self->protocol ) {
221 832 my ( $type, $options ) = split( /\//, $prot, 2 );
222 832 ▶ if ( $type eq 'dns' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "dns") 829 3 832
223 829 ▶ return ('dns/txt') if $options && $options eq 'txt';
Branch: 1 branch
BranchTrueFalseTotal
if $options and $options eq "txt" 816 13 829
Condition100%3/3
$options and $options eq "txt"
!ll&&!rl&&r
121816
MC/DC100%2/2
$options and $options eq "txt"
$options $options eq "txt"
Truth table100%3/3
A and B
A= $optionsB= $options eq "txt"
ABresult
0X0
100
111
224  
225 # prior to DKIM version 1, the '/txt' part was optional
226 13 ▶ if ( !$v ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($v) 12 1 13
227 12 ▶ return ('dns/txt') if !defined($options);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $options 12 0 12
228 }
229 }
230 }
231  
232 # unrecognized
233 2 return;
234 }
235  
236 # checks whether the version tag has an acceptable value
237 # returns true if so, otherwise false
238 #
239 435 ▶sub check_version {
Subroutine check_version: called CC=2 SCAR=6.9
Pod undocumented
240 435 my $self = shift;
241  
242 # check version
243 435 ▶ if ( my $version = $self->version ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $version = $self->version) 54 381 435
244 54 my @ALLOWED_VERSIONS = ( '0.5', '1' );
245 54 return ( grep { $_ eq $version } @ALLOWED_VERSIONS );
246 }
247  
248 # we still consider a missing v= tag acceptable,
249 # for backwards-compatibility
250 381 return 1;
251 }
252  
253  
254 2396 ▶sub data {
Subroutine data: called CC=3 SCAR=11.0
Pod documented
255 2396 my $self = shift;
256  
257 2396 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1448 948 2396
258 1448 $self->set_tag( 'b', shift );
259 }
260  
261 2396 my $b = $self->get_tag('b');
262 2396 ▶ $b =~ tr/\015\012 \t//d if defined $b;
Branch: 1 branch
BranchTrueFalseTotal
if defined $b 1366 1030 2396
263 2396 return $b;
264 }
265  
266 15 *signature = \*data;
267  
268 #undocumented, private function
269 #derived from MIME::Base64::Perl (allowed, thanks to the Perl license)
270 #
271 217 ▶sub decode_qp {
Subroutine decode_qp: called CC=2 SCAR=7.0
Pod undocumented
272 217 my $res = shift;
273  
274 #TODO- should I worry about non-ASCII systems here?
275 217 ▶ $res =~ s/=([\da-fA-F]{2})/pack('C', hex($1))/ge
Branch: 1 branch
BranchTrueFalseTotal
if defined $res 217 0 217
276 if defined $res;
277 217 return $res;
278 }
279  
280 #undocumented, private function
281 #derived from MIME::Base64::Perl (allowed, thanks to the Perl license)
282 #
283 2 ▶sub encode_qp {
Subroutine encode_qp: called CC=2 SCAR=7.4
Pod undocumented
284 2 my $res = shift;
285  
286 # note- unlike MIME quoted-printable, we don't allow whitespace chars
287 2 my $DISALLOWED = qr/[^!"#\$%&'()*+,\-.\/0-9:;<>?\@A-Z[\\\]^_`a-z{|}~]/;
288  
289 #TODO- should I worry about non-ASCII systems here?
290 2 ▶ $res =~ s/($DISALLOWED)/sprintf('=%02X', ord($1))/eg
Branch: 1 branch
BranchTrueFalseTotal
if defined $res 2 0 2
291 if defined $res;
292 2 return $res;
293 }
294  
295 238 ▶sub DEFAULT_PREFIX {
Subroutine DEFAULT_PREFIX: called CC=1 SCAR=0.0
Pod undocumented
296 238 return 'DKIM-Signature:';
297 }
298  
299 1954 ▶sub prefix {
Subroutine prefix: called CC=4 SCAR=13.9
Pod undocumented
300 1954 my $class = shift;
301 1954 ▶ if ( ref($class) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $class) 1068 886 1954
302 1068 ▶ $class->{prefix} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 1068 1068
303 1068 ▶ return $class->{prefix} if $class->{prefix};
Branch: 1 branch
BranchTrueFalseTotal
if $class->{"prefix"} 809 259 1068
304 }
305 1145 return $class->DEFAULT_PREFIX();
306 }
307  
308  
309 2985 ▶sub domain {
Subroutine domain: called CC=3 SCAR=11.0
Pod documented
310 2985 my $self = shift;
311  
312 2985 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 942 2043 2985
313 942 $self->set_tag( 'd', shift );
314 }
315  
316 2985 my $d = $self->get_tag('d');
317 2985 ▶ return defined $d ? lc $d : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $d ? : 2094 891 2985
318 }
319  
320  
321 422 ▶sub expiration {
Subroutine expiration: called CC=2 SCAR=6.9
Pod documented
322 422 my $self = shift;
323  
324 422 ▶ (@_)
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->set_tag("x", shift()) 3 419 422
325 and $self->set_tag( 'x', shift );
326  
327 422 return $self->get_tag('x');
328 }
329  
330 0 ▶sub tags {
Subroutine tags: not called CC=2 SCAR=17.9
Pod undocumented
331 0 my $self = shift;
332 0 my $tags = shift;
333  
334 0 for my $tag (sort keys %$tags) {
335 0 $self->set_tag( $tag, $tags->{$tag} );
336 }
337 0 (@_)
338  
339 }
340  
341 # allows the type of signature to determine what "algorithm" gets used
342 892 ▶sub get_algorithm_class {
Subroutine get_algorithm_class: called CC=5 SCAR=16.1
Pod undocumented
343 892 my $self = shift;
344 892 ▶ croak 'wrong number of arguments' unless ( @_ == 1 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 1 0 892 892
345 892 my ($algorithm) = @_;
346  
347 892 ▶ my $class =
Branch: 3 branches
BranchTrueFalseTotal
$algorithm eq 'rsa-sha1' ? : 88 804 892
$algorithm eq 'rsa-sha256' ? : 786 18 804
$algorithm eq 'ed25519-sha256' ? : 14 4 18
348 $algorithm eq 'rsa-sha1' ? 'Mail::DKIM::Algorithm::rsa_sha1'
349 : $algorithm eq 'rsa-sha256' ? 'Mail::DKIM::Algorithm::rsa_sha256'
350 : $algorithm eq 'ed25519-sha256' ? 'Mail::DKIM::Algorithm::ed25519_sha256'
351 : undef;
352 892 return $class;
353 }
354  
355 # [private method]
356 # fetch_public_key() - initiate a DNS query for fetching the key
357 #
358 # This method does NOT return the public key.
359 # Use get_public_key() for that.
360 #
361 424 ▶sub fetch_public_key {
Subroutine fetch_public_key: called CC=2 SCAR=6.9
Pod undocumented
362 424 my $self = shift;
363 424 ▶ return if exists $self->{public_key_query};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"public_key_query"} 0 424 424
364  
365 359 ▶ my $on_success = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
366 359 ▶ if ( $_[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]) { } 355 4 359
367 355 $self->{public} = $_[0];
368 }
369 else {
370 4 $self->{public_error} = "not available\n";
371 }
372 424 };
373  
374 424 my @methods = $self->check_protocol;
375 $self->{public_key_query} = Mail::DKIM::PublicKey->fetch_async(
376 Protocol => $methods[0],
377 Selector => $self->selector,
378 Domain => $self->domain,
379 Callbacks => {
380 Success => $on_success,
381 3 ▶ Error => sub { $self->{public_error} = shift },
Subroutine __ANON__: called CC=1 SCAR=0.0
382 },
383 424 );
384 422 return;
385 }
386  
387 #EXPERIMENTAL
388 0 ▶sub _refetch_public_key {
Subroutine _refetch_public_key: not called CC=2 SCAR=17.9
389 0 my $self = shift;
390 0 ▶ if ( $self->{public_key_query} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"public_key_query"}) 0 0 0
391  
392 # clear the existing query by waiting for it to complete
393 0 $self->{public_key_query}->();
394 }
395 0 delete $self->{public_key_query};
396 0 delete $self->{public};
397 0 delete $self->{public_error};
398 0 $self->fetch_public_key;
399 }
400  
401  
402 715 ▶sub get_public_key {
Subroutine get_public_key: called CC=4 SCAR=14.0
Pod documented
403 715 my $self = shift;
404  
405 # this ensures we only try fetching once, even if an error occurs
406 715 ▶ if ( not exists $self->{public_key_query} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"public_key_query"}) 0 715 715
407 0 $self->fetch_public_key;
408 }
409  
410 715 ▶ if ( $self->{public_key_query} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"public_key_query"}) 370 345 715
411  
412 # wait for public key query to finish
413 370 $self->{public_key_query}->();
414 362 $self->{public_key_query} = 0;
415 }
416  
417 707 ▶ if ( exists $self->{public} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'public'}) { } 700 7 707
418 700 return $self->{public};
419 }
420 else {
421 7 die $self->{public_error};
422 }
423 }
424  
425  
426 342 ▶sub hash_algorithm {
Subroutine hash_algorithm: called CC=4 SCAR=13.9
Pod documented
427 342 my $self = shift;
428 342 my $algorithm = $self->algorithm;
429  
430 return
431 342 ▶ $algorithm eq 'rsa-sha1' ? 'sha1'
Branch: 3 branches
BranchTrueFalseTotal
$algorithm eq 'rsa-sha1' ? : 28 314 342
$algorithm eq 'rsa-sha256' ? : 311 3 314
$algorithm eq 'ed25519-sha256' ? : 3 0 3
432 : $algorithm eq 'rsa-sha256' ? 'sha256'
433 : $algorithm eq 'ed25519-sha256' ? 'sha256'
434 : undef;
435 }
436  
437  
438 1127 ▶sub headerlist {
Subroutine headerlist: called CC=6 SCAR=17.9
Pod documented
439 1127 my $self = shift;
440  
441 1127 ▶ (@_)
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->set_tag("h", shift()) 580 547 1127
442 and $self->set_tag( 'h', shift );
443  
444 1127 ▶ my $h = $self->get_tag('h') || '';
Condition100%2/2
$self->get_tag('h') || ''
l!l
574553
MC/DC100%1/1
$self->get_tag('h') || ''
$self->get_tag('h')
Truth table100%2/2
A
A= $self->get_tag('h')
Aresult
11
00
445  
446 # remove whitespace next to colons
447 1127 $h =~ s/\s+:/:/g;
448 1127 $h =~ s/:\s+/:/g;
449 1127 $h = lc $h;
450  
451 1127 ▶ if ( wantarray and $h ) {
Branch: 2 branches
BranchTrueFalseTotal
if (wantarray and $h) { } 276 851 1127
elsif (wantarray) { } 8 843 851
Condition100%3/3
wantarray and $h
!ll&&!rl&&r
8438276
MC/DC100%2/2
wantarray and $h
wantarray $h
Truth table100%3/3
A and B
A= wantarrayB= $h
ABresult
0X0
100
111
452 276 my @list = split /:/, $h;
453 276 @list = map { s/^\s+|\s+$//g; $_ } @list;
454 276 return @list;
455 }
456 elsif (wantarray) {
457 8 return ();
458 }
459  
460 843 return $h;
461 }
462  
463  
464 302 ▶sub identity {
Subroutine identity: called CC=4 SCAR=13.9
Pod documented
465 302 my $self = shift;
466  
467 # set new identity if provided
468 302 ▶ (@_)
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->set_tag("i", encode_qp(shift())) 2 300 302
469 and $self->set_tag( 'i', encode_qp(shift) );
470  
471 302 my $i = $self->get_tag('i');
472 302 ▶ if ( defined $i ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $i) { } 217 85 302
473 217 return decode_qp($i);
474 }
475 else {
476 85 ▶ return '@' . ( $self->domain || '' );
Condition50%1/2
$self->domain || ''
l!l
850
MC/DC0%0/1
$self->domain || ''
$self->domain
Truth table50%1/2
A
A= $self->domain
Aresult
11
00
477 }
478 }
479  
480 0 ▶sub identity_matches {
Subroutine identity_matches: not called CC=2 SCAR=17.9
Pod undocumented
481 0 my $self = shift;
482 0 my ($addr) = @_;
483  
484 0 my $id = $self->identity;
485 0 ▶ if ( $id =~ /^\@/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id =~ /^\@/) 0 0 0
486  
487 # the identity is a domain-name only, so it only needs to match
488 # the domain part of the sender address
489 0 return ( lc( substr( $addr, -length($id) ) ) eq lc($id) );
490  
491 # TODO - compare the parent domains?
492 }
493 0 return lc($addr) eq lc($id);
494 }
495  
496  
497 53 ▶sub key {
Subroutine key: called CC=2 SCAR=7.0
Pod documented
498 53 my $self = shift;
499 53 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 53 0 53
500 53 $self->{Key} = shift;
501 53 $self->{KeyFile} = undef;
502 }
503 53 return $self->{Key};
504 }
505  
506  
507 0 ▶sub method {
Subroutine method: not called CC=3 SCAR=24.8
Pod documented
508 0 my $self = shift;
509  
510 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
511 0 $self->set_tag( 'c', shift );
512 }
513  
514 0 ▶ return ( lc $self->get_tag('c') ) || 'simple';
Condition0%0/2
lc $self->get_tag('c') || 'simple'
l!l
00
MC/DC0%0/1
lc $self->get_tag('c') || 'simple'
lc $self->get_tag('c')
Truth table0%0/2
A
A= lc $self->get_tag('c')
Aresult
11
00
515 }
516  
517  
518 834 ▶sub protocol {
Subroutine protocol: called CC=3 SCAR=11.0
Pod documented
519 834 my $self = shift;
520  
521 834 ▶ (@_)
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->set_tag("q", shift()) 0 834 834
522 and $self->set_tag( 'q', shift );
523  
524 834 my $q = $self->get_tag('q');
525 834 ▶ if ( defined $q ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $q) { } 85 749 834
526 85 return $q;
527 }
528 else {
529 749 return 'dns/txt';
530 }
531 }
532  
533  
534 1050 ▶sub result {
Subroutine result: called CC=3 SCAR=11.0
Pod documented
535 1050 my $self = shift;
536 1050 ▶ @_ and $self->{verify_result} = shift;
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->{"verify_result"} = shift() 408 642 1050
537 1050 ▶ @_ and $self->{verify_details} = shift;
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->{"verify_details"} = shift() 408 642 1050
538 1050 return $self->{verify_result};
539 }
540  
541  
542 471 ▶sub result_detail {
Subroutine result_detail: called CC=4 SCAR=13.9
Pod documented
543 471 my $self = shift;
544 471 ▶ croak 'wrong number of arguments' unless ( @_ == 0 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 0 0 471 471
545  
546 471 ▶ if ( $self->{verify_result} && $self->{verify_details} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"verify_result"} and $self->{"verify_details"}) 147 324 471
Condition100%3/3
$self->{"verify_result"} and $self->{"verify_details"}
!ll&&!rl&&r
44280147
MC/DC100%2/2
$self->{"verify_result"} and $self->{"verify_details"}
$self->{"verify_result"} $self->{"verify_details"}
Truth table100%3/3
A and B
A= $self->{"verify_result"}B= $self->{"verify_details"}
ABresult
0X0
100
111
547 147 return $self->{verify_result} . ' (' . $self->{verify_details} . ')';
548 }
549 324 return $self->{verify_result};
550 }
551  
552  
553 1816 ▶sub selector {
Subroutine selector: called CC=2 SCAR=6.9
Pod documented
554 1816 my $self = shift;
555  
556 1816 ▶ (@_)
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->set_tag("s", shift()) 965 851 1816
557 and $self->set_tag( 's', shift );
558  
559 1816 return $self->get_tag('s');
560 }
561  
562  
563 66 ▶sub prettify {
Subroutine prettify: called CC=1 SCAR=0.0
Pod documented
564 66 my $self = shift;
565 66 $self->wrap(
566 Start => length( $self->prefix() ),
567 Tags => {
568 b => 'b64',
569 bh => 'b64',
570 h => 'list',
571 },
572 );
573 }
574  
575  
576 63 ▶sub prettify_safe {
Subroutine prettify_safe: called CC=1 SCAR=0.0
Pod documented
577 63 my $self = shift;
578 63 $self->wrap(
579 Start => length( $self->prefix() ),
580 Tags => {
581 b => 'b64',
582 },
583 PreserveNames => 1,
584 Default => 'preserve', #preserves unknown tags
585 );
586 }
587  
588  
589 406 ▶sub timestamp {
Subroutine timestamp: called CC=2 SCAR=7.1
Pod documented
590 406 my $self = shift;
591  
592 406 ▶ (@_)
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->set_tag("t", shift()) 406 0 406
593 and $self->set_tag( 't', shift );
594  
595 406 return $self->get_tag('t');
596 }
597  
598  
599 1438 ▶sub version {
Subroutine version: called CC=2 SCAR=6.9
Pod documented
600 1438 my $self = shift;
601  
602 1438 ▶ (@_)
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->set_tag("v", shift()) 171 1267 1438
603 and $self->set_tag( 'v', shift );
604  
605 1438 return $self->get_tag('v');
606 }
607  
608  
609 15 1;
610  
611 __END__
« DKIM/MessageParser.pm ↑ Summary DKIM/PrivateKey.pm »