lib/Mail/DKIM2/Digest.pm

filter: Statementstmt 63.1% 48 / 76 Branchbran 37.5% 9 / 24 Conditioncond 42.8% 6 / 14 MC/DCmcdc 37.5% 3 / 8 Subroutinesub 63.1% 12 / 19 Podpod 100% 12 / 12 totaltotal 58.8% 90 / 153 CC 23 SCAR 16.2
CC
23
Cov
55%
openssl_available
9.8
openssl_available
9.8
new
6.5
CRAP 5.1
« lib/Mail/DKIM2/MessageStore.pm ↑ Summary lib/Mail/DKIM2/Util.pm »
1 package Mail::DKIM2::Digest;
2 196 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 196 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 196 our $VERSION = '0.33';
6  
7 196 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 196 ▶use Crypt::Digest::SHA256 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 196 ▶use Crypt::Digest::SHA512 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 # The hashes over message content -- every Message-Instance's header and
12 # body hashes -- are almost all of a verifier's work on a big message.
13 # CryptX's SHA-2 is portable C (about 460 MB/s on an Apple M-series, 150 on
14 # the dkim2.com box); OpenSSL's uses the CPU's SHA instructions where there
15 # are some (3.3 GB/s and 270 MB/s). So OpenSSL's, through Net::SSLeay, when
16 # that is installed (it usually is: IO::Socket::SSL needs it), and CryptX's
17 # otherwise. The digests are the same.
18  
19 196 my %CRYPTX = (
20 sha256 => 'Crypt::Digest::SHA256',
21 sha512 => 'Crypt::Digest::SHA512',
22 );
23  
24 196 my ($OPENSSL, %MD);
25 10085 ▶sub openssl_available {
Subroutine openssl_available: called CC=5 SCAR=22.8
Pod documented
26 0 ▶ $OPENSSL //= eval {
Subroutine openssl_available: not called CC=5 SCAR=22.8
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
eval { do { require Net::SSLeay; &Net::SSLeay::OpenSSL_add_all_digests(); foreach my $alg (keys %CRYPTX) { $MD{$alg} = &Net::SSLeay::EVP_get_digestbyname($alg) or die "no $alg\n"; } ; 1 } } ? : 161 0 161
eval { do { require Net::SSLeay; &Net::SSLeay::OpenSSL_add_all_digests(); foreach my $alg (keys %CRYPTX) { $MD{$alg} = &Net::SSLeay::EVP_get_digestbyname($alg) or die "no $alg\n"; } ; 1 } } ? : 0 0 0
Condition50%2/4
$OPENSSL //= eval { do { require Net::SSLeay; &Net::SSLeay::OpenSSL_add_all_digests(); foreach my $alg (keys %CRYPTX) { $MD{$alg} = &Net::SSLeay::EVP_get_digestbyname($alg) or die "no $alg\n"; } ; 1 } } ? 1 : 0
l!l
9924161
$OPENSSL //= eval { do { require Net::SSLeay; &Net::SSLeay::OpenSSL_add_all_digests(); foreach my $alg (keys %CRYPTX) { $MD{$alg} = &Net::SSLeay::EVP_get_digestbyname($alg) or die "no $alg\n"; } ; 1 } } ? 1 : 0
l!l
00
MC/DC100%1/1
$OPENSSL //= eval { do { require Net::SSLeay; &Net::SSLeay::OpenSSL_add_all_digests(); foreach my $alg (keys %CRYPTX) { $MD{$alg} = &Net::SSLeay::EVP_get_digestbyname($alg) or die "no $alg\n"; } ; 1 } } ? 1 : 0
$OPENSSL
MC/DC0%0/1
$OPENSSL //= eval { do { require Net::SSLeay; &Net::SSLeay::OpenSSL_add_all_digests(); foreach my $alg (keys %CRYPTX) { $MD{$alg} = &Net::SSLeay::EVP_get_digestbyname($alg) or die "no $alg\n"; } ; 1 } } ? 1 : 0
$OPENSSL
Truth table100%2/2
A
A= $OPENSSL
Aresult
11
00
Truth table0%0/2
A
A= $OPENSSL
Aresult
11
00
27 0 require Net::SSLeay;
28 0 Net::SSLeay::OpenSSL_add_all_digests();
29 0 for my $alg (keys %CRYPTX) {
30 0 ▶ $MD{$alg} = Net::SSLeay::EVP_get_digestbyname($alg) or die "no $alg\n";
Branch: 2 branches
BranchTrueFalseTotal
$MD{$alg} = &Net::SSLeay::EVP_get_digestbyname($alg) or die "no $alg\n" 322 0 322
$MD{$alg} = &Net::SSLeay::EVP_get_digestbyname($alg) or die "no $alg\n" 0 0 0
31 }
32 0 1;
33 } ? 1 : 0;
34 0 return $OPENSSL;
35 }
36  
37 # 'openssl' or 'cryptx'; set (local) to choose, as the tests do.
38 196 our $BACKEND;
39  
40 10009 ▶sub backend {
Subroutine backend: called CC=3 SCAR=15.7
Pod documented
41 0 ▶ $BACKEND //= openssl_available() ? 'openssl' : 'cryptx';
Subroutine backend: not called CC=3 SCAR=15.7
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
openssl_available() ? : 161 0 161
openssl_available() ? : 0 0 0
Condition50%2/4
$Mail::DKIM2::Digest::BACKEND //= openssl_available() ? "openssl" : "cryptx"
l!l
9848161
$Mail::DKIM2::Digest::BACKEND //= openssl_available() ? "openssl" : "cryptx"
l!l
00
MC/DC100%1/1
$Mail::DKIM2::Digest::BACKEND //= openssl_available() ? "openssl" : "cryptx"
$Mail::DKIM2::Digest::BACKEND
MC/DC0%0/1
$Mail::DKIM2::Digest::BACKEND //= openssl_available() ? "openssl" : "cryptx"
$Mail::DKIM2::Digest::BACKEND
Truth table100%2/2
A
A= $Mail::DKIM2::Digest::BACKEND
Aresult
11
00
Truth table0%0/2
A
A= $Mail::DKIM2::Digest::BACKEND
Aresult
11
00
42 0 return $BACKEND;
43 }
44  
45 # new($alg): an object with add($data, ...) and digest(), as CryptX's.
46 10008 ▶sub new {
Subroutine new: called CC=4 SCAR=18.7
Pod documented
47 0 ▶ my ($class, $alg) = @_;
Subroutine new: not called CC=4 SCAR=18.7
Pod documented
48 0 ▶ my $cx = $CRYPTX{$alg} or croak "unsupported hash algorithm: $alg";
Branch: 2 branches
BranchTrueFalseTotal
my $cx = $CRYPTX{$alg} or croak("unsupported hash algorithm: $alg") 10006 2 10008
my $cx = $CRYPTX{$alg} or croak("unsupported hash algorithm: $alg") 0 0 0
49 0 ▶ return $cx->new unless backend() eq 'openssl' && openssl_available();
Branch: 2 branches
BranchTrueFalseTotal
unless backend() eq "openssl" and openssl_available() 83 9923 10006
unless backend() eq "openssl" and openssl_available() 0 0 0
Condition33%2/6
backend() eq "openssl" and openssl_available()
!ll&&!rl&&r
8309923
backend() eq "openssl" and openssl_available()
!ll&&!rl&&r
000
MC/DC50%1/2
backend() eq "openssl" and openssl_available()
backend() eq "openssl" openssl_available()
MC/DC0%0/2
backend() eq "openssl" and openssl_available()
backend() eq "openssl" openssl_available()
Truth table66%2/3
A and B
A= backend() eq "openssl"B= openssl_available()
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= backend() eq "openssl"B= openssl_available()
ABresult
0X0
100
111
50 0 my $ctx = Net::SSLeay::EVP_MD_CTX_create();
51 0 Net::SSLeay::EVP_DigestInit($ctx, $MD{$alg});
52 0 return bless \$ctx, $class;
53 }
54  
55 15152 ▶sub add {
Subroutine add: called CC=2 SCAR=9.2
Pod documented
56 0 ▶ my $self = shift;
Subroutine add: not called CC=2 SCAR=9.2
Pod documented
57 0 Net::SSLeay::EVP_DigestUpdate($$self, $_) for @_;
58 0 return $self;
59 }
60  
61 9808 ▶sub digest {
Subroutine digest: called CC=1 SCAR=1.2
Pod documented
62 0 ▶ my ($self) = @_;
Subroutine digest: not called CC=1 SCAR=1.2
Pod documented
63 0 my $d = Net::SSLeay::EVP_DigestFinal($$self);
64 0 Net::SSLeay::EVP_MD_CTX_destroy($$self);
65 0 $$self = undef;
66 0 return $d;
67 }
68  
69 9828 ▶sub DESTROY {
Subroutine DESTROY: called CC=2 SCAR=9.2
70 0 ▶ my ($self) = @_;
Subroutine DESTROY: not called CC=2 SCAR=9.2
71 0 ▶ Net::SSLeay::EVP_MD_CTX_destroy($$self) if $$self;
Branch: 2 branches
BranchTrueFalseTotal
if $$self 25 9803 9828
if $$self 0 0 0
72 }
73  
74 # digest($alg, $data): the raw digest of $data.
75 6430 ▶sub digest_data {
Subroutine digest_data: called CC=1 SCAR=1.2
Pod documented
76 0 ▶ my $d = __PACKAGE__->new($_[0]);
Subroutine digest_data: not called CC=1 SCAR=1.2
Pod documented
77 0 $d->add($_[1]);
78 0 return $d->digest;
79 }
80  
81 196 1;
82  
83 __END__
« lib/Mail/DKIM2/MessageStore.pm ↑ Summary lib/Mail/DKIM2/Util.pm »