DKIM/Canonicalization/relaxed.pm

filter: Statementstmt 86.3% 38 / 44 Branchbran 50.0% 5 / 10 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 3 totaltotal 73.9% 51 / 69 CC 7 SCAR 13.2
CC
7
Cov
77%
canonicalize_body
6.9
canonicalize_header
3.0
BEGIN
1.0
CRAP 3.7
« DKIM/Canonicalization/DkimCommon.pm ↑ Summary DKIM/Algorithm/dk_rsa_sha1.pm »
1 package Mail::DKIM::Canonicalization::relaxed;
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: common canonicalization
6  
7 # Copyright 2005 Messiah College. All rights reserved.
8 # Jason Long <jlong@messiah.edu>
9  
10 # This program is free software; you can redistribute it and/or
11 # modify it under the same terms as Perl itself.
12  
13 20 ▶use base 'Mail::DKIM::Canonicalization::DkimCommon';
Subroutine BEGIN: called CC=1 SCAR=0.0
14 20 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1136 ▶sub init {
Subroutine init: called CC=1 SCAR=0.0
Pod undocumented
17 1136 my $self = shift;
18 1136 $self->SUPER::init;
19  
20 1136 $self->{canonicalize_body_empty_lines} = 0;
21 }
22  
23 5916 ▶sub canonicalize_header {
Subroutine canonicalize_header: called CC=3 SCAR=11.1
Pod undocumented
24 5916 my $self = shift;
25 5916 ▶ croak 'wrong number of parameters' unless ( @_ == 1 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 1 0 5916 5916
26 5916 my ($line) = @_;
27  
28 #
29 # step 1: convert all header field names (not the header field values)
30 # to lower case
31 #
32 5916 ▶ if ( $line =~ /^([^:]+):(.*)/s ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^([^:]+):(.*)/s) 5916 0 5916
33  
34 # lowercase field name
35 5916 $line = lc($1) . ":$2";
36 }
37  
38 #
39 # step 2: unwrap all header field continuation lines... i.e.
40 # remove any CRLF sequences that are followed by WSP
41 #
42 5916 $line =~ s/\015\012(\s)/$1/g;
43  
44 #
45 # step 3: convert all sequences of one or more WSP characters to
46 # a single SP character
47 #
48 5916 $line =~ s/[ \t]+/ /g;
49  
50 #
51 # step 4: delete all WSP characters at the end of the header field value
52 #
53 5916 $line =~ s/ \z//s;
54  
55 #
56 # step 5: delete any WSP character remaining before and after the colon
57 # separating the header field name from the header field value
58 #
59 5916 $line =~ s/^([^:\s]+)\s*:\s*/$1:/;
60  
61 5916 return $line;
62 }
63  
64 274 ▶sub canonicalize_body {
Subroutine canonicalize_body: called CC=5 SCAR=19.3
Pod undocumented
65 274 my ($self, $multiline) = @_;
66  
67 274 $multiline =~ s/\015\012\z//s;
68  
69 #
70 # step 1: reduce all sequences of WSP within a line to a single
71 # SP character
72 #
73 274 $multiline =~ s/[ \t]+/ /g;
74  
75 #
76 # step 2: ignore all white space at the end of lines
77 #
78 274 $multiline =~ s/[ \t]+(?=\015\012|\z)//g;
79  
80 274 $multiline .= "\015\012";
81  
82 #
83 # step 3: ignore empty lines at the end of the message body
84 # (i.e. do not emit empty lines until a following nonempty line
85 # is found)
86 #
87  
88 274 my $empty_lines = $self->{canonicalize_body_empty_lines};
89  
90 274 ▶ if ( $multiline =~ s/^((?:\015\012)+)// )
Branch: 1 branch
BranchTrueFalseTotal
if ($multiline =~ s/^((?:\015\012)+)//) 0 274 274
91 { # count & strip leading empty lines
92 0 $empty_lines += length($1) / 2;
93 }
94  
95 274 ▶ if ( $empty_lines > 0 && length($multiline) > 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($empty_lines > 0 and length $multiline > 0) 0 274 274
Condition33%1/3
$empty_lines > 0 and length $multiline > 0
!ll&&!rl&&r
27400
MC/DC0%0/2
$empty_lines > 0 and length $multiline > 0
$empty_lines > 0 length $multiline > 0
Truth table33%1/3
A and B
A= $empty_lines > 0B= length $multiline > 0
ABresult
0X0
100
111
96 { # re-insert leading white if any nonempty lines exist
97 0 $multiline = ( "\015\012" x $empty_lines ) . $multiline;
98 0 $empty_lines = 0;
99 }
100  
101 274 ▶ while ( $multiline =~ /\015\012\015\012\z/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($multiline =~ /\015\012\015\012\z/) 0 274 274
102 { # count & strip trailing empty lines
103 0 chop $multiline;
104 0 chop $multiline;
105 0 $empty_lines++;
106 }
107  
108 274 $self->{canonicalize_body_empty_lines} = $empty_lines;
109 274 return $multiline;
110 }
111  
112 20 1;
113  
114 __END__
« DKIM/Canonicalization/DkimCommon.pm ↑ Summary DKIM/Algorithm/dk_rsa_sha1.pm »