DKIM/Signature.pm

filter: Statementstmt 87.1% 230 / 264 Branchbran 78.5% 110 / 140 Conditioncond 84.2% 16 / 19 MC/DCmcdc 81.8% 9 / 11 Subroutinesub 88.4% 46 / 52 Podpod 62.5% 25 / 40 totaltotal 82.8% 436 / 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 19 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 19 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 19 our $VERSION = '1.20261105'; # 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 19 ▶use Mail::DKIM::PublicKey;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 19 ▶use Mail::DKIM::Algorithm::rsa_sha1;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 19 ▶use Mail::DKIM::Algorithm::rsa_sha256;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 19 ▶use Mail::DKIM::Algorithm::ed25519_sha256;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 19 ▶use base 'Mail::DKIM::KeyValueList';
Subroutine BEGIN: called CC=1 SCAR=0.0
20 19 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22  
23 199 ▶sub new {
Subroutine new: called CC=9 SCAR=22.0
Pod documented
24 199 my $class = shift;
25 199 my %prms = @_;
26 199 my $self = {};
27 199 bless $self, $class;
28  
29 199 $self->version('1');
30 199 ▶ $self->algorithm( $prms{'Algorithm'} || 'rsa-sha1' );
Condition100%2/2
$prms{'Algorithm'} || 'rsa-sha1'
l!l
17182
MC/DC100%1/1
$prms{'Algorithm'} || 'rsa-sha1'
$prms{'Algorithm'}
Truth table100%2/2
A
A= $prms{'Algorithm'}
Aresult
11
00
31 199 $self->signature( $prms{'Signature'} );
32 199 ▶ $self->canonicalization( $prms{'Method'} ) if exists $prms{'Method'};
Branch: 1 branch
BranchTrueFalseTotal
if exists $prms{"Method"} 17 182 199
33 199 $self->domain( $prms{'Domain'} );
34 199 $self->headerlist( $prms{'Headers'} );
35 199 ▶ $self->protocol( $prms{'Query'} ) if exists $prms{'Query'};
Branch: 1 branch
BranchTrueFalseTotal
if exists $prms{"Query"} 0 199 199
36 199 $self->selector( $prms{'Selector'} );
37 199 ▶ $self->identity( $prms{'Identity'} ) if exists $prms{'Identity'};
Branch: 1 branch
BranchTrueFalseTotal
if exists $prms{"Identity"} 2 197 199
38 199 ▶ $self->timestamp( $prms{'Timestamp'} ) if defined $prms{'Timestamp'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $prms{"Timestamp"} 5 194 199
39 199 ▶ $self->expiration( $prms{'Expiration'} ) if defined $prms{'Expiration'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $prms{"Expiration"} 3 196 199
40 199 ▶ $self->tags( $prms{'Tags'} ) if defined $prms{'Tags'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $prms{"Tags"} 0 199 199
41 199 ▶ $self->key( $prms{'Key'} ) if defined $prms{'Key'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $prms{"Key"} 15 184 199
42 199 return $self;
43 }
44  
45  
46 1302 ▶sub parse {
Subroutine parse: called CC=3 SCAR=11.1
Pod documented
47 1302 my $class = shift;
48 1302 ▶ croak 'wrong number of arguments' unless ( @_ == 1 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 1 0 1302 1302
49 1302 my ($string) = @_;
50  
51 # remove line terminator, if present
52 1302 $string =~ s/\015\012\z//;
53  
54 # remove field name, if present
55 1302 my $prefix = $class->prefix();
56 1302 ▶ if ( $string =~ s/^($prefix)//i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ s/^($prefix)//i) 1302 0 1302
57  
58 # save the field name (capitalization), so that it can be
59 # restored later
60 1302 $prefix = $1;
61 }
62  
63 1302 my $self = $class->SUPER::parse($string);
64 1296 $self->{prefix} = $prefix;
65  
66 1296 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 3923 ▶sub algorithm {
Subroutine algorithm: called CC=3 SCAR=11.0
Pod documented
88 3923 my $self = shift;
89  
90 3923 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1363 2560 3923
91 1363 $self->set_tag( 'a', shift );
92 }
93  
94 3923 my $a = $self->get_tag('a');
95 3923 ▶ return defined $a ? lc $a : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $a ? : 3919 4 3923
96 }
97  
98  
99 1183 ▶sub as_string {
Subroutine as_string: called CC=1 SCAR=0.0
Pod documented
100 1183 my $self = shift;
101  
102 1183 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 541 ▶sub as_string_without_data {
Subroutine as_string_without_data: called CC=2 SCAR=7.0
Pod documented
115 541 my $self = shift;
116 541 ▶ croak 'wrong number of arguments' unless ( @_ == 0 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 0 0 541 541
117  
118 541 my $alt = $self->clone;
119 541 $alt->signature('');
120  
121 541 return $alt->as_string;
122 }
123  
124  
125 345 ▶sub body_count {
Subroutine body_count: called CC=2 SCAR=7.1
Pod documented
126 345 my $self = shift;
127  
128 # set new body count if provided
129 345 ▶ (@_)
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->set_tag("l", shift()) 0 345 345
130 and $self->set_tag( 'l', shift );
131  
132 345 return $self->get_tag('l');
133 }
134  
135  
136 189 ▶sub body_hash {
Subroutine body_hash: called CC=3 SCAR=11.0
Pod documented
137 189 my $self = shift;
138  
139 # set new body hash if provided
140 189 ▶ (@_)
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->set_tag("bh", shift()) 40 149 189
141 and $self->set_tag( 'bh', shift );
142  
143 189 my $result = $self->get_tag('bh');
144 189 ▶ if ( defined $result ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $result) 189 0 189
145 189 $result =~ s/\s+//gs;
146 }
147 189 return $result;
148 }
149  
150  
151 735 ▶sub canonicalization {
Subroutine canonicalization: called CC=6 SCAR=17.9
Pod documented
152 735 my $self = shift;
153  
154 735 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 40 695 735
155 40 $self->set_tag( 'c', join( '/', @_ ) );
156 }
157  
158 735 my $c = $self->get_tag('c');
159 735 ▶ $c = lc $c if defined $c;
Branch: 1 branch
BranchTrueFalseTotal
if defined $c 733 2 735
160 735 ▶ if ( not $c ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($c) 4 731 735
161 4 $c = 'simple/simple';
162 }
163 735 my ( $c1, $c2 ) = split( /\//, $c, 2 );
164 735 ▶ if ( not defined $c2 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $c2) 149 586 735
165  
166 # default body canonicalization is "simple"
167 149 $c2 = 'simple';
168 }
169  
170 735 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 687 48 735
171 687 return ( $c1, $c2 );
172 }
173 else {
174 48 return "$c1/$c2";
175 }
176 }
177  
178 19 ▶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 604 ▶sub check_canonicalization {
Subroutine check_canonicalization: called CC=3 SCAR=11.0
Pod undocumented
184 604 my $self = shift;
185  
186 604 my ( $c1, $c2 ) = $self->canonicalization;
187  
188 604 my @known = ( 'nowsp', 'simple', 'relaxed', 'seal' );
189 604 ▶ return undef unless ( grep { $_ eq $c1 } @known );
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $c1;} @known 3 601 604
190 601 ▶ return undef unless ( grep { $_ eq $c2 } @known );
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $c2;} @known 0 601 601
191 601 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 614 ▶sub check_expiration {
Subroutine check_expiration: called CC=3 SCAR=11.0
Pod undocumented
203 614 my $self = shift;
204 614 my $x = $self->expiration;
205 614 ▶ return 1 if not defined $x;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $x 609 5 614
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 1167 ▶sub check_protocol {
Subroutine check_protocol: called CC=7 SCAR=19.5
Pod undocumented
216 1167 my $self = shift;
217  
218 1167 my $v = $self->version;
219  
220 1167 foreach my $prot ( split /:/, $self->protocol ) {
221 1169 my ( $type, $options ) = split( /\//, $prot, 2 );
222 1169 ▶ if ( $type eq 'dns' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "dns") 1166 3 1169
223 1166 ▶ return ('dns/txt') if $options && $options eq 'txt';
Branch: 1 branch
BranchTrueFalseTotal
if $options and $options eq "txt" 1153 13 1166
Condition100%3/3
$options and $options eq "txt"
!ll&&!rl&&r
1211153
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 615 ▶sub check_version {
Subroutine check_version: called CC=2 SCAR=6.9
Pod undocumented
240 615 my $self = shift;
241  
242 # check version
243 615 ▶ if ( my $version = $self->version ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $version = $self->version) 67 548 615
244 67 my @ALLOWED_VERSIONS = ( '0.5', '1' );
245 67 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 3087 ▶sub data {
Subroutine data: called CC=3 SCAR=11.0
Pod documented
255 3087 my $self = shift;
256  
257 3087 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1992 1095 3087
258 1992 $self->set_tag( 'b', shift );
259 }
260  
261 3087 my $b = $self->get_tag('b');
262 3087 ▶ $b =~ tr/\015\012 \t//d if defined $b;
Branch: 1 branch
BranchTrueFalseTotal
if defined $b 1633 1454 3087
263 3087 return $b;
264 }
265  
266 19 *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 266 ▶sub DEFAULT_PREFIX {
Subroutine DEFAULT_PREFIX: called CC=1 SCAR=0.0
Pod undocumented
296 266 return 'DKIM-Signature:';
297 }
298  
299 2622 ▶sub prefix {
Subroutine prefix: called CC=4 SCAR=13.9
Pod undocumented
300 2622 my $class = shift;
301 2622 ▶ if ( ref($class) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $class) 1320 1302 2622
302 1320 ▶ $class->{prefix} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 1320 1320
303 1320 ▶ return $class->{prefix} if $class->{prefix};
Branch: 1 branch
BranchTrueFalseTotal
if $class->{"prefix"} 1045 275 1320
304 }
305 1577 return $class->DEFAULT_PREFIX();
306 }
307  
308  
309 3936 ▶sub domain {
Subroutine domain: called CC=3 SCAR=11.0
Pod documented
310 3936 my $self = shift;
311  
312 3936 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1362 2574 3936
313 1362 $self->set_tag( 'd', shift );
314 }
315  
316 3936 my $d = $self->get_tag('d');
317 3936 ▶ return defined $d ? lc $d : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $d ? : 2629 1307 3936
318 }
319  
320  
321 602 ▶sub expiration {
Subroutine expiration: called CC=2 SCAR=6.9
Pod documented
322 602 my $self = shift;
323  
324 602 ▶ (@_)
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->set_tag("x", shift()) 3 599 602
325 and $self->set_tag( 'x', shift );
326  
327 602 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 1233 ▶sub get_algorithm_class {
Subroutine get_algorithm_class: called CC=5 SCAR=16.1
Pod undocumented
343 1233 my $self = shift;
344 1233 ▶ croak 'wrong number of arguments' unless ( @_ == 1 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 1 0 1233 1233
345 1233 my ($algorithm) = @_;
346  
347 1233 ▶ my $class =
Branch: 3 branches
BranchTrueFalseTotal
$algorithm eq 'rsa-sha1' ? : 88 1145 1233
$algorithm eq 'rsa-sha256' ? : 1127 18 1145
$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 1233 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 581 ▶sub fetch_public_key {
Subroutine fetch_public_key: called CC=2 SCAR=6.9
Pod undocumented
362 581 my $self = shift;
363 581 ▶ return if exists $self->{public_key_query};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"public_key_query"} 0 581 581
364  
365 475 ▶ my $on_success = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
366 475 ▶ if ( $_[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]) { } 345 130 475
367 345 $self->{public} = $_[0];
368 }
369 else {
370 130 $self->{public_error} = "not available\n";
371 }
372 581 };
373  
374 581 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 581 );
384 579 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 821 ▶sub get_public_key {
Subroutine get_public_key: called CC=4 SCAR=14.0
Pod documented
403 821 my $self = shift;
404  
405 # this ensures we only try fetching once, even if an error occurs
406 821 ▶ if ( not exists $self->{public_key_query} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"public_key_query"}) 0 821 821
407 0 $self->fetch_public_key;
408 }
409  
410 821 ▶ if ( $self->{public_key_query} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"public_key_query"}) 486 335 821
411  
412 # wait for public key query to finish
413 486 $self->{public_key_query}->();
414 478 $self->{public_key_query} = 0;
415 }
416  
417 813 ▶ if ( exists $self->{public} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'public'}) { } 680 133 813
418 680 return $self->{public};
419 }
420 else {
421 133 die $self->{public_error};
422 }
423 }
424  
425  
426 332 ▶sub hash_algorithm {
Subroutine hash_algorithm: called CC=4 SCAR=13.9
Pod documented
427 332 my $self = shift;
428 332 my $algorithm = $self->algorithm;
429  
430 return
431 332 ▶ $algorithm eq 'rsa-sha1' ? 'sha1'
Branch: 3 branches
BranchTrueFalseTotal
$algorithm eq 'rsa-sha1' ? : 28 304 332
$algorithm eq 'rsa-sha256' ? : 301 3 304
$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 1459 ▶sub headerlist {
Subroutine headerlist: called CC=6 SCAR=17.9
Pod documented
439 1459 my $self = shift;
440  
441 1459 ▶ (@_)
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->set_tag("h", shift()) 801 658 1459
442 and $self->set_tag( 'h', shift );
443  
444 1459 ▶ my $h = $self->get_tag('h') || '';
Condition100%2/2
$self->get_tag('h') || ''
l!l
687772
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 1459 $h =~ s/\s+:/:/g;
448 1459 $h =~ s/:\s+/:/g;
449 1459 $h = lc $h;
450  
451 1459 ▶ if ( wantarray and $h ) {
Branch: 2 branches
BranchTrueFalseTotal
if (wantarray and $h) { } 332 1127 1459
elsif (wantarray) { } 8 1119 1127
Condition100%3/3
wantarray and $h
!ll&&!rl&&r
11198332
MC/DC100%2/2
wantarray and $h
wantarray $h
Truth table100%3/3
A and B
A= wantarrayB= $h
ABresult
0X0
100
111
452 332 my @list = split /:/, $h;
453 332 @list = map { s/^\s+//; s/\s+$//; $_ } @list; # not s/^\s+|\s+$//g, quadratic
454 332 return @list;
455 }
456 elsif (wantarray) {
457 8 return ();
458 }
459  
460 1119 return $h;
461 }
462  
463  
464 346 ▶sub identity {
Subroutine identity: called CC=4 SCAR=13.9
Pod documented
465 346 my $self = shift;
466  
467 # set new identity if provided
468 346 ▶ (@_)
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->set_tag("i", encode_qp(shift())) 2 344 346
469 and $self->set_tag( 'i', encode_qp(shift) );
470  
471 346 my $i = $self->get_tag('i');
472 346 ▶ if ( defined $i ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $i) { } 250 96 346
473 250 return decode_qp($i);
474 }
475 else {
476 96 ▶ return '@' . ( $self->domain || '' );
Condition50%1/2
$self->domain || ''
l!l
960
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 1171 ▶sub protocol {
Subroutine protocol: called CC=3 SCAR=11.0
Pod documented
519 1171 my $self = shift;
520  
521 1171 ▶ (@_)
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->set_tag("q", shift()) 0 1171 1171
522 and $self->set_tag( 'q', shift );
523  
524 1171 my $q = $self->get_tag('q');
525 1171 ▶ if ( defined $q ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $q) { } 85 1086 1171
526 85 return $q;
527 }
528 else {
529 1086 return 'dns/txt';
530 }
531 }
532  
533  
534 1246 ▶sub result {
Subroutine result: called CC=3 SCAR=11.0
Pod documented
535 1246 my $self = shift;
536 1246 ▶ @_ and $self->{verify_result} = shift;
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->{"verify_result"} = shift() 528 718 1246
537 1246 ▶ @_ and $self->{verify_details} = shift;
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->{"verify_details"} = shift() 524 722 1246
538 1246 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 2573 ▶sub selector {
Subroutine selector: called CC=2 SCAR=6.9
Pod documented
554 2573 my $self = shift;
555  
556 2573 ▶ (@_)
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->set_tag("s", shift()) 1385 1188 2573
557 and $self->set_tag( 's', shift );
558  
559 2573 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 1983 ▶sub version {
Subroutine version: called CC=2 SCAR=6.9
Pod documented
600 1983 my $self = shift;
601  
602 1983 ▶ (@_)
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->set_tag("v", shift()) 199 1784 1983
603 and $self->set_tag( 'v', shift );
604  
605 1983 return $self->get_tag('v');
606 }
607  
608  
609 19 1;
610  
611 __END__
« DKIM/Canonicalization/nowsp.pm ↑ Summary DKIM/PrivateKey.pm »