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 7     7   41 use strict;
  7         10  
  7         215  
3 7     7   32 use warnings FATAL => 'all';
  7         12  
  7         287  
4 7     7   35 use Moo;
  7         17  
  7         33  
5 7     7   2038 use namespace::autoclean;
  7         11  
  7         37  
6 7     7   4486 use Net::SSLeay ();
  7         75732  
  7         373  
7             our $VERSION = '0.092'; # VERSION
8             # ABSTRACT: handles synchronous digest calculation using openssl
9              
10             sub BEGIN {
11 7     7   1835 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 549     549   3317 my ($self) = @_;
28 549         1899 my $md = Net::SSLeay::EVP_get_digestbyname($self->name);
29 549         1045 my $digest = Net::SSLeay::EVP_MD_CTX_create();
30 549         2969 Net::SSLeay::EVP_DigestInit($digest, $md);
31 549         2679 return $digest;
32             }
33              
34             sub calc_digest {
35 549     549 0 861 my ($self, $fh, $blksize)=@_;
36 549         536 my $buffer;
37 549         8652 while (read($fh, $buffer, $blksize)) {
38 543         11291 Net::SSLeay::EVP_DigestUpdate($self->_digest(), $buffer);
39             }
40 549         7517 my $result = Net::SSLeay::EVP_DigestFinal($self->_digest);
41 549         10341 Net::SSLeay::EVP_MD_CTX_destroy($self->_digest);
42 549         2997 delete $self->{_digest};
43 549         2523 return unpack('H*', $result);
44             }
45              
46 7     7   50 no Moo;
  7         12  
  7         41  
47             1;
48              
49             __END__