DKIM/Key.pm

filter: Statementstmt 72.7% 24 / 33 Branchbran 50.0% 7 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 62.5% 5 / 8 Podpod 0.0% 0 / 6 totaltotal 59.0% 36 / 61 CC 8 SCAR 12.1
CC
8
Cov
66%
errorstr
6.0
type
6.0
calculate_EM
3.1
CRAP 3.4
« DKIM/Algorithm/dk_rsa_sha1.pm ↑ Summary DKIM/DkSignature.pm »
1 package Mail::DKIM::Key;
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 # ABSTRACT: Represents a DKIM Key
5 20 our $VERSION = '1.20261116'; # VERSION
6  
7 # Copyright 2006 Jason Long. All rights reserved.
8 #
9 # Copyright (c) 2004 Anthony D. Urso. All rights reserved.
10 # This program is free software; you can redistribute it and/or
11 # modify it under the same terms as Perl itself.
12  
13 1493 ▶sub cork {
Subroutine cork: called CC=3 SCAR=11.0
Pod undocumented
14 1493 my $self = shift;
15  
16 (@_)
17 1493 ▶ and $self->{'CORK'} = shift;
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->{"CORK"} = shift() 393 1100 1493
18  
19 1493 ▶ $self->{'CORK'}
Branch: 1 branch
BranchTrueFalseTotal
$self->{"CORK"} or $self->convert 1099 394 1493
20 or $self->convert;
21  
22 1492 $self->{'CORK'};
23 }
24  
25 1152 ▶sub data {
Subroutine data: called CC=2 SCAR=7.1
Pod undocumented
26 1152 my $self = shift;
27  
28 (@_)
29 1152 ▶ and $self->{'DATA'} = shift;
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->{"DATA"} = shift() 0 1152 1152
30  
31 1152 $self->{'DATA'};
32 }
33  
34 0 ▶sub errorstr {
Subroutine errorstr: not called CC=2 SCAR=17.9
Pod undocumented
35 0 my $self = shift;
36  
37 (@_)
38 0 ▶ and $self->{'ESTR'} = shift;
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->{"ESTR"} = shift() 0 0 0
39  
40 0 $self->{'ESTR'};
41 }
42  
43 0 ▶sub size {
Subroutine size: not called CC=1 SCAR=6.9
Pod undocumented
44 0 my $self = shift;
45  
46 0 return $self->cork->size * 8;
47 }
48  
49 0 ▶sub type {
Subroutine type: not called CC=2 SCAR=17.9
Pod undocumented
50 0 my $self = shift;
51  
52 (@_)
53 0 ▶ and $self->{'TYPE'} = shift;
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->{"TYPE"} = shift() 0 0 0
54  
55 0 $self->{'TYPE'};
56 }
57  
58 398 ▶sub calculate_EM {
Subroutine calculate_EM: called CC=3 SCAR=11.3
Pod undocumented
59 398 my ( $digest_algorithm, $digest, $emLen ) = @_;
60  
61 # this function performs DER encoding of the algorithm ID for the
62 # hash function and the hash value itself
63 # It has this syntax:
64 # DigestInfo ::= SEQUENCE {
65 # digestAlgorithm AlgorithmIdentifier,
66 # digest OCTET STRING
67 # }
68  
69 # RFC 3447, page 42, provides the following octet values:
70 398 my %digest_encoding = (
71 'SHA-1' => pack( 'H*', '3021300906052B0E03021A05000414' ),
72 'SHA-256' => pack( 'H*', '3031300d060960864801650304020105000420' ),
73 );
74  
75 398 ▶ defined $digest_encoding{$digest_algorithm}
Branch: 1 branch
BranchTrueFalseTotal
defined $digest_encoding{$digest_algorithm} or die "Unsupported digest algorithm '${digest_algorithm}'" 398 0 398
76 or die "Unsupported digest algorithm '$digest_algorithm'";
77  
78 398 my $T = $digest_encoding{$digest_algorithm} . $digest;
79 398 my $tLen = length($T);
80  
81 398 ▶ if ( $emLen < $tLen + 11 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($emLen < $tLen + 11) 0 398 398
82 0 die 'Intended encoded message length too short.';
83 }
84  
85 398 my $PS = chr(0xff) x ( $emLen - $tLen - 3 );
86 398 my $EM = chr(0) . chr(1) . $PS . chr(0) . $T;
87 398 return $EM;
88 }
89  
90 20 1;
91  
92 __END__
« DKIM/Algorithm/dk_rsa_sha1.pm ↑ Summary DKIM/DkSignature.pm »