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 :int :io);
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)
=cut
my %ATTRS = (
- _block_index => 0,
- _buffer => \(my $buf = ''),
+ _block_index => int64(0),
+ _buffer => sub { \(my $buf = '') },
_finished => 0,
block_size => sub { $BLOCK_SIZE },
key => undef,
};
}
+=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 {
+ 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) = @_;
or throw 'Failed to read HMAC block', index => $self->_block_index, size => $size;
}
- my $packed_index = pack('Q<', $self->_block_index);
+ my $packed_index = pack_Ql($self->_block_index);
my $got_hmac = hmac('SHA256', $self->_hmac_key,
$packed_index,
$packed_size,
my $block = '';
$block = substr($$buffer, 0, $size, '') if 0 < $size;
- my $packed_index = pack('Q<', $self->_block_index);
+ my $packed_index = pack_Ql($self->_block_index);
my $packed_size = pack('L<', $size);
my $hmac = hmac('SHA256', $self->_hmac_key,
$packed_index,
my $key = shift // $self->key;
my $index = shift // $self->_block_index;
- my $packed_index = pack('Q<', $index);
+ my $packed_index = pack_Ql($index);
my $hmac_key = digest_data('SHA512', $packed_index, $key);
return $hmac_key;
}