X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fp5-File-KDBX;a=blobdiff_plain;f=lib%2FFile%2FKDBX%2FIO%2FHashBlock.pm;h=f4ab8b6fba9ab1e36e66135e4b6275a0716dd13e;hp=adb1cc6f28e60f7fc36c76bbb2328675fabd38c6;hb=37b09e0f2832514b33de4499a83f22d5ffe7c0a3;hpb=8a37f035ef35682b764c34e7b3c61ce03318b1c7 diff --git a/lib/File/KDBX/IO/HashBlock.pm b/lib/File/KDBX/IO/HashBlock.pm index adb1cc6..f4ab8b6 100644 --- a/lib/File/KDBX/IO/HashBlock.pm +++ b/lib/File/KDBX/IO/HashBlock.pm @@ -7,37 +7,17 @@ use strict; use Crypt::Digest qw(digest_data); use Errno; use File::KDBX::Error; -use File::KDBX::Util qw(:io); +use File::KDBX::Util qw(:class :io); use IO::Handle; use namespace::clean; -use parent 'File::KDBX::IO'; +extends 'File::KDBX::IO'; our $VERSION = '999.999'; # VERSION our $ALGORITHM = 'SHA256'; our $BLOCK_SIZE = 1048576; # 1MiB our $ERROR; -=method new - - $fh = File::KDBX::IO::HashBlock->new(%attributes); - $fh = File::KDBX::IO::HashBlock->new($fh, %attributes); - -Construct a new hash-block stream IO handle. - -=cut - -sub new { - my $class = shift; - my %args = @_ % 2 == 1 ? (fh => shift, @_) : @_; - my $self = $class->SUPER::new; - $self->_fh($args{fh}) or throw 'IO handle required'; - $self->algorithm($args{algorithm}); - $self->block_size($args{block_size}); - $self->_buffer; - return $self; -} - =attr algorithm Digest algorithm in hash-blocking the stream (default: C) @@ -50,7 +30,7 @@ Desired block size when writing (default: C<$File::KDBX::IO::HashBlock::BLOCK_SI my %ATTRS = ( _block_index => 0, - _buffer => \(my $buf = ''), + _buffer => sub { \(my $buf = '') }, _finished => 0, algorithm => sub { $ALGORITHM }, block_size => sub { $BLOCK_SIZE }, @@ -64,6 +44,26 @@ while (my ($attr, $default) = each %ATTRS) { }; } +=method new + + $fh = File::KDBX::IO::HashBlock->new(%attributes); + $fh = File::KDBX::IO::HashBlock->new($fh, %attributes); + +Construct a new hash-block stream IO handle. + +=cut + +sub new { + my $class = shift; + my %args = @_ % 2 == 1 ? (fh => shift, @_) : @_; + my $self = $class->SUPER::new; + $self->_fh($args{fh}) or throw 'IO handle required'; + $self->algorithm($args{algorithm}); + $self->block_size($args{block_size}); + $self->_buffer; + return $self; +} + sub _FILL { my ($self, $fh) = @_;