DKIM/DkSignature.pm

filter: Statementstmt 91.2% 94 / 103 Branchbran 68.4% 26 / 38 Conditioncond 78.5% 11 / 14 MC/DCmcdc 62.5% 5 / 8 Subroutinesub 75.8% 22 / 29 Podpod 72.7% 16 / 22 totaltotal 81.3% 174 / 214 CC 26 SCAR 10.4
CC
26
Cov
85%
identity_source
6.0
new
5.0
canonicalization
4.1
CRAP 2.8
« DKIM/Key.pm ↑ Summary DKIM/Canonicalization/dk_simple.pm »
1 package Mail::DKIM::DkSignature;
2 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 our $VERSION = '1.20261116'; # VERSION
5 # ABSTRACT: represents a DomainKeys-Signature header
6  
7 # Copyright 2005-2006 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 11 ▶use Mail::DKIM::PublicKey;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 11 ▶use Mail::DKIM::Algorithm::dk_rsa_sha1;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 11 ▶use base 'Mail::DKIM::Signature';
Subroutine BEGIN: called CC=1 SCAR=0.0
18 11 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20  
21 23 ▶sub new {
Subroutine new: called CC=5 SCAR=16.1
Pod documented
22 23 my $type = shift;
23 23 my %prms = @_;
24 23 my $self = {};
25 23 bless $self, $type;
26  
27 23 ▶ $self->algorithm( $prms{'Algorithm'} || 'rsa-sha1' );
Condition100%2/2
$prms{'Algorithm'} || 'rsa-sha1'
l!l
617
MC/DC100%1/1
$prms{'Algorithm'} || 'rsa-sha1'
$prms{'Algorithm'}
Truth table100%2/2
A
A= $prms{'Algorithm'}
Aresult
11
00
28 23 $self->signature( $prms{'Signature'} );
29 23 ▶ $self->canonicalization( $prms{'Method'} || 'simple' );
Condition100%2/2
$prms{'Method'} || 'simple'
l!l
617
MC/DC100%1/1
$prms{'Method'} || 'simple'
$prms{'Method'}
Truth table100%2/2
A
A= $prms{'Method'}
Aresult
11
00
30 23 $self->domain( $prms{'Domain'} );
31 23 $self->headerlist( $prms{'Headers'} );
32 23 ▶ $self->protocol( $prms{'Query'} || 'dns' );
Condition50%1/2
$prms{'Query'} || 'dns'
l!l
023
MC/DC0%0/1
$prms{'Query'} || 'dns'
$prms{'Query'}
Truth table50%1/2
A
A= $prms{'Query'}
Aresult
11
00
33 23 $self->selector( $prms{'Selector'} );
34 23 ▶ $self->key( $prms{'Key'} ) if defined $prms{'Key'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $prms{"Key"} 0 23 23
35  
36 23 return $self;
37 }
38  
39  
40 17 ▶sub parse {
Subroutine parse: called CC=3 SCAR=11.1
Pod documented
41 17 my $class = shift;
42 17 ▶ croak 'wrong number of arguments' unless ( @_ == 1 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 1 0 17 17
43 17 my ($string) = @_;
44  
45 # remove line terminator, if present
46 17 $string =~ s/\015\012\z//;
47  
48 # remove field name, if present
49 17 my $prefix;
50 17 ▶ if ( $string =~ /^(domainkey-signature:)(.*)/si ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /^(domainkey-signature:)(.*)/is) 17 0 17
51  
52 # save the field name (capitalization), so that it can be
53 # restored later
54 17 $prefix = $1;
55 17 $string = $2;
56 }
57  
58 17 my $self = $class->Mail::DKIM::KeyValueList::parse($string);
59 17 $self->{prefix} = $prefix;
60  
61 17 return $self;
62 }
63  
64  
65  
66 0 ▶sub as_string_without_data {
Subroutine as_string_without_data: not called CC=1 SCAR=6.9
Pod documented
67 0 croak 'as_string_without_data not implemented';
68 }
69  
70 0 ▶sub body_count {
Subroutine body_count: not called CC=1 SCAR=6.9
Pod documented
71 0 croak 'body_count not implemented';
72 }
73  
74 0 ▶sub body_hash {
Subroutine body_hash: not called CC=1 SCAR=6.9
Pod documented
75 0 croak 'body_hash not implemented';
76 }
77  
78  
79 91 ▶sub algorithm {
Subroutine algorithm: called CC=4 SCAR=13.9
Pod documented
80 91 my $self = shift;
81  
82 91 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 23 68 91
83 23 $self->set_tag( 'a', shift );
84 }
85  
86 91 my $a = $self->get_tag('a');
87 91 ▶ return defined $a && $a ne '' ? lc $a : 'rsa-sha1';
Branch: 1 branch
BranchTrueFalseTotal
defined $a && $a ne '' ? : 87 4 91
Condition66%2/3
defined $a and $a ne ""
!ll&&!rl&&r
4087
MC/DC50%1/2
defined $a and $a ne ""
defined $a $a ne ""
Truth table66%2/3
A and B
A= defined $aB= $a ne ""
ABresult
0X0
100
111
88 }
89  
90  
91 61 ▶sub canonicalization {
Subroutine canonicalization: called CC=4 SCAR=14.1
Pod documented
92 61 my $self = shift;
93 61 ▶ croak 'too many arguments' if ( @_ > 1 );
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 1 0 61 61
94  
95 61 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 23 38 61
96 23 $self->set_tag( 'c', shift );
97 }
98  
99 61 ▶ return lc( $self->get_tag('c') ) || 'simple';
Condition50%1/2
lc $self->get_tag('c') || 'simple'
l!l
610
MC/DC0%0/1
lc $self->get_tag('c') || 'simple'
lc $self->get_tag('c')
Truth table50%1/2
A
A= lc $self->get_tag('c')
Aresult
11
00
100 }
101  
102 22 ▶sub DEFAULT_PREFIX {
Subroutine DEFAULT_PREFIX: called CC=1 SCAR=0.0
Pod undocumented
103 22 return 'DomainKey-Signature:';
104 }
105  
106  
107 83 ▶sub domain {
Subroutine domain: called CC=3 SCAR=11.0
Pod documented
108 83 my $self = shift;
109  
110 83 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 23 60 83
111 23 $self->set_tag( 'd', shift );
112 }
113  
114 83 my $d = $self->get_tag('d');
115 83 ▶ return defined $d ? lc $d : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $d ? : 66 17 83
116 }
117  
118 15 ▶sub expiration {
Subroutine expiration: called CC=2 SCAR=7.1
Pod documented
119 15 my $self = shift;
120 15 ▶ croak 'cannot change expiration on ' . ref($self) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 15 15
121 15 return undef;
122 }
123  
124 11 ▶use MIME::Base64;
Subroutine BEGIN: called CC=1 SCAR=0.0
125  
126 17 ▶sub check_canonicalization {
Subroutine check_canonicalization: called CC=2 SCAR=7.0
Pod undocumented
127 17 my $self = shift;
128  
129 17 my $c = $self->canonicalization;
130  
131 17 my @known = ( 'nofws', 'simple' );
132 17 ▶ return unless ( grep { $_ eq $c } @known );
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $c;} @known 0 17 17
133 17 return 1;
134 }
135  
136 # Returns a filtered list of protocols that can be used to fetch the
137 # public key corresponding to this signature. An empty list means that
138 # all designated protocols are unrecognized.
139 # Note: at this time, the only recognized protocol for DomainKey
140 # signatures is "dns".
141 #
142 32 ▶sub check_protocol {
Subroutine check_protocol: called CC=3 SCAR=11.0
Pod undocumented
143 32 my $self = shift;
144  
145 32 my $protocol = $self->protocol;
146 32 ▶ return 'dns/txt' if $protocol && $protocol eq 'dns';
Branch: 1 branch
BranchTrueFalseTotal
if $protocol and $protocol eq "dns" 30 2 32
Condition100%3/3
$protocol and $protocol eq "dns"
!ll&&!rl&&r
1130
MC/DC100%2/2
$protocol and $protocol eq "dns"
$protocol $protocol eq "dns"
Truth table100%3/3
A and B
A= $protocolB= $protocol eq "dns"
ABresult
0X0
100
111
147 2 return;
148 }
149  
150 17 ▶sub check_version {
Subroutine check_version: called CC=1 SCAR=0.0
Pod undocumented
151  
152 #DomainKeys doesn't have a v= tag
153 17 return 1;
154 }
155  
156 38 ▶sub get_algorithm_class {
Subroutine get_algorithm_class: called CC=3 SCAR=11.3
Pod undocumented
157 38 my $self = shift;
158 38 ▶ croak 'wrong number of arguments' unless ( @_ == 1 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 1 0 38 38
159 38 my ($algorithm) = @_;
160  
161 38 ▶ my $class =
Branch: 1 branch
BranchTrueFalseTotal
$algorithm eq 'rsa-sha1' ? : 38 0 38
162 $algorithm eq 'rsa-sha1'
163 ? 'Mail::DKIM::Algorithm::dk_rsa_sha1'
164 : undef;
165 38 return $class;
166 }
167  
168 # get_public_key - same as parent class
169  
170 13 ▶sub hash_algorithm {
Subroutine hash_algorithm: called CC=2 SCAR=7.1
Pod documented
171 13 my $self = shift;
172 13 my $algorithm = $self->algorithm;
173  
174 13 ▶ return $algorithm eq 'rsa-sha1' ? 'sha1' : undef;
Branch: 1 branch
BranchTrueFalseTotal
$algorithm eq 'rsa-sha1' ? : 13 0 13
175 }
176  
177  
178 #sub headerlist
179 # is in Signature.pm
180  
181  
182 28 ▶sub identity {
Subroutine identity: called CC=2 SCAR=7.1
Pod documented
183 28 my $self = shift;
184 28 ▶ croak 'cannot change identity on ' . ref($self) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 28 28
185 28 return $self->{dk_identity};
186 }
187  
188  
189 0 ▶sub identity_source {
Subroutine identity_source: not called CC=2 SCAR=17.9
Pod documented
190 0 my $self = shift;
191 0 ▶ croak 'unexpected argument' if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
192 0 return $self->{dk_identity_source};
193 }
194  
195 # init_identity() - initialize the DomainKeys concept of identity
196 #
197 # The signing identity of a DomainKeys signature is the sender
198 # of the message itself, i.e. the address in the Sender/From header.
199 # The sender may not be known when the signature object is
200 # constructed (since the signature usually precedes the From/Sender
201 # header), so use this method when you have the From/Sender value.
202 # See also finish_header() in Mail::DKIM::Verifier.
203 #
204 21 ▶sub init_identity {
Subroutine init_identity: called CC=1 SCAR=0.0
Pod undocumented
205 21 my $self = shift;
206 21 $self->{dk_identity} = shift;
207 21 $self->{dk_identity_source} = shift;
208 }
209  
210 0 ▶sub method {
Subroutine method: not called CC=1 SCAR=6.9
Pod documented
211 0 croak 'method not implemented (use canonicalization instead)';
212 }
213  
214  
215 59 ▶sub protocol {
Subroutine protocol: called CC=3 SCAR=11.0
Pod documented
216 59 my $self = shift;
217  
218 59 ▶ (@_)
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->set_tag("q", shift()) 23 36 59
219 and $self->set_tag( 'q', shift );
220  
221 # although draft-delany-domainkeys-base-06 does mandate presence of a
222 # q=dns tag, it is quote common that q tag is missing - be merciful
223 59 ▶ return !defined( $self->get_tag('q') ) ? 'dns' : lc $self->get_tag('q');
Branch: 1 branch
BranchTrueFalseTotal
!defined($self->get_tag('q')) ? : 2 57 59
224 }
225  
226  
227 # same as parent class
228  
229  
230 # same as parent class
231  
232 0 ▶sub timestamp {
Subroutine timestamp: not called CC=1 SCAR=6.9
Pod documented
233 0 croak 'timestamp not implemented';
234 }
235  
236 0 ▶sub version {
Subroutine version: not called CC=1 SCAR=6.9
Pod documented
237 0 croak 'version not implemented';
238 }
239  
240  
241 11 1;
242  
243 __END__
« DKIM/Key.pm ↑ Summary DKIM/Canonicalization/dk_simple.pm »