File Coverage

blib/lib/Archive/BagIt/Role/OpenSSL/Sync.pm
Criterion Covered Total %
statement 19 32 59.3
branch n/a
condition n/a
subroutine 7 9 77.7
pod 0 1 0.0
total 26 42 61.9


line stmt bran cond sub pod time code
1             package Archive::BagIt::Role::OpenSSL::Sync;
2 1     1   165272 use strict;
  1         2  
  1         43  
3 1     1   5 use warnings FATAL => 'all';
  1         2  
  1         79  
4 1     1   569 use Moo;
  1         8907  
  1         6  
5 1     1   1922 use namespace::autoclean;
  1         18447  
  1         4  
6 1     1   713 use Net::SSLeay ();
  1         13968  
  1         96  
7             our $VERSION = '0.101'; # VERSION
8             # ABSTRACT: handles synchronous digest calculation using openssl
9              
10             sub BEGIN {
11 1     1   408 Net::SSLeay::OpenSSL_add_all_digests();
12             }
13              
14             has 'name' => (
15             required => 1,
16             is => 'ro',
17             );
18              
19             has '_digest' => (
20             is => 'ro',
21             lazy => 1,
22             builder => '_init_digest',
23             init_arg => undef,
24             );
25              
26             sub _init_digest {
27 0     0     my ($self) = @_;
28 0           my $md = Net::SSLeay::EVP_get_digestbyname($self->name);
29 0           my $digest = Net::SSLeay::EVP_MD_CTX_create();
30 0           Net::SSLeay::EVP_DigestInit($digest, $md);
31 0           return $digest;
32             }
33              
34             sub calc_digest {
35 0     0 0   my ($self, $fh, $blksize)=@_;
36 0           my $buffer;
37 0           while (read($fh, $buffer, $blksize)) {
38 0           Net::SSLeay::EVP_DigestUpdate($self->_digest(), $buffer);
39             }
40 0           my $result = Net::SSLeay::EVP_DigestFinal($self->_digest);
41 0           Net::SSLeay::EVP_MD_CTX_destroy($self->_digest);
42 0           delete $self->{_digest};
43 0           return unpack('H*', $result);
44             }
45              
46 1     1   13 no Moo;
  1         1  
  1         10  
47             1;
48              
49             __END__