DKIM/Canonicalization/simple.pm

filter: Statementstmt 95.0% 38 / 40 Branchbran 83.3% 10 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 4 totaltotal 87.5% 56 / 64 CC 7 SCAR 10.1
CC
7
Cov
92%
canonicalize_body
5.0
canonicalize_header
2.0
finish_body
2.0
CRAP 2.7
« DKIM/Algorithm/Base.pm ↑ Summary DKIM/Algorithm/ed25519_sha256.pm »
1 package Mail::DKIM::Canonicalization::simple;
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: simple 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 121 ▶sub init {
Subroutine init: called CC=1 SCAR=0.0
Pod undocumented
17 121 my $self = shift;
18 121 $self->SUPER::init;
19  
20 121 $self->{canonicalize_body_empty_lines} = 0;
21 }
22  
23 282 ▶sub canonicalize_header {
Subroutine canonicalize_header: called CC=2 SCAR=7.0
Pod undocumented
24 282 my $self = shift;
25 282 ▶ croak 'wrong number of parameters' unless ( @_ == 1 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 1 0 282 282
26 282 my ($line) = @_;
27  
28 #
29 # draft-allman-dkim-base-01.txt, section 3.4.1:
30 # the "simple" header field canonicalization algorithm does not
31 # change the header field in any way
32 #
33  
34 282 return $line;
35 }
36  
37 74 ▶sub canonicalize_body {
Subroutine canonicalize_body: called CC=5 SCAR=16.2
Pod undocumented
38 74 my $self = shift;
39 74 my ($multiline) = @_;
40  
41 #
42 # draft-allman-dkim-base-01.txt, section 3.4.3:
43 # the "simple" body canonicalization algorithm ignores all
44 # empty lines at the end of the message body
45 #
46  
47 #
48 # (i.e. do not emit empty lines until a following nonempty line
49 # is found)
50 #
51 74 my $empty_lines = $self->{canonicalize_body_empty_lines};
52  
53 74 ▶ if ( $multiline =~ s/^((?:\015\012)+)// )
Branch: 1 branch
BranchTrueFalseTotal
if ($multiline =~ s/^((?:\015\012)+)//) 1 73 74
54 { # count & strip leading empty lines
55 1 $empty_lines += length($1) / 2;
56 }
57  
58 74 ▶ if ( length($multiline) > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $multiline > 0) 73 1 74
59 73 $self->{canonicalize_body_started} = 1;
60 73 ▶ if ( $empty_lines > 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($empty_lines > 0) 0 73 73
61 { # re-insert leading white if any nonempty lines exist
62 0 $multiline = ( "\015\012" x $empty_lines ) . $multiline;
63 0 $empty_lines = 0;
64 }
65 }
66  
67 74 ▶ while ( $multiline =~ /\015\012\015\012\z/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($multiline =~ /\015\012\015\012\z/) 50126 74 50200
68 { # count & strip trailing empty lines
69 50126 chop $multiline;
70 50126 chop $multiline;
71 50126 $empty_lines++;
72 }
73  
74 74 $self->{canonicalize_body_empty_lines} = $empty_lines;
75 74 return $multiline;
76 }
77  
78 77 ▶sub finish_body {
Subroutine finish_body: called CC=2 SCAR=6.9
Pod undocumented
79 77 my $self = shift;
80 $self->{canonicalize_body_started}
81 77 ▶ or $self->output("\015\012");
Branch: 1 branch
BranchTrueFalseTotal
$self->{"canonicalize_body_started"} or $self->output("\r\n") 72 5 77
82 77 $self->SUPER::finish_body;
83 }
84  
85 20 1;
86  
87 __END__
« DKIM/Algorithm/Base.pm ↑ Summary DKIM/Algorithm/ed25519_sha256.pm »