blib/lib/Net/DNS/SEC/Digest.pm

filter: Statementstmt 90.4% 38 / 42 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 78.9% 15 / 19 Podpod 100% 3 / 3 totaltotal 87.5% 56 / 64 CC 1 SCAR 1.9
CC
1
Cov
90%
__ANON__
2.0
__ANON__
2.0
__ANON__
2.0
CRAP 1.2
« blib/lib/Net/DNS/SEC.pm ↑ Summary SEC.xs »
1 package Net::DNS::SEC::Digest;
2  
3 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 10 our $VERSION = (qw$Id: Digest.pm 2002 2025-01-07 09:57:46Z willem $)[2];
7  
8  
9 =head1 NAME
10  
11 Net::DNS::SEC::Digest - Message Digest Algorithms
12  
13  
14 =head1 SYNOPSIS
15  
16 require Net::DNS::SEC::Digest;
17  
18 $object = Net::DNS::SEC::Digest::SHA->new(256);
19 $object->add($text);
20 $object->add($more);
21 $digest = $object->digest;
22  
23  
24 =head1 DESCRIPTION
25  
26 Interface package providing access to the message digest algorithm
27 implementations within the OpenSSL libcrypto library.
28  
29 =cut
30  
31  
32 10 ▶use constant libcrypto_available => Net::DNS::SEC::libcrypto->can('EVP_MD_CTX_new');
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 10 ▶BEGIN { die 'Net::DNS::SEC not available' unless libcrypto_available }
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36  
37 my %digest = (
38 2 ▶ MD5 => sub { Net::DNS::SEC::libcrypto::EVP_md5() },
Subroutine __ANON__: called CC=1 SCAR=0.0
39  
40 2 ▶ SHA_1 => sub { Net::DNS::SEC::libcrypto::EVP_sha1() },
Subroutine __ANON__: called CC=1 SCAR=0.0
41 2 ▶ SHA_224 => sub { Net::DNS::SEC::libcrypto::EVP_sha224() },
Subroutine __ANON__: called CC=1 SCAR=0.0
42 2 ▶ SHA_256 => sub { Net::DNS::SEC::libcrypto::EVP_sha256() },
Subroutine __ANON__: called CC=1 SCAR=0.0
43 2 ▶ SHA_384 => sub { Net::DNS::SEC::libcrypto::EVP_sha384() },
Subroutine __ANON__: called CC=1 SCAR=0.0
44 2 ▶ SHA_512 => sub { Net::DNS::SEC::libcrypto::EVP_sha512() },
Subroutine __ANON__: called CC=1 SCAR=0.0
45  
46 0 ▶ SHA3_224 => sub { Net::DNS::SEC::libcrypto::EVP_sha3_224() },
Subroutine __ANON__: not called CC=1 SCAR=6.9
47 0 ▶ SHA3_256 => sub { Net::DNS::SEC::libcrypto::EVP_sha3_256() },
Subroutine __ANON__: not called CC=1 SCAR=6.9
48 0 ▶ SHA3_384 => sub { Net::DNS::SEC::libcrypto::EVP_sha3_384() },
Subroutine __ANON__: not called CC=1 SCAR=6.9
49 0 ▶ SHA3_512 => sub { Net::DNS::SEC::libcrypto::EVP_sha3_512() },
Subroutine __ANON__: not called CC=1 SCAR=6.9
50  
51 1 ▶ SM3 => sub { Net::DNS::SEC::libcrypto::EVP_sm3() },
Subroutine __ANON__: called CC=1 SCAR=0.0
52 10 );
53  
54  
55 7 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
56 7 my ( $class, @param ) = @_;
57 7 my ($index) = reverse split '::', join '_', $class, @param;
58 7 my $evpmd = $digest{$index};
59 7 my $mdctx = Net::DNS::SEC::libcrypto::EVP_MD_CTX_new();
60 7 Net::DNS::SEC::libcrypto::EVP_DigestInit( $mdctx, &$evpmd );
61 6 return bless( {ctx => $mdctx, md => &$evpmd}, $class );
62 }
63  
64 18 ▶sub add {
Subroutine add: called CC=1 SCAR=0.0
Pod documented
65 18 my $self = shift;
66 18 return Net::DNS::SEC::libcrypto::EVP_DigestUpdate( $self->{ctx}, shift );
67 }
68  
69 12 ▶sub digest {
Subroutine digest: called CC=1 SCAR=0.0
Pod documented
70 12 my $self = shift;
71 12 my $dgst = Net::DNS::SEC::libcrypto::EVP_DigestFinal( $self->{ctx} );
72  
73 # reinitialise; emulate API offered by Digest::SHA
74 12 Net::DNS::SEC::libcrypto::EVP_DigestInit( $self->{ctx}, $self->{md} );
75 12 return $dgst;
76 }
77  
78 6 ▶DESTROY {
Subroutine DESTROY: called CC=1 SCAR=0.0
79 6 my $self = shift;
80 6 return Net::DNS::SEC::libcrypto::EVP_MD_CTX_free( $self->{ctx} );
81 }
82  
83  
84 ## no critic ProhibitMultiplePackages
85 package Net::DNS::SEC::Digest::MD5;
86 10 our @ISA = qw(Net::DNS::SEC::Digest);
87  
88 package Net::DNS::SEC::Digest::SHA;
89 10 our @ISA = qw(Net::DNS::SEC::Digest);
90  
91 package Net::DNS::SEC::Digest::SHA3;
92 10 our @ISA = qw(Net::DNS::SEC::Digest);
93  
94 package Net::DNS::SEC::Digest::SM3;
95 10 our @ISA = qw(Net::DNS::SEC::Digest);
96  
97  
98 10 1;
99  
100 __END__
« blib/lib/Net/DNS/SEC.pm ↑ Summary SEC.xs »