X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fp5-File-KDBX;a=blobdiff_plain;f=lib%2FFile%2FKDBX%2FIO%2FHmacBlock.pm;h=50f054ba2d09fb810deb49cbbdad7b7520f164ac;hp=ac07e7e474bb6f5688feee516f2042c03daab7eb;hb=37b09e0f2832514b33de4499a83f22d5ffe7c0a3;hpb=8a37f035ef35682b764c34e7b3c61ce03318b1c7 diff --git a/lib/File/KDBX/IO/HmacBlock.pm b/lib/File/KDBX/IO/HmacBlock.pm index ac07e7e..50f054b 100644 --- a/lib/File/KDBX/IO/HmacBlock.pm +++ b/lib/File/KDBX/IO/HmacBlock.pm @@ -8,37 +8,15 @@ use Crypt::Digest qw(digest_data); use Crypt::Mac::HMAC qw(hmac); use Errno; use File::KDBX::Error; -use File::KDBX::Util qw(:io assert_64bit); +use File::KDBX::Util qw(:class :io assert_64bit); use namespace::clean; -use parent 'File::KDBX::IO'; +extends 'File::KDBX::IO'; our $VERSION = '999.999'; # VERSION our $BLOCK_SIZE = 1048576; # 1MiB our $ERROR; -=method new - - $fh = File::KDBX::IO::HmacBlock->new(%attributes); - $fh = File::KDBX::IO::HmacBlock->new($fh, %attributes); - -Construct a new HMAC-block stream IO handle. - -=cut - -sub new { - assert_64bit; - - my $class = shift; - my %args = @_ % 2 == 1 ? (fh => shift, @_) : @_; - my $self = $class->SUPER::new; - $self->_fh($args{fh}) or throw 'IO handle required'; - $self->key($args{key}) or throw 'Key required'; - $self->block_size($args{block_size}); - $self->_buffer; - return $self; -} - =attr block_size Desired block size when writing (default: C<$File::KDBX::IO::HmacBlock::BLOCK_SIZE> or 1,048,576 bytes) @@ -51,7 +29,7 @@ HMAC-SHA256 key for authenticating the data stream (required) my %ATTRS = ( _block_index => 0, - _buffer => \(my $buf = ''), + _buffer => sub { \(my $buf = '') }, _finished => 0, block_size => sub { $BLOCK_SIZE }, key => undef, @@ -65,6 +43,28 @@ while (my ($attr, $default) = each %ATTRS) { }; } +=method new + + $fh = File::KDBX::IO::HmacBlock->new(%attributes); + $fh = File::KDBX::IO::HmacBlock->new($fh, %attributes); + +Construct a new HMAC-block stream IO handle. + +=cut + +sub new { + assert_64bit; + + my $class = shift; + my %args = @_ % 2 == 1 ? (fh => shift, @_) : @_; + my $self = $class->SUPER::new; + $self->_fh($args{fh}) or throw 'IO handle required'; + $self->key($args{key}) or throw 'Key required'; + $self->block_size($args{block_size}); + $self->_buffer; + return $self; +} + sub _FILL { my ($self, $fh) = @_;