mirror of
https://github.com/qpdf/qpdf.git
synced 2024-11-01 11:22:29 +00:00
1639d972ea
If QPDF_CRYPTO_PROVIDER is set, just run the tests for the given provider. This is to support cases of running the entire test suite for each provider. If QPDF_CRYPTO_PROVIDER is not set, run the tests that exercise the cyrpto provider for each available provider.
93 lines
2.9 KiB
Perl
93 lines
2.9 KiB
Perl
#!/usr/bin/env perl
|
|
require 5.008;
|
|
BEGIN { $^W = 1; }
|
|
use strict;
|
|
use File::stat;
|
|
|
|
chdir("aes") or die "chdir testdir failed: $!\n";
|
|
|
|
require TestDriver;
|
|
|
|
my $td = new TestDriver('AES');
|
|
|
|
my @providers = ();
|
|
if (exists $ENV{'QPDF_CRYPTO_PROVIDER'})
|
|
{
|
|
push(@providers, $ENV{'QPDF_CRYPTO_PROVIDER'});
|
|
}
|
|
else
|
|
{
|
|
open(Q, "qpdf --show-crypto|") or die;
|
|
while (<Q>)
|
|
{
|
|
s/\s+$//s;
|
|
push(@providers, $_);
|
|
}
|
|
close(Q);
|
|
}
|
|
foreach my $p (@providers)
|
|
{
|
|
$ENV{'QPDF_CRYPTO_PROVIDER'} = $p;
|
|
|
|
cleanup();
|
|
|
|
my $key = '000102030405060708090a0b0c0d0e0f';
|
|
$td->runtest("encrypt test vector ($p)",
|
|
{$td->COMMAND =>
|
|
"aes -cbc -encrypt $key test-vector.clear tmp1"},
|
|
{$td->STRING => "", $td->EXIT_STATUS => 0});
|
|
$td->runtest("check output",
|
|
{$td->FILE => "tmp1"},
|
|
{$td->FILE => "test-vector.cipher"});
|
|
$td->runtest("decrypt test vector ($p)",
|
|
{$td->COMMAND => "aes -cbc -decrypt $key tmp1 tmp2"},
|
|
{$td->STRING => "", $td->EXIT_STATUS => 0});
|
|
$td->runtest("check output",
|
|
{$td->FILE => "tmp2"},
|
|
{$td->FILE => "test-vector.clear"});
|
|
|
|
$key = '243f6a8885243f6a8885243f6a888524';
|
|
foreach my $d (['data1', 17072], ['data2', 16032])
|
|
{
|
|
my ($file, $size) = @$d;
|
|
$td->runtest("encrypt $file ($p)",
|
|
{$td->COMMAND => "aes +cbc -encrypt $key $file tmp1"},
|
|
{$td->STRING => "", $td->EXIT_STATUS => 0});
|
|
# sleep one second so random number will get a different seed
|
|
sleep(1);
|
|
$td->runtest("encrypt $file again ($p)",
|
|
{$td->COMMAND => "aes +cbc -encrypt $key $file tmp2"},
|
|
{$td->STRING => "", $td->EXIT_STATUS => 0});
|
|
foreach my $f (qw(tmp1 tmp2))
|
|
{
|
|
$td->runtest("check size",
|
|
{$td->STRING => sprintf("%d\n", stat($f)->size)},
|
|
{$td->STRING => "$size\n"});
|
|
}
|
|
$td->runtest("verify files are different",
|
|
{$td->COMMAND => "cmp tmp1 tmp2"},
|
|
{$td->REGEXP => '.*', $td->EXIT_STATUS => '!0'});
|
|
$td->runtest("decrypt $file ($p)",
|
|
{$td->COMMAND => "aes +cbc -decrypt $key tmp1 tmp3"},
|
|
{$td->STRING => "", $td->EXIT_STATUS => 0});
|
|
$td->runtest("decrypt $file again ($p)",
|
|
{$td->COMMAND => "aes +cbc -decrypt $key tmp2 tmp4"},
|
|
{$td->STRING => "", $td->EXIT_STATUS => 0});
|
|
$td->runtest("check output",
|
|
{$td->FILE => "tmp3"},
|
|
{$td->FILE => $file});
|
|
$td->runtest("check output",
|
|
{$td->FILE => "tmp4"},
|
|
{$td->FILE => $file});
|
|
}
|
|
|
|
cleanup();
|
|
}
|
|
|
|
$td->report(22 * scalar(@providers));
|
|
|
|
sub cleanup
|
|
{
|
|
system("rm -f tmp?");
|
|
}
|