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 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: 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 15 ▶use base 'Mail::DKIM::Canonicalization::DkimCommon';
Subroutine BEGIN: called CC=1 SCAR=0.0
14 15 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 120 ▶sub init {
Subroutine init: called CC=1 SCAR=0.0
Pod undocumented
17 120 my $self = shift;
18 120 $self->SUPER::init;
19  
20 120 $self->{canonicalize_body_empty_lines} = 0;
21 }
22  
23 275 ▶sub canonicalize_header {
Subroutine canonicalize_header: called CC=2 SCAR=7.0
Pod undocumented
24 275 my $self = shift;
25 275 ▶ croak 'wrong number of parameters' unless ( @_ == 1 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 1 0 275 275
26 275 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 275 return $line;
35 }
36  
37 75 ▶sub canonicalize_body {
Subroutine canonicalize_body: called CC=5 SCAR=16.2
Pod undocumented
38 75 my $self = shift;
39 75 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 75 my $empty_lines = $self->{canonicalize_body_empty_lines};
52  
53 75 ▶ if ( $multiline =~ s/^((?:\015\012)+)// )
Branch: 1 branch
BranchTrueFalseTotal
if ($multiline =~ s/^((?:\015\012)+)//) 1 74 75
54 { # count & strip leading empty lines
55 1 $empty_lines += length($1) / 2;
56 }
57  
58 75 ▶ if ( length($multiline) > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $multiline > 0) 74 1 75
59 74 $self->{canonicalize_body_started} = 1;
60 74 ▶ if ( $empty_lines > 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($empty_lines > 0) 0 74 74
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 75 ▶ while ( $multiline =~ /\015\012\015\012\z/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($multiline =~ /\015\012\015\012\z/) 50126 75 50201
68 { # count & strip trailing empty lines
69 50126 chop $multiline;
70 50126 chop $multiline;
71 50126 $empty_lines++;
72 }
73  
74 75 $self->{canonicalize_body_empty_lines} = $empty_lines;
75 75 return $multiline;
76 }
77  
78 78 ▶sub finish_body {
Subroutine finish_body: called CC=2 SCAR=6.9
Pod undocumented
79 78 my $self = shift;
80 $self->{canonicalize_body_started}
81 78 ▶ or $self->output("\015\012");
Branch: 1 branch
BranchTrueFalseTotal
$self->{"canonicalize_body_started"} or $self->output("\r\n") 73 5 78
82 78 $self->SUPER::finish_body;
83 }
84  
85 15 1;
86  
87 __END__
« DKIM/Algorithm/Base.pm ↑ Summary DKIM/Algorithm/ed25519_sha256.pm »