]>
Dogcows Code - chaz/p5-File-KDBX/blob - t/hmac-block.t
7 use TestCommon
qw(:no_warnings_test);
9 use File
::KDBX
::Util
qw(can_fork);
13 BEGIN { use_ok
'PerlIO::via::File::KDBX::HmacBlock' }
15 my $KEY = "\x01" x
64;
18 my $expected_plaintext = 'Tiny food from Spain!';
20 pipe(my $read, my $write) or die "pipe failed: $!\n";
22 PerlIO
::via
::File
::KDBX
::HmacBlock-
>push($write, block_size
=> 3, key
=> $KEY);
23 print $write $expected_plaintext;
24 binmode($write, ':pop'); # finish stream
25 close($write) or die "close failed: $!";
27 PerlIO
::via
::File
::KDBX
::HmacBlock-
>push($read, key
=> $KEY);
28 my $plaintext = do { local $/; <$read> };
31 is $plaintext, $expected_plaintext, 'HMAC-block just a little bit';
34 subtest
'Error handling' => sub {
35 pipe(my $read, my $write) or die "pipe failed: $!\n";
37 PerlIO
::via
::File
::KDBX
::HmacBlock-
>push($read, key
=> $KEY);
39 print $write 'blah blah blah';
40 close($write) or die "close failed: $!";
42 is $read->error, 0, 'Read handle starts out fine';
43 my $data = do { local $/; <$read> };
44 is $read->error, 1, 'Read handle can enter and error state';
46 like
$PerlIO::via
::File
::KDBX
::HmacBlock
::ERROR
, qr/failed to read HMAC/i,
47 'Error object is available';
51 skip
'Tests require fork' if !can_fork
;
53 my $expected_plaintext = "\x64" x
(1024*1024*12 - 57);
55 pipe(my $read, my $write) or die "pipe failed: $!\n";
57 defined(my $pid = fork) or die "fork failed: $!\n";
59 PerlIO
::via
::File
::KDBX
::HmacBlock-
>push($write, key
=> $KEY);
60 print $write $expected_plaintext;
61 binmode($write, ':pop'); # finish stream
62 close($write) or die "close failed: $!";
66 PerlIO
::via
::File
::KDBX
::HmacBlock-
>push($read, key
=> $KEY);
67 my $plaintext = do { local $/; <$read> };
70 is $plaintext, $expected_plaintext, 'HMAC-block a lot';
72 waitpid($pid, 0) or die "wait failed: $!\n";
This page took 0.047075 seconds and 4 git commands to generate.