]>
Dogcows Code - chaz/p5-File-KDBX/blob - t/hmac-block.t
7 use TestCommon
qw(:no_warnings_test);
9 use File
::KDBX
::IO
::HmacBlock
;
10 use File
::KDBX
::Util
qw(can_fork);
14 my $KEY = "\x01" x
64;
17 my $expected_plaintext = 'Tiny food from Spain!';
19 pipe(my $read, my $write) or die "pipe failed: $!\n";
21 $write = File
::KDBX
::IO
::HmacBlock-
>new($write, block_size
=> 3, key
=> $KEY);
22 print $write $expected_plaintext;
23 close($write) or die "close failed: $!";
25 $read = File
::KDBX
::IO
::HmacBlock-
>new($read, key
=> $KEY);
26 my $plaintext = do { local $/; <$read> };
29 is $plaintext, $expected_plaintext, 'HMAC-block just a little bit';
31 is $File::KDBX
::IO
::HmacBlock
::ERROR
, undef, 'No error when successful';
35 skip
'fork required to test long data streams' if !can_fork
;
37 my $expected_plaintext = "\x64" x
(1024*1024*12 - 57);
39 local $SIG{CHLD
} = 'IGNORE';
40 pipe(my $read, my $write) or die "pipe failed: $!\n";
42 defined(my $pid = fork) or die "fork failed: $!\n";
44 $write = File
::KDBX
::IO
::HmacBlock-
>new($write, key
=> $KEY);
45 print $write $expected_plaintext;
46 close($write) or die "close failed: $!";
52 $read = File
::KDBX
::IO
::HmacBlock-
>new($read, key
=> $KEY);
53 my $plaintext = do { local $/; <$read> };
56 is $plaintext, $expected_plaintext, 'HMAC-block a lot';
59 subtest
'Error handling' => sub {
60 pipe(my $read, my $write) or die "pipe failed: $!\n";
62 $read = File
::KDBX
::IO
::HmacBlock-
>new($read, key
=> $KEY);
64 print $write 'blah blah blah';
65 close($write) or die "close failed: $!";
67 is $read->error, '', 'Read handle starts out fine';
68 my $data = do { local $/; <$read> };
69 is $read->error, 1, 'Read handle can enter an error state';
71 like
$File::KDBX
::IO
::HmacBlock
::ERROR
, qr/failed to read HMAC/i, 'Error object is available';
This page took 0.039081 seconds and 4 git commands to generate.