| 1 | package Archive::BagIt::Role::OpenSSL::Async; | ||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use IO::Async::Loop; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use IO::Async::Stream; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use Net::SSLeay (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | our $VERSION = '0.103'; # VERSION | |||||||||
| 10 | # ABSTRACT: handles asynchronous digest calculation using openssl | ||||||||||
| 11 | |||||||||||
| 12 | # FIXME, needs to be rewritten using futures and filename in calc_digests | ||||||||||
| 13 | |||||||||||
| 14 | 1 | ▶ | sub BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 1 | Net::SSLeay::OpenSSL_add_all_digests(); | |||||||||
| 16 | 1 | is => 'rw', | |||||||||
| 17 | |||||||||||
| 18 | } | ||||||||||
| 19 | |||||||||||
| 20 | 1 | has 'name' => ( | |||||||||
| 21 | required => 1, | ||||||||||
| 22 | is => 'ro', | ||||||||||
| 23 | ); | ||||||||||
| 24 | |||||||||||
| 25 | has '_io_loop' => ( | ||||||||||
| 26 | is => 'ro', | ||||||||||
| 27 | lazy => 1, | ||||||||||
| 28 | 0 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 29 | 0 | IO::Async::Loop->new | |||||||||
| 30 | }, | ||||||||||
| 31 | 1 | ); | |||||||||
| 32 | |||||||||||
| 33 | 1 | has '_digest' => ( | |||||||||
| 34 | is => 'ro', | ||||||||||
| 35 | lazy => 1, | ||||||||||
| 36 | builder => '_init_digest', | ||||||||||
| 37 | init_arg => undef, | ||||||||||
| 38 | ); | ||||||||||
| 39 | |||||||||||
| 40 | 0 | ▶ | sub _init_digest { | ||||||||
|
Subroutine
_init_digest: not called CC=1 SCAR=6.9
| |||||||||||
| 41 | 0 | my ($self) = @_; | |||||||||
| 42 | 0 | my $md = Net::SSLeay::EVP_get_digestbyname($self->name); | |||||||||
| 43 | 0 | my $digest = Net::SSLeay::EVP_MD_CTX_create(); | |||||||||
| 44 | 0 | Net::SSLeay::EVP_DigestInit($digest, $md); | |||||||||
| 45 | 0 | return $digest; | |||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | |||||||||||
| 49 | |||||||||||
| 50 | 0 | ▶ | sub calc_digest { | ||||||||
|
Subroutine
calc_digest: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 51 | 0 | my ($self, $fh, $blksize)=@_; | |||||||||
| 52 | 0 | my $loop = $self->_io_loop(); | |||||||||
| 53 | my $stream = IO::Async::Stream->new( | ||||||||||
| 54 | read_handle => $fh, | ||||||||||
| 55 | read_len => 1000 * $blksize, | ||||||||||
| 56 | 0 | ▶ | on_read => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 57 | 0 | my ($s, $buffref, $eof) = @_; | |||||||||
| 58 | 0 | ▶ | if (defined $$buffref) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 59 | 0 | Net::SSLeay::EVP_DigestUpdate($self->_digest, $$buffref); | |||||||||
| 60 | 0 | $$buffref = undef; | |||||||||
| 61 | } | ||||||||||
| 62 | 0 | return 0; | |||||||||
| 63 | }, | ||||||||||
| 64 | 0 | ▶ | on_read_eof => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 65 | 0 | $loop->stop(); | |||||||||
| 66 | }, | ||||||||||
| 67 | close_on_read_eof => 0, | ||||||||||
| 68 | 0 | ▶ | on_error => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 69 | 0 | croak (@_); | |||||||||
| 70 | } | ||||||||||
| 71 | 0 | ); | |||||||||
| 72 | 0 | $loop->add($stream); | |||||||||
| 73 | 0 | $loop->run(); | |||||||||
| 74 | 0 | $loop->remove($stream); | |||||||||
| 75 | 0 | my $result = Net::SSLeay::EVP_DigestFinal($self->_digest); | |||||||||
| 76 | 0 | Net::SSLeay::EVP_MD_CTX_destroy($self->_digest); | |||||||||
| 77 | 0 | delete $self->{_digest}; | |||||||||
| 78 | 0 | return unpack('H*', $result); | |||||||||
| 79 | } | ||||||||||
| 80 | |||||||||||
| 81 | |||||||||||
| 82 | 1 | ▶ | no Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 83 | 1 | 1; | |||||||||
| 84 | |||||||||||
| 85 | __END__ | ||||||||||