File Coverage

lib/Archive/BagIt/Role/OpenSSL/Sync.pm
Criterion Covered Total %
statement 32 32 100.0
branch n/a
condition n/a
subroutine 9 9 100.0
pod 0 1 0.0
total 41 42 97.6


line stmt bran cond sub pod time code
1             package Archive::BagIt::Role::OpenSSL::Sync;
2 8     8   47 use strict;
  8         16  
  8         251  
3 8     8   36 use warnings FATAL => 'all';
  8         18  
  8         320  
4 8     8   43 use Moo;
  8         12  
  8         43  
5 8     8   2370 use namespace::autoclean;
  8         14  
  8         57  
6 8     8   5026 use Net::SSLeay ();
  8         90913  
  8         605  
7             our $VERSION = '0.094'; # VERSION
8             # ABSTRACT: handles synchronous digest calculation using openssl
9              
10             sub BEGIN {
11 8     8   2266 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 550     550   3663 my ($self) = @_;
28 550         2471 my $md = Net::SSLeay::EVP_get_digestbyname($self->name);
29 550         1187 my $digest = Net::SSLeay::EVP_MD_CTX_create();
30 550         1914 Net::SSLeay::EVP_DigestInit($digest, $md);
31 550         3209 return $digest;
32             }
33              
34             sub calc_digest {
35 550     550 0 967 my ($self, $fh, $blksize)=@_;
36 550         574 my $buffer;
37 550         9995 while (read($fh, $buffer, $blksize)) {
38 544         11246 Net::SSLeay::EVP_DigestUpdate($self->_digest(), $buffer);
39             }
40 550         7920 my $result = Net::SSLeay::EVP_DigestFinal($self->_digest);
41 550         11250 Net::SSLeay::EVP_MD_CTX_destroy($self->_digest);
42 550         3322 delete $self->{_digest};
43 550         2744 return unpack('H*', $result);
44             }
45              
46 8     8   72 no Moo;
  8         14  
  8         59  
47             1;
48              
49             __END__