DKIM/Signature.pm

filter: Statementstmt 87.1% 230 / 264 Branchbran 79.2% 111 / 140 Conditioncond 84.2% 16 / 19 MC/DCmcdc 81.8% 9 / 11 Subroutinesub 88.4% 46 / 52 Podpod 62.5% 25 / 40 totaltotal 83.0% 437 / 526 CC 82 SCAR 15.2
CC
82
Cov
84%
wantheader
20.0
method
12.0
new
9.0
CRAP 4.6
« DKIM/Canonicalization/nowsp.pm ↑ Summary DKIM/PrivateKey.pm »
1 package Mail::DKIM::Signature;
2 20 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 20 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 20 our $VERSION = '1.20261116'; # 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 20 ▶use Mail::DKIM::PublicKey;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 20 ▶use Mail::DKIM::Algorithm::rsa_sha1;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 20 ▶use Mail::DKIM::Algorithm::rsa_sha256;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 20 ▶use Mail::DKIM::Algorithm::ed25519_sha256;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 20 ▶use base 'Mail::DKIM::KeyValueList';
Subroutine BEGIN: called CC=1 SCAR=0.0
20 20 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22  
23 212 ▶sub new {
Subroutine new: called CC=9 SCAR=22.0
Pod documented
24 212 my $class = shift;
25 212 my %prms = @_;
26 212 my $self = {};
27 212 bless $self, $class;
28  
29 212 $self->version('1');
30 212 ▶ $self->algorithm( $prms{'Algorithm'} || 'rsa-sha1' );
Condition100%2/2
$prms{'Algorithm'} || 'rsa-sha1'
l!l
17195
MC/DC100%1/1
$prms{'Algorithm'} || 'rsa-sha1'
$prms{'Algorithm'}
Truth table100%2/2
A
A= $prms{'Algorithm'}
Aresult
11
00
31 212 $self->signature( $prms{'Signature'} );
32 212 ▶ $self->canonicalization( $prms{'Method'} ) if exists $prms{'Method'};
Branch: 1 branch
BranchTrueFalseTotal
if exists $prms{"Method"} 17 195 212
33 212 $self->domain( $prms{'Domain'} );
34 212 $self->headerlist( $prms{'Headers'} );
35 212 ▶ $self->protocol( $prms{'Query'} ) if exists $prms{'Query'};
Branch: 1 branch
BranchTrueFalseTotal
if exists $prms{"Query"} 0 212 212
36 212 $self->selector( $prms{'Selector'} );
37 212 ▶ $self->identity( $prms{'Identity'} ) if exists $prms{'Identity'};
Branch: 1 branch
BranchTrueFalseTotal
if exists $prms{"Identity"} 2 210 212
38 212 ▶ $self->timestamp( $prms{'Timestamp'} ) if defined $prms{'Timestamp'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $prms{"Timestamp"} 5 207 212
39 212 ▶ $self->expiration( $prms{'Expiration'} ) if defined $prms{'Expiration'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $prms{"Expiration"} 3 209 212
40 212 ▶ $self->tags( $prms{'Tags'} ) if defined $prms{'Tags'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $prms{"Tags"} 0 212 212
41 212 ▶ $self->key( $prms{'Key'} ) if defined $prms{'Key'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $prms{"Key"} 15 197 212
42 212 return $self;
43 }
44  
45  
46 1315 ▶sub parse {
Subroutine parse: called CC=3 SCAR=11.1
Pod documented
47 1315 my $class = shift;
48 1315 ▶ croak 'wrong number of arguments' unless ( @_ == 1 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 1 0 1315 1315
49 1315 my ($string) = @_;
50  
51 # remove line terminator, if present
52 1315 $string =~ s/\015\012\z//;
53  
54 # remove field name, if present
55 1315 my $prefix = $class->prefix();
56 1315 ▶ if ( $string =~ s/^($prefix)//i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ s/^($prefix)//i) 1315 0 1315
57  
58 # save the field name (capitalization), so that it can be
59 # restored later
60 1315 $prefix = $1;
61 }
62  
63 1315 my $self = $class->SUPER::parse($string);
64 1309 $self->{prefix} = $prefix;
65  
66 1309 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 3962 ▶sub algorithm {
Subroutine algorithm: called CC=3 SCAR=11.0
Pod documented
88 3962 my $self = shift;
89  
90 3962 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1376 2586 3962
91 1376 $self->set_tag( 'a', shift );
92 }
93  
94 3962 my $a = $self->get_tag('a');
95 3962 ▶ return defined $a ? lc $a : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $a ? : 3958 4 3962
96 }
97  
98  
99 1189 ▶sub as_string {
Subroutine as_string: called CC=1 SCAR=0.0
Pod documented
100 1189 my $self = shift;
101  
102 1189 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 544 ▶sub as_string_without_data {
Subroutine as_string_without_data: called CC=2 SCAR=7.0
Pod documented
115 544 my $self = shift;
116 544 ▶ croak 'wrong number of arguments' unless ( @_ == 0 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 0 0 544 544
117  
118 544 my $alt = $self->clone;
119 544 $alt->signature('');
120  
121 544 return $alt->as_string;
122 }
123  
124  
125 348 ▶sub body_count {
Subroutine body_count: called CC=2 SCAR=7.1
Pod documented
126 348 my $self = shift;
127  
128 # set new body count if provided
129 348 ▶ (@_)
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->set_tag("l", shift()) 0 348 348
130 and $self->set_tag( 'l', shift );
131  
132 348 return $self->get_tag('l');
133 }
134  
135  
136 274 ▶sub body_hash {
Subroutine body_hash: called CC=3 SCAR=11.0
Pod documented
137 274 my $self = shift;
138  
139 # set new body hash if provided
140 274 ▶ (@_)
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->set_tag("bh", shift()) 40 234 274
141 and $self->set_tag( 'bh', shift );
142  
143 274 my $result = $self->get_tag('bh');
144 274 ▶ if ( defined $result ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $result) 271 3 274
145 271 $result =~ s/\s+//gs;
146 }
147 274 return $result;
148 }
149  
150  
151 748 ▶sub canonicalization {
Subroutine canonicalization: called CC=6 SCAR=17.9
Pod documented
152 748 my $self = shift;
153  
154 748 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 40 708 748
155 40 $self->set_tag( 'c', join( '/', @_ ) );
156 }
157  
158 748 my $c = $self->get_tag('c');
159 748 ▶ $c = lc $c if defined $c;
Branch: 1 branch
BranchTrueFalseTotal
if defined $c 746 2 748
160 748 ▶ if ( not $c ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($c) 4 744 748
161 4 $c = 'simple/simple';
162 }
163 748 my ( $c1, $c2 ) = split( /\//, $c, 2 );
164 748 ▶ if ( not defined $c2 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $c2) 148 600 748
165  
166 # default body canonicalization is "simple"
167 148 $c2 = 'simple';
168 }
169  
170 748 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 700 48 748
171 700 return ( $c1, $c2 );
172 }
173 else {
174 48 return "$c1/$c2";
175 }
176 }
177  
178 20 ▶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 614 ▶sub check_canonicalization {
Subroutine check_canonicalization: called CC=3 SCAR=11.0
Pod undocumented
184 614 my $self = shift;
185  
186 614 my ( $c1, $c2 ) = $self->canonicalization;
187  
188 614 my @known = ( 'nowsp', 'simple', 'relaxed', 'seal' );
189 614 ▶ return undef unless ( grep { $_ eq $c1 } @known );
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $c1;} @known 3 611 614
190 611 ▶ return undef unless ( grep { $_ eq $c2 } @known );
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $c2;} @known 0 611 611
191 611 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 624 ▶sub check_expiration {
Subroutine check_expiration: called CC=3 SCAR=11.0
Pod undocumented
203 624 my $self = shift;
204 624 my $x = $self->expiration;
205 624 ▶ return 1 if not defined $x;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $x 619 5 624
206 5 ▶ $self->{_verify_time} ||= time();
Condition100%2/2
$self->{"_verify_time"} ||= time
l!l
14
MC/DC100%1/1
$self->{"_verify_time"} ||= time
$self->{"_verify_time"}
Truth table100%2/2
A
A= $self->{"_verify_time"}
Aresult
11
00
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 1180 ▶sub check_protocol {
Subroutine check_protocol: called CC=7 SCAR=19.5
Pod undocumented
216 1180 my $self = shift;
217  
218 1180 my $v = $self->version;
219  
220 1180 foreach my $prot ( split /:/, $self->protocol ) {
221 1182 my ( $type, $options ) = split( /\//, $prot, 2 );
222 1182 ▶ if ( $type eq 'dns' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "dns") 1179 3 1182
223 1179 ▶ return ('dns/txt') if $options && $options eq 'txt';
Branch: 1 branch
BranchTrueFalseTotal
if $options and $options eq "txt" 1167 12 1179
Condition100%3/3
$options and $options eq "txt"
!ll&&!rl&&r
1111167
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 12 ▶ if ( !$v ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($v) 11 1 12
227 11 ▶ return ('dns/txt') if !defined($options);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $options 11 0 11
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 625 ▶sub check_version {
Subroutine check_version: called CC=2 SCAR=6.9
Pod undocumented
240 625 my $self = shift;
241  
242 # check version
243 625 ▶ if ( my $version = $self->version ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $version = $self->version) 77 548 625
244 77 my @ALLOWED_VERSIONS = ( '0.5', '1' );
245 77 return ( grep { $_ eq $version } @ALLOWED_VERSIONS );
246 }
247  
248 # we still consider a missing v= tag acceptable,
249 # for backwards-compatibility
250 548 return 1;
251 }
252  
253  
254 3109 ▶sub data {
Subroutine data: called CC=3 SCAR=11.0
Pod documented
255 3109 my $self = shift;
256  
257 3109 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 2008 1101 3109
258 2008 $self->set_tag( 'b', shift );
259 }
260  
261 3109 my $b = $self->get_tag('b');
262 3109 ▶ $b =~ tr/\015\012 \t//d if defined $b;
Branch: 1 branch
BranchTrueFalseTotal
if defined $b 1642 1467 3109
263 3109 return $b;
264 }
265  
266 20 *signature = \*data;
267  
268 #undocumented, private function
269 #derived from MIME::Base64::Perl (allowed, thanks to the Perl license)
270 #
271 250 ▶sub decode_qp {
Subroutine decode_qp: called CC=2 SCAR=7.0
Pod undocumented
272 250 my $res = shift;
273  
274 #TODO- should I worry about non-ASCII systems here?
275 250 ▶ $res =~ s/=([\da-fA-F]{2})/pack('C', hex($1))/ge
Branch: 1 branch
BranchTrueFalseTotal
if defined $res 250 0 250
276 if defined $res;
277 250 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 0 ▶ $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 279 ▶sub DEFAULT_PREFIX {
Subroutine DEFAULT_PREFIX: called CC=1 SCAR=0.0
Pod undocumented
296 279 return 'DKIM-Signature:';
297 }
298  
299 2641 ▶sub prefix {
Subroutine prefix: called CC=4 SCAR=13.9
Pod undocumented
300 2641 my $class = shift;
301 2641 ▶ if ( ref($class) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $class) 1326 1315 2641
302 1326 ▶ $class->{prefix} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 1326 1326
303 1326 ▶ return $class->{prefix} if $class->{prefix};
Branch: 1 branch
BranchTrueFalseTotal
if $class->{"prefix"} 1051 275 1326
304 }
305 1590 return $class->DEFAULT_PREFIX();
306 }
307  
308  
309 3981 ▶sub domain {
Subroutine domain: called CC=3 SCAR=11.0
Pod documented
310 3981 my $self = shift;
311  
312 3981 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1375 2606 3981
313 1375 $self->set_tag( 'd', shift );
314 }
315  
316 3981 my $d = $self->get_tag('d');
317 3981 ▶ return defined $d ? lc $d : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $d ? : 2661 1320 3981
318 }
319  
320  
321 612 ▶sub expiration {
Subroutine expiration: called CC=2 SCAR=6.9
Pod documented
322 612 my $self = shift;
323  
324 612 ▶ (@_)
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->set_tag("x", shift()) 3 609 612
325 and $self->set_tag( 'x', shift );
326  
327 612 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 1246 ▶sub get_algorithm_class {
Subroutine get_algorithm_class: called CC=5 SCAR=16.1
Pod undocumented
343 1246 my $self = shift;
344 1246 ▶ croak 'wrong number of arguments' unless ( @_ == 1 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 1 0 1246 1246
345 1246 my ($algorithm) = @_;
346  
347 1246 ▶ my $class =
Branch: 3 branches
BranchTrueFalseTotal
$algorithm eq 'rsa-sha1' ? : 87 1159 1246
$algorithm eq 'rsa-sha256' ? : 1141 18 1159
$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 1246 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 584 ▶sub fetch_public_key {
Subroutine fetch_public_key: called CC=2 SCAR=6.9
Pod undocumented
362 584 my $self = shift;
363 584 ▶ return if exists $self->{public_key_query};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"public_key_query"} 0 584 584
364  
365 478 ▶ my $on_success = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
366 478 ▶ if ( $_[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]) { } 348 130 478
367 348 $self->{public} = $_[0];
368 }
369 else {
370 130 $self->{public_error} = "not available\n";
371 }
372 584 };
373  
374 584 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 584 );
384 582 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 827 ▶sub get_public_key {
Subroutine get_public_key: called CC=4 SCAR=14.0
Pod documented
403 827 my $self = shift;
404  
405 # this ensures we only try fetching once, even if an error occurs
406 827 ▶ if ( not exists $self->{public_key_query} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"public_key_query"}) 0 827 827
407 0 $self->fetch_public_key;
408 }
409  
410 827 ▶ if ( $self->{public_key_query} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"public_key_query"}) 489 338 827
411  
412 # wait for public key query to finish
413 489 $self->{public_key_query}->();
414 481 $self->{public_key_query} = 0;
415 }
416  
417 819 ▶ if ( exists $self->{public} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'public'}) { } 686 133 819
418 686 return $self->{public};
419 }
420 else {
421 133 die $self->{public_error};
422 }
423 }
424  
425  
426 335 ▶sub hash_algorithm {
Subroutine hash_algorithm: called CC=4 SCAR=13.9
Pod documented
427 335 my $self = shift;
428 335 my $algorithm = $self->algorithm;
429  
430 return
431 335 ▶ $algorithm eq 'rsa-sha1' ? 'sha1'
Branch: 3 branches
BranchTrueFalseTotal
$algorithm eq 'rsa-sha1' ? : 27 308 335
$algorithm eq 'rsa-sha256' ? : 305 3 308
$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 1236 ▶sub headerlist {
Subroutine headerlist: called CC=6 SCAR=17.9
Pod documented
439 1236 my $self = shift;
440  
441 1236 ▶ (@_)
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->set_tag("h", shift()) 814 422 1236
442 and $self->set_tag( 'h', shift );
443  
444 1236 ▶ my $h = $self->get_tag('h') || '';
Condition100%2/2
$self->get_tag('h') || ''
l!l
453783
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 1236 $h =~ s/\s+:/:/g;
448 1236 $h =~ s/:\s+/:/g;
449 1236 $h = lc $h;
450  
451 1236 ▶ if ( wantarray and $h ) {
Branch: 2 branches
BranchTrueFalseTotal
if (wantarray and $h) { } 412 824 1236
elsif (wantarray) { } 10 814 824
Condition100%3/3
wantarray and $h
!ll&&!rl&&r
81410412
MC/DC100%2/2
wantarray and $h
wantarray $h
Truth table100%3/3
A and B
A= wantarrayB= $h
ABresult
0X0
100
111
452 412 my @list = split /:/, $h;
453 412 @list = map { s/^\s+//; s/\s+$//; $_ } @list; # not s/^\s+|\s+$//g, quadratic
454 412 return @list;
455 }
456 elsif (wantarray) {
457 10 return ();
458 }
459  
460 814 return $h;
461 }
462  
463  
464 352 ▶sub identity {
Subroutine identity: called CC=4 SCAR=13.9
Pod documented
465 352 my $self = shift;
466  
467 # set new identity if provided
468 352 ▶ (@_)
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->set_tag("i", encode_qp(shift())) 2 350 352
469 and $self->set_tag( 'i', encode_qp(shift) );
470  
471 352 my $i = $self->get_tag('i');
472 352 ▶ if ( defined $i ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $i) { } 250 102 352
473 250 return decode_qp($i);
474 }
475 else {
476 102 ▶ return '@' . ( $self->domain || '' );
Condition50%1/2
$self->domain || ''
l!l
1020
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 57 ▶sub key {
Subroutine key: called CC=2 SCAR=7.0
Pod documented
498 57 my $self = shift;
499 57 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 57 0 57
500 57 $self->{Key} = shift;
501 57 $self->{KeyFile} = undef;
502 }
503 57 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 1184 ▶sub protocol {
Subroutine protocol: called CC=3 SCAR=11.0
Pod documented
519 1184 my $self = shift;
520  
521 1184 ▶ (@_)
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->set_tag("q", shift()) 0 1184 1184
522 and $self->set_tag( 'q', shift );
523  
524 1184 my $q = $self->get_tag('q');
525 1184 ▶ if ( defined $q ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $q) { } 84 1100 1184
526 84 return $q;
527 }
528 else {
529 1100 return 'dns/txt';
530 }
531 }
532  
533  
534 1266 ▶sub result {
Subroutine result: called CC=3 SCAR=11.0
Pod documented
535 1266 my $self = shift;
536 1266 ▶ @_ and $self->{verify_result} = shift;
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->{"verify_result"} = shift() 538 728 1266
537 1266 ▶ @_ and $self->{verify_details} = shift;
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->{"verify_details"} = shift() 534 732 1266
538 1266 return $self->{verify_result};
539 }
540  
541  
542 466 ▶sub result_detail {
Subroutine result_detail: called CC=4 SCAR=13.9
Pod documented
543 466 my $self = shift;
544 466 ▶ croak 'wrong number of arguments' unless ( @_ == 0 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 0 0 466 466
545  
546 466 ▶ if ( $self->{verify_result} && $self->{verify_details} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"verify_result"} and $self->{"verify_details"}) 130 336 466
Condition100%3/3
$self->{"verify_result"} and $self->{"verify_details"}
!ll&&!rl&&r
58278130
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 130 return $self->{verify_result} . ' (' . $self->{verify_details} . ')';
548 }
549 336 return $self->{verify_result};
550 }
551  
552  
553 2599 ▶sub selector {
Subroutine selector: called CC=2 SCAR=6.9
Pod documented
554 2599 my $self = shift;
555  
556 2599 ▶ (@_)
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->set_tag("s", shift()) 1398 1201 2599
557 and $self->set_tag( 's', shift );
558  
559 2599 return $self->get_tag('s');
560 }
561  
562  
563 70 ▶sub prettify {
Subroutine prettify: called CC=1 SCAR=0.0
Pod documented
564 70 my $self = shift;
565 70 $self->wrap(
566 Start => length( $self->prefix() ),
567 Tags => {
568 b => 'b64',
569 bh => 'b64',
570 h => 'list',
571 },
572 );
573 }
574  
575  
576 67 ▶sub prettify_safe {
Subroutine prettify_safe: called CC=1 SCAR=0.0
Pod documented
577 67 my $self = shift;
578 67 $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 605 ▶sub timestamp {
Subroutine timestamp: called CC=2 SCAR=7.1
Pod documented
590 605 my $self = shift;
591  
592 605 ▶ (@_)
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->set_tag("t", shift()) 605 0 605
593 and $self->set_tag( 't', shift );
594  
595 605 return $self->get_tag('t');
596 }
597  
598  
599 2019 ▶sub version {
Subroutine version: called CC=2 SCAR=6.9
Pod documented
600 2019 my $self = shift;
601  
602 2019 ▶ (@_)
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->set_tag("v", shift()) 212 1807 2019
603 and $self->set_tag( 'v', shift );
604  
605 2019 return $self->get_tag('v');
606 }
607  
608  
609 20 1;
610  
611 __END__
« DKIM/Canonicalization/nowsp.pm ↑ Summary DKIM/PrivateKey.pm »